Skip to content
Snippets Groups Projects
Commit a06beb38 authored by Xiao Gui's avatar Xiao Gui
Browse files

Merge remote-tracking branch 'origin/master' into staging

parents 4a237aea 318c4ec3
No related branches found
No related tags found
No related merge requests found
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
})
}
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)
}
}
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})
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment