Skip to content

Commit

Permalink
Merge pull request #48 from bastelfreak/comment
Browse files Browse the repository at this point in the history
only comment to a PR when allowed to
  • Loading branch information
bastelfreak authored Aug 1, 2019
2 parents f783ec4 + f876660 commit a600290
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 9 deletions.
12 changes: 6 additions & 6 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,12 @@ GEM
concurrent-ruby (1.1.5)
connection_pool (2.2.2)
crass (1.0.4)
elasticsearch (7.2.1)
elasticsearch-api (= 7.2.1)
elasticsearch-transport (= 7.2.1)
elasticsearch-api (7.2.1)
elasticsearch (7.3.0)
elasticsearch-api (= 7.3.0)
elasticsearch-transport (= 7.3.0)
elasticsearch-api (7.3.0)
multi_json
elasticsearch-transport (7.2.1)
elasticsearch-transport (7.3.0)
faraday
multi_json
erubi (1.8.0)
Expand Down Expand Up @@ -287,7 +287,7 @@ GEM
redcarpet (3.5.0)
redis (4.1.2)
regexp_parser (1.6.0)
rubocop (0.73.0)
rubocop (0.74.0)
jaro_winkler (~> 1.5.1)
parallel (~> 1.10)
parser (>= 2.6)
Expand Down
9 changes: 7 additions & 2 deletions app/models/pull_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ def ensure_label_is_detached(label)
# Add a comment with the given text
def add_comment(text)
Github.client.add_comment(gh_repository_id, number, text)
update(eligible_for_comment: false)
end

##
Expand All @@ -77,14 +78,18 @@ def add_comment(text)
# The saved_changes variable includes all the stuff that has changed.
# We currently don't care about them

def validate(_saved_changes)
def validate(saved_changes)
# Don't run through the validaten, if only the eligable_for_comment attribute got updated
return if saved_changes.keys.sort == %w[updated_at eligable_for_comment].sort

label = Label.needs_rebase
if mergeable == true
ensure_label_is_detached(label)
update(eligible_for_comment: true)
elsif mergeable == false
repository.ensure_label_exists(label)
ensure_label_is_attached(label)
add_comment(I18n.t('comment.needs_rebase', author: author))
add_comment(I18n.t('comment.needs_rebase', author: author)) if eligible_for_comment
end
end

Expand Down
5 changes: 5 additions & 0 deletions db/migrate/20190731222648_add_author_to_pull_requests.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddEligibleForCommentToPullRequests < ActiveRecord::Migration[5.2]
def change
add_column :pull_requests, :eligible_for_comment, :boolean
end
end
3 changes: 2 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 2019_07_30_215048) do
ActiveRecord::Schema.define(version: 2019_07_31_223410) do

create_table "labels", force: :cascade do |t|
t.string "name"
Expand Down Expand Up @@ -41,6 +41,7 @@
t.boolean "mergeable"
t.integer "gh_repository_id"
t.integer "github_id"
t.boolean "eligible_for_comment"
t.string "author"
t.index ["repository_id"], name: "index_pull_requests_on_repository_id"
end
Expand Down

0 comments on commit a600290

Please sign in to comment.