Skip to content

[WIP] refactor(resolution): replace go-scm with internal scmclient#10208

Draft
ary82 wants to merge 2 commits into
tektoncd:mainfrom
ary82:cleanup/resolution-replace-go-scm-lib-9989
Draft

[WIP] refactor(resolution): replace go-scm with internal scmclient#10208
ary82 wants to merge 2 commits into
tektoncd:mainfrom
ary82:cleanup/resolution-replace-go-scm-lib-9989

Conversation

@ary82

@ary82 ary82 commented Jun 7, 2026

Copy link
Copy Markdown

Closes #9989

Changes

The git resolver's API depended on github.com/jenkins-x/go-scm for fetching file content from SCM providers, causing a heavy dependency and ongoing maintenance pain.

This change introduces the scmclient internal package, which defines lightweight implementations of the SCM providers according to the SCMClient interface. It has three methods (GetFileContent, GetCommitSHA, GetCloneURL)

/kind cleanup

Submitter Checklist

As the author of this PR, please check off the items in this checklist:

  • Has Docs if any changes are user facing, including updates to minimum requirements e.g. Kubernetes version bumps
  • Has Tests included if any functionality added or changed
  • pre-commit Passed
  • Follows the commit message standard
  • Meets the Tekton contributor standards (including functionality, content, code)
  • Has a kind label. You can add one by adding a comment on this PR that contains /kind <type>. Valid types are bug, cleanup, design, documentation, feature, flake, misc, question, tep
  • Release notes block below has been updated with any user facing changes (API changes, bug fixes, changes requiring upgrade notices or deprecation warnings). See some examples of good release notes.
  • Release notes contains the string "action required" if the change requires additional action from users switching to the new release

Release Notes

NONE

@tekton-robot tekton-robot added release-note-none Denotes a PR that doesnt merit a release note. do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. labels Jun 7, 2026
@tekton-robot tekton-robot requested review from afrittoli and khrm June 7, 2026 21:02
@tekton-robot tekton-robot added the size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. label Jun 7, 2026
@ary82 ary82 force-pushed the cleanup/resolution-replace-go-scm-lib-9989 branch from 351a9f9 to f6f9cff Compare June 8, 2026 02:59
@vdemeester vdemeester self-assigned this Jun 8, 2026
@vdemeester vdemeester requested a review from Copilot June 8, 2026 08:02

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refactors the git resolver’s API-mode SCM integration to stop depending on github.com/jenkins-x/go-scm by introducing a new internal pkg/internal/scmclient package that implements a lightweight SCMClient interface (GetFileContent / GetCommitSHA / GetCloneURL) and wiring the resolver(s) to use it.

Changes:

  • Added pkg/internal/scmclient with HTTP-based clients (GitHub/GitLab/Gitea) behind a small interface plus a fake for unit tests.
  • Updated both in-tree git resolvers to construct SCM clients via scmclient.New instead of go-scm/factory.NewClient.
  • Expanded/adjusted e2e tests to validate API mode for additional providers (GitHub/GitLab) and refactored Gitea API-mode tests.

Reviewed changes

Copilot reviewed 18 out of 18 changed files in this pull request and generated 12 comments.

Show a summary per file
File Description
test/resolvers_git_test.go E2E updates: adds GitHub/GitLab API-mode tests and refactors Gitea API-mode tests/config handling.
pkg/resolution/resolver/git/resolver.go Switches API-mode resolution to use pkg/internal/scmclient instead of go-scm.
pkg/resolution/resolver/git/resolver_test.go Updates unit tests to mock via scmclient.FakeSCMClient and adjusts expected errors.
pkg/remoteresolution/resolver/git/resolver.go Switches remoteresolution git resolver to use pkg/internal/scmclient.
pkg/remoteresolution/resolver/git/resolver_test.go Updates remoteresolution unit tests to mock via scmclient.FakeSCMClient.
pkg/internal/scmclient/client.go Adds SCMClient interface and provider factory.
pkg/internal/scmclient/http.go Adds a small HTTP helper for request/response handling.
pkg/internal/scmclient/github.go / github_test.go Adds GitHub REST client + unit tests.
pkg/internal/scmclient/gitlab.go / gitlab_test.go Adds GitLab REST client + unit tests.
pkg/internal/scmclient/gitea.go / gitea_test.go Adds Gitea REST client + unit tests.
pkg/internal/scmclient/fake.go Adds a fake implementation for resolver unit tests.
pkg/internal/scmclient/bitbucketcloud.go Placeholder Bitbucket Cloud client (currently panics).
pkg/internal/scmclient/bitbucketserver.go Placeholder Bitbucket Server client (currently panics).
pkg/internal/scmclient/azure.go Placeholder Azure DevOps client (currently panics).
pkg/internal/scmclient/client_test.go Tests factory behavior for supported provider keys.
Comments suppressed due to low confidence (1)

