Skip to content
Open
Show file tree
Hide file tree
Changes from 3 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
35 changes: 35 additions & 0 deletions sources/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions sources/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
"@actions/glob": "0.6.1",
"@actions/http-client": "4.0.0",
"@actions/tool-cache": "4.0.0",
"@octokit/graphql-schema": "15.26.1",
"@octokit/webhooks-types": "7.6.1",
"cheerio": "1.2.0",
"semver": "7.7.4",
Expand Down
53 changes: 51 additions & 2 deletions sources/src/job-summary.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import * as core from '@actions/core'
import * as github from '@actions/github'
import {GitHub} from '@actions/github/lib/utils'
import {Repository} from '@octokit/graphql-schema'

import {BuildResult} from './build-results'
import {SummaryConfig, getActionId, getGithubToken} from './configuration'
import {DependencyGraphConfig, getActionId, getGithubToken, getJobMatrix, SummaryConfig} from './configuration'
import {Deprecation, getDeprecations, getErrors} from './deprecation-collector'

export async function generateJobSummary(
Expand Down Expand Up @@ -48,7 +50,11 @@ async function addPRComment(jobSummary: string): Promise<void> {
const pull_request_number = context.payload.pull_request.number
core.info(`Adding Job Summary as comment to PR #${pull_request_number}.`)

const prComment = `<h3>Job Summary for Gradle</h3>
const jobCorrelator = DependencyGraphConfig.constructJobCorrelator(context.workflow, context.job, getJobMatrix())
const marker = `<!-- gradle-job-summary: ${jobCorrelator} -->`

const prComment = `${marker}
<h3>Job Summary for Gradle</h3>
<a href="${context.serverUrl}/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}" target="_blank">
<h5>${context.workflow} :: <em>${context.job}</em></h5>
</a>
Expand All @@ -57,6 +63,8 @@ ${jobSummary}`

const github_token = getGithubToken()
const octokit = github.getOctokit(github_token)
await minimizeComments(octokit, pull_request_number, marker)

try {
await octokit.rest.issues.createComment({
...context.repo,
Expand Down Expand Up @@ -201,3 +209,44 @@ function truncateString(str: string, maxLength: number): string {
return str
}
}

async function minimizeComments(octokit: InstanceType<typeof GitHub>, prNumber: number, marker: string): Promise<void> {
const {owner, repo} = github.context.repo

const query = `
query($owner: String!, $repo: String!, $prNumber: Int!) {
repository(owner: $owner, name: $repo) {
pullRequest(number: $prNumber) {
comments(last: 100) {
nodes { id body isMinimized url }
}
}
}
}
`
let comments
try {
const {repository} = await octokit.graphql<{repository: Repository}>(query, {owner, repo, prNumber})
comments = repository.pullRequest?.comments?.nodes?.filter((c): c is NonNullable<typeof c> => c !== null) ?? []
} catch (error) {
return core.warning(`Failed to fetch comments: ${error}`)
}

const mutation = `
mutation($id: ID!) {
minimizeComment(input: {subjectId: $id, classifier: OUTDATED}) {
clientMutationId
}
}
`

const commentsToMinimize = comments
.filter(c => !c.isMinimized && c.body.includes(marker))
.map(async c =>
octokit
.graphql(mutation, {id: c.id})
.then(() => core.info(`Successfully minimized (id:${c.id}, url:${c.url})`))
.catch(e => core.warning(`Failed to minimize (id:${c.id}, url:${c.url}, error:${e?.message || e})`))
)
await Promise.allSettled(commentsToMinimize)
}
Loading