From 824c3276086677fd8bcd967a2e756fe92acf285a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=ED=99=A9=EC=A4=80=EC=9D=BC?= Date: Tue, 23 Jul 2024 17:54:55 +0900 Subject: [PATCH 01/25] Update assignment-6-ci.yml --- .github/workflows/assignment-6-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/assignment-6-ci.yml b/.github/workflows/assignment-6-ci.yml index 433db70d1..5154202ab 100644 --- a/.github/workflows/assignment-6-ci.yml +++ b/.github/workflows/assignment-6-ci.yml @@ -1,7 +1,7 @@ name: CI Assignment 6 on: - pull_request: + pull_request_target: types: - opened paths: From 108bd591c8c633f24a0bc400697885d754b805fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=ED=99=A9=EC=A4=80=EC=9D=BC?= Date: Tue, 23 Jul 2024 17:58:41 +0900 Subject: [PATCH 02/25] Update pull_request_template.md --- .github/pull_request_template.md | 85 +++----------------------------- 1 file changed, 6 insertions(+), 79 deletions(-) diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md index 728f0f113..7029f3036 100644 --- a/.github/pull_request_template.md +++ b/.github/pull_request_template.md @@ -1,84 +1,11 @@ ## 체크포인트 -### 코드 작성 체크포인트 +### PR 올리기 전에 확인사항 -- 가독성 - - [ ] 변수와 함수의 이름이 용도와 기능을 명확히 나타내는가? - - [ ] 중복되는 로직을 별도의 함수로 추출했는가? - - [ ] 중첩된 if 문을 피하고 조건문을 단순화했는가? - - [ ] 매직 넘버와 반복되는 문자열을 상수로 정의했는가? - - [ ] 데이터 처리에 reduce, filter, map 등의 고차 함수를 사용했는가? - - [ ] 일관된 코딩 스타일, 적절한 들여쓰기, 논리적인 함수 배치로 가독성을 향상시켰는가? -- 단일 책임 원칙 - - [ ] 함수/훅이 하나의 명확한 목적만을 가지고 있는가? - - [ ] 함수/훅의 이름이 그 목적을 명확하게 나타내는가? -- 순수 함수 - - [ ] 동일한 입력에 대해 항상 동일한 출력을 반환하는가? - - [ ] 외부 상태를 변경하지 않는가? - - [ ] 입력 데이터를 직접 수정하지 않고 새로운 데이터를 반환하는가? -- 합성 가능성 - - [ ] 함수/훅을 다른 함수/훅과 쉽게 조합할 수 있는가? -- 관심사 분리 - - [ ] 비즈니스 로직과 UI 로직이 적절히 분리되어 있는가? -- DRY (Don't Repeat Yourself) 원칙 - - [ ] 이 함수/훅이 중복 코드를 제거하는 데 도움이 되는가? -- 테스트 용이성 - - [ ] 함수/훅에 대한 단위 테스트를 쉽게 작성할 수 있는가? - (input에 대한 output을 정의하기 수월한가) +1. head barnch와 sync를 맞춰주세요. -### advanced 과제 체크포인트 +```bash +$ git pull https://github.com/hanghae-plus/front_2nd.git main +``` -- [ ] advanced.test.ts에 있는 시나리오 테스트를 모두 통과한다. -- [ ] 3개 이상의 custom hook을 통해서 리팩토링을 진행했고, 해당 hook에 대한 테스트 코드가 작성되었다. -- [ ] 3개 이상의 순수함수를 통해서 리팩토링을 진행했고, 해당 함수에 대한 테스트 코드가 작성되었다. - - -## 고민했던 부분과 새롭게 알게 된 점 - - -### 고민했던 부분 -- -- - -### 새롭게 알게 된 점 -- -- - -## 해결하지 못한 문제 - -- -- - -## 리뷰 요청 사항 - -- -- - -## 자기 평가 - - -### 성장 포인트 - -1. -2. -3. - -### 개선하고 싶은 부분 -- -- - -## 인사이트 - -현재 작성된 코드가 요구사항에 잘 대응할 수 있는지 자체적으로 점검해보세요. **내가 작성한 코드가 좋은 코드인지 판단해볼 수 있습니다.** - -1. start:advanced로 실행하면 초기 데이터를 localStorage에서 불러오고, 추가하고, 수정하고, 삭제할 수 있다. -2. start:api-mock로 실행하면 초기 데이터를 API를 통해서 불러오고, 추가하고, 수정하고, 삭제할 수 있다. - - API는 [msw](https://mswjs.io/)로 만든다. -3. 회원 등급별 할인 기능 - - 관리자는 회원 등급을 추가할 수 있다. - - 회원 등급에 따른 할인율이 존재한다. - - 예시) 일반: 3%, 실버: 5%, 골드: 7%, VIP: 10%, - - 장바구니 페이지에서 현재 회원 등급을 임의로 선택할 수 있다. - - 회원 등급에 따라 총 구매 가격에 할인율이 적용되어야 한다. - -이 외에도 다양한 요구사항이 추가될 수 있습니다. +2. base branch를 `hanghae-plus:main`이 아니라 `hanghae-plus:<본안아이디>` 로 수정해주세요 확인해주세요. From 41dcf59b605b78f5f128578986ff5fa04936eccc Mon Sep 17 00:00:00 2001 From: junilhwang Date: Tue, 23 Jul 2024 18:29:11 +0900 Subject: [PATCH 03/25] =?UTF-8?q?chore:=20assignment-6=20ci=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/assignment-6-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/assignment-6-ci.yml b/.github/workflows/assignment-6-ci.yml index 5154202ab..433db70d1 100644 --- a/.github/workflows/assignment-6-ci.yml +++ b/.github/workflows/assignment-6-ci.yml @@ -1,7 +1,7 @@ name: CI Assignment 6 on: - pull_request_target: + pull_request: types: - opened paths: From 534b890cfcfdde6ce7ed57c77a8b9c3013049fcb Mon Sep 17 00:00:00 2001 From: yoosion030 Date: Wed, 24 Jul 2024 00:33:42 +0900 Subject: [PATCH 04/25] =?UTF-8?q?6=EC=A3=BC=EC=B0=A8=20=EA=B3=BC=EC=A0=9C?= =?UTF-8?q?=20=ED=92=80=EC=9D=B4=20-=20basic?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: yoosion030 --- .github/workflows/assignment-6-ci.yml | 247 +++++++++++++++++++++++-- packages/assignment-6/.lighthouserc.js | 14 ++ packages/assignment-6/package.json | 6 +- 3 files changed, 254 insertions(+), 13 deletions(-) create mode 100644 packages/assignment-6/.lighthouserc.js diff --git a/.github/workflows/assignment-6-ci.yml b/.github/workflows/assignment-6-ci.yml index 433db70d1..cdc6f2c73 100644 --- a/.github/workflows/assignment-6-ci.yml +++ b/.github/workflows/assignment-6-ci.yml @@ -4,36 +4,261 @@ on: pull_request: types: - opened + - reopened + - synchronize paths: - - 'packages/assignment-6/**' + - "packages/assignment-6/**" + - ".github/workflows/assignment-6-ci.yml" jobs: build: runs-on: ubuntu-latest steps: - - name: job1 구현 - run: echo "job1의 내용을 구현해주세요" + - uses: actions/checkout@v4 + - uses: pnpm/action-setup@v4 + with: + version: latest + - uses: actions/setup-node@v4 + with: + node-version: 20 + cache: "pnpm" + + - name: Build + run: | + pnpm install + pnpm -F assignment-6 build lint: runs-on: ubuntu-latest steps: - - name: job2 구현 - run: echo "job2의 내용을 구현해주세요" + - uses: actions/checkout@v4 + - uses: pnpm/action-setup@v4 + with: + version: latest + - uses: actions/setup-node@v4 + with: + node-version: 20 + cache: "pnpm" + + - name: Lint + run: | + pnpm install + pnpm -F assignment-6 lint > eslint_report.txt + - name: Lint Failure + if: failure() + uses: actions/github-script@v6 + with: + github-token: ${{ secrets.TOKEN_FOR_CI }} + script: | + const fs = require('fs') + const eslintReport = fs.readFileSync('eslint_report.txt', 'utf8') + github.rest.issues.createComment({ + issue_number: context.issue.number, + owner: context.repo.owner, + repo: context.repo.repo, + body: ` + ## ESLint Results + + ${eslintReport} + ` + }); test: runs-on: ubuntu-latest steps: - - name: job3 구현 - run: echo "job3의 내용을 구현해주세요" + - uses: actions/checkout@v4 + - uses: pnpm/action-setup@v4 + with: + version: latest + - uses: actions/setup-node@v4 + with: + node-version: 20 + cache: "pnpm" + + - name: Testing and Coverage + run: | + pnpm install + pnpm -F assignment-6 test + pnpm -F assignment-6 coverage + + - name: Comment Test Coverage + uses: actions/github-script@v6 + if: success() + with: + github-token: ${{ secrets.TOKEN_FOR_CI }} + script: | + const fs = require('fs'); + + const coverage = JSON.parse(fs.readFileSync("packages/assignment-6/coverage/coverage-summary.json", 'utf8')); + const totalCoverage = coverage.total; + + const coverageComment = ` + + ## 테스트 성공 ✅ + ### 커버리지 결과 + + - 라인 커버리지: ${totalCoverage.lines.pct}% + - 브랜치 커버리지: ${totalCoverage.branches.pct}% + - 함수 커버리지: ${totalCoverage.functions.pct}% + - 구문 커버리지: ${totalCoverage.statements.pct}% + `; + + github.rest.issues.createComment({ + issue_number: context.issue.number, + owner: context.repo.owner, + repo: context.repo.repo, + body: coverageComment + }); + + - name: Comment Test Coverage on Failure + if: failure() + uses: actions/github-script@v6 + with: + github-token: ${{secrets.TOKEN_FOR_CI}} + script: | + const coverageComment = ` + ## 테스트 실패 ❌ + + 테스트 코드를 확인해주세요. + ` + github.rest.issues.createComment({ + issue_number: context.issue.number, + owner: context.repo.owner, + repo: context.repo.repo, + body: coverageComment + }); lighthouse: runs-on: ubuntu-latest + steps: - - name: job4 구현 - run: echo "job4의 내용을 구현해주세요" + - uses: actions/checkout@v4 + - uses: pnpm/action-setup@v4 + with: + version: latest + - uses: actions/setup-node@v4 + with: + node-version: 20 + cache: "pnpm" + + - name: Install Lighthouse CI + run: | + npm i -E -g @lhci/cli + pnpm install + - name: Build Local Server + run: | + pnpm -F assignment-6 build + pnpm -F assignment-6 lighthouse + - name: Report Lighthouse + if: success() + uses: actions/github-script@v6 + env: + LHCI_GITHUB_APP_TOKEN: ${{ secrets.LHCI_GITHUB_APP_TOKEN }} + with: + github-token: ${{ secrets.TOKEN_FOR_CI }} + script: | + const fs = require('fs'); + const results = JSON.parse(fs.readFileSync("packages/assignment-6/lhci_reports/manifest.json", 'utf-8')) + console.log(results) + + let comments = ""; + + results.forEach((result) => { + const { summary, jsonPath } = result; + const details = JSON.parse(fs.readFileSync(jsonPath)) + const { audits } = details; + + const formatResult = (res) => Math.round(res * 100); + + Object.keys(summary).forEach( + (key) => (summary[key] = formatResult(summary[key])) + ); + + + const score = (res) => (res >= 90 ? "🟢" : res >= 50 ? "🟠" : "🔴"); + + const comment = [ + `⚡️ Lighthouse report!`, + `| Category | Score |`, + `| --- | --- |`, + `| ${score(summary.performance)} Performance | ${summary.performance} |`, + `| ${score(summary.accessibility)} Accessibility | ${ + summary.accessibility + } |`, + `| ${score(summary['best-practices'])} Best practices | ${ + summary['best-practices'] + } |`, + `| ${score(summary.seo)} SEO | ${summary.seo} |`, + '' + ].join('\n'); + + const detail = [ + `📊 Lighthouse Detail`, + `| Category | Score |`, + `| --- | --- |`, + `| ${score( + audits['first-contentful-paint'].score * 100 + )} First Contentful Paint | ${ + audits['first-contentful-paint'].displayValue + } |`, + `| ${score( + audits['largest-contentful-paint'].score * 100 + )} Largest Contentful Paint | ${ + audits['largest-contentful-paint'].displayValue + } |`, + `| ${score( + audits['total-blocking-time'].score * 100 + )} Total Blocking Time | ${audits['total-blocking-time'].displayValue} |`, + `| ${score( + audits['cumulative-layout-shift'].score * 100 + )} Cumulative Layout Shift | ${ + audits['cumulative-layout-shift'].displayValue + } |`, + `| ${score(audits['speed-index'].score * 100)} Speed Index | ${ + audits['speed-index'].displayValue + } |`, + ].join('\n'); + + comments += comment + "\n" + detail + "\n"; + }); + + github.rest.issues.createComment({ + issue_number: context.issue.number, + owner: context.repo.owner, + repo: context.repo.repo, + body: comments + }); assign_reviewer: runs-on: ubuntu-latest steps: - - name: job5 구현 - run: echo "job5의 내용을 구현해주세요" + - uses: actions/checkout@v4 + - uses: pnpm/action-setup@v4 + with: + version: latest + - uses: actions/setup-node@v4 + with: + node-version: 20 + cache: "pnpm" + + - name: Assign Reviewer + uses: actions/github-script@v6 + with: + github-token: ${{secrets.TOKEN_FOR_CI}} + script: | + const reviewers = ["yoosion030", "dhp94d", "lydiahjchung", "callipenguin"]; + const randomReviewer = reviewers[Math.floor(Math.random() * reviewers.length)]; + + github.rest.issues.createComment({ + issue_number: context.issue.number, + owner: context.repo.owner, + repo: context.repo.repo, + body: `@, 리뷰를 부탁드립니다.` + }); + + github.rest.pulls.requestReviewers({ + pull_number: context.issue.number, + owner: context.repo.owner, + repo: context.repo.repo, + reviewers: [randomReviewer] + }); diff --git a/packages/assignment-6/.lighthouserc.js b/packages/assignment-6/.lighthouserc.js new file mode 100644 index 000000000..1e4abbdb8 --- /dev/null +++ b/packages/assignment-6/.lighthouserc.js @@ -0,0 +1,14 @@ +module.exports = { + ci: { + collect: { + staticDistDir: "./dist", + url: ["http://localhost:5173"], + numberOfRuns: 1, + }, + upload: { + target: "filesystem", + outputDir: "./lhci_reports", + reportFilenamePattern: "%%PATHNAME%%-%%DATETIME%%-report.%%EXTENSION%%", + }, + }, +}; diff --git a/packages/assignment-6/package.json b/packages/assignment-6/package.json index 2ed9d0369..5923ead6e 100644 --- a/packages/assignment-6/package.json +++ b/packages/assignment-6/package.json @@ -2,13 +2,14 @@ "name": "assignment-6", "private": true, "version": "0.0.0", - "type": "module", "scripts": { "start": "vite", "test": "vitest", "test:ui": "vitest --ui", "build": "tsc -b && vite build", - "lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0" + "lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0", + "coverage": "vitest --coverage.enabled --reporter=junit --coverage.reporter=json-summary", + "lighthouse": "lhci autorun" }, "dependencies": { "react": "^18.3.1", @@ -23,6 +24,7 @@ "@typescript-eslint/eslint-plugin": "^7.13.1", "@typescript-eslint/parser": "^7.13.1", "@vitejs/plugin-react-swc": "^3.5.0", + "@vitest/coverage-v8": "^2.0.4", "@vitest/ui": "^1.6.0", "eslint": "^8.57.0", "eslint-plugin-react-hooks": "^4.6.2", From 1dc3c6158e981a70079d837b5adf528b184083af Mon Sep 17 00:00:00 2001 From: yoosion030 Date: Wed, 24 Jul 2024 00:35:27 +0900 Subject: [PATCH 05/25] =?UTF-8?q?feat:=20=EB=9E=9C=EB=8D=A4=20=EB=A6=AC?= =?UTF-8?q?=EB=B7=B0=EC=96=B4=20=EB=93=B1=EB=A1=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: yoosion030 --- .github/workflows/assignment-6-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/assignment-6-ci.yml b/.github/workflows/assignment-6-ci.yml index cdc6f2c73..7583a2e63 100644 --- a/.github/workflows/assignment-6-ci.yml +++ b/.github/workflows/assignment-6-ci.yml @@ -253,7 +253,7 @@ jobs: issue_number: context.issue.number, owner: context.repo.owner, repo: context.repo.repo, - body: `@, 리뷰를 부탁드립니다.` + body: `@${randomReviewer}, 리뷰를 부탁드립니다.` }); github.rest.pulls.requestReviewers({ From 2f513affaf84db345f4b53e0f25ee19780866186 Mon Sep 17 00:00:00 2001 From: yoosion030 Date: Wed, 24 Jul 2024 00:40:41 +0900 Subject: [PATCH 06/25] =?UTF-8?q?feat:=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20?= =?UTF-8?q?=EC=BD=94=EB=93=9C=20=EC=8A=A4=ED=81=AC=EB=A6=BD=ED=8A=B8=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: yoosion030 --- .github/workflows/assignment-6-ci.yml | 14 +++++++------- packages/assignment-6/package.json | 1 - 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/.github/workflows/assignment-6-ci.yml b/.github/workflows/assignment-6-ci.yml index 7583a2e63..89eb4a93d 100644 --- a/.github/workflows/assignment-6-ci.yml +++ b/.github/workflows/assignment-6-ci.yml @@ -52,7 +52,7 @@ jobs: script: | const fs = require('fs') const eslintReport = fs.readFileSync('eslint_report.txt', 'utf8') - github.rest.issues.createComment({ + await github.rest.issues.createComment({ issue_number: context.issue.number, owner: context.repo.owner, repo: context.repo.repo, @@ -77,7 +77,7 @@ jobs: - name: Testing and Coverage run: | - pnpm install + pnpm install --prefer-frozen-lockfile pnpm -F assignment-6 test pnpm -F assignment-6 coverage @@ -103,7 +103,7 @@ jobs: - 구문 커버리지: ${totalCoverage.statements.pct}% `; - github.rest.issues.createComment({ + await github.rest.issues.createComment({ issue_number: context.issue.number, owner: context.repo.owner, repo: context.repo.repo, @@ -121,7 +121,7 @@ jobs: 테스트 코드를 확인해주세요. ` - github.rest.issues.createComment({ + await ithub.rest.issues.createComment({ issue_number: context.issue.number, owner: context.repo.owner, repo: context.repo.repo, @@ -222,7 +222,7 @@ jobs: comments += comment + "\n" + detail + "\n"; }); - github.rest.issues.createComment({ + await github.rest.issues.createComment({ issue_number: context.issue.number, owner: context.repo.owner, repo: context.repo.repo, @@ -249,14 +249,14 @@ jobs: const reviewers = ["yoosion030", "dhp94d", "lydiahjchung", "callipenguin"]; const randomReviewer = reviewers[Math.floor(Math.random() * reviewers.length)]; - github.rest.issues.createComment({ + await github.rest.issues.createComment({ issue_number: context.issue.number, owner: context.repo.owner, repo: context.repo.repo, body: `@${randomReviewer}, 리뷰를 부탁드립니다.` }); - github.rest.pulls.requestReviewers({ + await github.rest.pulls.requestReviewers({ pull_number: context.issue.number, owner: context.repo.owner, repo: context.repo.repo, diff --git a/packages/assignment-6/package.json b/packages/assignment-6/package.json index 5923ead6e..b98bc52bb 100644 --- a/packages/assignment-6/package.json +++ b/packages/assignment-6/package.json @@ -24,7 +24,6 @@ "@typescript-eslint/eslint-plugin": "^7.13.1", "@typescript-eslint/parser": "^7.13.1", "@vitejs/plugin-react-swc": "^3.5.0", - "@vitest/coverage-v8": "^2.0.4", "@vitest/ui": "^1.6.0", "eslint": "^8.57.0", "eslint-plugin-react-hooks": "^4.6.2", From afda6b0d1d2471f232839a42b62e451d4e78e7a0 Mon Sep 17 00:00:00 2001 From: yoosion030 Date: Wed, 24 Jul 2024 00:42:21 +0900 Subject: [PATCH 07/25] =?UTF-8?q?feat:=20=20package.json=20=EC=97=85?= =?UTF-8?q?=EB=8D=B0=EC=9D=B4=ED=8A=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: yoosion030 --- .github/workflows/assignment-6-ci.yml | 2 +- packages/assignment-6/package.json | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/assignment-6-ci.yml b/.github/workflows/assignment-6-ci.yml index 89eb4a93d..2221eca22 100644 --- a/.github/workflows/assignment-6-ci.yml +++ b/.github/workflows/assignment-6-ci.yml @@ -121,7 +121,7 @@ jobs: 테스트 코드를 확인해주세요. ` - await ithub.rest.issues.createComment({ + await github.rest.issues.createComment({ issue_number: context.issue.number, owner: context.repo.owner, repo: context.repo.repo, diff --git a/packages/assignment-6/package.json b/packages/assignment-6/package.json index b98bc52bb..5923ead6e 100644 --- a/packages/assignment-6/package.json +++ b/packages/assignment-6/package.json @@ -24,6 +24,7 @@ "@typescript-eslint/eslint-plugin": "^7.13.1", "@typescript-eslint/parser": "^7.13.1", "@vitejs/plugin-react-swc": "^3.5.0", + "@vitest/coverage-v8": "^2.0.4", "@vitest/ui": "^1.6.0", "eslint": "^8.57.0", "eslint-plugin-react-hooks": "^4.6.2", From e81f3481e3b005fd820c372e46be6a73e7d778a5 Mon Sep 17 00:00:00 2001 From: yoosion030 Date: Wed, 24 Jul 2024 00:45:42 +0900 Subject: [PATCH 08/25] =?UTF-8?q?feat:=20=EC=9D=98=EC=A1=B4=EC=84=B1=20?= =?UTF-8?q?=EC=84=A4=EC=B9=98=20=EB=B0=A9=EC=8B=9D=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: yoosion030 --- .github/workflows/assignment-6-ci.yml | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/.github/workflows/assignment-6-ci.yml b/.github/workflows/assignment-6-ci.yml index 2221eca22..dedfa9bca 100644 --- a/.github/workflows/assignment-6-ci.yml +++ b/.github/workflows/assignment-6-ci.yml @@ -25,7 +25,7 @@ jobs: - name: Build run: | - pnpm install + pnpm install --prefer-frozen-lockfile pnpm -F assignment-6 build lint: @@ -42,7 +42,7 @@ jobs: - name: Lint run: | - pnpm install + pnpm install --prefer-frozen-lockfile pnpm -F assignment-6 lint > eslint_report.txt - name: Lint Failure if: failure() @@ -143,7 +143,7 @@ jobs: - name: Install Lighthouse CI run: | - npm i -E -g @lhci/cli + npm i @lhci/cli --prefer-frozen-lockfile pnpm install - name: Build Local Server run: | @@ -174,7 +174,6 @@ jobs: (key) => (summary[key] = formatResult(summary[key])) ); - const score = (res) => (res >= 90 ? "🟢" : res >= 50 ? "🟠" : "🔴"); const comment = [ From b4e4c7ff2324c75870fb2caea7d87275ce5cb18d Mon Sep 17 00:00:00 2001 From: yoosion030 Date: Wed, 24 Jul 2024 00:47:39 +0900 Subject: [PATCH 09/25] =?UTF-8?q?feat:=20lighthouse=20=EC=9D=98=EC=A1=B4?= =?UTF-8?q?=EC=84=B1=20=EC=84=A4=EC=B9=98=20=EB=B0=A9=EC=8B=9D=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: yoosion030 --- .github/workflows/assignment-6-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/assignment-6-ci.yml b/.github/workflows/assignment-6-ci.yml index dedfa9bca..42a565089 100644 --- a/.github/workflows/assignment-6-ci.yml +++ b/.github/workflows/assignment-6-ci.yml @@ -143,7 +143,7 @@ jobs: - name: Install Lighthouse CI run: | - npm i @lhci/cli --prefer-frozen-lockfile + npm i -g @lhci/cli --prefer-frozen-lockfile pnpm install - name: Build Local Server run: | From 018fd31c3bfe5aec3b46fa03e8a4329c439fb9d9 Mon Sep 17 00:00:00 2001 From: yoosion030 Date: Wed, 24 Jul 2024 00:49:34 +0900 Subject: [PATCH 10/25] =?UTF-8?q?feat:=20lighthouse=20=EC=9D=98=EC=A1=B4?= =?UTF-8?q?=EC=84=B1=20=EC=84=A4=EC=B9=98=20=EB=B0=A9=EC=8B=9D=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: yoosion030 --- .github/workflows/assignment-6-ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/assignment-6-ci.yml b/.github/workflows/assignment-6-ci.yml index 42a565089..f04ad0143 100644 --- a/.github/workflows/assignment-6-ci.yml +++ b/.github/workflows/assignment-6-ci.yml @@ -143,8 +143,8 @@ jobs: - name: Install Lighthouse CI run: | - npm i -g @lhci/cli --prefer-frozen-lockfile - pnpm install + npm i -g @lhci/cli + pnpm install --prefer-frozen-lockfile - name: Build Local Server run: | pnpm -F assignment-6 build From 58a66aa5024034ec6e0f93d17390b602ef8fa60f Mon Sep 17 00:00:00 2001 From: yoosion030 Date: Wed, 24 Jul 2024 00:50:16 +0900 Subject: [PATCH 11/25] =?UTF-8?q?fix:=20=EB=A6=B0=ED=8A=B8=20=EC=97=90?= =?UTF-8?q?=EB=9F=AC=20=ED=95=B4=EA=B2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: yoosion030 --- packages/assignment-6/src/main.tsx | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/packages/assignment-6/src/main.tsx b/packages/assignment-6/src/main.tsx index db8548ee8..eb97831a8 100644 --- a/packages/assignment-6/src/main.tsx +++ b/packages/assignment-6/src/main.tsx @@ -1,11 +1,10 @@ -import React from 'react' -import ReactDOM from 'react-dom/client' -import App from './App.tsx' -import { forLintError } from './forLintError.ts' +import React from "react"; +import ReactDOM from "react-dom/client"; +import App from "./App.tsx"; +// import { forLintError } from './forLintError.ts' - -ReactDOM.createRoot(document.getElementById('root')!).render( +ReactDOM.createRoot(document.getElementById("root")!).render( - , -) + +); From 9f10dbdd57cd4889bcf9cfec07349f819ef8a970 Mon Sep 17 00:00:00 2001 From: yoosion030 Date: Thu, 25 Jul 2024 00:00:53 +0900 Subject: [PATCH 12/25] =?UTF-8?q?feat:=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20?= =?UTF-8?q?=EC=BB=A4=EB=B2=84=EB=A6=AC=EC=A7=80=20scripts=20js=20=EC=BD=94?= =?UTF-8?q?=EB=93=9C=EB=A1=9C=20=EB=B6=84=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: yoosion030 --- .github/scripts/comment.js | 0 .github/scripts/test-coverage.js | 37 +++++++++++++++++++++++++++ .github/workflows/assignment-6-ci.yml | 37 +++++++-------------------- 3 files changed, 46 insertions(+), 28 deletions(-) create mode 100644 .github/scripts/comment.js create mode 100644 .github/scripts/test-coverage.js diff --git a/.github/scripts/comment.js b/.github/scripts/comment.js new file mode 100644 index 000000000..e69de29bb diff --git a/.github/scripts/test-coverage.js b/.github/scripts/test-coverage.js new file mode 100644 index 000000000..41f163758 --- /dev/null +++ b/.github/scripts/test-coverage.js @@ -0,0 +1,37 @@ +const reportTestSuccess = async ({ totalCoverage, github, context }) => { + const coverageComment = ` +## 테스트 성공 ✅ +### 커버리지 결과 + +- 라인 커버리지: ${totalCoverage.lines.pct}% +- 브랜치 커버리지: ${totalCoverage.branches.pct}% +- 함수 커버리지: ${totalCoverage.functions.pct}% +- 구문 커버리지: ${totalCoverage.statements.pct}% +`; + + await github.rest.issues.createComment({ + issue_number: context.issue.number, + owner: context.repo.owner, + repo: context.repo.repo, + body: coverageComment, + }); +}; + +const reportTestFailure = async ({ github, context }) => { + const coverageComment = ` +## 테스트 실패 ❌ + +테스트 코드를 확인해주세요. +`; + await github.rest.issues.createComment({ + issue_number: context.issue.number, + owner: context.repo.owner, + repo: context.repo.repo, + body: coverageComment, + }); +}; + +module.exports = { + reportTestSuccess, + reportTestFailure, +}; diff --git a/.github/workflows/assignment-6-ci.yml b/.github/workflows/assignment-6-ci.yml index f04ad0143..b49054264 100644 --- a/.github/workflows/assignment-6-ci.yml +++ b/.github/workflows/assignment-6-ci.yml @@ -88,26 +88,13 @@ jobs: github-token: ${{ secrets.TOKEN_FOR_CI }} script: | const fs = require('fs'); - const coverage = JSON.parse(fs.readFileSync("packages/assignment-6/coverage/coverage-summary.json", 'utf8')); - const totalCoverage = coverage.total; - - const coverageComment = ` - - ## 테스트 성공 ✅ - ### 커버리지 결과 - - - 라인 커버리지: ${totalCoverage.lines.pct}% - - 브랜치 커버리지: ${totalCoverage.branches.pct}% - - 함수 커버리지: ${totalCoverage.functions.pct}% - - 구문 커버리지: ${totalCoverage.statements.pct}% - `; - await github.rest.issues.createComment({ - issue_number: context.issue.number, - owner: context.repo.owner, - repo: context.repo.repo, - body: coverageComment + const testCoverage = require('.github/scripts/test-coverage.js'); + await testCoverage.reportTestSuccess({ + totalCoverage: coverage.total, + context, + github }); - name: Comment Test Coverage on Failure @@ -116,16 +103,10 @@ jobs: with: github-token: ${{secrets.TOKEN_FOR_CI}} script: | - const coverageComment = ` - ## 테스트 실패 ❌ - - 테스트 코드를 확인해주세요. - ` - await github.rest.issues.createComment({ - issue_number: context.issue.number, - owner: context.repo.owner, - repo: context.repo.repo, - body: coverageComment + const testCoverage = require('.github/scripts/test-coverage.js'); + await testCoverage.reportTestFailure({ + context, + github }); lighthouse: From 4b4cac03c77feff4b9b11c19c6ce2d53a0468c6b Mon Sep 17 00:00:00 2001 From: yoosion030 Date: Thu, 25 Jul 2024 00:09:25 +0900 Subject: [PATCH 13/25] =?UTF-8?q?feat:=20=EB=A6=B0=ED=8A=B8=20scripts=20js?= =?UTF-8?q?=20=EC=BD=94=EB=93=9C=EB=A1=9C=20=EB=B6=84=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: yoosion030 --- .github/scripts/lint.js | 26 ++++++++++++++++++++++ .github/workflows/assignment-6-ci.yml | 32 +++++++++++++++++++-------- 2 files changed, 49 insertions(+), 9 deletions(-) create mode 100644 .github/scripts/lint.js diff --git a/.github/scripts/lint.js b/.github/scripts/lint.js new file mode 100644 index 000000000..4089d40d3 --- /dev/null +++ b/.github/scripts/lint.js @@ -0,0 +1,26 @@ +const reportLintSuccess = async ({ context, github }) => { + await github.rest.issues.createComment({ + issue_number: context.issue.number, + owner: context.repo.owner, + repo: context.repo.repo, + body: `Lint 성공 🎉`, + }); +}; + +const reportLintFailure = async ({ eslintReport, context, github }) => { + await github.rest.issues.createComment({ + issue_number: context.issue.number, + owner: context.repo.owner, + repo: context.repo.repo, + body: ` +## ESLint Results + +${eslintReport} +`, + }); +}; + +module.exports = { + reportLintSuccess, + reportLintFailure, +}; diff --git a/.github/workflows/assignment-6-ci.yml b/.github/workflows/assignment-6-ci.yml index b49054264..48aaa3891 100644 --- a/.github/workflows/assignment-6-ci.yml +++ b/.github/workflows/assignment-6-ci.yml @@ -44,6 +44,22 @@ jobs: run: | pnpm install --prefer-frozen-lockfile pnpm -F assignment-6 lint > eslint_report.txt + + - name: Lint Success + if: success() + uses: actions/github-script@v6 + with: + github-token: ${{ secrets.TOKEN_FOR_CI }} + script: | + const fs = require('fs') + const eslintReport = fs.readFileSync('eslint_report.txt', 'utf8') + + const lint = require('.github/scripts/lint.js'); + await lint.reportLintSuccess({ + context, + github + }); + - name: Lint Failure if: failure() uses: actions/github-script@v6 @@ -52,15 +68,12 @@ jobs: script: | const fs = require('fs') const eslintReport = fs.readFileSync('eslint_report.txt', 'utf8') - await github.rest.issues.createComment({ - issue_number: context.issue.number, - owner: context.repo.owner, - repo: context.repo.repo, - body: ` - ## ESLint Results - ${eslintReport} - ` + const lint = require('.github/scripts/lint.js'); + await lint.reportLintFailure({ + eslintReport, + context, + github }); test: @@ -126,10 +139,12 @@ jobs: run: | npm i -g @lhci/cli pnpm install --prefer-frozen-lockfile + - name: Build Local Server run: | pnpm -F assignment-6 build pnpm -F assignment-6 lighthouse + - name: Report Lighthouse if: success() uses: actions/github-script@v6 @@ -140,7 +155,6 @@ jobs: script: | const fs = require('fs'); const results = JSON.parse(fs.readFileSync("packages/assignment-6/lhci_reports/manifest.json", 'utf-8')) - console.log(results) let comments = ""; From 6827dd3f246dd96f0fe7e5e1b4b9482a835bb095 Mon Sep 17 00:00:00 2001 From: yoosion030 Date: Thu, 25 Jul 2024 00:16:25 +0900 Subject: [PATCH 14/25] =?UTF-8?q?feat:=20lighthouse=20scripts=20js=20?= =?UTF-8?q?=EC=BD=94=EB=93=9C=EB=A1=9C=20=EB=B6=84=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: yoosion030 --- .github/scripts/lighthouse.js | 82 ++++++++++++++++++++++++ .github/workflows/assignment-6-ci.yml | 92 +++++++-------------------- 2 files changed, 106 insertions(+), 68 deletions(-) create mode 100644 .github/scripts/lighthouse.js diff --git a/.github/scripts/lighthouse.js b/.github/scripts/lighthouse.js new file mode 100644 index 000000000..00b680c81 --- /dev/null +++ b/.github/scripts/lighthouse.js @@ -0,0 +1,82 @@ +const reportLighthouseSuccess = async ({ github, context, results }) => { + let comments = ""; + + results.forEach((result) => { + const { summary, jsonPath } = result; + const details = JSON.parse(fs.readFileSync(jsonPath)); + const { audits } = details; + + const formatResult = (res) => Math.round(res * 100); + + Object.keys(summary).forEach( + (key) => (summary[key] = formatResult(summary[key])) + ); + + const score = (res) => (res >= 90 ? "🟢" : res >= 50 ? "🟠" : "🔴"); + + const comment = [ + `⚡️ Lighthouse report!`, + `| Category | Score |`, + `| --- | --- |`, + `| ${score(summary.performance)} Performance | ${summary.performance} |`, + `| ${score(summary.accessibility)} Accessibility | ${ + summary.accessibility + } |`, + `| ${score(summary["best-practices"])} Best practices | ${ + summary["best-practices"] + } |`, + `| ${score(summary.seo)} SEO | ${summary.seo} |`, + "", + ].join("\n"); + + const detail = [ + `📊 Lighthouse Detail`, + `| Category | Score |`, + `| --- | --- |`, + `| ${score( + audits["first-contentful-paint"].score * 100 + )} First Contentful Paint | ${ + audits["first-contentful-paint"].displayValue + } |`, + `| ${score( + audits["largest-contentful-paint"].score * 100 + )} Largest Contentful Paint | ${ + audits["largest-contentful-paint"].displayValue + } |`, + `| ${score( + audits["total-blocking-time"].score * 100 + )} Total Blocking Time | ${audits["total-blocking-time"].displayValue} |`, + `| ${score( + audits["cumulative-layout-shift"].score * 100 + )} Cumulative Layout Shift | ${ + audits["cumulative-layout-shift"].displayValue + } |`, + `| ${score(audits["speed-index"].score * 100)} Speed Index | ${ + audits["speed-index"].displayValue + } |`, + ].join("\n"); + + comments += comment + "\n" + detail + "\n"; + }); + + await github.rest.issues.createComment({ + issue_number: context.issue.number, + owner: context.repo.owner, + repo: context.repo.repo, + body: comments, + }); +}; + +const reportLighthouseFailure = async ({ github, context }) => { + await github.rest.issues.createComment({ + issue_number: context.issue.number, + owner: context.repo.owner, + repo: context.repo.repo, + body: `빌드가 실패하여 Lighthouse 결과를 측정할 수 없습니다.`, + }); +}; + +module.exports = { + reportLighthouseSuccess, + reportLighthouseFailure, +}; diff --git a/.github/workflows/assignment-6-ci.yml b/.github/workflows/assignment-6-ci.yml index 48aaa3891..e66fc9811 100644 --- a/.github/workflows/assignment-6-ci.yml +++ b/.github/workflows/assignment-6-ci.yml @@ -45,7 +45,7 @@ jobs: pnpm install --prefer-frozen-lockfile pnpm -F assignment-6 lint > eslint_report.txt - - name: Lint Success + - name: Report Lint Success if: success() uses: actions/github-script@v6 with: @@ -60,7 +60,7 @@ jobs: github }); - - name: Lint Failure + - name: Report Lint Failure if: failure() uses: actions/github-script@v6 with: @@ -94,7 +94,7 @@ jobs: pnpm -F assignment-6 test pnpm -F assignment-6 coverage - - name: Comment Test Coverage + - name: Report Test Coverage uses: actions/github-script@v6 if: success() with: @@ -110,7 +110,7 @@ jobs: github }); - - name: Comment Test Coverage on Failure + - name: Report Test Coverage on Failure if: failure() uses: actions/github-script@v6 with: @@ -156,71 +156,27 @@ jobs: const fs = require('fs'); const results = JSON.parse(fs.readFileSync("packages/assignment-6/lhci_reports/manifest.json", 'utf-8')) - let comments = ""; - - results.forEach((result) => { - const { summary, jsonPath } = result; - const details = JSON.parse(fs.readFileSync(jsonPath)) - const { audits } = details; - - const formatResult = (res) => Math.round(res * 100); - - Object.keys(summary).forEach( - (key) => (summary[key] = formatResult(summary[key])) - ); - - const score = (res) => (res >= 90 ? "🟢" : res >= 50 ? "🟠" : "🔴"); - - const comment = [ - `⚡️ Lighthouse report!`, - `| Category | Score |`, - `| --- | --- |`, - `| ${score(summary.performance)} Performance | ${summary.performance} |`, - `| ${score(summary.accessibility)} Accessibility | ${ - summary.accessibility - } |`, - `| ${score(summary['best-practices'])} Best practices | ${ - summary['best-practices'] - } |`, - `| ${score(summary.seo)} SEO | ${summary.seo} |`, - '' - ].join('\n'); - - const detail = [ - `📊 Lighthouse Detail`, - `| Category | Score |`, - `| --- | --- |`, - `| ${score( - audits['first-contentful-paint'].score * 100 - )} First Contentful Paint | ${ - audits['first-contentful-paint'].displayValue - } |`, - `| ${score( - audits['largest-contentful-paint'].score * 100 - )} Largest Contentful Paint | ${ - audits['largest-contentful-paint'].displayValue - } |`, - `| ${score( - audits['total-blocking-time'].score * 100 - )} Total Blocking Time | ${audits['total-blocking-time'].displayValue} |`, - `| ${score( - audits['cumulative-layout-shift'].score * 100 - )} Cumulative Layout Shift | ${ - audits['cumulative-layout-shift'].displayValue - } |`, - `| ${score(audits['speed-index'].score * 100)} Speed Index | ${ - audits['speed-index'].displayValue - } |`, - ].join('\n'); - - comments += comment + "\n" + detail + "\n"; + const lighthouse = require('.github/scripts/lighthouse.js'); + await lighthouse.reportLighthouseSuccess({ + results, + context, + github }); - await github.rest.issues.createComment({ - issue_number: context.issue.number, - owner: context.repo.owner, - repo: context.repo.repo, - body: comments + - name: Report Lighthouse on Failure + if: failure() + uses: actions/github-script@v6 + env: + LHCI_GITHUB_APP_TOKEN: ${{ secrets.LHCI_GITHUB_APP_TOKEN }} + with: + github-token: ${{ secrets.TOKEN_FOR_CI }} + script: | + const fs = require('fs'); + + const lighthouse = require('.github/scripts/lighthouse.js'); + await lighthouse.reportLighthouseFailure({ + context, + github }); assign_reviewer: @@ -243,7 +199,7 @@ jobs: const reviewers = ["yoosion030", "dhp94d", "lydiahjchung", "callipenguin"]; const randomReviewer = reviewers[Math.floor(Math.random() * reviewers.length)]; - await github.rest.issues.createComment({ + await github.rest.issues.createReport({ issue_number: context.issue.number, owner: context.repo.owner, repo: context.repo.repo, From 0e0643285ae48656f5240367fb4edf0ad927c8c6 Mon Sep 17 00:00:00 2001 From: yoosion030 Date: Thu, 25 Jul 2024 00:19:04 +0900 Subject: [PATCH 15/25] =?UTF-8?q?fix:=20lighthouse=20scripts=20=EB=82=B4?= =?UTF-8?q?=EB=B6=80=EC=97=90=EC=84=9C=20fs=EC=97=90=20=EC=A0=91=EA=B7=BC?= =?UTF-8?q?=ED=95=A0=20=EC=88=98=20=EC=97=86=EB=8A=94=20=EB=AC=B8=EC=A0=9C?= =?UTF-8?q?=20=ED=95=B4=EA=B2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: yoosion030 --- .github/scripts/lighthouse.js | 2 +- .github/workflows/assignment-6-ci.yml | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/.github/scripts/lighthouse.js b/.github/scripts/lighthouse.js index 00b680c81..4e5c2c962 100644 --- a/.github/scripts/lighthouse.js +++ b/.github/scripts/lighthouse.js @@ -1,4 +1,4 @@ -const reportLighthouseSuccess = async ({ github, context, results }) => { +const reportLighthouseSuccess = async ({ github, context, results, fs }) => { let comments = ""; results.forEach((result) => { diff --git a/.github/workflows/assignment-6-ci.yml b/.github/workflows/assignment-6-ci.yml index e66fc9811..731820038 100644 --- a/.github/workflows/assignment-6-ci.yml +++ b/.github/workflows/assignment-6-ci.yml @@ -160,7 +160,8 @@ jobs: await lighthouse.reportLighthouseSuccess({ results, context, - github + github, + fs }); - name: Report Lighthouse on Failure @@ -199,7 +200,7 @@ jobs: const reviewers = ["yoosion030", "dhp94d", "lydiahjchung", "callipenguin"]; const randomReviewer = reviewers[Math.floor(Math.random() * reviewers.length)]; - await github.rest.issues.createReport({ + await github.rest.issues.createComment({ issue_number: context.issue.number, owner: context.repo.owner, repo: context.repo.repo, From 91852f525ba1c77e6db7e5bf49eed577dbf4151e Mon Sep 17 00:00:00 2001 From: yoosion030 Date: Thu, 25 Jul 2024 00:24:56 +0900 Subject: [PATCH 16/25] =?UTF-8?q?feat:=20review=20scripts=20js=20=EC=BD=94?= =?UTF-8?q?=EB=93=9C=EB=A1=9C=20=EB=B6=84=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: yoosion030 --- .github/scripts/review.js | 35 +++++++++++++++++++++++++++ .github/workflows/assignment-6-ci.yml | 21 ++++++---------- 2 files changed, 43 insertions(+), 13 deletions(-) create mode 100644 .github/scripts/review.js diff --git a/.github/scripts/review.js b/.github/scripts/review.js new file mode 100644 index 000000000..97a4bf6a8 --- /dev/null +++ b/.github/scripts/review.js @@ -0,0 +1,35 @@ +const reviewers = ["yoosion030", "dhp94d", "lydiahjchung", "callipenguin"]; + +const getRandomReviewer = (reviewers) => { + const randomReviewer = + reviewers[Math.floor(Math.random() * reviewers.length)]; + + return randomReviewer; +}; + +const commentReviewer = async ({ github, context }) => { + const randomReviewer = getRandomReviewer(reviewers); + + await github.rest.issues.createComment({ + issue_number: context.issue.number, + owner: context.repo.owner, + repo: context.repo.repo, + body: `@${randomReviewer}, 리뷰를 부탁드립니다.`, + }); +}; + +const assignReviewer = async ({ github, context }) => { + const randomReviewer = getRandomReviewer(reviewers); + + await github.rest.pulls.requestReviewers({ + pull_number: context.issue.number, + owner: context.repo.owner, + repo: context.repo.repo, + reviewers: [randomReviewer], + }); +}; + +module.exports = { + commentReviewer, + assignReviewer, +}; diff --git a/.github/workflows/assignment-6-ci.yml b/.github/workflows/assignment-6-ci.yml index 731820038..4da23dcd4 100644 --- a/.github/workflows/assignment-6-ci.yml +++ b/.github/workflows/assignment-6-ci.yml @@ -197,19 +197,14 @@ jobs: with: github-token: ${{secrets.TOKEN_FOR_CI}} script: | - const reviewers = ["yoosion030", "dhp94d", "lydiahjchung", "callipenguin"]; - const randomReviewer = reviewers[Math.floor(Math.random() * reviewers.length)]; - - await github.rest.issues.createComment({ - issue_number: context.issue.number, - owner: context.repo.owner, - repo: context.repo.repo, - body: `@${randomReviewer}, 리뷰를 부탁드립니다.` + const review = require('.github/scripts/reviewer.js'); + + await review.commentReviewer({ + context, + github }); - await github.rest.pulls.requestReviewers({ - pull_number: context.issue.number, - owner: context.repo.owner, - repo: context.repo.repo, - reviewers: [randomReviewer] + await review.assignReviewer({ + context, + github }); From 76ad4ea84241ace0b51db2ddaf9e54dfd88e30e9 Mon Sep 17 00:00:00 2001 From: yoosion030 Date: Thu, 25 Jul 2024 00:25:44 +0900 Subject: [PATCH 17/25] =?UTF-8?q?fix:=20=EC=9E=98=EB=AA=BB=20=EC=A0=91?= =?UTF-8?q?=EA=B7=BC=ED=95=98=EA=B3=A0=20=EC=9E=88=EB=8D=98=20review.js=20?= =?UTF-8?q?=ED=8C=8C=EC=9D=BC=20=EC=A3=BC=EC=86=8C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: yoosion030 --- .github/workflows/assignment-6-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/assignment-6-ci.yml b/.github/workflows/assignment-6-ci.yml index 4da23dcd4..12bc1e0fc 100644 --- a/.github/workflows/assignment-6-ci.yml +++ b/.github/workflows/assignment-6-ci.yml @@ -197,7 +197,7 @@ jobs: with: github-token: ${{secrets.TOKEN_FOR_CI}} script: | - const review = require('.github/scripts/reviewer.js'); + const review = require('.github/scripts/review.js'); await review.commentReviewer({ context, From 1b543770a41ec4b8662d484ca71defe54e41e46e Mon Sep 17 00:00:00 2001 From: yoosion030 Date: Thu, 25 Jul 2024 00:31:50 +0900 Subject: [PATCH 18/25] =?UTF-8?q?refactor:=20lighthouse=20score=20?= =?UTF-8?q?=EA=B3=84=EC=82=B0=20=EB=A1=9C=EC=A7=81=20=EA=B0=9C=EC=84=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: yoosion030 --- .github/scripts/lighthouse.js | 109 +++++++++++++++++----------------- 1 file changed, 55 insertions(+), 54 deletions(-) diff --git a/.github/scripts/lighthouse.js b/.github/scripts/lighthouse.js index 4e5c2c962..2d726f340 100644 --- a/.github/scripts/lighthouse.js +++ b/.github/scripts/lighthouse.js @@ -1,63 +1,64 @@ -const reportLighthouseSuccess = async ({ github, context, results, fs }) => { - let comments = ""; +const formatScore = (score) => Math.round(score * 100); +const getScoreEmoji = (score) => + score >= 90 ? "🟢" : score >= 50 ? "🟠" : "🔴"; - results.forEach((result) => { - const { summary, jsonPath } = result; - const details = JSON.parse(fs.readFileSync(jsonPath)); - const { audits } = details; +const createMarkdownTable = (headers, rows) => { + return [ + `| ${headers.join(" | ")} |`, + `| ${headers.map(() => "---").join(" | ")} |`, + ...rows.map((row) => `| ${row.join(" | ")} |`), + ].join("\n"); +}; - const formatResult = (res) => Math.round(res * 100); +const createLighthouseComment = (summary, audits) => { + const formattedSummary = Object.fromEntries( + Object.entries(summary).map(([key, value]) => [key, formatScore(value)]) + ); - Object.keys(summary).forEach( - (key) => (summary[key] = formatResult(summary[key])) - ); + const summaryTable = createMarkdownTable( + ["Category", "Score"], + Object.entries(formattedSummary).map(([key, value]) => [ + `${getScoreEmoji(value)} ${key.charAt(0).toUpperCase() + key.slice(1)}`, + value, + ]) + ); - const score = (res) => (res >= 90 ? "🟢" : res >= 50 ? "🟠" : "🔴"); + const detailRows = [ + "first-contentful-paint", + "largest-contentful-paint", + "total-blocking-time", + "cumulative-layout-shift", + "speed-index", + ].map((metric) => { + const score = formatScore(audits[metric].score * 100); + return [ + `${getScoreEmoji(score)} ${metric + .split("-") + .map((word) => word.charAt(0).toUpperCase() + word.slice(1)) + .join(" ")}`, + audits[metric].displayValue, + ]; + }); - const comment = [ - `⚡️ Lighthouse report!`, - `| Category | Score |`, - `| --- | --- |`, - `| ${score(summary.performance)} Performance | ${summary.performance} |`, - `| ${score(summary.accessibility)} Accessibility | ${ - summary.accessibility - } |`, - `| ${score(summary["best-practices"])} Best practices | ${ - summary["best-practices"] - } |`, - `| ${score(summary.seo)} SEO | ${summary.seo} |`, - "", - ].join("\n"); + const detailTable = createMarkdownTable(["Category", "Score"], detailRows); - const detail = [ - `📊 Lighthouse Detail`, - `| Category | Score |`, - `| --- | --- |`, - `| ${score( - audits["first-contentful-paint"].score * 100 - )} First Contentful Paint | ${ - audits["first-contentful-paint"].displayValue - } |`, - `| ${score( - audits["largest-contentful-paint"].score * 100 - )} Largest Contentful Paint | ${ - audits["largest-contentful-paint"].displayValue - } |`, - `| ${score( - audits["total-blocking-time"].score * 100 - )} Total Blocking Time | ${audits["total-blocking-time"].displayValue} |`, - `| ${score( - audits["cumulative-layout-shift"].score * 100 - )} Cumulative Layout Shift | ${ - audits["cumulative-layout-shift"].displayValue - } |`, - `| ${score(audits["speed-index"].score * 100)} Speed Index | ${ - audits["speed-index"].displayValue - } |`, - ].join("\n"); + return ` +⚡️ Lighthouse report! +${summaryTable} - comments += comment + "\n" + detail + "\n"; - }); +📊 Lighthouse Detail +${detailTable} + `.trim(); +}; + +const reportLighthouseSuccess = async ({ github, context, results, fs }) => { + const comments = results + .map((result) => { + const { summary, jsonPath } = result; + const { audits } = JSON.parse(fs.readFileSync(jsonPath)); + return createLighthouseComment(summary, audits); + }) + .join("\n\n"); await github.rest.issues.createComment({ issue_number: context.issue.number, @@ -72,7 +73,7 @@ const reportLighthouseFailure = async ({ github, context }) => { issue_number: context.issue.number, owner: context.repo.owner, repo: context.repo.repo, - body: `빌드가 실패하여 Lighthouse 결과를 측정할 수 없습니다.`, + body: "빌드가 실패하여 Lighthouse 결과를 측정할 수 없습니다.", }); }; From 5b88f800f845eb2b6ef0925b398ea6b1ce8c80cd Mon Sep 17 00:00:00 2001 From: yoosion030 Date: Thu, 25 Jul 2024 00:48:00 +0900 Subject: [PATCH 19/25] =?UTF-8?q?refactor:=20step=20=EA=B5=AC=EB=B6=84=20?= =?UTF-8?q?=EC=97=86=EC=9D=B4=20try=20catch=EB=A1=9C=20=EC=97=90=EB=9F=AC?= =?UTF-8?q?=20=EC=B2=98=EB=A6=AC=20=ED=95=98=EB=8F=84=EB=A1=9D=20=EA=B0=9C?= =?UTF-8?q?=EC=84=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: yoosion030 --- .github/workflows/assignment-6-ci.yml | 35 ++++++++++----------------- 1 file changed, 13 insertions(+), 22 deletions(-) diff --git a/.github/workflows/assignment-6-ci.yml b/.github/workflows/assignment-6-ci.yml index 12bc1e0fc..2e12f20e9 100644 --- a/.github/workflows/assignment-6-ci.yml +++ b/.github/workflows/assignment-6-ci.yml @@ -45,8 +45,7 @@ jobs: pnpm install --prefer-frozen-lockfile pnpm -F assignment-6 lint > eslint_report.txt - - name: Report Lint Success - if: success() + - name: Report Lint uses: actions/github-script@v6 with: github-token: ${{ secrets.TOKEN_FOR_CI }} @@ -55,26 +54,18 @@ jobs: const eslintReport = fs.readFileSync('eslint_report.txt', 'utf8') const lint = require('.github/scripts/lint.js'); - await lint.reportLintSuccess({ - context, - github - }); - - - name: Report Lint Failure - if: failure() - uses: actions/github-script@v6 - with: - github-token: ${{ secrets.TOKEN_FOR_CI }} - script: | - const fs = require('fs') - const eslintReport = fs.readFileSync('eslint_report.txt', 'utf8') - - const lint = require('.github/scripts/lint.js'); - await lint.reportLintFailure({ - eslintReport, - context, - github - }); + try { + await lint.reportLintSuccess({ + context, + github + }); + } catch(e) { + await lint.reportLintFailure({ + eslintReport, + context, + github + }); + } test: runs-on: ubuntu-latest From 305c9e4af7d4ef5a91f20302a14859dd2128920f Mon Sep 17 00:00:00 2001 From: yoosion030 Date: Thu, 25 Jul 2024 00:51:04 +0900 Subject: [PATCH 20/25] =?UTF-8?q?feat:=20=EB=A6=B0=ED=8A=B8=20=EC=97=90?= =?UTF-8?q?=EB=9F=AC=20=EB=B0=9C=EC=83=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: yoosion030 --- packages/assignment-6/src/main.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/assignment-6/src/main.tsx b/packages/assignment-6/src/main.tsx index eb97831a8..28c9b3d1c 100644 --- a/packages/assignment-6/src/main.tsx +++ b/packages/assignment-6/src/main.tsx @@ -1,7 +1,7 @@ import React from "react"; import ReactDOM from "react-dom/client"; import App from "./App.tsx"; -// import { forLintError } from './forLintError.ts' +import { forLintError } from "./forLintError.ts"; ReactDOM.createRoot(document.getElementById("root")!).render( From dd929a195d8f7836aee84a2ad6ee556b33aeaf6d Mon Sep 17 00:00:00 2001 From: yoosion030 Date: Thu, 25 Jul 2024 00:55:33 +0900 Subject: [PATCH 21/25] =?UTF-8?q?fix:=20=EC=97=90=EB=9F=AC=EA=B0=80=20?= =?UTF-8?q?=EB=B0=9C=EC=83=9D=ED=95=98=EC=97=AC=EB=8F=84=20Report=EB=A5=BC?= =?UTF-8?q?=20=ED=95=A0=20=EC=88=98=20=EC=9E=88=EB=8F=84=EB=A1=9D=20?= =?UTF-8?q?=ED=95=B4=EA=B2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: yoosion030 --- .github/workflows/assignment-6-ci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/assignment-6-ci.yml b/.github/workflows/assignment-6-ci.yml index 2e12f20e9..fe9907f3b 100644 --- a/.github/workflows/assignment-6-ci.yml +++ b/.github/workflows/assignment-6-ci.yml @@ -41,6 +41,7 @@ jobs: cache: "pnpm" - name: Lint + continue-on-error: true run: | pnpm install --prefer-frozen-lockfile pnpm -F assignment-6 lint > eslint_report.txt From 74e7ad5304a7cd0326e67bf2f18c082ef475c166 Mon Sep 17 00:00:00 2001 From: yoosion030 Date: Thu, 25 Jul 2024 01:02:37 +0900 Subject: [PATCH 22/25] =?UTF-8?q?refactor:=20pnpm=20install=20step=20?= =?UTF-8?q?=EB=B6=84=EB=A6=AC=20=EB=B0=8F=20cache=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: yoosion030 --- .github/workflows/assignment-6-ci.yml | 114 ++++++++++++++++++++------ 1 file changed, 90 insertions(+), 24 deletions(-) diff --git a/.github/workflows/assignment-6-ci.yml b/.github/workflows/assignment-6-ci.yml index fe9907f3b..0405a21fd 100644 --- a/.github/workflows/assignment-6-ci.yml +++ b/.github/workflows/assignment-6-ci.yml @@ -17,15 +17,29 @@ jobs: - uses: actions/checkout@v4 - uses: pnpm/action-setup@v4 with: - version: latest + version: 8 + run_install: false + - uses: actions/setup-node@v4 with: node-version: 20 cache: "pnpm" + - name: Get pnpm store directory + shell: bash + run: | + echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV + - name: Install PNPM + run: | + pnpm install --prefer-frozen-lockfile + - name: Cache dependencies + uses: actions/cache@v4 + with: + path: ~/.pnpm-store + key: ${{ runner.os }}-pnpm-${{ hashFiles('**/pnpm-lock.yaml') }} + - name: Build run: | - pnpm install --prefer-frozen-lockfile pnpm -F assignment-6 build lint: @@ -34,19 +48,33 @@ jobs: - uses: actions/checkout@v4 - uses: pnpm/action-setup@v4 with: - version: latest + version: 8 + run_install: false + - uses: actions/setup-node@v4 with: node-version: 20 cache: "pnpm" - - name: Lint - continue-on-error: true + - name: Get pnpm store directory + shell: bash + run: | + echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV + - name: Install PNPM run: | pnpm install --prefer-frozen-lockfile + - name: Cache dependencies + uses: actions/cache@v4 + with: + path: ~/.pnpm-store + key: ${{ runner.os }}-pnpm-${{ hashFiles('**/pnpm-lock.yaml') }} + + - name: Lint + run: | pnpm -F assignment-6 lint > eslint_report.txt - - name: Report Lint + - name: Report Lint Success + if: success() uses: actions/github-script@v6 with: github-token: ${{ secrets.TOKEN_FOR_CI }} @@ -55,18 +83,26 @@ jobs: const eslintReport = fs.readFileSync('eslint_report.txt', 'utf8') const lint = require('.github/scripts/lint.js'); - try { - await lint.reportLintSuccess({ - context, - github - }); - } catch(e) { - await lint.reportLintFailure({ - eslintReport, - context, - github - }); - } + await lint.reportLintSuccess({ + context, + github + }); + + - name: Report Lint Failure + if: failure() + uses: actions/github-script@v6 + with: + github-token: ${{ secrets.TOKEN_FOR_CI }} + script: | + const fs = require('fs') + const eslintReport = fs.readFileSync('eslint_report.txt', 'utf8') + + const lint = require('.github/scripts/lint.js'); + await lint.reportLintFailure({ + eslintReport, + context, + github + }); test: runs-on: ubuntu-latest @@ -74,15 +110,29 @@ jobs: - uses: actions/checkout@v4 - uses: pnpm/action-setup@v4 with: - version: latest + version: 8 + run_install: false + - uses: actions/setup-node@v4 with: node-version: 20 cache: "pnpm" - - name: Testing and Coverage + - name: Get pnpm store directory + shell: bash + run: | + echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV + - name: Install PNPM run: | pnpm install --prefer-frozen-lockfile + - name: Cache dependencies + uses: actions/cache@v4 + with: + path: ~/.pnpm-store + key: ${{ runner.os }}-pnpm-${{ hashFiles('**/pnpm-lock.yaml') }} + + - name: Testing and Coverage + run: | pnpm -F assignment-6 test pnpm -F assignment-6 coverage @@ -121,16 +171,30 @@ jobs: - uses: actions/checkout@v4 - uses: pnpm/action-setup@v4 with: - version: latest + version: 8 + run_install: false + - uses: actions/setup-node@v4 with: node-version: 20 cache: "pnpm" - - name: Install Lighthouse CI + - name: Get pnpm store directory + shell: bash + run: | + echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV + - name: Install PNPM run: | - npm i -g @lhci/cli pnpm install --prefer-frozen-lockfile + - name: Cache dependencies + uses: actions/cache@v4 + with: + path: ~/.pnpm-store + key: ${{ runner.os }}-pnpm-${{ hashFiles('**/pnpm-lock.yaml') }} + + - name: Install Lighthouse CI + run: | + npm i -g @lhci/cli - name: Build Local Server run: | @@ -178,7 +242,9 @@ jobs: - uses: actions/checkout@v4 - uses: pnpm/action-setup@v4 with: - version: latest + version: 8 + run_install: false + - uses: actions/setup-node@v4 with: node-version: 20 From 3355f116a113c34b588a210692a22555bb518c59 Mon Sep 17 00:00:00 2001 From: yoosion030 Date: Thu, 25 Jul 2024 01:20:03 +0900 Subject: [PATCH 23/25] =?UTF-8?q?feat:=20composite=20setup=20action=20?= =?UTF-8?q?=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: yoosion030 --- .../setup-node-dependencies/action.yml | 32 +++++++ .github/workflows/assignment-6-ci.yml | 93 ++----------------- 2 files changed, 40 insertions(+), 85 deletions(-) create mode 100644 .github/actions/setup-node-dependencies/action.yml diff --git a/.github/actions/setup-node-dependencies/action.yml b/.github/actions/setup-node-dependencies/action.yml new file mode 100644 index 000000000..4b82457c0 --- /dev/null +++ b/.github/actions/setup-node-dependencies/action.yml @@ -0,0 +1,32 @@ +name: Setup Node.js and Dependencies +description: Sets up Node.js, pnpm, and installs dependencies + +runs: + using: "composite" + steps: + - name: Install pnpm + uses: pnpm/action-setup@v4 + with: + version: 8 + - name: Set up Node.js + uses: actions/setup-node@v4 + with: + node-version: 20 + cache: "pnpm" + + - name: Get pnpm cache directory path + run: echo "dir=$(pnpm store path)" >> $GITHUB_ENV + shell: bash + + - name: Cache pnpm dependencies + id: pnpm-cache + uses: actions/cache@v4 + with: + path: ${{ env.dir }} + key: ${{ runner.os }}-pnpm-${{ hashFiles('**/pnpm-lock.yaml') }} + restore-keys: | + ${{ runner.os }}-pnpm- + + - name: Install dependencies + run: pnpm install --prefer-frozen-lockfile + shell: bash diff --git a/.github/workflows/assignment-6-ci.yml b/.github/workflows/assignment-6-ci.yml index 0405a21fd..b3704264e 100644 --- a/.github/workflows/assignment-6-ci.yml +++ b/.github/workflows/assignment-6-ci.yml @@ -15,28 +15,9 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - - uses: pnpm/action-setup@v4 - with: - version: 8 - run_install: false - - uses: actions/setup-node@v4 - with: - node-version: 20 - cache: "pnpm" - - - name: Get pnpm store directory - shell: bash - run: | - echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV - - name: Install PNPM - run: | - pnpm install --prefer-frozen-lockfile - - name: Cache dependencies - uses: actions/cache@v4 - with: - path: ~/.pnpm-store - key: ${{ runner.os }}-pnpm-${{ hashFiles('**/pnpm-lock.yaml') }} + - name: Setup Node.js and Dependencies + uses: ./.github/actions/setup-node-dependencies - name: Build run: | @@ -46,28 +27,9 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - - uses: pnpm/action-setup@v4 - with: - version: 8 - run_install: false - - uses: actions/setup-node@v4 - with: - node-version: 20 - cache: "pnpm" - - - name: Get pnpm store directory - shell: bash - run: | - echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV - - name: Install PNPM - run: | - pnpm install --prefer-frozen-lockfile - - name: Cache dependencies - uses: actions/cache@v4 - with: - path: ~/.pnpm-store - key: ${{ runner.os }}-pnpm-${{ hashFiles('**/pnpm-lock.yaml') }} + - name: Setup Node.js and Dependencies + uses: ./.github/actions/setup-node-dependencies - name: Lint run: | @@ -108,28 +70,9 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - - uses: pnpm/action-setup@v4 - with: - version: 8 - run_install: false - - uses: actions/setup-node@v4 - with: - node-version: 20 - cache: "pnpm" - - - name: Get pnpm store directory - shell: bash - run: | - echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV - - name: Install PNPM - run: | - pnpm install --prefer-frozen-lockfile - - name: Cache dependencies - uses: actions/cache@v4 - with: - path: ~/.pnpm-store - key: ${{ runner.os }}-pnpm-${{ hashFiles('**/pnpm-lock.yaml') }} + - name: Setup Node.js and Dependencies + uses: ./.github/actions/setup-node-dependencies - name: Testing and Coverage run: | @@ -169,28 +112,9 @@ jobs: steps: - uses: actions/checkout@v4 - - uses: pnpm/action-setup@v4 - with: - version: 8 - run_install: false - - uses: actions/setup-node@v4 - with: - node-version: 20 - cache: "pnpm" - - - name: Get pnpm store directory - shell: bash - run: | - echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV - - name: Install PNPM - run: | - pnpm install --prefer-frozen-lockfile - - name: Cache dependencies - uses: actions/cache@v4 - with: - path: ~/.pnpm-store - key: ${{ runner.os }}-pnpm-${{ hashFiles('**/pnpm-lock.yaml') }} + - name: Setup Node.js and Dependencies + uses: ./.github/actions/setup-node-dependencies - name: Install Lighthouse CI run: | @@ -243,7 +167,6 @@ jobs: - uses: pnpm/action-setup@v4 with: version: 8 - run_install: false - uses: actions/setup-node@v4 with: From 7dae14339347099dc7de1a07f5b178fad7595cc2 Mon Sep 17 00:00:00 2001 From: yoosion030 Date: Thu, 25 Jul 2024 20:37:49 +0900 Subject: [PATCH 24/25] =?UTF-8?q?feat:=20=EB=A6=B0=ED=8A=B8=20=EC=97=90?= =?UTF-8?q?=EB=9F=AC=20=ED=95=B4=EA=B2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: yoosion030 --- packages/assignment-6/src/main.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/assignment-6/src/main.tsx b/packages/assignment-6/src/main.tsx index 28c9b3d1c..6b23509aa 100644 --- a/packages/assignment-6/src/main.tsx +++ b/packages/assignment-6/src/main.tsx @@ -1,7 +1,7 @@ import React from "react"; import ReactDOM from "react-dom/client"; import App from "./App.tsx"; -import { forLintError } from "./forLintError.ts"; +// import { forLintError } from "./forLintError.ts"; ReactDOM.createRoot(document.getElementById("root")!).render( From 50211ce94bf4b6a5426b72bc2703067df7fac776 Mon Sep 17 00:00:00 2001 From: yoosion030 Date: Thu, 25 Jul 2024 20:41:45 +0900 Subject: [PATCH 25/25] =?UTF-8?q?fix:=20comment=20=EB=A6=AC=EB=B7=B0?= =?UTF-8?q?=EC=96=B4=EC=99=80=20assign=20=EB=A6=AC=EB=B7=B0=EC=96=B4?= =?UTF-8?q?=EA=B0=80=20=EB=8B=A4=EB=A5=B8=20=EC=9D=B4=EC=8A=88=20=ED=95=B4?= =?UTF-8?q?=EA=B2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit reviewer를 함수 실행할 때 주입하도록 해결 Signed-off-by: yoosion030 --- .github/scripts/comment.js | 0 .github/scripts/review.js | 34 +++++++++++++++++++-------- .github/workflows/assignment-6-ci.yml | 7 ++++-- 3 files changed, 29 insertions(+), 12 deletions(-) delete mode 100644 .github/scripts/comment.js diff --git a/.github/scripts/comment.js b/.github/scripts/comment.js deleted file mode 100644 index e69de29bb..000000000 diff --git a/.github/scripts/review.js b/.github/scripts/review.js index 97a4bf6a8..71697c576 100644 --- a/.github/scripts/review.js +++ b/.github/scripts/review.js @@ -1,35 +1,49 @@ -const reviewers = ["yoosion030", "dhp94d", "lydiahjchung", "callipenguin"]; - -const getRandomReviewer = (reviewers) => { +const getRandomReviewer = () => { + const reviewers = ["yoosion030", "dhp94d", "lydiahjchung", "callipenguin"]; const randomReviewer = reviewers[Math.floor(Math.random() * reviewers.length)]; return randomReviewer; }; -const commentReviewer = async ({ github, context }) => { - const randomReviewer = getRandomReviewer(reviewers); - +const commentReviewer = async ({ github, context, reviewer }) => { await github.rest.issues.createComment({ issue_number: context.issue.number, owner: context.repo.owner, repo: context.repo.repo, - body: `@${randomReviewer}, 리뷰를 부탁드립니다.`, + body: `@${reviewer}, 리뷰를 부탁드립니다.`, }); }; -const assignReviewer = async ({ github, context }) => { - const randomReviewer = getRandomReviewer(reviewers); +const assignReviewer = async ({ github, context, reviewer }) => { + const currentReviewers = await github.rest.pulls.listRequestedReviewers({ + pull_number: context.issue.number, + owner: context.repo.owner, + repo: context.repo.repo, + }); + + if (currentReviewers.data.users.length > 0) { + const reviewersToRemove = currentReviewers.data.users.map( + (user) => user.login + ); + await github.rest.pulls.removeRequestedReviewers({ + pull_number: context.issue.number, + owner: context.repo.owner, + repo: context.repo.repo, + reviewers: reviewersToRemove, + }); + } await github.rest.pulls.requestReviewers({ pull_number: context.issue.number, owner: context.repo.owner, repo: context.repo.repo, - reviewers: [randomReviewer], + reviewers: [reviewer], }); }; module.exports = { commentReviewer, assignReviewer, + getRandomReviewer, }; diff --git a/.github/workflows/assignment-6-ci.yml b/.github/workflows/assignment-6-ci.yml index b3704264e..3f7800584 100644 --- a/.github/workflows/assignment-6-ci.yml +++ b/.github/workflows/assignment-6-ci.yml @@ -179,13 +179,16 @@ jobs: github-token: ${{secrets.TOKEN_FOR_CI}} script: | const review = require('.github/scripts/review.js'); + const randomReviewer = review.getRandomReviewer(); await review.commentReviewer({ context, - github + github, + reviewer: randomReviewer }); await review.assignReviewer({ context, - github + github, + reviewer: randomReviewer });