Skip to content

Commit

Permalink
feat: Change GitHub issuer to GitHub App instead of GitHub account
Browse files Browse the repository at this point in the history
  • Loading branch information
Han-Joon-Hyeok committed Aug 28, 2024
1 parent d0c59f8 commit defa408
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 13 deletions.
5 changes: 4 additions & 1 deletion src/modules/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@ const env = {
githubConfig: {
owner: process.env.GITHUB_OWNER,
repo: process.env.GITHUB_REPO,
auth: process.env.GITHUB_TOKEN
auth: process.env.GITHUB_TOKEN,
appId: process.env.APP_ID,
privateKey: process.env.APP_PRIVATE_KEY,
installationId: process.env.APP_INSTALLATION_ID,
},
dbConfig: {
username: process.env.DATABASE_USERNAME,
Expand Down
24 changes: 12 additions & 12 deletions src/modules/github.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Octokit } from "octokit";
import { Octokit } from "@octokit/rest";
import { createAppAuth } from "@octokit/auth-app";

import { eventType } from "eventType";
import env from "@modules/env";
Expand All @@ -10,29 +11,28 @@ import Get from "./di";
import { content } from "./content";

const octokit = new Octokit({
auth: env.githubConfig.auth,
authStrategy: createAppAuth,
auth: {
appId: env.githubConfig.appId,
privateKey: env.githubConfig.privateKey,
installationId: env.githubConfig.installationId,
},
});

const OWNER = env.githubConfig.owner;
const REPO = env.githubConfig.repo;

const github = async (event: eventType) => {
const repository: IRepository<Events | Exams> = Get.get("Repository");
const logger = new Logger("github");
const body = content(event);
const { owner, repo } = env.githubConfig;

try {
const response = await octokit.request(
`POST /repos/${OWNER}/${REPO}/issues`,
const response = await octokit.issues.create(
{
owner: "OWNER",
repo: "REPO",
owner,
repo,
title: event.name,
body: body,
labels: [env.nodeConfig.type === "event" ? "event" : "exam"],
headers: {
"X-GitHub-Api-Version": "2022-11-28",
},
}
);
logger.latency(200, new Date().getTime());
Expand Down

0 comments on commit defa408

Please sign in to comment.