Skip to content

Commit

Permalink
Merge pull request #1294 from metacpan/haarg/watchstar
Browse files Browse the repository at this point in the history
fetch stars and watchers from github
  • Loading branch information
haarg authored Oct 22, 2024
2 parents 6de1a23 + 7f3023f commit d924853
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 24 deletions.
16 changes: 16 additions & 0 deletions lib/MetaCPAN/Script/Mapping/CPAN/Distribution.pm
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,22 @@ sub mapping {
}
}
},
"repo" : {
"dynamic" : true,
"properties" : {
"github" : {
"dynamic" : true,
"properties" : {
"stars" : {
"type" : "integer"
},
"watchers" : {
"type" : "integer"
}
}
}
}
},
"name" : {
"ignore_above" : 2048,
"index" : "not_analyzed",
Expand Down
63 changes: 39 additions & 24 deletions lib/MetaCPAN/Script/Tickets.pm
Original file line number Diff line number Diff line change
Expand Up @@ -126,57 +126,72 @@ 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
}
watchers: watchers {
totalCount
}
stargazerCount: stargazerCount
}
}
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'};
delete $dist_summary->{'repo'}{'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;
$dist_summary->{'repo'}{'github'} = {
stars => $repo_data->{stargazerCount},
watchers => $repo_data->{watchers}{totalCount},
};
}

log_info {"writing github data"};
Expand Down

0 comments on commit d924853

Please sign in to comment.