Repository: 8398a7/action-slack
Pull request #88 (2020-07-01 14:06:29)

Issue/87
refs: #87


Patch:
diff --git a/docs/content/fields.md b/docs/content/fields.md
index 6ab60e7..43d4edf 100644
--- a/docs/content/fields.md
+++ b/docs/content/fields.md
@@ -16,11 +16,14 @@ Corresponding types are as follows.
 | eventName | no                      | `AS_EVENT_NAME`      | trigger event name                    |
 | ref       | no                      | `AS_REF`             | git refrence                          |
 | workflow  | no                      | `AS_WORKFLOW`        | GitHub Actions workflow name          |
+| action    | no                      | `AS_ACTION`          | Generate a workflow link from git sha |
 | message   | yes                     | `AS_MESSAGE`         | commit message                        |
 | author    | yes                     | `AS_AUTHOR`          | The author who pushed                 |
 | job       | yes                     | `AS_JOB`             | The name of the job that was executed |
 | took      | yes                     | `AS_TOOK`            | Execution time for the job            |
 
+caution: The Field in `action` is similar to what you get in workflow. It will be removed in the next major release version.
+
 ```yaml
 steps:
   - uses: 8398a7/action-slack@v3
diff --git a/src/fields.ts b/src/fields.ts
index fc40e78..a56c96d 100644
--- a/src/fields.ts
+++ b/src/fields.ts
@@ -45,6 +45,9 @@ export class FieldFactory {
         this.includes('author')
           ? createAttachment('author', await this.author())
           : undefined,
+        this.includes('action')
+          ? createAttachment('action', await this.action())
+          : undefined,
         this.includes('job')
           ? createAttachment('job', await this.job())
           : undefined,
@@ -171,6 +174,15 @@ export class FieldFactory {
     return value;
   }
 
+  private async action(): Promise<string> {
+    const sha = context.payload.pull_request?.head.sha ?? context.sha;
+    const { owner, repo } = context.repo;
+
+    const value = `<https://github.com/${owner}/${repo}/commit/${sha}/checks|action>`;
+    process.env.AS_ACTION = value;
+    return value;
+  }
+
   private async getCommit() {
     const { owner, repo } = context.repo;
     const { sha: ref } = context;


Test patch:
diff --git a/__tests__/client.test.ts b/__tests__/client.test.ts
index 06ff2f8..a3e1425 100644
--- a/__tests__/client.test.ts
+++ b/__tests__/client.test.ts
@@ -75,6 +75,16 @@ const workflow = (sha?: string): Field => {
   };
 };
 
+const action = (sha?: string): Field => {
+  return {
+    short: true,
+    title: 'action',
+    value: `<https://github.com/8398a7/action-slack/commit/${
+      sha ?? process.env.GITHUB_SHA
+    }/checks|action>`,
+  };
+};
+
 const job = (): Field => {
   return {
     short: true,
@@ -99,6 +109,7 @@ const fixedFields = (fields: string, sha?: string) => {
       ff.includes('message') ? message() : undefined,
       ff.includes('commit') ? commit() : undefined,
       ff.includes('author') ? author() : undefined,
+      ff.includes('action') ? action(sha) : undefined,
       ff.includes('job') ? job() : undefined,
       ff.includes('took') ? took() : undefined,
       ff.includes('eventName') ? eventName() : undefined,
@@ -179,7 +190,8 @@ describe('8398a7/action-slack', () => {
         icon_emoji: '',
         icon_url: '',
         channel: '',
-        fields: 'repo,message,commit,author,job,eventName,ref,workflow,took',
+        fields:
+          'repo,message,commit,author,job,action,eventName,ref,workflow,took',
       };
       const client = new Client(withParams, process.env.GITHUB_TOKEN, '');
       const payload = getTemplate(withParams.fields, `${successMsg}\n`);