Skip to content

Commit

Permalink
Don't spam pull requests with coverage comments. (#296)
Browse files Browse the repository at this point in the history
* Renamed workflows for consitency.

Signed-off-by: dblock <[email protected]>

* Only add a comment if coverage has changed.

Signed-off-by: dblock <[email protected]>

* More renames for consistency.

Signed-off-by: dblock <[email protected]>

---------

Signed-off-by: dblock <[email protected]>
  • Loading branch information
dblock authored May 16, 2024
1 parent deeb400 commit 25bd55d
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 18 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
name: Links
name: Check Links

on:
push:
pull_request:

jobs:
linkChecker:
check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,16 @@ jobs:
total=`jq -r '.paths | keys | length' build/local-openapi.json`
percent=$((current * 100 / total))
echo "API specs implemented for $current/$total ($percent%) APIs."
cat >>"coverage.json" <<EOL
cat >>"coverage-api.json" <<EOL
{
"pull_request":${{ github.event.number }},
"sha":"${{ github.sha }}",
"current":$current,
"total":$total,
"percent":$percent
}
EOL
- uses: actions/upload-artifact@v4
with:
name: coverage
path: coverage.json
name: coverage-api
path: coverage-api.json
52 changes: 45 additions & 7 deletions .github/workflows/coverage-comment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ jobs:
uses: actions/download-artifact@v4
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
name: coverage
pattern: coverage-*
merge-multiple: true
run-id: ${{ github.event.workflow_run.id }}

- name: 'Comment on PR'
Expand All @@ -26,11 +27,48 @@ jobs:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const fs = require('fs');
const data = JSON.parse(fs.readFileSync('./coverage.json'));
console.log(data);
await github.issues.createComment({
const coverage_api = JSON.parse(fs.readFileSync('./coverage-api.json'));
console.log(coverage_api);
body = `API specs implemented for ${coverage_api.current}/${coverage_api.total} (${coverage_api.percent}%) APIs.`;
commit = `Commit ${coverage_api.sha}.`
const { data: comments } = await github.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: data.pull_request,
body: `API specs implemented for ${data.current}/${data.total} (${data.percent}%) APIs.`
});
issue_number: coverage_api.pull_request
});
const existing_comment = comments.find(
comment => comment.body.startsWith("API specs implemented for ")
);
if (existing_comment && ! existing_comment.body.startsWith(body)) {
// change in coverage, delete existing comment
console.log(`Deleting ${existing_comment.url}.`);
await github.issues.deleteComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: coverage_api.pull_request,
comment_id: existing_comment.id
});
}
if (existing_comment && existing_comment.body.startsWith(body)) {
// no change in coverage, update commit id
await github.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: coverage_api.pull_request,
comment_id: existing_comment.id,
body: body + "\n" + commit
});
} else {
// create a new comment
await github.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: coverage_api.pull_request,
body: body + "\n" + commit
});
}
4 changes: 2 additions & 2 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# deploys to https://opensearch-project.github.io/opensearch-api-specification/
name: Deploy
name: Deploy to GitHub Pages

on:
push:
Expand All @@ -14,7 +14,7 @@ permissions:
contents: write

jobs:
build:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout the repo
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Tools Testing
name: Test Tools

on:
push:
Expand All @@ -11,7 +11,7 @@ on:
- 'tools/**'

jobs:
tools-tests:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ on:
- 'tools/src/linter/**'

jobs:
lint-spec:
validate:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
Expand Down
2 changes: 2 additions & 0 deletions DEVELOPER_GUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
- [Global Parameters](#global-parameters)
- [OpenAPI Extensions](#openapi-extensions)
- [Tools](#tools)
- [Merger](#merger)
- [Linter](#linter)

# Developer Guide

Expand Down
2 changes: 1 addition & 1 deletion coverage/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

Builds the OpenAPI spec, and uses the [opensearch-api plugin](https://github.com/dblock/opensearch-api) and [openapi-diff](https://github.com/OpenAPITools/openapi-diff) to show the differences.

API coverage is run on all pull requests via the [coverage workflow](../.github/workflows/coverage-gather.yml).
API coverage is run on all pull requests via the [coverage workflow](../.github/workflows/coverage-api.yml).

0 comments on commit 25bd55d

Please sign in to comment.