func (r *release) prepareForApiCalls() (client *github.Client, owner, repo string, err error) { if r.client == nil { r.client = ghutil.NewClient(r.tool.config.Token) } if r.owner == "" || r.repo == "" { var err error r.owner, r.repo, err = ghutil.ParseUpstreamURL() if err != nil { return nil, "", "", err } } return r.client, r.owner, r.repo, nil }
func loadConfig() (*moduleConfig, error) { task := fmt.Sprintf("Load config for module '%v'", ModuleId) // Load the config. spec := newConfigSpec() if err := loader.LoadConfig(spec); err != nil { return nil, errs.NewError(task, err) } // Parse the main repo upstream URL. owner, repo, err := github.ParseUpstreamURL() if err != nil { return nil, errs.NewError(task, err) } // Assemble the config object. var ( local = spec.local global = spec.global ) return &moduleConfig{ GitHubOwner: owner, GitHubRepository: repo, UserToken: global.UserToken, StoryLabels: local.StoryLabels, ApprovedLabel: local.StateLabels.ApprovedLabel, BeingImplementedLabel: local.StateLabels.BeingImplementedLabel, ImplementedLabel: local.StateLabels.ImplementedLabel, ReviewedLabel: local.StateLabels.ReviewedLabel, SkipReviewLabel: local.StateLabels.SkipReviewLabel, PassedTestingLabel: local.StateLabels.PassedTestingLabel, FailedTestingLabel: local.StateLabels.FailedTestingLabel, SkipTestingLabel: local.StateLabels.SkipTestingLabel, StagedLabel: local.StateLabels.StagedLabel, RejectedLabel: local.StateLabels.RejectedLabel, SkipCheckLabels: local.SkipCheckLabels, }, nil }
func (tool *codeReviewTool) PostReviewRequests( ctxs []*common.ReviewContext, opts map[string]interface{}, ) (err error) { // Get the GitHub owner and repository from the upstream URL. owner, repo, err := ghutil.ParseUpstreamURL() if err != nil { return err } // Group commits by story ID. // // In case the commit is associated with a story, we add it to the relevant story group. // Otherwise the commit is marked as unassigned and added to the relevant list. var ( ctxsByStoryId = make(map[string][]*common.ReviewContext, 1) unassignedCommits = make([]*git.Commit, 0, 1) ) for _, ctx := range ctxs { story := ctx.Story if story != nil { sid := story.ReadableId() rcs, ok := ctxsByStoryId[sid] if ok { rcs = append(rcs, ctx) } else { rcs = []*common.ReviewContext{ctx} } ctxsByStoryId[sid] = rcs } else { unassignedCommits = append(unassignedCommits, ctx.Commit) } } // Post the assigned commits. _, open := opts["open"] for _, ctxs := range ctxsByStoryId { var ( story = ctxs[0].Story commits = make([]*git.Commit, 0, len(ctxs)) ) for _, ctx := range ctxs { commits = append(commits, ctx.Commit) } // Create/update the review issue. issue, postedCommits, ex := postAssignedReviewRequest( tool.config, owner, repo, story, commits, opts) if ex != nil { errs.Log(ex) err = errPostReviewRequest continue } // Add comments to the commits posted for review. linkCommitsToReviewIssue(tool.config, owner, repo, *issue.Number, postedCommits) // Open the review issue in the browser if requested. if open { openIssue(issue) } } // Get the value of -fixes. var fixes int flagFixes, ok := opts["fixes"] if ok { if v, ok := flagFixes.(uint); ok && v != 0 { fixes = int(v) } } // Post the unassigned commits. for _, commit := range unassignedCommits { var ( issue *github.Issue postedCommits []*git.Commit ex error ) if fixes != 0 { // Extend the specified review issue. issue, postedCommits, ex = extendUnassignedReviewRequest( tool.config, owner, repo, fixes, commit, opts) } else { // Create/update the review issue. issue, postedCommits, ex = postUnassignedReviewRequest( tool.config, owner, repo, commit, opts) } if ex != nil { errs.Log(ex) err = errPostReviewRequest continue } // Add comments to the commits posted for review. linkCommitsToReviewIssue(tool.config, owner, repo, *issue.Number, postedCommits) // Open the review issue in the browser if requested. if open { openIssue(issue) } } return }
func (manager *releaseNotesManager) PostReleaseNotes( releaseNotes *common.ReleaseNotes, ) (action.Action, error) { // Get the GitHub owner and repository from the upstream URL. owner, repo, err := github.ParseUpstreamURL() if err != nil { return nil, err } // Instantiate the API client. client := github.NewClient(manager.config.Token) // Format the release notes. task := "Format the release notes" body := bytes.NewBufferString(` ## Summary ## **PLEASE FILL IN THE RELEASE SUMMARY** `) encoder, err := notes.NewEncoder(notes.EncodingMarkdown, body) if err != nil { return nil, errs.NewError(task, err) } if err := encoder.Encode(releaseNotes, nil); err != nil { return nil, errs.NewError(task, err) } bodyString := body.String() // Create GitHub release for the given version. tag := releaseNotes.Version.ReleaseTagString() releaseTask := fmt.Sprintf("Create GitHub release for tag '%v'", tag) log.Run(releaseTask) release, _, err := client.Repositories.CreateRelease(owner, repo, &gh.RepositoryRelease{ TagName: gh.String(tag), Name: gh.String("Release " + releaseNotes.Version.BaseString()), Body: &bodyString, Draft: gh.Bool(true), }) if err != nil { return nil, err } // Delete the GitHub release on rollback. rollback := func() error { log.Rollback(releaseTask) task := fmt.Sprintf("Delete GitHub release for tag '%v'", tag) _, err := client.Repositories.DeleteRelease(owner, repo, *release.ID) if err != nil { return errs.NewError(task, err) } return nil } // Open the release in the browser so that the user can fill in the details. task = "Open the release notes in the browser" if err := webbrowser.Open(*release.HTMLURL); err != nil { if ex := rollback(); ex != nil { errs.Log(ex) } return nil, errs.NewError(task, err) } // Return the rollback function. return action.ActionFunc(rollback), nil }