generated from actions/typescript-action
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Specifically, and fields for the pull request number, the opt-in status of the pull request author, and a timestamp for when the data was generated.
- Loading branch information
Showing
4 changed files
with
132 additions
and
46 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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,56 @@ | ||
import * as core from '@actions/core' | ||
import { DefaultArtifactClient } from '@actions/artifact' | ||
import { PullRequest } from '@octokit/webhooks-types' // eslint-disable-line import/no-unresolved | ||
import * as fs from 'fs' | ||
import * as path from 'path' | ||
import { Score } from 'sizeup-core' | ||
import { Configuration } from './configuration' | ||
import { OptInStatus } from './initializer' | ||
|
||
export async function createScoreArtifact( | ||
pull: PullRequest, | ||
score: Score, | ||
optInStatus: OptInStatus, | ||
config: Configuration | ||
): Promise<void> { | ||
if (!config.archiving?.persistScoreArtifact) { | ||
core.info('Skipping score artifact creation') | ||
return | ||
} | ||
|
||
core.info('Creating score artifact') | ||
|
||
const tmpDir = path.resolve(__dirname, './tmp') | ||
const scoreFile = path.resolve(tmpDir, './sizeup-score/sizeup-score.csv') | ||
|
||
fs.mkdirSync(path.dirname(scoreFile), { recursive: true }) | ||
fs.writeFileSync(scoreFile, scoreFileContents(pull, score, optInStatus)) | ||
|
||
const client = new DefaultArtifactClient() | ||
await client.uploadArtifact('sizeup-score', [scoreFile], tmpDir, { | ||
retentionDays: config.archiving?.artifactRetention | ||
}) | ||
} | ||
|
||
function scoreFileContents( | ||
pull: PullRequest, | ||
score: Score, | ||
optInStatus: OptInStatus | ||
): string { | ||
const fields = [ | ||
['pull-request-number', `${pull.number}`], | ||
['opted-in', `${optInStatus === OptInStatus.In}`], | ||
['score', `${score.result}`], | ||
['category', score.category?.name || ''], | ||
['timestamp', `${Date.now()}`] | ||
] | ||
|
||
const header = [] | ||
const data = [] | ||
for (const [key, value] of fields) { | ||
header.push(key) | ||
data.push(value) | ||
} | ||
|
||
return [header.join(','), data.join(',')].join('\n') | ||
} |
This file contains 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