import ( "context" "fmt" "github.com/google/go-github/v33/github" "k8s.io/contrib/mungegithub/github" ) func main() { ctx := context.Background() client := github.NewClient(ctx) org := "my-org" repo := "my-repo" issueNum := 123 issue, _, err := client.Issues.Get(ctx, org, repo, issueNum) if err != nil { fmt.Printf("Error getting issue: %v\n", err) return } munge := &github.MungeObject{ Issue: &github.MungeIssue{ LabelsToAdd: []string{"my-label"}, }, Type: github.MungeIssueType, Number: issueNum, } _, _, err = client.Munges.Munge(ctx, org, repo, munge) if err != nil { fmt.Printf("Error applying munge: %v\n", err) return } fmt.Println("Label added to issue!") }
import ( "context" "fmt" "github.com/google/go-github/v33/github" "k8s.io/contrib/mungegithub/github" ) func main() { ctx := context.Background() client := github.NewClient(ctx) org := "my-org" repo := "my-repo" prNum := 321 pr, _, err := client.PullRequests.Get(ctx, org, repo, prNum) if err != nil { fmt.Printf("Error getting PR: %v\n", err) return } munge := &github.MungeObject{ PullRequest: &github.MungePullRequest{ Body: github.String(pr.GetBody() + "\n\nThis was added by the Github MungeObject!"), }, Type: github.MungePullRequestType, Number: prNum, } _, _, err = client.Munges.Munge(ctx, org, repo, munge) if err != nil { fmt.Printf("Error applying munge: %v\n", err) return } fmt.Println("PR description modified!") }This example retrieves an existing pull request from Github, creates a MungeObject to append a message to the pull request's description, and applies the munge using the Github API. The MungeObject is defined with a MungePullRequest field to specify the modification to make to the pull request, and a Type and Number field to identify the specific pull request to modify.