Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add workflowRun field #230

Merged
merged 2 commits into from
Nov 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/content/usage/fields.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ Corresponding types are as follows.
| eventName | `AS_EVENT_NAME` | trigger event name |
| ref | `AS_REF` | git reference |
| workflow | `AS_WORKFLOW` | Generate a workflow link from git sha |
| workflowRun | `AS_WORKFLOW_RUN` | Generate a link to the present workflow run |
| message | `AS_MESSAGE` | commit message |
| author | `AS_AUTHOR` | The author who pushed |
| job | `AS_JOB` | Generate a job run link of the job that was executed |
Expand Down
10 changes: 10 additions & 0 deletions src/fields.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ export class FieldFactory {
this.includes('workflow')
? createAttachment('workflow', await this.workflow())
: undefined,
this.includes('workflowRun')
? createAttachment('workflow', await this.workflowRun())
: undefined,
this.includes('pullRequest')
? createAttachment('pullRequest', await this.pullRequest())
: undefined,
Expand Down Expand Up @@ -214,6 +217,13 @@ export class FieldFactory {
return value;
}

private async workflowRun(): Promise<string> {
const { owner, repo } = context.repo;
const value = `<${this.gitHubBaseUrl}/${owner}/${repo}/actions/runs/${context.runId}|${context.workflow}>`;
process.env.AS_WORKFLOW_RUN = value;
return value;
}

private async pullRequest(): Promise<string> {
let value;
if (context.eventName.startsWith('pull_request')) {
Expand Down