Skip to content

Commit

Permalink
GitHub GraphQL: use variables
Browse files Browse the repository at this point in the history
Use variables rather than interpolating json data in GraphQL query.
Clean up some other bits of the github issue/pr code.
  • Loading branch information
haarg committed Oct 21, 2024
1 parent 6de1a23 commit d1cd682
Showing 1 changed file with 30 additions and 24 deletions.
54 changes: 30 additions & 24 deletions lib/MetaCPAN/Script/Tickets.pm
Original file line number Diff line number Diff line change
Expand Up @@ -126,57 +126,63 @@ RELEASE: while ( my $release = $scroll->next ) {
next unless $user;
log_debug {"Retrieving issues from $user/$repo"};

my $data = $self->github_graphql->query(
sprintf <<'END_QUERY', map $json->encode($_), $user, $repo );
query {
repository(owner: %s, name: %s) {
openIssues: issues(states: OPEN) {
totalCount
}
closedIssues: issues(states: CLOSED) {
totalCount
}
openPullRequests: pullRequests(states: OPEN) {
totalCount
}
closedPullRequests: pullRequests(states: [CLOSED, MERGED]) {
totalCount
}
my $dist_summary = $summary{ $release->{'distribution'} } ||= {};

my $vars = {
user => $user,
repo => $repo,
};
my $data = $self->github_graphql->query( <<'END_QUERY', $vars );
query($user:String!, $repo:String!) {
repository(owner: $user, name: $repo) {
openIssues: issues(states: OPEN) {
totalCount
}
closedIssues: issues(states: CLOSED) {
totalCount
}
openPullRequests: pullRequests(states: OPEN) {
totalCount
}
closedPullRequests: pullRequests(states: [CLOSED, MERGED]) {
totalCount
}
}
}
END_QUERY

if ( my $error = $data->{errors} ) {
for my $error (@$error) {
my $log_message
= "[$release->{distribution}] $error->{message}";
if ( $error->{type} eq 'NOT_FOUND' ) {
delete $summary{ $release->{'distribution'} }{'bugs'}
{'github'};
delete $dist_summary->{'bugs'}{'github'};
log_info {$log_message};
}
else {
log_error {$log_message};
}
}
if (@$error) {
next RELEASE;
}
}

my $repo_data = $data->{data}{repository};
my $open
= $data->{data}{repository}{openIssues}{totalCount}
+ $data->{data}{repository}{openPullRequests}{totalCount};
= $repo_data->{openIssues}{totalCount}
+ $repo_data->{openPullRequests}{totalCount};
my $closed
= $data->{data}{repository}{closedIssues}{totalCount}
+ $data->{data}{repository}{closedPullRequests}{totalCount};
= $repo_data->{closedIssues}{totalCount}
+ $repo_data->{closedPullRequests}{totalCount};

my $rec = {
$dist_summary->{'bugs'}{'github'} = {
active => $open,
open => $open,
closed => $closed,
source => $source,
};

$summary{ $release->{'distribution'} }{'bugs'}{'github'} = $rec;
}

log_info {"writing github data"};
Expand Down

0 comments on commit d1cd682

Please sign in to comment.