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

Update Report Snapshot #6

Closed
Closed
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
15 changes: 13 additions & 2 deletions .github/workflows/update_report_snapshot.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
name: Update Report Snapshot

on:
push:
branches: [feat/338_WeeklyReportScript]
workflow_dispatch:
schedule:
- cron: '0 0 * * 1'
Expand All @@ -19,12 +21,17 @@ jobs:
ref: ${{ github.ref }}

- name: report:update
id: report_update
env:
# The script requires public_repo, read:org, read:project permissions, and needs a personal access token (classic) to obtain these permissions.
GITHUB_TOKEN: ${{ secrets.REPORT_GITHUB_TOKEN }}
run: |
yarn install
yarn workspace @magickbase-website/scripts report:update
{
echo 'DEVLOG<<EOF'
yarn workspace @magickbase-website/scripts report:update | sed '0,/^generateDevlogFromSnapshotsDiff():$/d'
echo EOF
} >> $GITHUB_OUTPUT
git add packages/scripts/snapshots

- name: Set GPG
Expand All @@ -40,6 +47,10 @@ jobs:
with:
title: Update Report Snapshot
commit-message: 'feat: update report snapshot'
body: 'After this PR is merged, a corresponding discussion will be automatically created'
body: '
After this PR is merged, a corresponding devlog discussion will be automatically created, with the content preview as follows\n\n
---\n\n
${{ steps.report_update.outputs.DEVLOG }}
'
committer: ${{ vars.COMMITTER }}
branch: update-report-snapshot
1 change: 1 addition & 0 deletions packages/scripts/snapshots/current.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"CKB Explorer":[{"id":"PVTI_lADOBjLfC84AMiKwzgFHFMs","content":{"title":"Display live cells of a specific address","number":19,"url":"https://github.com/Magickbase/ckb-explorer-public-issues/issues/19"},"fieldValues":{"nodes":[{"field":{"name":"Assignees"}},{"repository":{"name":"ckb-explorer-public-issues","url":"https://github.com/Magickbase/ckb-explorer-public-issues"},"field":{"name":"Repository"}},{"labels":{"nodes":[{"id":"LA_kwDOHFQx5M7tEEBJ","name":"enhancement","description":"New feature or request"}]},"field":{"name":"Labels"}},{"text":"Display live cells of a specific address","field":{"name":"Title"}},{"name":"🎨 Designing","field":{"name":"Status"}},{"name":"🏔 High","field":{"name":"Priority"}},{"text":"已提交PRD,待反馈(Dec11)。已修改(Dec18)。预计本周进入前端开发。Updated Jan2","field":{"name":"Description"}}]}},{"id":"PVTI_lADOBjLfC84AMiKwzgFHFRg","content":{"title":"Data inconsistent with Token City Explorer","number":96,"url":"https://github.com/Magickbase/ckb-explorer-public-issues/issues/96"},"fieldValues":{"nodes":[{"field":{"name":"Assignees"}},{"repository":{"name":"ckb-explorer-public-issues","url":"https://github.com/Magickbase/ckb-explorer-public-issues"},"field":{"name":"Repository"}},{"labels":{"nodes":[{"id":"LA_kwDOHFQx5M7tEEBM","name":"help wanted","description":"Extra attention is needed"},{"id":"LA_kwDOHFQx5M7tEEBO","name":"question","description":"Further information is requested"}]},"field":{"name":"Labels"}},{"milestone":{"title":"2022/10/26 - 2022/11/02","dueOn":"2022-11-02T00:00:00Z"},"field":{"name":"Milestone"}},{"text":"Data inconsistent with Token City Explorer","field":{"name":"Title"}},{"name":"📫Hold On","field":{"name":"Status"}},{"name":"🏝 Low","field":{"name":"Priority"}}]}},{"id":"PVTI_lADOBjLfC84AMiKwzgFHFSE","content":{"title":"Add statistic data of cells having `data` in `Cell count` chart","number":36,"url":"https://github.com/Magickbase/ckb-explorer-public-issues/issues/36"},"fieldValues":{"nodes":[{"field":{"name":"Assignees"}},{"repository":{"name":"ckb-explorer-public-issues","url":"https://github.com/Magickbase/ckb-explorer-public-issues"},"field":{"name":"Repository"}},{"labels":{"nodes":[{"id":"LA_kwDOHFQx5M7tEEBJ","name":"enhancement","description":"New feature or request"}]},"field":{"name":"Labels"}},{"text":"Add statistic data of cells having `data` in `Cell count` chart","field":{"name":"Title"}},{"name":"📋 Backlog","field":{"name":"Status"}},{"name":"🏝 Low","field":{"name":"Priority"}}]}},{"id":"PVTI_lADOBjLfC84AMiKwzgFHFSs","content":{"title":"data sorting/filtering","number":42,"url":"https://github.com/Magickbase/ckb-explorer-public-issues/issues/42"},"fieldValues":{"nodes":[{"field":{"name":"Assignees"}},{"repository":{"name":"ckb-explorer-public-issues","url":"https://github.com/Magickbase/ckb-explorer-public-issues"},"field":{"name":"Repository"}},{"labels":{"nodes":[{"id":"LA_kwDOHFQx5M74_7JE","name":"feature","description":""}]},"field":{"name":"Labels"}},{"text":"data sorting/filtering","field":{"name":"Title"}},{"name":"🚩Pre Release","field":{"name":"Status"}},{"name":"🌋 Urgent","field":{"name":"Priority"}},{"title":"Iteration 2","startDate":"2023-03-27","duration":29,"field":{"name":"Iteration"}},{"date":"2023-04-03","field":{"name":"Start Processing Date"}},{"date":"2023-04-04","field":{"name":"Expected Done Date"}}]}},{"id":"PVTI_lADOBjLfC84AMiKwzgFHFUU","content":{"title":"Make workflow of m-nft synchronization clear and maybe provide a standalone service","number":49,"url":"https://github.com/Magickbase/ckb-explorer-public-issues/issues/49"},"fieldValues":{"nodes":[{"field":{"name":"Assignees"}},{"repository":{"name":"ckb-explorer-public-issues","url":"https://github.com/Magickbase/ckb-explorer-public-issues"},"field":{"name":"Repository"}},{"labels":{"nodes":[{"id":"LA_kwDOHFQx5M7tEEBJ","name":"enhancement","description":"New feature or request"}]},"field":{"name":"Labels"}},{"text":"Make workflow of m-nft synchronization clear and maybe provide a standalone service","field":{"name":"Title"}},{"name":"🆕 New","field":{"name":"Status"}},{"name":"🏝 Low","field":{"name":"Priority"}}]}}]}
36 changes: 36 additions & 0 deletions packages/scripts/snapshots/prev.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"CKB Explorer": [
{
"id": "PVTI_lADOBjLfC84AMiKwzgFHFUU",
"content": {
"title": "Make workflow of m-nft synchronization clear and maybe provide a standalone service",
"number": 49,
"url": "https://github.com/Magickbase/ckb-explorer-public-issues/issues/49"
},
"fieldValues": {
"nodes": [
{ "field": { "name": "Assignees" } },
{
"repository": {
"name": "ckb-explorer-public-issues",
"url": "https://github.com/Magickbase/ckb-explorer-public-issues"
},
"field": { "name": "Repository" }
},
{
"labels": {
"nodes": [{ "id": "LA_kwDOHFQx5M7tEEBJ", "name": "enhancement", "description": "New feature or request" }]
},
"field": { "name": "Labels" }
},
{
"text": "Make workflow of m-nft synchronization clear and maybe provide a standalone service",
"field": { "name": "Title" }
},
{ "name": "🆕 New", "field": { "name": "Status" } },
{ "name": "🏝 Low", "field": { "name": "Priority" } }
]
}
}
]
}
140 changes: 2 additions & 138 deletions packages/scripts/src/compare_report_snapshot.ts
Original file line number Diff line number Diff line change
@@ -1,140 +1,4 @@
import './prepare'
import { join } from 'path'
import { mkdirSync, readFileSync } from 'fs'
import { ProjectItem, createDiscussion } from './utils/github'
import { assert } from './utils/error'
import { createDevlogDiscussion } from './utils/report'

const sortedStatusValues = [
'🆕 New',
'📫Hold On',
'📋 Backlog',
'📌Planning',
'🎨 Designing',
'🏗 In Progress',
'🔎 Code Review',
'👀 Testing',
'🚩Pre Release',
'✅ Done',
]

const folder = join(process.cwd(), 'snapshots')
mkdirSync(folder, { recursive: true })

const currentFilepath = join(folder, 'current.json')
const prevFilepath = join(folder, 'prev.json')

const currentProjectItemsMap = JSON.parse(readFileSync(currentFilepath).toString()) as Record<string, ProjectItem[]>
const prevProjectItemsMap = JSON.parse(readFileSync(prevFilepath).toString()) as Record<string, ProjectItem[]>

function itemsToItemMap(items: ProjectItem[]): Record<ProjectItem['id'], ProjectItem> {
const map: Record<ProjectItem['id'], ProjectItem> = {}
for (const item of items) {
map[item.id] = item
}
return map
}

function getField(item: ProjectItem, filedName: string) {
return item.fieldValues.nodes.find(n => n.field.name === filedName)
}

let devLog = ''

for (const [title, currentItems] of Object.entries(currentProjectItemsMap)) {
const prevItems = prevProjectItemsMap[title]
if (!prevItems) continue

const currentMap = itemsToItemMap(currentItems)
const prevMap = itemsToItemMap(prevItems)

const newItems: ProjectItem[] = []
const update: ProjectItem[] = []
const done: ProjectItem[] = []

for (const id of Object.keys(currentMap)) {
const currentItem = currentMap[id]
const prevItem = prevMap[id]
assert(currentItem)

const hasAnyChange = !prevItem || JSON.stringify(currentItem) !== JSON.stringify(prevItem)
const hasStatusChange = !prevItem || getField(currentItem, 'Status')?.name !== getField(prevItem, 'Status')?.name
if (!hasAnyChange) continue

const currentStatus = getField(currentItem, 'Status')?.name ?? ''
switch (currentStatus) {
case '🆕 New':
newItems.push(currentItem)
break
case '🚩Pre Release':
case '✅ Done':
const prevStatus = prevItem == null ? '' : getField(prevItem, 'Status')?.name ?? ''
const prevIsDone = ['🚩Pre Release', '✅ Done'].includes(prevStatus)
if (hasStatusChange && !prevIsDone) {
done.push(currentItem)
}
break
default:
update.push(currentItem)
break
}
}

;[newItems, update, done].forEach(items =>
items.sort((a, b) => {
const aStatus = getField(a, 'Status')?.name ?? ''
const bStatus = getField(b, 'Status')?.name ?? ''
return sortedStatusValues.indexOf(aStatus) - sortedStatusValues.indexOf(bStatus)
}),
)

const getStatusChangeLog = (item: ProjectItem) => {
const currentStatus = getField(item, 'Status')?.name
const prevItem = prevMap[item.id]
const prevStatus = prevItem == null ? undefined : getField(prevItem, 'Status')?.name
if (prevStatus == null || currentStatus === prevStatus) return ` [${currentStatus}]`
return ` [${prevStatus} -> ${currentStatus}]`
}

const getContentURL = (item: ProjectItem) =>
item.content.url != null ? ` [#${item.content.number}](${item.content.url})` : ''

const getDescription = (item: ProjectItem) => {
const desc = getField(item, 'Description')?.text
return desc != null ? ` [${desc}]` : ''
}

devLog += `# ${title}\n\n`

if (newItems.length > 0) {
devLog += '## [NEW]\n\n'
newItems.forEach((item, idx) => {
devLog += `${idx + 1}. ${item.content.title}${getContentURL(item)}${getDescription(item)}\n`
})
devLog += '\n'
}

if (update.length > 0) {
devLog += '## [UPDATE]\n\n'
update.forEach((item, idx) => {
devLog += `${idx + 1}.${getStatusChangeLog(item)} ${item.content.title}${getContentURL(item)}${getDescription(
item,
)}\n`
})
devLog += '\n'
}

if (done.length > 0) {
devLog += '## [DONE]\n\n'
done.forEach((item, idx) => {
devLog += `${idx + 1}. [${getField(item, 'Status')?.name}] ${item.content.title}${getContentURL(
item,
)}${getDescription(item)}\n`
})
}

devLog += '\n'
}

