Merge pull request #6344 from cli/yaml-dispatch

Recognize `.yaml` in addition to `.yml` suffix as workflow file name
This commit is contained in:
Mislav Marohnić 2022-09-26 11:54:25 +02:00 committed by GitHub
commit 465b952d85
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 1 deletions

View file

@ -470,6 +470,26 @@ jobs:
wantErr: true,
errOut: "could not create workflow dispatch event: HTTP 422 (https://api.github.com/repos/OWNER/REPO/actions/workflows/12345/dispatches)",
},
{
name: "yaml file extension",
tty: false,
opts: &RunOptions{
Selector: "workflow.yaml",
},
httpStubs: func(reg *httpmock.Registry) {
reg.Register(
httpmock.REST("GET", "repos/OWNER/REPO/actions/workflows/workflow.yaml"),
httpmock.StatusStringResponse(200, `{"id": 12345}`))
reg.Register(
httpmock.REST("POST", "repos/OWNER/REPO/actions/workflows/12345/dispatches"),
httpmock.StatusStringResponse(204, ""))
},
wantBody: map[string]interface{}{
"inputs": map[string]interface{}{},
"ref": "trunk",
},
wantErr: false,
},
{
// TODO this test is somewhat silly; it's more of a placeholder in case I decide to handle the API error more elegantly
name: "input fields, missing required",

View file

@ -124,7 +124,7 @@ func FindWorkflow(client *api.Client, repo ghrepo.Interface, workflowSelector st
return nil, errors.New("empty workflow selector")
}
if _, err := strconv.Atoi(workflowSelector); err == nil || strings.HasSuffix(workflowSelector, ".yml") {
if _, err := strconv.Atoi(workflowSelector); err == nil || isWorkflowFile(workflowSelector) {
workflow, err := getWorkflowByID(client, repo, workflowSelector)
if err != nil {
return nil, err
@ -139,6 +139,11 @@ func GetWorkflow(client *api.Client, repo ghrepo.Interface, workflowID int64) (*
return getWorkflowByID(client, repo, strconv.FormatInt(workflowID, 10))
}
func isWorkflowFile(f string) bool {
name := strings.ToLower(f)
return strings.HasSuffix(name, ".yml") || strings.HasSuffix(name, ".yaml")
}
// ID can be either a numeric database ID or the workflow file name
func getWorkflowByID(client *api.Client, repo ghrepo.Interface, ID string) (*Workflow, error) {
var workflow Workflow