test/resolvers_git_test.go:558

  • This test verification request places the auth token in the URL query (...&token=...) and uses http.Get without a context. Tokens in query strings are easily leaked via logs/proxies, and omitting context can cause the call to hang beyond the test deadline. Prefer sending the token via Authorization header and using http.NewRequestWithContext.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +40 to +44
case "bitbucketcloud":
return newBitbucketCloudClient(serverURL, token), nil
case "bitbucketserver":
return newBitbucketServerClient(serverURL, token), nil
case "azure":
Comment thread pkg/internal/scmclient/github.go Outdated
}

func (c *githubClient) GetFileContent(ctx context.Context, org, repo, path, ref string) ([]byte, error) {
url := fmt.Sprintf("%s/repos/%s/%s/contents/%s?ref=%s", c.baseURL, org, repo, url.PathEscape(path), ref)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Github does handle path param that is PathEscaped. I can confirm this works.
Fixed for ref QueryEscape.

cURL request for PathEscaped content path
╰─➤  curl -L \                                                                                                                                                                         3s
  -H "Accept: application/vnd.github+json" \
  -H "Authorization: Bearer $GITHUB_TOKEN" \
  -H "X-GitHub-Api-Version: 2026-03-10" \
  https://api.github.com/repos/tektoncd/pipeline/contents/test%2Fgit-resolver%2Fremote-task.yaml
{
  "name": "remote-task.yaml",
  "path": "test/git-resolver/remote-task.yaml",
  "sha": "95f0e8d4b27050ef7826701f22274145c63b9f5e",
  "size": 203,
  "url": "https://api.github.com/repos/tektoncd/pipeline/contents/test/git-resolver/remote-task.yaml?ref=main",
  "html_url": "https://github.com/tektoncd/pipeline/blob/main/test/git-resolver/remote-task.yaml",
  "git_url": "https://api.github.com/repos/tektoncd/pipeline/git/blobs/95f0e8d4b27050ef7826701f22274145c63b9f5e",
  "download_url": "https://raw.githubusercontent.com/tektoncd/pipeline/main/test/git-resolver/remote-task.yaml",
  "type": "file",
  "content": "YXBpVmVyc2lvbjogdGVrdG9uLmRldi92MWJldGExCmtpbmQ6IFRhc2sKbWV0\nYWRhdGE6CiAgbmFtZTogcmVtb3RlLXNjbS1yZXNvbHZlci10YXNrCnNwZWM6\nCiAgc3RlcHM6CiAgLSBuYW1lOiBzbGVlcAogICAgaW1hZ2U6IG1pcnJvci5n\nY3IuaW8vYnVzeWJveAogICAgY29tbWFuZDogWycvYmluL3NoJ10KICAgIGFy\nZ3M6IFsnLWMnLCAnc2xlZXAgMTAnXQo=\n",
  "encoding": "base64",
  "_links": {
    "self": "https://api.github.com/repos/tektoncd/pipeline/contents/test/git-resolver/remote-task.yaml?ref=main",
    "git": "https://api.github.com/repos/tektoncd/pipeline/git/blobs/95f0e8d4b27050ef7826701f22274145c63b9f5e",
    "html": "https://github.com/tektoncd/pipeline/blob/main/test/git-resolver/remote-task.yaml"
  }
}

Comment thread pkg/internal/scmclient/github.go
Comment thread pkg/internal/scmclient/github.go Outdated
Comment thread pkg/internal/scmclient/gitlab.go Outdated
Comment thread pkg/internal/scmclient/gitea.go Outdated
Comment thread pkg/internal/scmclient/gitea.go Outdated
Comment on lines +45 to +50
func (f *FakeSCMClient) GetCommitSHA(_ context.Context, org, repo, ref string) (string, error) {
if f.Err != nil {
return "", f.Err
}
return f.CommitSHAs[org+"/"+repo+"/"+ref], nil
}
Comment on lines +52 to +57
func (f *FakeSCMClient) GetCloneURL(_ context.Context, org, repo string) (string, error) {
if f.Err != nil {
return "", f.Err
}
return f.CloneURLs[org+"/"+repo], nil
}
Comment thread pkg/internal/scmclient/github_test.go Outdated
@ary82 ary82 force-pushed the cleanup/resolution-replace-go-scm-lib-9989 branch from f6f9cff to 8f43882 Compare June 8, 2026 08:38
@tekton-robot

Copy link
Copy Markdown
Collaborator

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
To complete the pull request process, please ask for approval from vdemeester after the PR has been reviewed.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

The git resolver's API depended on `github.com/jenkins-x/go-scm` for
fetching file content from SCM providers, causing a heavy dependency and
ongoing maintenance pain.

This change introduces the `scmclient` internal package, which defines
lightweight implementations of the SCM providers according to the
`SCMClient` interface. It has three methods (GetFileContent,
GetCommitSHA, GetCloneURL)

Signed-off-by: Aryan Goyal <mail@ary82.dev>
@ary82 ary82 force-pushed the cleanup/resolution-replace-go-scm-lib-9989 branch from 8f43882 to 3e7d091 Compare June 8, 2026 15:12
@vdemeester vdemeester requested a review from Copilot June 17, 2026 14:42

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 19 out of 19 changed files in this pull request and generated 15 comments.

Comments suppressed due to low confidence (1)

test/resolvers_git_test.go:619

  • The verification request puts the Gitea token into the query string and uses http.Get without context. Tokens in URLs can leak via logs/proxies, and the request won’t be canceled if the test context is canceled. Prefer an Authorization header with a context-aware request, and ensure the response body is closed via defer.

Comment on lines 344 to 355
// find the actual git commit sha by the ref
commit, _, err := scmClient.Git.FindCommit(ctx, orgRepo, ref)
if err != nil || commit == nil {
sha, err := client.GetCommitSHA(ctx, org, repo, ref)
if err != nil {
return nil, fmt.Errorf("couldn't fetch the commit sha for the ref %s in the repo: %w", ref, err)
}

// fetch the repository URL
repo, _, err := scmClient.Repositories.Find(ctx, orgRepo)
// fetch the repository clone URL
cloneURL, err := client.GetCloneURL(ctx, org, repo)
if err != nil {
return nil, fmt.Errorf("couldn't fetch repository: %w", err)
}

Comment thread pkg/internal/scmclient/gitlab.go
Comment thread pkg/internal/scmclient/bitbucketcloud.go
Comment thread pkg/internal/scmclient/bitbucketcloud.go
Comment thread pkg/internal/scmclient/bitbucketcloud.go
Comment on lines +19 to +23
import (
"context"
"net/http"
"strings"
)
Comment on lines +45 to +47
func (c *azureClient) GetFileContent(ctx context.Context, org, repo, path, ref string) ([]byte, error) {
panic("unimplemented")
}
Comment on lines +49 to +51
func (c *azureClient) GetCommitSHA(ctx context.Context, org, repo, ref string) (string, error) {
panic("unimplemented")
}
Comment on lines +53 to +55
func (c *azureClient) GetCloneURL(ctx context.Context, org, repo string) (string, error) {
panic("unimplemented")
}
Comment on lines +33 to +48
switch scmType {
case "github":
return newGitHubClient(serverURL, token), nil
case "gitlab":
return newGitLabClient(serverURL, token), nil
case "gitea":
return newGiteaClient(serverURL, token), nil
case "bitbucketcloud":
return newBitbucketCloudClient(serverURL, token), nil
case "bitbucketserver":
return newBitbucketServerClient(serverURL, token), nil
case "azure":
return newAzureClient(serverURL, token), nil
default:
return nil, fmt.Errorf("unsupported scm type %q", scmType)
}
@ary82 ary82 force-pushed the cleanup/resolution-replace-go-scm-lib-9989 branch from 0548234 to e9cc80c Compare June 17, 2026 16:06
Signed-off-by: Aryan Goyal <mail@ary82.dev>
@ary82 ary82 force-pushed the cleanup/resolution-replace-go-scm-lib-9989 branch from e9cc80c to 77a75d5 Compare June 18, 2026 10:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. release-note-none Denotes a PR that doesnt merit a release note. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Replace jenkins-x/go-scm with lightweight internal SCM client in git resolver

4 participants