-
Notifications
You must be signed in to change notification settings - Fork 0
✨ feat: pr 이벤트 발생 시 슬랙에 노티 #20
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
Closed
Closed
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next
Next commit
✨ feat: pr 이벤트 발생 시 슬랙에 노티
- Loading branch information
commit acf3d054e4fed131e2377dab4bcf6b4cd414470f
There are no files selected for viewing
This file contains hidden or 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,32 @@ | ||
name: Notify Slack on PR Events | ||
|
||
on: | ||
pull_request: | ||
types: [review_requested] | ||
pull_request_review: | ||
types: [submitted] | ||
|
||
jobs: | ||
notify: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v2 | ||
|
||
- name: Set up Node.js | ||
uses: actions/setup-node@v2 | ||
with: | ||
node-version: "14" | ||
|
||
- name: Install dependencies | ||
run: npm install | ||
|
||
- name: Run Slack Notification Script | ||
env: | ||
SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }} | ||
SLACK_SIGNING_SECRET: ${{ secrets.SLACK_SIGNING_SECRET }} | ||
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} | ||
GITHUB_EVENT_PATH: ${{ github.event_path }} | ||
GITHUB_EVENT_NAME: ${{ github.event_name }} | ||
run: node script/sendMessageToSlack.js |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or 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
This file contains hidden or 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,6 @@ | ||
/* eslint-disable no-undef */ | ||
const users = { | ||
bicochan: 'U07C75ZKHEX', | ||
}; | ||
|
||
module.exports = users; |
This file contains hidden or 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,58 @@ | ||
/* eslint-disable no-undef */ | ||
/* eslint-disable @typescript-eslint/no-var-requires */ | ||
const users = require('./constant'); | ||
|
||
function createReviewSubmittedMessage(event) { | ||
const reviewer = event.review.user.login; | ||
const reviewerId = users[reviewer]; | ||
const prOwner = event.pull_request.user.login; | ||
const prOwnerId = users[prOwner]; | ||
const reviewUrl = event.review.html_url; | ||
|
||
const blocks = [ | ||
{ | ||
type: 'rich_text', | ||
elements: [ | ||
{ | ||
type: 'rich_text_section', | ||
elements: [ | ||
{ | ||
type: 'user', | ||
user_id: reviewerId, | ||
}, | ||
{ | ||
type: 'text', | ||
text: ' 님이 ', | ||
}, | ||
{ | ||
type: 'user', | ||
user_id: prOwnerId, | ||
}, | ||
{ | ||
type: 'text', | ||
text: ' 님의 PR에 ', | ||
}, | ||
{ | ||
type: 'emoji', | ||
name: 'link', | ||
unicode: '1f517', | ||
}, | ||
{ | ||
type: 'link', | ||
url: reviewUrl, | ||
text: '리뷰', | ||
}, | ||
{ | ||
type: 'text', | ||
text: '를 등록했어요.', | ||
}, | ||
], | ||
}, | ||
], | ||
}, | ||
]; | ||
|
||
return { blocks }; | ||
} | ||
|
||
module.exports = createReviewSubmittedMessage; |
This file contains hidden or 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,59 @@ | ||
/* eslint-disable no-undef */ | ||
/* eslint-disable @typescript-eslint/no-var-requires */ | ||
const users = require('./constant'); | ||
|
||
function createReviewerAssignedMessage(event) { | ||
const prOwner = event.pull_request.user.login; | ||
const prOwnerId = users[prOwner]; | ||
const reviewers = event.pull_request.requested_reviewers.map( | ||
(reviewer) => users[reviewer.login] | ||
); | ||
const prUrl = event.pull_request.html_url; | ||
|
||
const blocks = [ | ||
{ | ||
type: 'rich_text', | ||
elements: [ | ||
{ | ||
type: 'rich_text_section', | ||
elements: [ | ||
{ | ||
type: 'user', | ||
user_id: reviewers.join(', '), | ||
}, | ||
{ | ||
type: 'text', | ||
text: ' 님이 ', | ||
}, | ||
{ | ||
type: 'user', | ||
user_id: prOwnerId, | ||
}, | ||
{ | ||
type: 'text', | ||
text: ' 님의 ', | ||
}, | ||
{ | ||
type: 'emoji', | ||
name: 'link', | ||
unicode: '1f517', | ||
}, | ||
{ | ||
type: 'link', | ||
url: prUrl, | ||
text: 'PR', | ||
}, | ||
{ | ||
type: 'text', | ||
text: '에 리뷰어로 등록됐어요.', | ||
}, | ||
], | ||
}, | ||
], | ||
}, | ||
]; | ||
|
||
return { blocks }; | ||
} | ||
|
||
module.exports = createReviewerAssignedMessage; |
This file contains hidden or 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,46 @@ | ||
/* eslint-disable no-undef */ | ||
/* eslint-disable @typescript-eslint/no-var-requires */ | ||
const fs = require('fs'); | ||
const axios = require('axios'); | ||
const dotenv = require('dotenv'); | ||
const createReviewerAssignedMessage = require('./createReviewerAssignedMessage'); | ||
const createReviewSubmittedMessage = require('./createReviewSubmittedMessage'); | ||
|
||
dotenv.config(); | ||
|
||
const GITHUB_EVENT_PATH = process.env.GITHUB_EVENT_PATH; | ||
const SLACK_WEBHOOK_URL = process.env.SLACK_WEBHOOK_URL; | ||
|
||
const event = JSON.parse(fs.readFileSync(GITHUB_EVENT_PATH, 'utf8')); | ||
const eventName = process.env.GITHUB_EVENT_NAME; | ||
|
||
let message = {}; | ||
|
||
switch (eventName) { | ||
case 'pull_request': | ||
if (event.action === 'review_requested') { | ||
message = createReviewerAssignedMessage(event); | ||
} | ||
break; | ||
case 'pull_request_review': | ||
if (event.action === 'submitted') { | ||
message = createReviewSubmittedMessage(event); | ||
} | ||
break; | ||
default: | ||
console.log('No action needed for this event type.'); | ||
return; | ||
} | ||
|
||
if (Object.keys(message).length > 0) { | ||
axios | ||
.post(SLACK_WEBHOOK_URL, message) | ||
.then((response) => { | ||
console.log('Message sent: ', response.data); | ||
}) | ||
.catch((error) => { | ||
console.error('Error sending message: ', error); | ||
}); | ||
} else { | ||
console.log('No message to send.'); | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
리뷰 테스트