@@ -18,55 +18,10 @@ const fs = require("fs");
18
18
// Data
19
19
//-----------------------------------------------------------------------------
20
20
21
- const { GITHUB_TOKEN , OPENAI_API_KEY } = process . env ;
21
+ const { GITHUB_TOKEN } = process . env ;
22
22
const now = moment ( ) ;
23
23
const firstDayOfPreviousMonth = now . clone ( ) . subtract ( 1 , "month" ) . startOf ( "month" ) ;
24
24
const lastDayOfPreviousMonth = firstDayOfPreviousMonth . clone ( ) . endOf ( "month" ) ;
25
-
26
- const AI_URL = "https://api.openai.com/v1/chat/completions" ;
27
- const AI_MODEL = "gpt-4o-mini" ;
28
-
29
- const PROMPT = `You will be given a JSON object where the keys are GitHub
30
- usernames and the values are arrays of pull request objects that were
31
- written by the user. Your task is to create a Markdown report of this
32
- activity.
33
-
34
- For each user, create a heading like this:
35
-
36
- <example>
37
- ## GitHub username (pull request count)
38
- </example>
39
-
40
- Under each heading, list each pull request in the following format:
41
-
42
- <example>
43
- 1. Pull request title linked to the PR URL
44
- A three-sentence summary of the pull request description ('body' field in the PR object).
45
- * **Time to merge:** X days, Y hours
46
- * **Effort Estimate:** X
47
- </example>
48
-
49
- The effort estimate is the amount of effort it took for the author to complete the PR
50
- on a scale of 1 (not much work, very easy) to 5 (a lot of work). This should be
51
- based on the complexity of the changes, the amount of review comments, the overall
52
- size of the PR, the number of reactions, and the time taken to complete it.
53
-
54
- The format of the JSON pull request object is as follows:
55
-
56
- - user: The GitHub username of the pull request author
57
- - title: The pull request title
58
- - body: The pull request description in Markdown
59
- - html_url: The URL of the pull request
60
- - created_at: The date the pull request was created
61
- - closed_at: The date the pull request was merged
62
- - reactions: The total number of reactions on the pull request
63
- - comments: The total number of comments on the pull request
64
-
65
- The title of the report should be "Contributor Pool Report for [Month] [Year]".
66
-
67
- IMPORTANT: Every pull request in the JSON array must be included in the report.
68
- ` ;
69
-
70
25
const prKeys = new Set ( [
71
26
"html_url" ,
72
27
"title" ,
@@ -130,7 +85,6 @@ async function fetchGitHubSearchResults() {
130
85
console . log ( `Fetched ${ allItems . length } PRs total\n` ) ;
131
86
132
87
return allItems
133
- . filter ( pr => pr . author_association !== "MEMBER" )
134
88
. map ( pr => {
135
89
const smallPr = { } ;
136
90
@@ -149,42 +103,34 @@ async function fetchGitHubSearchResults() {
149
103
}
150
104
151
105
/**
152
- * Fetches the AI model response based on the provided results .
153
- * @param {Object } grouped The array of PRs to be processed by the AI model .
154
- * @returns {Promise< string> } A promise that resolves to the AI-generated report.
106
+ * Generates a report based on the grouped PRs .
107
+ * @param {Object } grouped The grouped PRs by user .
108
+ * @returns {string } The formatted report.
155
109
*/
156
- async function fetchModelResponse ( grouped ) {
157
-
158
- const response = await fetch ( AI_URL , {
159
- method : "POST" ,
160
- headers : {
161
- "Content-Type" : "application/json" ,
162
- Authorization : `Bearer ${ OPENAI_API_KEY } `
163
- } ,
164
- body : JSON . stringify ( {
165
- model : AI_MODEL ,
166
- messages : [
167
- { role : "system" , content : PROMPT } ,
168
- { role : "user" , content : JSON . stringify ( grouped ) }
169
- ] ,
170
- temperature : 0.7
171
- } )
172
- } ) ;
173
-
174
- if ( ! response . ok ) {
175
- console . log ( await response . text ( ) ) ;
176
- throw new Error ( `AI model request failed with status ${ response . status } ` ) ;
177
- }
110
+ function generateReport ( grouped ) {
178
111
179
- const data = await response . json ( ) ;
112
+ return `
113
+ # Contributor Pool Report (${ firstDayOfPreviousMonth . format ( "MM/DD/YYYY" ) } - ${ lastDayOfPreviousMonth . format ( "MM/DD/YYYY" ) } )
180
114
181
- if ( ! data . choices || data . choices . length === 0 ) {
182
- throw new Error ( "No response from AI model" ) ;
183
- }
115
+ ${
116
+ Object . entries ( grouped ) . sort ( ( a , b ) => b [ 1 ] . length - a [ 1 ] . length ) . map ( ( [ user , prs ] ) => {
117
+
118
+ const prList = prs . map ( pr => {
119
+ const createdAt = moment ( pr . created_at ) ;
120
+ const closedAt = moment ( pr . closed_at ) ;
121
+ const duration = moment . duration ( closedAt . diff ( createdAt ) ) ;
122
+ const days = Math . floor ( duration . asDays ( ) ) ;
123
+ const hours = duration . hours ( ) ;
184
124
185
- return data . choices [ 0 ] . message . content ;
125
+ return `1. [${ pr . title } ](${ pr . html_url } ) (💬 ${ pr . comments } 😐 ${ pr . reactions } ) \n Time to merge: ${ days } days, ${ hours } hours` ;
126
+ } ) . join ( "\n\n" ) ;
127
+
128
+ return `## ${ user } (${ prs . length } )\n\n${ prList } ` ;
129
+ } ) . join ( "\n\n" )
186
130
}
131
+ ` . trimStart ( ) ;
187
132
133
+ }
188
134
189
135
/**
190
136
* Generates the transcript file output path.
@@ -208,7 +154,7 @@ function generateOutputPath(dateString) {
208
154
209
155
console . log ( `Found ${ results . length } contributor PRs merged.` ) ;
210
156
211
- const report = `${ await fetchModelResponse ( grouped ) } \n\n---\n\nGitHub search URL: https://github.com/issues?q=${ encodeURIComponent ( query ) } \n\nTotal PRs: ${ results . length } \n\nDate of report generation: ${ now . format ( "MM/DD/YYYY" ) } ` ;
157
+ const report = `${ generateReport ( grouped ) } \n\n---\n\nGitHub search URL: https://github.com/issues?q=${ encodeURIComponent ( query ) } \n\nTotal PRs: ${ results . length } \n\nDate of report generation: ${ now . format ( "MM/DD/YYYY" ) } ` ;
212
158
const dateString = now . clone ( ) . startOf ( "month" ) . format ( "MM/DD/YYYY" ) ;
213
159
const outputPath = generateOutputPath ( dateString ) ;
214
160
0 commit comments