Skip to content

Commit

Permalink
Andrey hura/take only latest statuses export json (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
andrey-hura authored Dec 10, 2024
1 parent 2ccef54 commit f4aec26
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions statusChecks.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ package main

import (
"context"
"fmt"
"encoding/json"
"github.com/google/go-github/v62/github"
"strings"
)

func setStatusCheck(client *github.Client, ctx *context.Context, repositoryName string, repositoryOwner string,
Expand All @@ -21,15 +22,22 @@ func setStatusCheck(client *github.Client, ctx *context.Context, repositoryName
func listStatusChecks(client *github.Client, ctx *context.Context, repositoryName string, repositoryOwner string, sha string) map[string]string {
statuses, _, err := client.Repositories.ListStatuses(*ctx, repositoryOwner, repositoryName, sha, nil)
failOnErr(err)
var allStatuses string = ""
allStatuses := ""
allStatusesMap := map[string]string{}
for i, status := range statuses {
var prefix string = ""
prefix := ""
if i > 0 {
prefix = ", "
}
allStatuses += prefix + *status.Context + " " + *status.State
if !strings.Contains(allStatuses, *status.Context) {
allStatuses += prefix + *status.Context + " " + *status.State
allStatusesMap[*status.Context] = *status.State
}
}
statusesJson, err := json.Marshal(allStatusesMap)
fields := map[string]string{
"STATUSES": allStatuses,
"STATUSES_JSON": string(statusesJson),
}
fmt.Println(allStatuses)
fields := map[string]string{"STATUSES": allStatuses}
return fields
}

0 comments on commit f4aec26

Please sign in to comment.