Skip to content

Commit f2796f5

Browse files
committed
Use head ref for url generation in offense formatter
1 parent f8279c1 commit f2796f5

File tree

4 files changed

+8
-7
lines changed

4 files changed

+8
-7
lines changed

lib/danger-packwerk/danger_package_todo_yml_changes.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def check(
4242
)
4343
offenses_formatter ||= Update::DefaultFormatter.new
4444
repo_link = github.pr_json[:base][:repo][:html_url]
45-
repo_url_builder = ->(constant_path) { "#{repo_link}/blob/main/#{constant_path}" }
45+
repo_url_builder = ->(constant_path) { "#{repo_link}/blob/#{github.pr_json[:head][:ref]}/#{constant_path}" }
4646
org_name = github.pr_json[:base][:repo][:owner][:login]
4747

4848
git_filesystem = Private::GitFilesystem.new(git: git, root: root_path || '')

lib/danger-packwerk/danger_packwerk.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ def check(
6464
)
6565
offenses_formatter ||= Check::DefaultFormatter.new
6666
repo_link = github.pr_json[:base][:repo][:html_url]
67-
repo_url_builder = ->(constant_path) { "#{repo_link}/blob/main/#{constant_path}" }
67+
repo_url_builder = ->(constant_path) { "#{repo_link}/blob/#{github.pr_json[:head][:ref]}/#{constant_path}" }
6868
org_name = github.pr_json[:base][:repo][:owner][:login]
6969

7070
# This is important because by default, Danger will leave a concantenated list of all its messages if it can't find a commentable place in the

spec/danger_packwerk/danger_packwerk_spec.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -859,7 +859,7 @@ def format_offenses(offenses, repo_link, org_name, repo_url_builder: nil)
859859
expected = <<~EXPECTED
860860
**Packwerk Violation**
861861
- Type: Privacy :lock:
862-
- Constant: [<ins>`PrivateConstant`</ins>](https://github.com/MyOrg/my_repo/blob/main/packs/gusto_slack/app/services/private_constant.rb)
862+
- Constant: [<ins>`PrivateConstant`</ins>](https://github.com/MyOrg/my_repo/blob/my_branch/packs/gusto_slack/app/services/private_constant.rb)
863863
- Owning pack: packs/gusto_slack
864864
- Owned by [<ins>@MyOrg/product-infrastructure</ins>](https://github.com/orgs/MyOrg/teams/product-infrastructure/members) (Slack: [<ins>#prod-infra</ins>](https://slack.com/app_redirect?channel=prod-infra))
865865
@@ -900,7 +900,7 @@ def format_offenses(offenses, repo_link, org_name, repo_url_builder: nil)
900900
expected = <<~EXPECTED
901901
**Packwerk Violation**
902902
- Type: Privacy :lock:
903-
- Constant: [<ins>`PrivateConstant`</ins>](https://github.com/MyOrg/my_repo/blob/main/packs/gusto_slack/app/services/private_constant.rb)
903+
- Constant: [<ins>`PrivateConstant`</ins>](https://github.com/MyOrg/my_repo/blob/my_branch/packs/gusto_slack/app/services/private_constant.rb)
904904
- Owning pack: packs/gusto_slack
905905
- This pack is unowned.
906906
@@ -943,7 +943,7 @@ def format_offenses(offenses, repo_link, org_name, repo_url_builder: nil)
943943
expected = <<~EXPECTED
944944
**Packwerk Violation**
945945
- Type: Dependency :knot:
946-
- Constant: [<ins>`PrivateConstant`</ins>](https://github.com/MyOrg/my_repo/blob/main/packs/gusto_slack/app/services/private_constant.rb)
946+
- Constant: [<ins>`PrivateConstant`</ins>](https://github.com/MyOrg/my_repo/blob/my_branch/packs/gusto_slack/app/services/private_constant.rb)
947947
- Owning pack: packs/gusto_slack
948948
- Owned by [<ins>@MyOrg/product-infrastructure</ins>](https://github.com/orgs/MyOrg/teams/product-infrastructure/members) (Slack: [<ins>#prod-infra</ins>](https://slack.com/app_redirect?channel=prod-infra))
949949
@@ -984,7 +984,7 @@ def format_offenses(offenses, repo_link, org_name, repo_url_builder: nil)
984984
expected = <<~EXPECTED
985985
**Packwerk Violation**
986986
- Type: Privacy :lock: + Dependency :knot:
987-
- Constant: [<ins>`PrivateConstant`</ins>](https://github.com/MyOrg/my_repo/blob/main/packs/gusto_slack/app/services/private_constant.rb)
987+
- Constant: [<ins>`PrivateConstant`</ins>](https://github.com/MyOrg/my_repo/blob/my_branch/packs/gusto_slack/app/services/private_constant.rb)
988988
- Owning pack: packs/gusto_slack
989989
- Owned by [<ins>@MyOrg/product-infrastructure</ins>](https://github.com/orgs/MyOrg/teams/product-infrastructure/members) (Slack: [<ins>#prod-infra</ins>](https://slack.com/app_redirect?channel=prod-infra))
990990
@@ -1057,7 +1057,7 @@ def format_offenses(offenses, repo_link, org_name, repo_url_builder: nil)
10571057
expected = <<~EXPECTED
10581058
**Packwerk Violation**
10591059
- Type: Privacy :lock:
1060-
- Constant: [<ins>`PrivateConstant`</ins>](https://github.com/MyOrg/my_repo/blob/main/packs/gusto_slack/app/services/private_constant.rb)
1060+
- Constant: [<ins>`PrivateConstant`</ins>](https://github.com/MyOrg/my_repo/blob/my_branch/packs/gusto_slack/app/services/private_constant.rb)
10611061
- Owning pack: packs/gusto_slack
10621062
- Owned by [<ins>@MyOrg/product-infrastructure</ins>](https://github.com/orgs/MyOrg/teams/product-infrastructure/members) (Slack: [<ins>#prod-infra</ins>](https://slack.com/app_redirect?channel=prod-infra))
10631063

spec/support/danger_plugin.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
let(:renamed_files) { [] }
77
let(:pr_json) do
88
{
9+
head: { ref: 'my_branch' },
910
base: {
1011
repo: {
1112
html_url: 'https://github.com/MyOrg/my_repo',

0 commit comments

Comments
 (0)