Commit abb8409

Anton Golub <antongolub@antongolub.com>
2024-12-04 20:16:21
feat: capture pr labels (#90)
* feat: capture PR labels * test: enhance main manual test * ci: use nodejs 22 for build
1 parent a1ea10f
.github/workflows/pages.yml
@@ -24,6 +24,10 @@ jobs:
     if: ${{ github.event.workflow_run.conclusion == 'success' }}
 
     steps:
+      - name: Setup Node.js 22.x
+        uses: actions/setup-node@v4
+        with:
+          node-version: 22.x
       - name: Checkout
         uses: actions/checkout@v4
       - name: Install dependencies
.github/workflows/release.yml
@@ -22,6 +22,11 @@ jobs:
         with:
           ref: master
 
+      - name: Use Node.js 22.x
+        uses: actions/setup-node@v4
+        with:
+          node-version: 22.x
+
       - name: Configure git
         run: |
           git config user.name "${GITHUB_ACTOR}"
.github/workflows/test.yml
@@ -6,6 +6,10 @@ jobs:
   test:
     runs-on: ubuntu-latest
     steps:
+      - name: Setup Node.js 22.x
+        uses: actions/setup-node@v4
+        with:
+          node-version: 22.x
       - uses: actions/checkout@v4
       - name: Install dependencies
         run: npm ci
src/task/pulls/pulls.graphql
@@ -11,6 +11,12 @@ fragment PullRequest on PullRequest {
   mergedBy {
     login
   }
+  labels(first: 10) {
+    totalCount
+    nodes {
+      name
+    }
+  }
   repository {
     nameWithOwner
     owner {
src/task/pulls/pulls.graphql.ts
@@ -14,6 +14,12 @@ fragment PullRequest on PullRequest {
   mergedBy {
     login
   }
+  labels(first: 10) {
+    totalCount
+    nodes {
+      name
+    }
+  }
   repository {
     nameWithOwner
     owner {
@@ -80,6 +86,12 @@ export type PullRequest = {
   mergedBy: {
     login: string
   } | null
+  labels: {
+    totalCount: number
+    nodes: Array<{
+      name: string
+    }> | null
+  } | null
   repository: {
     nameWithOwner: string
     owner: {
src/main.test.ts
@@ -1,17 +1,30 @@
-import { describe, it } from 'vitest'
+import { describe, it, expect, afterAll } from 'vitest'
+import fs from 'node:fs/promises'
 import { main } from './main.js'
 import os from 'node:os'
 import { log } from './log.js'
+import { Badge } from './badges.js'
+import { Data } from './data.js'
 
 const temp = `${os.tmpdir()}/${Math.random().toString(36).slice(2)}`
 
 describe.skip('main', () => {
   log.info('temp', temp)
+  afterAll(async () => fs.rm(temp, { recursive: true }))
+
+  // prettier-ignore
   it(
     'generates badges by repo name',
     async () => {
-      await main(['--user', 'semrel-extra-bot', '--cwd', temp])
+      await main(['--user', 'semrel-extra-bot', '--cwd', temp, '--dryrun'])
+      const myBadgesJson = JSON.parse(await fs.readFile(`${temp}/repo/my-badges/my-badges.json`, 'utf8'))
+      const dataJson: Data = JSON.parse(await fs.readFile(`${temp}/data/semrel-extra-bot.json`, 'utf8'))
+
+      expect(myBadgesJson.some(({id}: Badge) => id === 'chore-commit')).toBeTruthy()
+      expect(myBadgesJson.some(({id}: Badge) => id === 'favorite-word')).toBeTruthy()
+      expect(dataJson.repos.some(({name}) => name === 'semrel-extra-bot')).toBeTruthy()
+      expect(dataJson.user.pinnedItems.nodes?.some((node) => node?.name === 'zx-semrel')).toBeTruthy()
     },
-    15 * 60 * 1000,
+    10 * 60 * 1000,
   )
 })
package.json
@@ -16,6 +16,7 @@
     "fmt:check": "prettier --check .",
     "start": "tsc --watch",
     "tsc": "tsc",
+    "prebuild": "npm run megaera",
     "build": "tsc",
     "check-images": "node scripts/check-images.mjs",
     "generate-gh-pages": "node scripts/generate-gh-pages.mjs",