Skip to content

Commit

Permalink
Feat/fetch users from repo (#51)
Browse files Browse the repository at this point in the history
* feat: 유저 목록을 다른 레포에서 가져오도록 수정

* remove test code

* notification version update
  • Loading branch information
evan-moon authored Dec 1, 2021
1 parent 6177507 commit d8abae9
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/slack-notification.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
- name: Checkout
uses: actions/checkout@master
- name: Fire Notification
uses: Lubycon/github-reviewer-slack-noti-action@v2.1.1
uses: Lubycon/github-reviewer-slack-noti-action@v3.1.0
with:
slack-bot-token: ${{ secrets.SLACK_BOT_TOKEN }}
slack-channel-id: ${{ secrets.SLACK_CHANNEL_ID }}
Expand Down
10 changes: 5 additions & 5 deletions src/utils/github/pullRequests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ import {
import { fetchDevelopers, getDeveloperByGithubUser } from 'utils/user';
import { getCodeOwners, getRepositoryName } from './repositories';

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

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

export async function getDeveloperFromGithubUser(user: RawGithubUser) {
const developers = fetchDevelopers();
const developers = await 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 = getPullRequestOwner();
const owner = await 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 = getPullRequestOwner();
const pullRequestOwner = await getPullRequestOwner();
try {
const contents = await readFile(filePath);
const codeOwners = contents
Expand Down
9 changes: 5 additions & 4 deletions src/utils/user.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { User } from '../models/developer';
import { createSlackMention } from './slack';
import users from '../../developers.json';
import fetch from 'node-fetch';

export function fetchDevelopers() {
return users;
export async function fetchDevelopers() {
const response = await fetch('https://raw.githubusercontent.com/Lubycon/lubycon-users/main/users.json');
return (await response.json()) as User[];
}

export function getDeveloperByGithubUser(developers: User[], githubUserName: string) {
Expand All @@ -24,7 +25,7 @@ export function hasMentionInMessage(message: string) {

async function replaceGithubUserInString(message: string, replacer: (developer: User) => string) {
const words = message.split(/\s/);
const developers = fetchDevelopers();
const developers = await fetchDevelopers();

return words
.map(message => {
Expand Down

0 comments on commit d8abae9

Please sign in to comment.