Skip to content

Accept any repository type in PrepareRepoContext and PreparePRContext - #663

Open
Mattbusel wants to merge 2 commits into
palantir:developfrom
Mattbusel:repo-context-interface
Open

Mattbusel wants to merge 2 commits into
palantir:developfrom
Mattbusel:repo-context-interface

Conversation

@Mattbusel

Copy link
Copy Markdown

Fixes #75.

Before this PR

PrepareRepoContext and PreparePRContext took a *github.Repository but only read the name and owner login. Handlers for push events, which carry a *github.PushEventRepository, had to build a *github.Repository just to get the log keys.

After this PR

==COMMIT_MSG==
PrepareRepoContext and PreparePRContext accept any repository type with GetName and GetOwner, including *github.PushEventRepository, through a new RepositoryInfo interface.
==COMMIT_MSG==

  • RepositoryInfo has the two getters the functions use; compile-time assertions check that *github.Repository and *github.PushEventRepository satisfy it. The name is a suggestion, happy to rename.
  • Existing callers compile unchanged, including the example app.
  • A nil repository still adds no repository log keys. Because a typed nil pointer is a non-nil interface, attachRepoLogKeys skips a repository with no owner and no name, which covers (*github.Repository)(nil) and (*github.PushEventRepository)(nil).
  • New tests: a push event repository, and nil repositories (untyped, typed *github.Repository, typed *github.PushEventRepository). go vet ./... and go test ./... pass.

Possible downsides?

Code that stores these functions in a variable typed with the old signature (func(context.Context, int64, *github.Repository) ...) would need to update that type. Direct calls are unaffected. A non-nil repository with neither a name nor an owner no longer gets two empty log keys.

Prepared with AI assistance (Claude); the change and tests were run locally before opening.

@palantirtech

Copy link
Copy Markdown
Member

Thanks for your interest in palantir/go-githubapp, @Mattbusel! Before we can accept your pull request, you need to sign our contributor license agreement - just visit https://cla.palantir.com/ and follow the instructions. Once you sign, I'll automatically update this pull request.

@changelog-app

changelog-app Bot commented Nov 17, 2026

Copy link
Copy Markdown

Generate changelog in changelog/@unreleased

Type (Select exactly one)

  • Feature (Adding new functionality)
  • Improvement (Improving existing functionality)
  • Fix (Fixing an issue with existing functionality)
  • Break (Creating a new major version by breaking public APIs)
  • Deprecation (Removing functionality in a non-breaking way)
  • Migration (Automatically moving data/functionality to a new system)

Description

PrepareRepoContext and PreparePRContext accept any repository type with GetName and GetOwner, including *github.PushEventRepository, through a new RepositoryInfo interface.

Check the box to generate changelog(s)

  • Generate changelog entry

Both functions only read the repository name and owner login, but took a
*github.Repository, so handlers for push events had to convert a
*github.PushEventRepository first. Take a small RepositoryInfo interface
(GetName, GetOwner) instead, which *github.Repository and
*github.PushEventRepository both satisfy. Existing callers compile
unchanged. A nil repository, typed or untyped, still adds no repository
log keys.

Fixes palantir#75
@Mattbusel
Mattbusel force-pushed the repo-context-interface branch from c8249e7 to 044c027 Compare November 18, 2026 00:33
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 this pull request may close these issues.

PrepareRepoContext should take an interface

2 participants