Skip to content

pre-deploy hook: sample file fails to work because it parses git remotes incorrectly #1538

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
miguno opened this issue May 6, 2025 · 0 comments · May be fixed by #1539
Open

pre-deploy hook: sample file fails to work because it parses git remotes incorrectly #1538

miguno opened this issue May 6, 2025 · 0 comments · May be fixed by #1539

Comments

@miguno
Copy link

miguno commented May 6, 2025

TL;DR: The sample file for the pre-deploy hook (https://github.com/basecamp/kamal/blob/main/lib/kamal/cli/templates/sample_hooks/pre-deploy.sample) passes the wrong GitHub repo string to Octokit.

Expected behavior

When I test-drive the pre-deploy hook in a local checkout of a public GitHub repository, then it should correctly check the build status.

$ git config --get remote.origin.url
https://github.com/basecamp/kamal.git

$ KAMAL_DESTINATION=production ruby pre-deploy.sample
Checking build status...
Build not started...
Build not started...
Build not started...
[...snip...]

Actual behavior

$ git config --get remote.origin.url
https://github.com/basecamp/kamal.git

$ KAMAL_DESTINATION=production ruby pre-deploy.sample
Checking build status...
Build status could not be found
$
# exit code is 1

The problem is that Octokit requires a different format for the GH repo in this call:

  def refresh!
    @combined_status = github_client.combined_status(remote_url, git_sha)
  end

The current pre-deploy hook incorrectly passes basecamp/kamal.git instead of basecamp/kamal (no .git suffix).

A related problem is that the current pre-deploy hook only understands https://github.com/... remotes, but not [email protected]: remotes:

$ git config --get remote.origin.url
[email protected]:basecamp/kamal.git # <== see here

$ KAMAL_DESTINATION=production ruby pre-deploy.sample
Checking build status...
/Users/miguno/.local/share/mise/installs/ruby/3.4.3/lib/ruby/gems/3.4.0/gems/octokit-10.0.0/lib/octokit/repository.rb:99:in 'Octokit::Repository#raise_invalid_repository!': "[email protected]:miguno/sauber.git" is invalid as a repository identifier. Use the user/repo (String) format, or the repository ID (Integer), or a hash containing :repo and :user keys. (Octokit::InvalidRepository)

      raise Octokit::InvalidRepository, msg
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        from /Users/miguno/.local/share/mise/installs/ruby/3.4.3/lib/ruby/gems/3.4.0/gems/octokit-10.0.0/lib/octokit/repository.rb:36:in 'Octokit::Repository#initialize'
        from /Users/miguno/.local/share/mise/installs/ruby/3.4.3/lib/ruby/gems/3.4.0/gems/octokit-10.0.0/lib/octokit/repository.rb:59:in 'Class#new'
        from /Users/miguno/.local/share/mise/installs/ruby/3.4.3/lib/ruby/gems/3.4.0/gems/octokit-10.0.0/lib/octokit/repository.rb:59:in 'Octokit::Repository.path'
        from /Users/miguno/.local/share/mise/installs/ruby/3.4.3/lib/ruby/gems/3.4.0/gems/octokit-10.0.0/lib/octokit/client/statuses.rb:27:in 'Octokit::Client::Statuses#combined_status'
        from pre-deploy:53:in 'GithubStatusChecks#refresh!'
        from pre-deploy:49:in 'GithubStatusChecks#initialize'
        from pre-deploy:89:in 'Class#new'
        from pre-deploy:89:in '<main>'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant