From a1c6ac41d0b77b9a8e268671d966f497793cbe4d Mon Sep 17 00:00:00 2001 From: "Michael G. Noll" Date: Tue, 6 May 2025 09:16:41 +0200 Subject: [PATCH] Fix: correctly parse git remote origin urls for calling Octokit --- .../cli/templates/sample_hooks/pre-deploy.sample | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/kamal/cli/templates/sample_hooks/pre-deploy.sample b/lib/kamal/cli/templates/sample_hooks/pre-deploy.sample index 665197f1..05b3055b 100755 --- a/lib/kamal/cli/templates/sample_hooks/pre-deploy.sample +++ b/lib/kamal/cli/templates/sample_hooks/pre-deploy.sample @@ -43,7 +43,7 @@ class GithubStatusChecks attr_reader :remote_url, :git_sha, :github_client, :combined_status def initialize - @remote_url = `git config --get remote.origin.url`.strip.delete_prefix("https://github.com/") + @remote_url = github_repo_from_remote_url @git_sha = `git rev-parse HEAD`.strip @github_client = Octokit::Client.new(access_token: ENV["GITHUB_TOKEN"]) refresh! @@ -77,6 +77,18 @@ class GithubStatusChecks "Build not started..." end end + + private + def github_repo_from_remote_url + url = `git config --get remote.origin.url`.strip.delete_suffix(".git") + if url.start_with?("https://github.com/") + url.delete_prefix("https://github.com/") + elsif url.start_with?("git@github.com:") + url.delete_prefix("git@github.com:") + else + url + end + end end