diff --git a/.github/workflows/code/create-checklist-comment.js b/.github/workflows/code/create-checklist-comment.js new file mode 100644 index 0000000000000000000000000000000000000000..f59b6f7516501d28f41416550f1d2f110861832f --- /dev/null +++ b/.github/workflows/code/create-checklist-comment.js @@ -0,0 +1,13 @@ +module.exports = async ({github, context}) => { + const pathToChecklist = './e2e/checklist.md' + const fs = require('fs') + const { promisify } = require('util') + const asyncReadFile = promisify(fs.readFile) + const text = await asyncReadFile(pathToChecklist, 'utf-8') + github.rest.issues.createComment({ + issue_number: context.issue.number, + owner: context.repo.owner, + repo: context.repo.repo, + body: text + }) +} diff --git a/.github/workflows/code/minimise-all-checklist-comments.js b/.github/workflows/code/minimise-all-checklist-comments.js new file mode 100644 index 0000000000000000000000000000000000000000..9d530c1457204b07a3dbe4f2f97531eaab255ab4 --- /dev/null +++ b/.github/workflows/code/minimise-all-checklist-comments.js @@ -0,0 +1,94 @@ +module.exports = async ({github, context}) => { + + const querySpec = `query($owner:String!, $name:String!, $issueNumber:Int!, $cursor:String) { + repository(owner: $owner, name: $name) { + pullRequest(number: $issueNumber) { + title + comments(first:50, after: $cursor){ + totalCount + edges{ + node { + author{ + login + } + bodyText, + isMinimized, + id + } + cursor + } + } + } + } + }` + const variables = { + owner: context.repo.owner, + name: context.repo.repo, + issueNumber: context.issue.number, + } + const results = [] + let cursor, totalCount = 0 + + const query = async ({ cursor }) => { + const resp = await github.graphql(querySpec, { + ...variables, + cursor + }) + const {totalCount = 0, edges = [] } = (() => { + try { + return resp.repository.pullRequest.comments + } catch (e) { + console.warn('accessor error', e) + return {} + } + })() + return { + results: edges.map(edge => edge.node), + cursor: (() => { + try { + return edges[edges.length - 1].cursor + } catch (e) { + return null + } + })(), + totalCount + } + } + + do { + const { + results: queryResults, + cursor: queryCursor, + totalCount: queryTotalCount + } = await query({ cursor }) + results.push(...queryResults) + cursor = queryCursor + totalCount = queryTotalCount + } while(!!cursor && totalCount > results.length) + + const commentsToMinimize = results.filter(res => res.author.login === 'github-actions' && !res.isMinimized) + + const mutation = `mutation($minComInput: MinimizeCommentInput!) { + minimizeComment(input: $minComInput) { + clientMutationId + minimizedComment{ + minimizedReason + viewerCanMinimize + isMinimized + } + } + }` + + console.log(`Minimizing ${commentsToMinimize.length} previous checklist comments.`) + + for (const result of results) { + const mutationVariable = { + "minComInput": { + "subjectId": result.id, + "classifier": "OUTDATED", + "clientMutationId": "gha" + } + } + await github.graphql(mutation, mutationVariable) + } +} diff --git a/.github/workflows/manual_e2e.yml b/.github/workflows/manual_e2e.yml new file mode 100644 index 0000000000000000000000000000000000000000..27877ea0cb6cb3167b8a8bc3833c392d63e02c14 --- /dev/null +++ b/.github/workflows/manual_e2e.yml @@ -0,0 +1,34 @@ +name: '[manual-e2e]' + +on: + pull_request: + branches: + - master + +jobs: + hide_previous_if_exists: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + with: + ref: 'master' + - uses: actions/github-script@v5 + with: + script: | + const script = require('./.github/workflows/code/minimise-all-checklist-comments.js') + await script({github, context}) + + add_e2e_checklist: + needs: hide_previous_if_exists + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + with: + ref: 'master' + - name: 'Add checklist comment' + uses: actions/github-script@v5 + with: + script: | + const script = require('./.github/workflows/code/create-checklist-comment.js') + await script({github, context})