createDiscussion('Magickbase', 'shaping', 'Dev Log', `Dev Log ${new Date().toISOString().slice(0, 10)}`, devLog)
.then(res => console.log('Dev log created', res.id))
.catch(console.error)
await createDevlogDiscussion()
29 changes: 5 additions & 24 deletions packages/scripts/src/update_report_snapshot.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,7 @@
import './prepare'
import { join } from 'path'
import { existsSync, mkdirSync, renameSync, writeFileSync } from 'fs'
import { ProjectItem, getOrganizationProjects, getProjectItems } from './utils/github'
import { assert } from './utils/error'
import { generateDevlogFromSnapshotsDiff, updateSnapshots } from './utils/report'

const projectNames = ['Neuron', 'CKB Explorer']
const projects = await getOrganizationProjects('Magickbase')
const filteredProjects = projects.filter(p => projectNames.includes(p.title))
assert(filteredProjects.length === projectNames.length)

const projectItemsMap: Record<string, ProjectItem[]> = {}
for (const project of filteredProjects) {
projectItemsMap[project.title] = await getProjectItems(project.id)
}

const folder = join(process.cwd(), 'snapshots')
mkdirSync(folder, { recursive: true })

const currentFilepath = join(folder, 'current.json')
const prevFilepath = join(folder, 'prev.json')

if (existsSync(currentFilepath)) {
renameSync(currentFilepath, prevFilepath)
}
writeFileSync(currentFilepath, JSON.stringify(projectItemsMap))
await updateSnapshots()
// These outputs are for use with GitHub Actions.
console.log('generateDevlogFromSnapshotsDiff():')
console.log(generateDevlogFromSnapshotsDiff())
8 changes: 8 additions & 0 deletions packages/scripts/src/utils/file.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { existsSync, mkdirSync } from 'fs'
import { dirname } from 'path'

export function ensureFileFolderExists(filePath: string) {
const folder = dirname(filePath)
if (existsSync(folder)) return
mkdirSync(folder, { recursive: true })
}
4 changes: 2 additions & 2 deletions packages/scripts/src/utils/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ export interface ProjectItem {
}

export async function getProjectItems(id: string) {
const res = await octokit.graphql.paginate<{
const res = await octokit.graphql<{
node: {
items: {
nodes: ProjectItem[]
Expand All @@ -145,7 +145,7 @@ export async function getProjectItems(id: string) {
query($cursor: String, $id: ID!) {
node(id: $id) {
... on ProjectV2 {
items(first: 20, after: $cursor) {
items(first: 5, after: $cursor) {
nodes {
id
content {
Expand Down
Loading