@@ -6,28 +6,42 @@ const prBody = process.argv[3];
6
6
const screenshotUrl = `https://raw.githubusercontent.com/nishant0708/awesome-github-profiles/main/screenshots/${ username } .png` ;
7
7
8
8
// Extract selected categories from the PR body
9
- const categories = ( prBody . match ( / \[ ( x | ) \] ( .+ ) / g) || [ ] ) . map ( line => line . replace ( / ^ \[ ( x | ) \] / , '' ) ) ;
9
+ const categories = ( prBody . match ( / \[ x \] < s p a n c l a s s = " t a g " > ( .+ ? ) < \/ s p a n > / g) || [ ] ) . map ( tag => tag . replace ( / \[ x \] < s p a n c l a s s = " t a g " > ( . + ? ) < \/ s p a n > / , '$1 ' ) ) ;
10
10
11
+ // Path to .all-contributorsrc file
11
12
const contributorsFilePath = path . join ( process . cwd ( ) , '.all-contributorsrc' ) ;
12
- const contributorsData = JSON . parse ( fs . readFileSync ( contributorsFilePath , 'utf8' ) ) ;
13
13
14
- // Check if the user already exists in the contributors data
15
- const existingContributor = contributorsData . contributors . find ( contributor => contributor . login === username ) ;
14
+ // Read the existing contributors file
15
+ let contributorsData ;
16
+ try {
17
+ contributorsData = JSON . parse ( fs . readFileSync ( contributorsFilePath , 'utf8' ) ) ;
18
+ } catch ( error ) {
19
+ console . error ( `Failed to read .all-contributorsrc: ${ error . message } ` ) ;
20
+ process . exit ( 1 ) ;
21
+ }
22
+
23
+ // Find existing contributor or create a new one
24
+ let contributor = contributorsData . contributors . find ( contributor => contributor . login === username ) ;
16
25
17
- if ( existingContributor ) {
18
- // Update existing contributor's categories
19
- existingContributor . contributions = categories ;
26
+ if ( contributor ) {
27
+ contributor . contributions = categories ;
20
28
} else {
21
- // Add a new contributor
22
- contributorsData . contributors . push ( {
29
+ contributor = {
23
30
login : username ,
24
31
name : username , // Customize as needed
25
32
avatar_url : `https://avatars.githubusercontent.com/${ username } ` ,
26
33
ScreenShot : screenshotUrl ,
27
34
profile : `https://github.com/${ username } ` ,
28
35
contributions : categories
29
- } ) ;
36
+ } ;
37
+ contributorsData . contributors . push ( contributor ) ;
30
38
}
31
39
32
- fs . writeFileSync ( contributorsFilePath , JSON . stringify ( contributorsData , null , 2 ) ) ;
33
- console . log ( 'Contributors file updated successfully!' ) ;
40
+ // Write the updated data back to the file
41
+ try {
42
+ fs . writeFileSync ( contributorsFilePath , JSON . stringify ( contributorsData , null , 2 ) ) ;
43
+ console . log ( 'Contributors file updated successfully!' ) ;
44
+ } catch ( error ) {
45
+ console . error ( `Failed to write to .all-contributorsrc: ${ error . message } ` ) ;
46
+ process . exit ( 1 ) ;
47
+ }
0 commit comments