-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
144 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/** | ||
* @typedef {Object} Actor | ||
* @property {string} username | ||
* @property {string} avatarUrl | ||
* @property {string} profileUrl | ||
*/ | ||
|
||
/** | ||
* @typedef {Object} PRData | ||
* @property {string} title | ||
* @property {string} body | ||
* @property {Actor} actor | ||
*/ | ||
|
||
/** | ||
* @typedef {Object} Formatter | ||
* @property {(data: PRData) => string} generateMsg | ||
*/ | ||
|
||
/** | ||
* Slack is using their own Markdown format, see: | ||
* https://api.slack.com/reference/surfaces/formatting#basics | ||
* https://app.slack.com/block-kit-builder | ||
* @type {Formatter} | ||
*/ | ||
const slackFormatter = { | ||
generateMsg: ({ title, body, actor }) => { | ||
const markdown = text => ({ type: 'section', text: { type: 'mrkdwn', text } }); | ||
const header = text => ({ type: 'header', text: { type: 'plain_text', text } }); | ||
const context = (imgUrl, text) => ({ | ||
type: 'context', | ||
elements: [ | ||
...(imgUrl ? [{ type: 'image', image_url: imgUrl, alt_text: 'avatar' }] : []), | ||
{ type: 'mrkdwn', text }, | ||
], | ||
}); | ||
const blocks = []; | ||
|
||
blocks.push(header(`openapi-specs: ${title}`)); | ||
|
||
blocks.push(markdown(body)); | ||
blocks.push(markdown('\n')); | ||
blocks.push(context(actor.avatarUrl, `<${actor.profileUrl}|*${actor.username}*> created this PR.`)); | ||
|
||
return JSON.stringify({ blocks }); | ||
}, | ||
}; | ||
|
||
/** | ||
* @type {Record<string, Formatter>} | ||
*/ | ||
const formatters = { | ||
slack: slackFormatter, | ||
}; | ||
|
||
/* | ||
* @returns {Actor} | ||
*/ | ||
const createActor = username => { | ||
return { username, avatarUrl: `https://github.com/${username}.png`, profileUrl: `https://github.com/${username}` }; | ||
}; | ||
|
||
const run = async () => { | ||
const { title, user } = JSON.parse(process.argv[2]); | ||
const body = process.argv[3]; | ||
const actor = createActor(user.login); | ||
|
||
const formatter = formatters['slack']; | ||
if (!formatter) { | ||
throw new Error('Invalid formatter, supported formatters are: ' + Object.keys(formatters).join(', ')); | ||
} | ||
|
||
console.log(formatter.generateMsg({ title, body, actor })); | ||
} | ||
|
||
run() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
name: Create Linear ticket | ||
|
||
on: | ||
pull_request: | ||
types: [opened] | ||
|
||
jobs: | ||
linear-ticket: | ||
runs-on: ubuntu-latest | ||
permissions: | ||
pull-requests: write | ||
steps: | ||
- name: Create Linear ticket | ||
id: createIssue | ||
uses: ctriolo/[email protected] | ||
with: | ||
linear-api-key: ${{ secrets.LINEAR_API_KEY }} | ||
linear-team-key: "ECO" | ||
linear-issue-title: ${{ github.event.pull_request.title }} | ||
linear-issue-description: ${{ github.event.pull_request.body }} | ||
linear-attachment-url: ${{ github.event.pull_request.html_url }} | ||
linear-attachment-title: ${{ github.event.pull_request.title }} | ||
|
||
- name: Create comment for Linear ticket link | ||
uses: marocchino/[email protected] | ||
with: | ||
GITHUB_TOKEN: ${{ secrets.CLERK_COOKIE_PAT }} | ||
number: ${{ github.event.issue.number }} | ||
header: linear-issue-url | ||
message: | | ||
A Linear ticket has been created for this PR: ${{ steps.createIssue.outputs.linear-issue-url }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
name: Slack Notification | ||
|
||
on: | ||
pull_request: | ||
types: [opened] | ||
|
||
jobs: | ||
slack-notify: | ||
name: Slack Notification | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout repo | ||
uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 | ||
show-progress: false | ||
- name: Convert PR body to Slack format | ||
id: slackify | ||
uses: LoveToKnow/[email protected] | ||
with: | ||
text: ${{ github.event.pull_request.body }} | ||
- name: Generate notification payload | ||
id: notification | ||
env: | ||
BODY: ${{ github.event.pull_request.body }} | ||
PULL_REQUEST_DATA: ${{ toJson(github.event.pull_request) }} | ||
run: | | ||
payload=$(node ./.github/utils/slack-notify.mjs '${{ env.PULL_REQUEST_DATA }}' '${{ steps.slackify.outputs.text }}') | ||
echo "payload=${payload//$'\n'/'%0A'}" >> $GITHUB_OUTPUT | ||
- name: Send PR to Slack | ||
id: slack | ||
uses: slackapi/[email protected] | ||
with: | ||
payload: ${{ steps.notification.outputs.payload }} | ||
env: | ||
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_CHANGELOG_WEBHOOK_URL }} | ||
SLACK_WEBHOOK_TYPE: INCOMING_WEBHOOK |