Skip to content

Commit 53b0d84

Browse files
committed
Fixed docs and added an email mode
1 parent 5e6f2b4 commit 53b0d84

1 file changed

Lines changed: 35 additions & 11 deletions

File tree

advanced_bin/github-pullrequestcheck

Lines changed: 35 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ sub run {
4242

4343
my $duration_format = DateTime::Format::Duration->new(pattern => '%Y years, %m months, %e days');
4444

45+
my $msg = q{};
46+
4547
foreach my $repo (@{$repos}) {
4648
my $pulls = get_pull_requests($opts, $repo);
4749
my @old_pulls =
@@ -50,7 +52,7 @@ sub run {
5052
@{$pulls};
5153

5254
next unless @old_pulls;
53-
print "* ${repo}: old pull requests found\n\n";
55+
$msg .= "* ${repo}: old pull requests found\n\n";
5456
foreach my $pull (@old_pulls) {
5557
my $url = $pull->{html_url};
5658
my $title = $pull->{title};
@@ -59,17 +61,33 @@ sub run {
5961
my $age_of_pull = $duration_format->format_duration($now->subtract_datetime($recent_date));
6062
my $base = $pull->{base}->{label};
6163

62-
print "\t* USER : ${user}\n";
63-
print "\t* TITLE: ${title}\n";
64-
print "\t* AGE : ${age_of_pull}\n";
65-
print "\t* DATE : ${recent_date}\n";
66-
print "\t* BASE : ${base}\n";
67-
print "\t* URL : ${url}\n";
64+
$msg .= "\t* USER : ${user}\n";
65+
$msg .= "\t* TITLE: ${title}\n";
66+
$msg .= "\t* AGE : ${age_of_pull}\n";
67+
$msg .= "\t* DATE : ${recent_date}\n";
68+
$msg .= "\t* BASE : ${base}\n";
69+
$msg .= "\t* URL : ${url}\n";
6870

69-
print "\n";
71+
$msg .= "\n";
72+
}
73+
$msg .= "\n----------------------------\n";
74+
}
75+
76+
if($msg) {
77+
my $email = $opts->{email};
78+
if($email) {
79+
open my $sendmail, '|sendmail -t' or die "Cannot open sendmaill: $!";
80+
print $sendmail "To: $email\n";
81+
print $sendmail "Subject: Old Pull Requests Detected\n";
82+
print $sendmail "Content-type: text/plain\n\n";
83+
print $sendmail $msg;
84+
close $sendmail;
85+
}
86+
else {
87+
print $msg;
7088
}
71-
print "\n----------------------------\n";
7289
}
90+
7391
return;
7492
}
7593

@@ -119,6 +137,7 @@ sub parse_command_line {
119137
oauth=s
120138
oauth_file=s
121139
organisation|organization=s
140+
email=s
122141
help|?
123142
man
124143
/) or pod2usage(2);
@@ -143,7 +162,7 @@ github-pullrequestcheck - Check for old pull requests
143162
144163
=head1 SYNOPSIS
145164
146-
github-pullrequestcheck [--oauth OAUTH] [--oauth_file FILE] [--organisation ORG] [--repository REPO] [-h] [-m]
165+
github-pullrequestcheck [--oauth OAUTH] [--oauth_file FILE] [--organisation ORG] [--repository REPO] [--email usr@example.com] [-h] [-m]
147166
148167
# Search for all open old pull requests with no oauth authentication
149168
@@ -163,10 +182,11 @@ github-pullrequestcheck --oauth_file ~/.private/github-oauth
163182
164183
# Using a different organisation
165184
166-
github-switchbranch --organisation EnsemblGenomes
185+
github-pullrequestcheck --organisation EnsemblGenomes
167186
168187
=head1 DESCRIPTION
169188
189+
Performs a scan of the given organisation listing stale/old pull requests.
170190
171191
All of this is done via GitHub's REST API and requires the generation of an oauth token for authentication purposes. You can do this via your account's setting page under Applications and generate a B<Personal Access Token>.
172192
@@ -192,6 +212,10 @@ The GitHub organisation to list repositories for. Defaults to Ensembl
192212
193213
The repository to use. If not specified we use all public repositories
194214
215+
=item B<--email>
216+
217+
If specified we will send all output to an email address rather than to stdout. Requires a configured sendmail binary on your machine
218+
195219
=item B<--help>
196220
197221
Print the help information

0 commit comments

Comments
 (0)