mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-11-24 22:20:35 +00:00
Fixes git references wrongly transmitted to the action run
This commit is contained in:
parent
9634d954d4
commit
9b225b56a9
|
@ -5,6 +5,7 @@ package git
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"code.gitea.io/gitea/modules/util"
|
"code.gitea.io/gitea/modules/util"
|
||||||
|
@ -61,3 +62,19 @@ func parseTags(refs []string) []string {
|
||||||
}
|
}
|
||||||
return results
|
return results
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ExpandRef expands any partial reference to its full form
|
||||||
|
func (repo *Repository) ExpandRef(ref string) (string, error) {
|
||||||
|
if strings.HasPrefix(ref, "refs/") {
|
||||||
|
return ref, nil
|
||||||
|
} else if strings.HasPrefix(ref, "tags/") || strings.HasPrefix(ref, "heads/") {
|
||||||
|
return "refs/" + ref, nil
|
||||||
|
} else if repo.IsTagExist(ref) {
|
||||||
|
return TagPrefix + ref, nil
|
||||||
|
} else if repo.IsBranchExist(ref) {
|
||||||
|
return BranchPrefix + ref, nil
|
||||||
|
} else if repo.IsCommitExist(ref) {
|
||||||
|
return ref, nil
|
||||||
|
}
|
||||||
|
return "", fmt.Errorf("could not expand reference '%s'", ref)
|
||||||
|
}
|
||||||
|
|
|
@ -141,6 +141,11 @@ func (entry *Workflow) Dispatch(ctx context.Context, inputGetter InputValueGette
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetWorkflowFromCommit(gitRepo *git.Repository, ref, workflowID string) (*Workflow, error) {
|
func GetWorkflowFromCommit(gitRepo *git.Repository, ref, workflowID string) (*Workflow, error) {
|
||||||
|
ref, err := gitRepo.ExpandRef(ref)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
commit, err := gitRepo.GetCommit(ref)
|
commit, err := gitRepo.GetCommit(ref)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
|
@ -426,8 +426,10 @@ func TestWorkflowDispatchEvent(t *testing.T) {
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
defer gitRepo.Close()
|
defer gitRepo.Close()
|
||||||
|
|
||||||
workflow, err := actions_service.GetWorkflowFromCommit(gitRepo, sha, "dispatch.yml")
|
workflow, err := actions_service.GetWorkflowFromCommit(gitRepo, "main", "dispatch.yml")
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
assert.Equal(t, "refs/heads/main", workflow.Ref)
|
||||||
|
assert.Equal(t, sha, workflow.Commit.ID.String())
|
||||||
|
|
||||||
inputGetter := func(key string) string {
|
inputGetter := func(key string) string {
|
||||||
return ""
|
return ""
|
||||||
|
|
Loading…
Reference in a new issue