0
0
mirror of https://github.com/go-gitea/gitea.git synced 2026-05-13 00:16:07 +02:00

fix(api): return 404 for workflow lookup on repo with empty default branch

Under the gogit build tag, an empty repo.DefaultBranch causes
GetBranchCommit to fail go-git's reference-name validation with an
"invalid reference name" error that does not unwrap to util.ErrNotExist,
so the workflow runs API returns 500 instead of 404. Short-circuit when
DefaultBranch is empty to match GitHub's 404 for missing workflows.

Co-Authored-By: Claude (Opus 4.7) <noreply@anthropic.com>
This commit is contained in:
silverwind 2026-05-09 00:24:28 +02:00
parent 89199c42d5
commit e0dc7ac0b8
No known key found for this signature in database
GPG Key ID: 2E62B41C93869443

View File

@ -596,6 +596,9 @@ func ListActionWorkflows(ctx context.Context, gitrepo *git.Repository, repo *rep
}
func GetActionWorkflow(ctx context.Context, gitrepo *git.Repository, repo *repo_model.Repository, workflowID string) (*api.ActionWorkflow, error) {
if repo.DefaultBranch == "" {
return nil, util.NewNotExistErrorf("workflow %q not found", workflowID)
}
defaultBranchCommit, err := gitrepo.GetBranchCommit(repo.DefaultBranch)
if err != nil {
return nil, err