1919
2020# setup
2121my $rt_summary_url //= ' https://rt.cpan.org/Public/bugs-per-dist.tsv' ;
22- my $gh_issues_url
23- / /= 'https://api.github.com/repos/%s /%s /issues?per_page=100';
2422
2523$ENV {PERL_LWP_SSL_VERIFY_HOSTNAME } = 0;
2624
162160
163161 log_debug {" Retrieving issues from $user /$repo " };
164162
165- my $data
166- = $gh_graphql -> query( _gh_graphql_query( $json , $user , $repo ) );
163+ my $dist_summary = $summary { $r -> {' distribution' } } ||= {};
164+
165+ my $vars = {
166+ user => $user ,
167+ repo => $repo ,
168+ };
169+ my $gh_query = _gh_graphql_query( $user , $repo );
170+ my $data = $gh_graphql -> query( $gh_query , $vars );
167171
168172 if ( my $error = $data -> {errors } ) {
169173 for my $error (@$error ) {
170174 my $log_message = sprintf " [%s ] %s " , $r -> {distribution },
171175 $error -> {message };
172176 if ( $error -> {type } eq ' NOT_FOUND' ) {
173- delete $summary { $r -> {distribution } }{bugs }{github };
177+ delete $dist_summary -> {' bugs' }{' github' };
178+ delete $dist_summary -> {' repo' }{' github' };
174179 log_info {$log_message };
175180 }
176181 else {
177182 log_error {$log_message };
178183 }
179- next RELEASE;
184+ next RELEASE if @$error ;
180185 }
181186 }
182187
183- my $open = $data -> {data }{repository }{openIssues }{totalCount }
184- + $data -> {data }{repository }{openPullRequests }{totalCount };
188+ my $repo_data = $data -> {data }{repository };
189+ my $open = $repo_data -> {openIssues }{totalCount }
190+ + $repo_data -> {openPullRequests }{totalCount };
191+ my $closed = $repo_data -> {closedIssues }{totalCount }
192+ + $repo_data -> {closedPullRequests }{totalCount };
185193
186- my $closed = $data -> {data }{repository }{closedIssues }{totalCount }
187- + $data -> {data }{repository }{closedPullRequests }{totalCount };
188-
189- my $rec = {
194+ $dist_summary -> {' bugs' }{' github' } = {
190195 active => $open ,
191196 open => $open ,
192197 closed => $closed ,
193198 source => $source ,
194199
195200 };
196201
197- $summary { $r -> {distribution } }{bugs }{github } = $rec ;
202+ $dist_summary -> {' repo' }{' github' } = {
203+ stars => $repo_data -> {stargazerCount },
204+ watchers => $repo_data -> {watchers }{totalCount },
205+ };
198206 }
199207
200208 log_info {" writing github data" };
201-
202209 _bulk_update( \%summary );
203210}
204211
@@ -227,10 +234,10 @@ ($resources)
227234 return ();
228235}
229236
230- sub _gh_graphql_query ( $json , $ user , $repo ) {
231- sprintf <<END_QUERY , map $json -> encode( $_ ), $user , $repo ;
232- query {
233- repository(owner: %s , name: %s ) {
237+ sub _gh_graphql_query ( $user , $repo ) {
238+ sprintf <<END_QUERY ;
239+ query( $user :String!, $repo :String!) {
240+ repository(owner: $user , name: $repo ) {
234241 openIssues: issues(states: OPEN) {
235242 totalCount
236243 }
@@ -243,6 +250,10 @@ ( $json, $user, $repo )
243250 closedPullRequests: pullRequests(states: [CLOSED, MERGED]) {
244251 totalCount
245252 }
253+ watchers: watchers {
254+ totalCount
255+ }
256+ stargazerCount: stargazerCount
246257 }
247258}
248259END_QUERY
0 commit comments