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

feat: 매터모스트 제거하고 슬랙 다시 추가 #42

Merged
merged 5 commits into from
Dec 1, 2021
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
2 changes: 1 addition & 1 deletion .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -1 +1 @@
* @evan-moon @pa-rang @devGW
* @evan-moon @pa-rang @zi-gae
5 changes: 3 additions & 2 deletions .github/workflows/slack-notification.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: PR Slack Notification
# on: [pull_request, pull_request_review, pull_request_review_comment]
on: [pull_request, pull_request_review, pull_request_review_comment]

jobs:
create-pull-request:
Expand All @@ -12,4 +12,5 @@ jobs:
uses: Lubycon/github-reviewer-slack-noti-action@v1.5.1
with:
github-token: ${{ secrets.LUBYCON_GITHUB_TOKEN }}
mattermost-webhook: ${{ secrets.MATTERMOST_WEBHOOK_URL }}
slack-bot-token: ${{ secrets.SLACK_BOT_TOKEN }}
slack-channel-id: ${{ secrets.SLACK_CHANNEL_ID }}
5 changes: 3 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: Test Run
on: [pull_request, pull_request_review, pull_request_review_comment]
# on: [push]

jobs:
build:
Expand Down Expand Up @@ -31,4 +31,5 @@ jobs:
id: pr-reviewer-notify
with:
github-token: ${{ secrets.LUBYCON_GITHUB_TOKEN }}
mattermost-webhook: ${{ secrets.MATTERMOST_WEBHOOK_URL }}
slack-bot-token: ${{ secrets.LUBYCON_SLACK_BOT_TOKEN }}
slack-channel-id: ${{ secrets.TEST_SLACK_CHANNEL_ID }}
12 changes: 7 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@ jobs:
uses: Lubycon/github-reviewer-noti-action@v2.0.0
with:
github-token: ${{ secrets.LUBYCON_GITHUB_TOKEN }}
mattermost-webhook: ${{ secrets.MATTERMOST_WEBHOOK_URL }}
slack-bot-token: ${{ secrets.SLACK_BOT_TOKEN }}
slack-channel-id: ${{ secrets.SLACK_CHANNEL_ID }}
```

## Configuration

| 이름 | 설명 |
| -------------------- | ------------------------------------------------------------------- |
| `github-token` | Github Personal Access Token. `repo` 스코프를 지정해서 생성해주세요 |
| `mattermost-webhook` | 매터모스트 웹훅 URL (존재하면 매터모스트에도 노티를 보냅니다) |
| 이름 | 설명 |
| ------------------ | -------------------------------------------------------------------------------------------------- |
| `github-token` | Github Personal Access Token. `repo` 스코프를 지정해서 생성해주세요 |
| `slack-bot-token` | 메세지를 보낼 슬랙봇 토큰. 루비콘 멤버라면 루비콘의 Org Secrets에 저장된 토큰을 사용할 수 있습니다 |
| `slack-channel-id` | 노티를 쏘고 싶은 슬랙 채널 ID |
7 changes: 5 additions & 2 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@ inputs:
github-token:
description: 'Personal access token with repository rights.'
required: true
mattermost-webhook:
description: 'Mattermost Webhook URL.'
slack-bot-token:
description: "OAuth token for your Slack App Bot to sign requests to Slack's API with."
required: true
slack-channel-id:
description: 'ID of the channel or conversation in Slack you would like messages posted to.'
required: true
runs:
using: 'node12'
Expand Down
42 changes: 42 additions & 0 deletions developers.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
[
{
"email": "bboydart91@gmail.com",
"githubUserName": "evan-moon",
"slackUserId": "U02P1TCRH3N"
},
{
"email": "93kimhyunjun@gmail.com",
"githubUserName": "Junkim93",
"slackUserId": "U02P185665R"
},
{
"email": "somony9292@gmail.com",
"githubUserName": "s-ong-c",
"slackUserId": "U02NZN0V5NW"
},
{
"email": "somony9292@gmail.com",
"githubUserName": "s-ong-c",
"slackUserId": "U02NZN0V5NW"
},
{
"email": "ssong758@gmail.com",
"githubUserName": "ssMinji",
"slackUserId": "U02PPKDU77S"
},
{
"email": "appdler96@gmail.com",
"githubUserName": "pa-rang",
"slackUserId": "U02NLAR38BZ"
},
{
"email": "doscmdev@gmail.com",
"githubUserName": "zi-gae",
"slackUserId": "U02P0214VJP"
},
{
"email": "hyein.ju92@gmail.com",
"githubUserName": "theJunimo",
"slackUserId": "U02P10HAPRQ"
}
]
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@
"dev": "ts-node ./index.ts",
"release": "semantic-release",
"build": "ncc build --source-map --license licenses.txt",
"test": "ts-node ./test/mattermost.ts"
"test": "ts-node ./test/slack.ts"
},
"author": "",
"license": "UNLICENSED",
"dependencies": {
"@actions/core": "^1.2.7",
"@actions/github": "^4.0.0",
"@lubycon/mattermost": "^1.1.14",
"@slack/web-api": "^6.5.1",
"@vercel/ncc": "^0.28.3",
"node-fetch": "^2.6.1",
"ts-node": "^9.1.1",
Expand Down
9 changes: 3 additions & 6 deletions src/models/developer.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
export interface LubyconUser {
name: string;
githubUserName: string;
export interface User {
email: string;
role: string | null;
chapters: string[];
teams: string[];
githubUserName: string;
slackUserId: string;
}
8 changes: 4 additions & 4 deletions src/models/github.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { LubyconUser } from './developer';
import { User } from './developer';

export interface RawGithubUser {
avatar_url: string;
Expand Down Expand Up @@ -43,13 +43,13 @@ export interface GithubPullRequest {
title: string;
body: string;
link: string;
reviewers: LubyconUser[];
owner: LubyconUser;
reviewers: User[];
owner: User;
repository: string;
}

export interface GithubPullRequestComment {
author: LubyconUser;
author: User;
message: string;
}

Expand Down
14 changes: 7 additions & 7 deletions src/utils/github/pullRequests.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as github from '@actions/github';
import { LubyconUser } from 'models/developer';
import { User } from 'models/developer';
import {
RawGithubUser,
RawGithubPullRequestReview,
Expand All @@ -11,15 +11,15 @@ import {
import { fetchDevelopers, getDeveloperByGithubUser } from 'utils/user';
import { getCodeOwners, getRepositoryName } from './repositories';

export async function getPullRequestOwner() {
export function getPullRequestOwner() {
const { pull_request } = github.context.payload;
const developers = await fetchDevelopers();
const developers = fetchDevelopers();
const owner = pull_request?.user as RawGithubUser;
return getDeveloperByGithubUser(developers, owner.login);
}

export async function getAssignedPullRequestReviewers() {
const developers = await fetchDevelopers();
const developers = fetchDevelopers();
const { pull_request } = github.context.payload;
const codeOwners = await getCodeOwners();
const prReviewers: RawGithubUser[] = pull_request?.requested_reviewers;
Expand All @@ -28,7 +28,7 @@ export async function getAssignedPullRequestReviewers() {

return reviewers
.map(user => getDeveloperByGithubUser(developers, user))
.filter<LubyconUser>((user): user is LubyconUser => user != null);
.filter<User>((user): user is User => user != null);
}

export function getRawPullReuqestReview() {
Expand All @@ -40,15 +40,15 @@ export function getRawPullRequestComment() {
}

export async function getDeveloperFromGithubUser(user: RawGithubUser) {
const developers = await fetchDevelopers();
const developers = fetchDevelopers();
const rawGithubUserName = user.login;
return getDeveloperByGithubUser(developers, rawGithubUserName);
}

export async function getPullRequest(): Promise<GithubPullRequest> {
const { pull_request } = github.context.payload;
const reviewers = await getAssignedPullRequestReviewers();
const owner = await getPullRequestOwner();
const owner = getPullRequestOwner();
const repository = getRepositoryName() ?? '';

return {
Expand Down
2 changes: 1 addition & 1 deletion src/utils/github/repositories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { getPullRequestOwner } from './pullRequests';

export async function getCodeOwners() {
const filePath = path.join(process.env.GITHUB_WORKSPACE ?? './', CODEOWNERS_PATH);
const pullRequestOwner = await getPullRequestOwner();
const pullRequestOwner = getPullRequestOwner();
try {
const contents = await readFile(filePath);
const codeOwners = contents
Expand Down
4 changes: 3 additions & 1 deletion src/utils/input.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import * as core from '@actions/core';

export const SLACK_BOT_TOKEN = core.getInput('slack-bot-token');
export const TARGET_SLACK_CHANNEL_ID = core.getInput('slack-channel-id');

export const GITHUB_TOKEN = core.getInput('github-token');
export const MATTERMOST_WEBHOOK_URL = core.getInput('mattermost-webhook');
88 changes: 0 additions & 88 deletions src/utils/mattermost.ts

This file was deleted.

Loading