Skip to content

Commit

Permalink
fix writing to correct issue
Browse files Browse the repository at this point in the history
  • Loading branch information
amenocal committed Jul 23, 2024
1 parent 515e07f commit 79367a2
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
15 changes: 9 additions & 6 deletions internal/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,31 +263,34 @@ func UploadAssetViaURL(uploadURL string, asset *github.ReleaseAsset) error {
return nil
}

func WriteToIssue(issueNumber int, comment string) error {
func WriteToIssue(owner string, repository string, 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})
_, _, err := client.Issues.CreateComment(ctx, owner, repository, issueNumber, &github.IssueComment{Body: &comment})
if err != nil {
return err
}

return nil
}

func GetIssueNumberfromContext() (int, error) {
func GetDatafromGitHubContext() (string, string, int, error) {
githubContext := os.Getenv("GITHUB_CONTEXT")
if githubContext == "" {
return 0, 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 0, fmt.Errorf("error unmarshalling GITHUB_CONTEXT: %v", err)
return "", "", 0, fmt.Errorf("error unmarshalling GITHUB_CONTEXT: %v", err)
}
organization := *issueEvent.Repository.Owner.Login
repository := *issueEvent.Repository.Name
issueNumber := *issueEvent.Issue.Number

return *issueEvent.Issue.Number, nil
return organization, repository, issueNumber, nil
}
4 changes: 2 additions & 2 deletions pkg/sync/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,11 @@ func SyncReleases() {
"```",
len(releases), len(releases)-failed, failed,
)
issueNumber, err := api.GetIssueNumberfromContext()
organization, repository, issueNumber, err := api.GetDatafromGitHubContext()
if err != nil {
pterm.Error.Printf("Error getting issue number: %v", err)
}
err = api.WriteToIssue(issueNumber, message)
err = api.WriteToIssue(organization, repository, issueNumber, message)
if err != nil {
pterm.Error.Printf("Error writing releases table to issue: %v", err)
}
Expand Down

0 comments on commit 79367a2

Please sign in to comment.