Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit8988b78

Browse files
committed
Return custom errors when main ref is supplied
1 parentcccf36e commit8988b78

File tree

1 file changed

+10
-18
lines changed

1 file changed

+10
-18
lines changed

‎pkg/github/repositories.go‎

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1855,7 +1855,7 @@ func looksLikeSHA(s string) bool {
18551855
// 1. If a specific commit `sha` is provided, it takes precedence and is used directly,
18561856
// and all reference resolution is skipped.
18571857
//
1858-
// 1a. If `sha` is empty but `ref` looks like a commit SHA (7-40 hexadecimal characters),
1858+
// 1a. If `sha` is empty but `ref` looks like a commit SHA (40 hexadecimal characters),
18591859
// it is returned as-is without any API calls or reference resolution.
18601860
//
18611861
// 2. If no `sha` is provided and `ref` does not look like a SHA, the function resolves
@@ -1927,25 +1927,14 @@ func resolveGitReference(ctx context.Context, githubClient *github.Client, owner
19271927
// The tag lookup also failed. Check if it was a 404 Not Found error.
19281928
ghErr2,isGhErr2:=err.(*github.ErrorResponse)
19291929
ifisGhErr2&&ghErr2.Response.StatusCode==http.StatusNotFound {
1930-
switchoriginalRef {
1931-
case"main":
1932-
// Try "master" next.
1933-
branchRef="refs/heads/master"
1934-
reference,resp,err=githubClient.Git.GetRef(ctx,owner,repo,branchRef)
1935-
iferr==nil {
1936-
ref=branchRef// It's the "master" branch.
1937-
break
1938-
}
1939-
returnnil,fmt.Errorf("attempted to resolve ref %q as 'main' but not found, and 'master' also not found",originalRef)
1940-
default:
1941-
returnnil,fmt.Errorf("could not resolve ref %q as a branch or a tag",originalRef)
1930+
iforiginalRef=="main" {
1931+
returnnil,fmt.Errorf("could not find branch or tag 'main'. Some repositories use 'master' as the default branch name")
19421932
}
19431933
}
1944-
iferr!=nil {
1945-
// The tag lookup failed for a different reason.
1946-
_,_=ghErrors.NewGitHubAPIErrorToCtx(ctx,"failed to get reference (tag)",resp,err)
1947-
returnnil,fmt.Errorf("failed to get reference for tag '%s': %w",originalRef,err)
1948-
}
1934+
1935+
// The tag lookup failed for a different reason.
1936+
_,_=ghErrors.NewGitHubAPIErrorToCtx(ctx,"failed to get reference (tag)",resp,err)
1937+
returnnil,fmt.Errorf("failed to get reference for tag '%s': %w",originalRef,err)
19491938
}
19501939
}else {
19511940
// The branch lookup failed for a different reason.
@@ -1958,6 +1947,9 @@ func resolveGitReference(ctx context.Context, githubClient *github.Client, owner
19581947
ifreference==nil {
19591948
reference,resp,err=githubClient.Git.GetRef(ctx,owner,repo,ref)
19601949
iferr!=nil {
1950+
ifref=="refs/heads/main" {
1951+
returnnil,fmt.Errorf("could not find branch 'main'. Some repositories use 'master' as the default branch name")
1952+
}
19611953
_,_=ghErrors.NewGitHubAPIErrorToCtx(ctx,"failed to get final reference",resp,err)
19621954
returnnil,fmt.Errorf("failed to get final reference for %q: %w",ref,err)
19631955
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp