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

Author #1

Merged
merged 3 commits into from
Sep 20, 2021
Merged
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 .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
node_modules
yarn-error.log
.vscode
.idea/
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# Unreleased

- Fetches the Actor ("The name of the person or app that initiated the workflow") and sets that as an Author field in the
Slack attachment.

# [1.5.0](https://github.com/voxmedia/github-action-slack-notify-build/compare/v1.4.0...v1.5.0) (2021-03-05)


12 changes: 12 additions & 0 deletions __tests__/utils.spec.js
Original file line number Diff line number Diff line change
@@ -3,6 +3,8 @@ import { GITHUB_PUSH_EVENT, GITHUB_PR_EVENT } from '../fixtures';
const runId = parseInt(process.env.GITHUB_RUN_ID, 10);

describe('Utils', () => {
process.env.GITHUB_REPOSITORY = 'voxmedia/github-action-slack-notify-build';

describe('formatChannelName', () => {
it('strips #', () => {
expect(formatChannelName('#app-notifications')).toBe('app-notifications');
@@ -30,6 +32,16 @@ describe('Utils', () => {
});
});

it('show author/actor', () => {
const attachments = buildSlackAttachments({ status: 'STARTED', color: 'good', github: GITHUB_PUSH_EVENT });

expect(attachments[0].fields.find(a => a.title === 'Author')).toEqual({
title: 'Author',
value: 'Codertocat',
short: true,
});
});

describe('for push events', () => {
it('links to the action workflow', () => {
const attachments = buildSlackAttachments({ status: 'STARTED', color: 'good', github: GITHUB_PUSH_EVENT });
2 changes: 2 additions & 0 deletions fixtures.js
Original file line number Diff line number Diff line change
@@ -10,6 +10,7 @@ export const GITHUB_PUSH_EVENT = {
payload: {
repository,
},
actor: 'Codertocat',
ref: 'refs/heads/my-branch',
workflow: 'CI',
eventName: 'push',
@@ -30,6 +31,7 @@ export const GITHUB_PR_EVENT = {
},
},
},
actor: 'Codertocat',
workflow: 'CI',
eventName: 'pull_request',
sha: 'abc123',
7 changes: 6 additions & 1 deletion src/utils.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const { context } = require('@actions/github');

function buildSlackAttachments({ status, color, github }) {
const { payload, ref, workflow, eventName } = github.context;
const { payload, ref, workflow, eventName, actor } = github.context;
const { owner, repo } = context.repo;
const event = eventName;
const branch = event === 'pull_request' ? payload.pull_request.head.ref : ref.replace('refs/heads/', '');
@@ -47,6 +47,11 @@ function buildSlackAttachments({ status, color, github }) {
value: event,
short: true,
},
{
title: 'Author',
value: actor,
short: true,
},
],
footer_icon: 'https://github.githubassets.com/favicon.ico',
footer: `<https://github.com/${owner}/${repo} | ${owner}/${repo}>`,
Loading