Commit 48c732b
authored
fix: Don't report check to invalid sha (#515)
* fix: Don't report check to old sha
This fixes an issue where a failed git checkout (because of a missing
ref, network, or auth issues) would cause a failure to be posted to
GitHub for the wrong sha - most often the last successfully built sha.
This has caused confusion when one or more checks was reported as
passing only to be unexpectedly changed to failing for an unrelated
reason. It looks for cases where the git build data doesn't match the
current build and returning an empty string for the sha if that's the
case. Otherwise the behavior should remain the same.
I added a new test to cover this case and I've tested it both with a
manual repro in a sandbox environment and in a production environment
(we run approximately 100k PR checks through this plugin on an average
day) to confirm that it's working as expected when build failures occur
before or during checkout.
Prior to this fix - a failure during git checkout would report the
failure to the previous successful sha:
```
> gh api "repos/$ORG/$REPO/commits/$SHA/check-runs?filter=all" | jq
'.check_runs[] | {name, head_sha, status, conclusion, completed_at}'
{
"name": "gh-checks-plugin-fix-test",
"head_sha": "71a1cc8f8b956b11b12036b8687acd7a5fafa868",
"status": "completed",
"conclusion": "failure",
"completed_at": "2026-02-18T15:49:53Z"
}
{
"name": "gh-checks-plugin-fix-test",
"head_sha": "71a1cc8f8b956b11b12036b8687acd7a5fafa868",
"status": "completed",
"conclusion": "success",
"completed_at": "2026-02-18T15:48:46Z"
}
```
And with this fix, the build failed. But, as expected, it skipped
reporting the failure to the wrong sha:
```
> gh api "repos/$ORG/$REPO/commits/$SHA/check-runs?filter=all" | jq
'.check_runs[] | {name, head_sha, status, conclusion, completed_at}'
{
"name": "gh-checks-plugin-fix-test",
"head_sha": "5dd2fbbbf2d102e0bb72f1ab76e5c00b8b29cf2e",
"status": "completed",
"conclusion": "success",
"completed_at": "2026-02-18T15:58:32Z"
}
```
The main caveat with this is that we use Freestyle jobs, not Pipeline
jobs, so I'm relying on the existing test case to ensure it's still
working as expected for pipelines.
* fix tests
I had made the original changes based on an older version of the plugin
so it would be compatible with the older version of Jenkins we're still
using and I forgot to re-run the tests after I cherry-picked the commit
to the latest on `master`. This is now passing when I run tests locally.
* Avoid potential null pointer exception to fix spotbugs
* mock builddata1 parent a1bb1dc commit 48c732b
File tree
3 files changed
+50
-0
lines changed- src
- main/java/io/jenkins/plugins/checks/github
- test/java/io/jenkins/plugins/checks/github
3 files changed
+50
-0
lines changedLines changed: 11 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
48 | 48 | | |
49 | 49 | | |
50 | 50 | | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
51 | 62 | | |
52 | 63 | | |
53 | 64 | | |
| |||
Lines changed: 8 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| 9 | + | |
| 10 | + | |
9 | 11 | | |
10 | 12 | | |
11 | 13 | | |
| |||
78 | 80 | | |
79 | 81 | | |
80 | 82 | | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
81 | 89 | | |
82 | 90 | | |
83 | 91 | | |
| |||
Lines changed: 31 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
82 | 82 | | |
83 | 83 | | |
84 | 84 | | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
85 | 116 | | |
0 commit comments