-
Notifications
You must be signed in to change notification settings - Fork 0
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
feat: create automated dashboard ci #171
base: main
Are you sure you want to change the base?
Changes from 78 commits
e7feeea
00f8d3a
3b23654
a4f1d8f
464c08c
dfb4fd5
579b4e0
0e055d7
409e98b
aa010d4
222f2f1
c0f93ad
993a897
b1a1de2
635236d
7a8d9fd
b2ef9d4
3330787
d0aacd1
e3d32f2
f81c894
f8ae876
446377a
16aaf23
52ba7b5
7251905
2ead9d4
728537c
e4e4c42
41941e7
5e7929a
a72e1c5
8694d8f
87ffa11
58f2a9e
b536de2
b15e073
1c09ae7
018db92
5851228
9326b14
ccbfa69
bb1f251
f3ab4d1
d4ea8f0
a395dd0
6c5e40a
e84e8d1
d0b7550
838cf7f
cd64edf
5679cb2
99f6b70
9cdae58
cbfa2a9
cfcccdb
51db604
8a931b2
28fef86
699c6d6
2871834
98b27a4
52f404e
07dbf0b
f290874
098ea61
993df8b
b3875cf
a552862
d8b4059
bd24ab7
580fee3
69e67ae
244feac
2d2abfc
a25eff9
7708817
53f064c
e499a82
56e8492
80eb13c
9d52418
a16cecb
5d7d6d1
622973c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,186 @@ | ||
name: Project Dashboard | ||
|
||
on: | ||
pull_request: | ||
paths: | ||
- '.github/workflows/project-dashboard.yaml' | ||
workflow_dispatch: | ||
schedule: | ||
- cron: '0 * * * *' | ||
|
||
concurrency: | ||
group: ${{ github.workflow }} | ||
cancel-in-progress: false | ||
|
||
jobs: | ||
dashboard: | ||
runs-on: | ||
labels: [ self-hosted, linux, x64 ] | ||
group: light | ||
steps: | ||
|
||
- uses: actions/github-script@v7 | ||
id: dashboard-updater | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.DASHBOARD_TEST_TOKEN }} | ||
with: | ||
result-encoding: string | ||
retries: 3 | ||
retry-exempt-status-codes: 400,401 | ||
github-token: ${{ secrets.DASHBOARD_TEST_TOKEN }} | ||
script: | | ||
const clearQuery = `mutation ClearBoard($boardID: ID!, $itemID: ID!) { | ||
deleteProjectV2Item(input: {projectId: $boardID, itemId: $itemID}) { | ||
deletedItemId | ||
} | ||
}`; | ||
|
||
const getProjectData = `query GetProjectData($boardID: ID!, $cursor: String){node(id: $boardID) { | ||
... on ProjectV2 { | ||
items(first: 100, after: $cursor) { | ||
pageInfo { | ||
hasNextPage | ||
endCursor | ||
} | ||
items: edges { | ||
node { | ||
id | ||
} | ||
} | ||
} | ||
} | ||
}}`; | ||
|
||
const board = `query { | ||
organization(login: "SwanseaUniversityMedical") { | ||
projectV2(number: 15) { | ||
id | ||
} | ||
} | ||
}`; | ||
|
||
const boardData = await github.graphql(board); | ||
const boardID = boardData.organization.projectV2.id; | ||
|
||
let cursor = null; | ||
let hasNextPage = true; | ||
const boardItems = []; | ||
|
||
while (hasNextPage) { | ||
const response = await github.graphql(getProjectData, { boardID, cursor }); | ||
boardItems.push(...response.node.items.items.map(item => item.node.id)); | ||
hasNextPage = response.node.items.pageInfo.hasNextPage; | ||
cursor = response.node.items.pageInfo.endCursor; | ||
} | ||
|
||
for (let i = 0; i < boardItems.length; i++) { | ||
await github.graphql(clearQuery, { boardID, itemID: boardItems[i] }); | ||
} | ||
|
||
const query = `query Search($cursor: String) { | ||
search(query: "org:SwanseaUniversityMedical", type: REPOSITORY, first: 100, after: $cursor) { | ||
pageInfo { | ||
hasNextPage | ||
endCursor | ||
}, | ||
repos: edges { | ||
node { | ||
... on Repository { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What's this There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It forces graphql to make sure that the node is the correct type iirc, it also has other functions in graphql depending on how you use it, on line 103 I think it helps expand the response and acts like a for loop while if used in other places it can make blocks reusable: https://graphql.org/learn/queries/#fragments |
||
name | ||
isPrivate | ||
} | ||
} | ||
} | ||
} | ||
}`; | ||
|
||
cursor = null; | ||
hasNextPage = true; | ||
const repositories = []; | ||
|
||
while (hasNextPage) { | ||
const response = await github.graphql(query, { cursor }); | ||
repositories.push(...response.search.repos.map(repo => repo.node.name)); | ||
hasNextPage = response.search.pageInfo.hasNextPage; | ||
cursor = response.search.pageInfo.endCursor; | ||
} | ||
|
||
const repos = repositories.join(', '); // Return as a comma-separated string | ||
rdash99 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
const PRQuery = `query PRs($cursor: String, $repo: String!) { | ||
organization(login: "SwanseaUniversityMedical") { | ||
repository(name: $repo) { | ||
pullRequests(first: 100, after: $cursor, states: [OPEN]) { | ||
pageInfo { | ||
hasNextPage | ||
endCursor | ||
} | ||
PRs: edges { | ||
node { | ||
id | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we limit it to only authored by There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can't limit by author unfortunately - it was one of the first things I tried to do |
||
} | ||
} | ||
} | ||
} | ||
} | ||
}`; | ||
|
||
const IssueQuery = `query Issues($cursor: String, $repo: String!) { | ||
organization(login: "SwanseaUniversityMedical") { | ||
repository(name: $repo) { | ||
issues(first: 100, after: $cursor, states: [OPEN]) { | ||
pageInfo { | ||
hasNextPage | ||
endCursor | ||
} | ||
issues: edges { | ||
node { | ||
id | ||
rdash99 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
} | ||
} | ||
} | ||
} | ||
}`; | ||
|
||
const addToBoard = `mutation AddToBoard($boardID: ID!, $ID: ID!) { | ||
addProjectV2ItemById(input: {projectId: $boardID, contentId: $ID}) { | ||
item { | ||
id | ||
} | ||
} | ||
}`; | ||
|
||
for (let i = 0; i < repositories.length; i++) { | ||
let cursor = null; | ||
let hasNextPage = true; | ||
const PRS = []; | ||
|
||
while (hasNextPage) { | ||
const response = await github.graphql(PRQuery, { cursor, repo: repositories[i] }); | ||
PRS.push(...response.organization.repository.pullRequests.PRs.map(pr => pr.node.id)); | ||
hasNextPage = response.organization.repository.pullRequests.pageInfo.hasNextPage; | ||
cursor = response.organization.repository.pullRequests.pageInfo.endCursor; | ||
} | ||
|
||
for (let j = 0; j < PRS.length; j++) { | ||
await github.graphql(addToBoard, { boardID, ID: PRS[j] }); | ||
} | ||
} | ||
|
||
for (let i = 0; i < repositories.length; i++) { | ||
let cursor = null; | ||
let hasNextPage = true; | ||
const issues = []; | ||
|
||
while (hasNextPage) { | ||
const response = await github.graphql(IssueQuery, { cursor, repo: repositories[i] }); | ||
issues.push(...response.organization.repository.issues.issues.map(issue => issue.node.id)); | ||
hasNextPage = response.organization.repository.issues.pageInfo.hasNextPage; | ||
cursor = response.organization.repository.issues.pageInfo.endCursor; | ||
} | ||
|
||
for (let j = 0; j < issues.length; j++) { | ||
await github.graphql(addToBoard, { boardID, ID: issues[j] }); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we filter the query for what to remove to look for things closed or merged more than X days ago?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe though what I'm grabbing now is just 'everything on the board'
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How long are we talking days wise?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nvm - this doesn't look possible, you can find the type (issue/pr etc) but not any further details and the only option I can see as to ordering is the order it appears on the project board itself