Skip to content

Commit

Permalink
Check SDK: support in_progress checks (#664)
Browse files Browse the repository at this point in the history
Prior to this the default status was `queued`, which is misleading if a
check wants to say it's started and then later finished.

Signed-off-by: Jason Hall <[email protected]>
  • Loading branch information
imjasonh authored Dec 12, 2024
1 parent d0a5519 commit cb40064
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
15 changes: 14 additions & 1 deletion modules/github-bots/sdk/check/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,17 @@ const (
truncationMessage = "\n\n⚠️ _Summary has been truncated_"
)

type Status string

const (
StatusQueued Status = "queued"
StatusInProgress Status = "in_progress"
StatusCompleted Status = "completed"
StatusWaiting Status = "waiting"
StatusRequested Status = "requested"
StatusPending Status = "pending"
)

type Conclusion string

const (
Expand All @@ -32,6 +43,7 @@ type Builder struct {
md strings.Builder
name, headSHA string
Summary string
Status Status
Conclusion Conclusion
}

Expand Down Expand Up @@ -71,6 +83,7 @@ func (b *Builder) CheckRunCreate() *github.CreateCheckRunOptions {
cr := &github.CreateCheckRunOptions{
Name: b.name,
HeadSHA: b.headSHA,
Status: github.String(string(StatusInProgress)),
Output: &github.CheckRunOutput{
Title: &b.Summary,
Summary: &b.Summary,
Expand All @@ -87,7 +100,7 @@ func (b *Builder) CheckRunCreate() *github.CreateCheckRunOptions {
// Providing conclusion will automatically set the status parameter to completed.
if b.Conclusion != "" {
cr.Conclusion = github.String(string(b.Conclusion))
cr.Status = github.String("completed")
cr.Status = github.String(string(StatusCompleted))
}
return cr
}
Expand Down
5 changes: 4 additions & 1 deletion modules/github-bots/sdk/check/check_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@ import (

func TestCheckRun(t *testing.T) {
b := NewBuilder("name", "headSHA")
b.Status = StatusInProgress
b.Writef("test %d", 123)

if diff := cmp.Diff(b.CheckRunCreate(), &github.CreateCheckRunOptions{
Name: "name",
HeadSHA: "headSHA",
Status: github.String("in_progress"),
Output: &github.CheckRunOutput{
Title: github.String("name"),
Summary: github.String("name"),
Expand All @@ -24,7 +26,8 @@ func TestCheckRun(t *testing.T) {
t.Errorf("CheckRunCreate() mismatch (-want +got):\n%s", diff)
}
if diff := cmp.Diff(b.CheckRunUpdate(), &github.UpdateCheckRunOptions{
Name: "name",
Name: "name",
Status: github.String("in_progress"),
Output: &github.CheckRunOutput{
Title: github.String("name"),
Summary: github.String("name"),
Expand Down

0 comments on commit cb40064

Please sign in to comment.