Skip to content

Commit

Permalink
prevent push if there are uncommitted changes
Browse files Browse the repository at this point in the history
  • Loading branch information
fwuensche committed Sep 22, 2024
1 parent de7bdb8 commit 91cff2d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 14 deletions.
10 changes: 6 additions & 4 deletions bin/commands/push.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,13 @@ export default function (program: Command) {
.option('--api-key <api_key>', 'your cherrypush.com API key')
.option('--quiet', 'reduce output to a minimum')
.action(async (options) => {
const sha = await git.sha()
const configuration = await getConfiguration()
const initialBranch = await git.branchName()
if (!initialBranch) panic('Not on a branch, checkout a branch before pushing metrics.')
const sha = await git.sha()

const hasUncommitedChanges = (await git.uncommittedFiles()).length > 0
if (hasUncommitedChanges) panic('Please commit your changes before running cherry diff.')

const apiKey = options.apiKey || process.env.CHERRY_API_KEY
if (!apiKey) panic('Please provide an API key with --api-key or CHERRY_API_KEY environment variable')
Expand All @@ -36,8 +39,7 @@ export default function (program: Command) {

await upload(apiKey, configuration.project_name, await git.commitDate(sha), occurrences)

console.log('')
console.log('Computing metrics for previous commit...')
console.log('\nComputing metrics for previous commit...')
await git.checkout(`${sha}~`)
const previousOccurrences = await findOccurrences({
configuration,
Expand All @@ -49,7 +51,7 @@ export default function (program: Command) {
const contributions = computeContributions(occurrences, previousOccurrences)

if (contributions.length) {
console.log(` Uploading contributions...`)
console.log('\nUploading contributions...')
await uploadContributions(
apiKey,
configuration.project_name,
Expand Down
20 changes: 10 additions & 10 deletions src/occurrences.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import { Configuration, EvalMetric, Metric, Occurrence, PatternMetric, PluginName, Plugins } from './types.js'
import { executeWithTiming, warnsAboutLongRunningTasks } from './helpers/timer.js'
import { Configuration, EvalMetric, Metric, Occurrence, PatternMetric, PluginName, Plugins } from './types.js'

import Spinnies from 'spinnies'
import _ from 'lodash'
import minimatch from 'minimatch'
import pLimit from 'p-limit'
import Spinnies from 'spinnies'
import { isEvalMetric } from '../bin/helpers.js'
import { panic } from './error.js'
import { readLines } from './files.js'
import { buildPermalink } from './permalink.js'
import eslint from './plugins/eslint.js'
import { isEvalMetric } from '../bin/helpers.js'
import jsCircularDependencies from './plugins/js_circular_dependencies.js'
import jsUnimported from './plugins/js_unimported.js'
import loc from './plugins/loc.js'
import minimatch from 'minimatch'
import npmOutdated from './plugins/npm_outdated.js'
import pLimit from 'p-limit'
import { panic } from './error.js'
import { readLines } from './files.js'
import rubocop from './plugins/rubocop.js'
import yarnOutdated from './plugins/yarn_outdated.js'

Expand Down Expand Up @@ -102,7 +102,7 @@ const matchPatterns = async (files: string[], metrics: PatternMetric[], quiet: b
'All pattern metrics together'
)

if (!quiet) promise.then(() => spinnies.succeed('patterns', { text: 'Matching patterns' }))
if (!quiet) await promise.then(() => spinnies.succeed('patterns', { text: 'Matching patterns' }))

return promise
}
Expand All @@ -124,7 +124,7 @@ const runEvals = async (metrics: EvalMetric[], codeOwners: any, quiet: boolean):

// TODO: properly type executeWithTiming and remove the cast
const occurrences = (await executeWithTiming(
async () => await metric.eval({ codeOwners }),
async () => metric.eval({ codeOwners }),
`Metric '${metric.name}'`
)) as Occurrence[]

Expand All @@ -135,7 +135,7 @@ const runEvals = async (metrics: EvalMetric[], codeOwners: any, quiet: boolean):
})
)

if (!quiet) promise.then(() => spinnies.succeed('evals', { text: 'Running eval()' }))
if (!quiet) await promise.then(() => spinnies.succeed('evals', { text: 'Running eval()' }))

return promise
}
Expand Down

0 comments on commit 91cff2d

Please sign in to comment.