Skip to content

Commit

Permalink
write to issue
Browse files Browse the repository at this point in the history
  • Loading branch information
amenocal committed Jul 23, 2024
1 parent 62e25b5 commit 515e07f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 16 deletions.
29 changes: 16 additions & 13 deletions internal/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,27 +264,30 @@ func UploadAssetViaURL(uploadURL string, asset *github.ReleaseAsset) error {
}

func WriteToIssue(issueNumber int, comment string) error {

client := newGHRestClient(viper.GetString("TARGET_TOKEN"), "")

ctx := context.WithValue(context.Background(), github.SleepUntilPrimaryRateLimitResetWhenRateLimited, true)
_, _, err := client.Issues.CreateComment(ctx, viper.Get("TARGET_ORGANIZATION").(string), viper.Get("REPOSITORY").(string), issueNumber, &github.IssueComment{Body: &comment})
if err != nil {
return err
}

return nil
}

func GetIssueNumberfromContext() (int, error) {
githubContext := os.Getenv("GITHUB_CONTEXT")
if githubContext == "" {
return fmt.Errorf("GITHUB_CONTEXT is not set or empty")
return 0, fmt.Errorf("GITHUB_CONTEXT is not set or empty")
}

var issueEvent github.IssueEvent

err := json.Unmarshal([]byte(githubContext), &issueEvent)
if err != nil {
return fmt.Errorf("error unmarshalling GITHUB_CONTEXT: %v", err)
return 0, fmt.Errorf("error unmarshalling GITHUB_CONTEXT: %v", err)
}
//client := newGHRestClient(viper.GetString("TARGET_TOKEN"), "")

//ctx := context.WithValue(context.Background(), github.SleepUntilPrimaryRateLimitResetWhenRateLimited, true)
//fmt.Printf("github context: %v", os.Getenv("GITHUB_CONTEXT"))
fmt.Printf("github Issue Number: %v", *issueEvent.Issue.Number)
fmt.Printf("comment: %v", comment)
//_, _, err := client.Issues.CreateComment(ctx, viper.Get("TARGET_ORGANIZATION").(string), viper.Get("REPOSITORY").(string), issueNumber, &github.IssueComment{Body: &comment})
// if err != nil {
// return err
// }

return nil
return *issueEvent.Issue.Number, nil
}
9 changes: 6 additions & 3 deletions pkg/sync/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,13 @@ func SyncReleases() {
"```",
len(releases), len(releases)-failed, failed,
)
var id int = 1
err := api.WriteToIssue(id, message)
issueNumber, err := api.GetIssueNumberfromContext()
if err != nil {
pterm.Error.Printf("Error writing to issue: %v", err)
pterm.Error.Printf("Error getting issue number: %v", err)
}
err = api.WriteToIssue(issueNumber, message)
if err != nil {
pterm.Error.Printf("Error writing releases table to issue: %v", err)
}
}

Expand Down

0 comments on commit 515e07f

Please sign in to comment.