From f6ea182c201dfc4ce05e2cc87211b201601b8b22 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Steenis Date: Mon, 2 May 2022 13:47:11 +0200 Subject: [PATCH] Add source of workflow dispatch in PR --- .github/workflows/git-actions-go-generate.yml | 32 +++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/.github/workflows/git-actions-go-generate.yml b/.github/workflows/git-actions-go-generate.yml index 40c8c213..3701510c 100644 --- a/.github/workflows/git-actions-go-generate.yml +++ b/.github/workflows/git-actions-go-generate.yml @@ -1,5 +1,18 @@ name: Go Generate -on: workflow_dispatch +on: + workflow_dispatch: + inputs: + source_url: + type: string + description: "URL of the source for this workflow run" + source_author: + type: string + description: "Username of the source for this workflow run" + +env: + INPUT_SOURCE_URL: ${{ github.event.inputs.source_url }} + INPUT_SOURCE_AUTHOR: ${{ github.event.inputs.source_author }} + permissions: contents: write pull-requests: write @@ -41,9 +54,17 @@ jobs: with: github-token: ${{ secrets.GITHUB_TOKEN }} script: | + let body = 'Auto-generated by GitHub Actions\n\n' + if ( `${ process.env.INPUT_SOURCE_URL }` ) { + body += `\nSource URL: ${ process.env.INPUT_SOURCE_URL }` + } + if ( `${ process.env.INPUT_SOURCE_AUTHOR }` ) { + body += `\nSource AUTHOR: @${ process.env.INPUT_SOURCE_AUTHOR}` + } + const { data: pr } = await github.rest.pulls.create({ title: "[${{ github.ref_name }}] go generate", - body: 'Auto-generated by GitHub Actions', + body: body, owner: context.repo.owner, repo: context.repo.repo, base: "${{ github.ref_name }}", @@ -54,6 +75,13 @@ jobs: issue_number: pr.number, labels: ["status/auto-created"], }); + if ( `${ process.env.INPUT_SOURCE_AUTHOR }` ) { + await github.rest.issues.addAssignees({ + ...context.repo, + issue_number: pr.number, + assignees: [`${ process.env.INPUT_SOURCE_AUTHOR}`], + }); + } console.log('Created new pull request'); return pr.html_url; - name: Check outputs