-
Notifications
You must be signed in to change notification settings - Fork 0
Compliance fixes #13
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
Merged
Merged
Compliance fixes #13
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
e191b7f
Fix formatting for single exports to be single line
pr0uxx 17930b0
Migrate scripts to typescript
pr0uxx f23e023
Reintroduce exports
pr0uxx 0b59ed0
Fix coverage summary import path
pr0uxx 8bd5cac
.npmignore ignores .gitattributes now. yay.
pr0uxx File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file was deleted.
Oops, something went wrong.
File renamed without changes.
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,121 @@ | ||
| import { readFile } from 'node:fs/promises'; | ||
|
|
||
| /** Represents a GitHub issue comment. */ | ||
| interface IssueComment { | ||
| /** Gets the comment body. */ | ||
| 'body'?: string | null; | ||
| /** Gets the comment identifier. */ | ||
| 'id': number; | ||
| } | ||
|
|
||
| /** Defines the GitHub Script inputs needed to publish a coverage comment. */ | ||
| interface PublishCoverageCommentOptions { | ||
| /** Provides GitHub Actions workflow context. */ | ||
| 'context': { | ||
| /** Provides pull request or issue details. */ | ||
| 'issue': { | ||
| /** Gets the issue number. */ | ||
| 'number': number; | ||
| }; | ||
| /** Provides the target repository details. */ | ||
| 'repo': { | ||
| /** Gets the repository owner. */ | ||
| 'owner': string; | ||
| /** Gets the repository name. */ | ||
| 'repo': string; | ||
| }; | ||
| }; | ||
| /** Provides the GitHub REST client. */ | ||
| 'github': { | ||
| /** Retrieves all pages for a REST endpoint. */ | ||
| 'paginate': ( | ||
| route: unknown, | ||
| parameters: { | ||
| /** Specifies the issue number. */ | ||
| 'issue_number': number; | ||
| /** Specifies the repository owner. */ | ||
| 'owner': string; | ||
| /** Specifies the number of results per page. */ | ||
| 'per_page': number; | ||
| /** Specifies the repository name. */ | ||
| 'repo': string; | ||
| } | ||
| ) => Promise<IssueComment[]>; | ||
| /** Exposes GitHub REST endpoint groups. */ | ||
| 'rest': { | ||
| /** Exposes issue and issue-comment endpoints. */ | ||
| 'issues': { | ||
| /** Creates an issue comment. */ | ||
| 'createComment': (parameters: { | ||
| /** Specifies the comment body. */ | ||
| 'body': string; | ||
| /** Specifies the issue number. */ | ||
| 'issue_number': number; | ||
| /** Specifies the repository owner. */ | ||
| 'owner': string; | ||
| /** Specifies the repository name. */ | ||
| 'repo': string; | ||
| }) => Promise<unknown>; | ||
| /** Lists issue comments. */ | ||
| 'listComments': unknown; | ||
| /** Updates an issue comment. */ | ||
| 'updateComment': (parameters: { | ||
| /** Specifies the comment body. */ | ||
| 'body': string; | ||
| /** Specifies the comment identifier. */ | ||
| 'comment_id': number; | ||
| /** Specifies the repository owner. */ | ||
| 'owner': string; | ||
| /** Specifies the repository name. */ | ||
| 'repo': string; | ||
| }) => Promise<unknown>; | ||
| }; | ||
| }; | ||
| }; | ||
| /** Specifies the path to the generated coverage summary. */ | ||
| 'summaryPath': string; | ||
| } | ||
|
|
||
| /** Identifies coverage comments managed by this script. */ | ||
| const marker = '<!-- log-engine-coverage-report -->'; | ||
| /** | ||
| * Publishes or updates the coverage summary comment on the current issue. | ||
| * @param options Provides the GitHub Script inputs. | ||
| */ | ||
| export default async function publishCoverageComment(options: PublishCoverageCommentOptions) { | ||
| /** Gets the GitHub Script inputs. */ | ||
| const { github, context, summaryPath } = options; | ||
| /** Gets the Markdown coverage summary. */ | ||
| const coverageSummary = (await readFile(summaryPath, 'utf8')).trim(); | ||
| /** Gets the managed coverage comment body. */ | ||
| const body = `${ marker }\n${ coverageSummary }`; | ||
| /** Gets the target repository owner and name. */ | ||
| const { owner, repo } = context.repo; | ||
| /** Gets the issue number for the coverage comment. */ | ||
| const issueNumber = context.issue.number; | ||
| /** Gets all existing comments on the current issue. */ | ||
| const comments = await github.paginate(github.rest.issues.listComments, { | ||
| owner, | ||
| repo, | ||
| 'issue_number': issueNumber, | ||
| 'per_page': 100 | ||
| }); | ||
| /** Gets the existing managed coverage comment, when present. */ | ||
| const existingComment = comments.find((comment) => comment.body?.includes(marker) ?? false); | ||
| if (existingComment) { | ||
| await github.rest.issues.updateComment({ | ||
| owner, | ||
| repo, | ||
| 'comment_id': existingComment.id, | ||
| body | ||
| }); | ||
| } | ||
| else { | ||
| await github.rest.issues.createComment({ | ||
| owner, | ||
| repo, | ||
| 'issue_number': issueNumber, | ||
| body | ||
| }); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.