Skip to content

Commit

Permalink
🐛 Get rid of CI prefix in commit hash.
Browse files Browse the repository at this point in the history
  • Loading branch information
hybloid authored and tiulpin committed May 2, 2024
1 parent 7acf90c commit d6f7751
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
11 changes: 8 additions & 3 deletions core/system.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,11 @@ func RunAnalysis(ctx context.Context, options *QodanaOptions) int {
log.Fatal("Cannot use git related functionality without a git executable")
}

isCiPrMode := false
if strings.HasPrefix(options.Commit, "CI") {
options.Commit = strings.TrimPrefix(options.Commit, "CI")
isCiPrMode = true
}
startHash, err := options.StartHash()
if err != nil {
log.Fatal(err)
Expand All @@ -185,7 +190,7 @@ func RunAnalysis(ctx context.Context, options *QodanaOptions) int {
case runScenarioFullHistory:
return runWithFullHistory(ctx, options, startHash)
case runScenarioLocalChanges:
return runLocalChanges(ctx, options, startHash)
return runLocalChanges(ctx, options, startHash, isCiPrMode)
case runScenarioScoped:
return runScopeScript(ctx, options, startHash)
case runScenarioDefault:
Expand All @@ -196,7 +201,7 @@ func RunAnalysis(ctx context.Context, options *QodanaOptions) int {
}
}

func runLocalChanges(ctx context.Context, options *QodanaOptions, startHash string) int {
func runLocalChanges(ctx context.Context, options *QodanaOptions, startHash string, isCiPrMode bool) int {
var exitCode int
options.GitReset = false
if r := platform.GitCurrentRevision(options.ProjectDir); options.DiffEnd != "" && options.DiffEnd != r {
Expand All @@ -213,7 +218,7 @@ func runLocalChanges(ctx context.Context, options *QodanaOptions, startHash stri

exitCode = runQodana(ctx, options)

if options.GitReset && !strings.HasPrefix(startHash, "CI") {
if options.GitReset && isCiPrMode {
_ = platform.GitResetBack(options.ProjectDir)
}
return exitCode
Expand Down
2 changes: 1 addition & 1 deletion platform/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func gitRun(cwd string, command []string) error {

// GitReset resets the git repository to the given commit.
func GitReset(cwd string, sha string) error {
return gitRun(cwd, []string{"reset", "--soft", strings.TrimPrefix(sha, "CI")})
return gitRun(cwd, []string{"reset", "--soft", sha})
}

// GitResetBack aborts the git reset.
Expand Down

0 comments on commit d6f7751

Please sign in to comment.