Skip to content
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

Add more useful fields to the CSV artifact, as well as configuration for artifact retention. #46

Merged
merged 2 commits into from
Mar 4, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
3 changes: 2 additions & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
dist/
node_modules/
coverage/
coverage/
src/configuration.ts
2 changes: 1 addition & 1 deletion badges/coverage.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 14 additions & 4 deletions dist/config/schema.json

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

88 changes: 73 additions & 15 deletions dist/index.js

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

56 changes: 56 additions & 0 deletions src/archiver.ts
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')
}
18 changes: 14 additions & 4 deletions src/config/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,20 @@
"type": "boolean",
"default": false
},
"persistScoreArtifact": {
"description": "Whether or not to create a workflow artifact that contains details about the score",
"type": "boolean",
"default": false
"archiving": {
"description": "Configuration options for persisting the output of this workflow",
"type": "object",
"properties": {
"persistScoreArtifact": {
"description": "Whether or not to create a workflow artifact that contains details about the score",
"type": "boolean",
"default": false
},
"artifactRetention": {
"description": "Retention period (in days) for the artifact created by this workflow. The actual retention period used may be shorter than this in the presence of an overriding repository- or organization- level retention period setting.",
"type": "number"
}
}
},
"sizeup": {
"$ref": "https://raw.githubusercontent.com/lerebear/sizeup/main/src/config/schema.json"
Expand Down
Loading
Loading