-
-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reposts PRs if they still haven't been reviewed in over 30 minutes
But we only repost if it hasn't been reposted already.
- Loading branch information
Showing
11 changed files
with
116 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
class PullRequestReposter | ||
def initialize(pull_requests) | ||
@pull_requests = pull_requests | ||
end | ||
|
||
def self.run(pull_requests) | ||
self.new(pull_requests).run | ||
end | ||
|
||
def run | ||
pull_requests.each do |pull_request| | ||
post_to_slack(pull_request) | ||
mark_as_reposted(pull_request) | ||
end | ||
end | ||
|
||
private | ||
|
||
attr_reader :pull_requests | ||
|
||
def post_to_slack(pull_request) | ||
WebhookNotifier.new(pull_request).send_notification | ||
end | ||
|
||
def mark_as_reposted(pull_request) | ||
pull_request.update(reposted: true) | ||
end | ||
end |
5 changes: 5 additions & 0 deletions
5
db/migrate/20150108191114_add_reposted_at_to_pull_requests.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
class AddRepostedAtToPullRequests < ActiveRecord::Migration | ||
def change | ||
add_column :pull_requests, :reposted_at, :timestamp | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
desc "Reposts PRs that have not been reviewed for over 30 min. nor reposted" | ||
task repost_prs: :environment do | ||
PullRequestReposter.run(PullRequest.needs_reposting) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
require "rails_helper" | ||
|
||
describe PullRequestReposter do | ||
describe ".run" do | ||
it "reposts the given PRs to Slack" do | ||
prs_to_review = build_pair(:pull_request) | ||
notifier = double(:webhook_notifier) | ||
allow(WebhookNotifier).to receive(:new).and_return(notifier) | ||
allow(notifier).to receive(:send_notification) | ||
|
||
PullRequestReposter.run(prs_to_review) | ||
|
||
expect(notifier).to have_received(:send_notification).twice | ||
end | ||
|
||
it "sets the timestamp for when the review was reposted" do | ||
pr_to_review = create(:pull_request, reposted_at: nil) | ||
|
||
PullRequestReposter.run([pr_to_review]) | ||
|
||
expect(pr_to_review.reload).to be_reposted | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters