Skip to content

Commit 2edc439

Browse files
authored
feat(github_hooks): emit PullRequestUnmergeable event (#390)
When a pull request branch becomes unmergeable, we should emit an event, so the UI can invalidate that branch page cache for that branch. ### Other changes The gRPC library was updated to 1.62 because it's not possible to generate the proto files on MacOS ARM on the version we were using.
1 parent 8669daa commit 2edc439

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+198
-1034
lines changed

github_hooks/Gemfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ gem "faraday", "~> 1.3.0"
1414
gem "faraday_middleware" # used for json
1515
gem "net-http" # https://github.com/ruby/net-imap/issues/16#issuecomment-803086765
1616
gem 'net-imap', '~> 0.5.7'
17-
gem "grpc", "~> 1.57.0"
17+
gem "grpc", "~> 1.62.1"
18+
gem "googleapis-common-protos-types", "~> 1.18.0"
1819
gem "httparty", "~> 0.21.0"
1920
gem "httpclient"
2021
gem "json"

github_hooks/Gemfile.lock

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -153,11 +153,11 @@ GEM
153153
raabro (~> 1.4)
154154
globalid (1.2.1)
155155
activesupport (>= 6.1)
156-
google-protobuf (3.25.5)
157-
googleapis-common-protos-types (1.8.0)
158-
google-protobuf (~> 3.18)
159-
grpc (1.57.0)
160-
google-protobuf (~> 3.23)
156+
google-protobuf (3.25.8)
157+
googleapis-common-protos-types (1.18.0)
158+
google-protobuf (>= 3.18, < 5.a)
159+
grpc (1.62.3)
160+
google-protobuf (~> 3.25)
161161
googleapis-common-protos-types (~> 1.0)
162162
grpc-tools (1.68.1)
163163
hashdiff (1.1.2)
@@ -457,7 +457,8 @@ DEPENDENCIES
457457
factory_bot_rails (< 5)
458458
faraday (~> 1.3.0)
459459
faraday_middleware
460-
grpc (~> 1.57.0)
460+
googleapis-common-protos-types (~> 1.18.0)
461+
grpc (~> 1.62.1)
461462
grpc-tools
462463
httparty (~> 0.21.0)
463464
httpclient
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
module Semaphore::Events
2+
class PullRequestUnmergeable
3+
4+
def self.emit(workflow, branch)
5+
event = InternalApi::RepoProxy::PullRequestUnmergeable.new(
6+
:project_id => workflow.project_id,
7+
:branch_name => branch.name,
8+
:timestamp => ::Google::Protobuf::Timestamp.new(:seconds => Time.now.to_i)
9+
)
10+
11+
message = InternalApi::RepoProxy::PullRequestUnmergeable.encode(event)
12+
13+
options = {
14+
:exchange => "hook_exchange",
15+
:routing_key => "pr_unmergeable",
16+
:url => App.amqp_url
17+
}
18+
19+
Logman.info "Publishing pr_unmergeable event for project #{workflow.project_id}, branch #{branch.name}"
20+
21+
Tackle.publish(message, options)
22+
end
23+
end
24+
end

github_hooks/lib/semaphore/repo_host/hooks/handler.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,11 @@ def self.project_member?(project, github_username)
312312

313313
def self.update_pull_request_mergeable(workflow, mergeable)
314314
if (branch = find_branch(workflow))
315+
mergeable_before = branch.pull_request_mergeable
315316
branch.update(:pull_request_mergeable => mergeable)
317+
if !mergeable && mergeable_before
318+
Semaphore::Events::PullRequestUnmergeable.emit(workflow, branch)
319+
end
316320
end
317321
end
318322

github_hooks/protobuffer/generated/auth_pb.rb

Lines changed: 0 additions & 41 deletions
This file was deleted.

github_hooks/protobuffer/generated/auth_services_pb.rb

Lines changed: 0 additions & 36 deletions
This file was deleted.

github_hooks/protobuffer/generated/branch_pb.rb

Lines changed: 0 additions & 54 deletions
This file was deleted.

github_hooks/protobuffer/generated/branch_services_pb.rb

Lines changed: 0 additions & 45 deletions
This file was deleted.

github_hooks/protobuffer/generated/cache_pb.rb

Lines changed: 1 addition & 23 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

github_hooks/protobuffer/generated/encryptor_pb.rb

Lines changed: 1 addition & 22 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)