Skip to content

Commit

Permalink
custom description file, instructions
Browse files Browse the repository at this point in the history
  • Loading branch information
Danny Ranson committed Apr 8, 2024
1 parent 0152766 commit a866392
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 8 deletions.
18 changes: 15 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -217,13 +217,25 @@ redacted/redacted OPEN REVIEW_REQUIRE
...
```

#### Closing all PRs
#### Updating PRs

To close all PRs currently opened under the campaign, there is a `--close` flag:
Use the `update-prs` command to update PRs after creating them. Current options for updating PRs are:

- Update PR titles and descriptions with `--amend-description`:

```turbolift update-prs --amend-description [--yes]```

As with creating PRs, use the flag `--description` to specify an alternative file to README.md.

```turblift update-prs --amend-description --description prDescriptionFile1.md```

- Close PRs with the `--close` flag:

```turbolift update-prs --close [--yes]```

If the flag `--yes` is not present, a confirmation prompt will be presented to the user.
If the flag `--yes` is not passed with an `update-prs` command, a confirmation prompt will be presented to the user.

As always, use the `--repos` flag to specify an alternative repo file to repos.txt.

## Status: Preview

Expand Down
4 changes: 3 additions & 1 deletion cmd/updateprs/updateprs.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ var (
updateDescriptionFlag bool
yesFlag bool
repoFile string
prDescriptionFile string
)

func NewUpdatePRsCmd() *cobra.Command {
Expand All @@ -52,6 +53,7 @@ func NewUpdatePRsCmd() *cobra.Command {
cmd.Flags().BoolVar(&updateDescriptionFlag, "amend-description", false, "Update PR titles and descriptions")
cmd.Flags().BoolVar(&yesFlag, "yes", false, "Skips the confirmation prompt")
cmd.Flags().StringVar(&repoFile, "repos", "repos.txt", "A file containing a list of repositories to clone.")
cmd.Flags().StringVar(&prDescriptionFile, "description", "README.md", "A file containing the title and description for the PRs.")

return cmd
}
Expand All @@ -70,7 +72,6 @@ func onlyOne(args ...bool) bool {
}

func validateFlags(closeFlag bool, updateDescriptionFlag bool) error {
// only option at the moment is `close`
if !onlyOne(closeFlag, updateDescriptionFlag) {
return errors.New("update-prs needs one and only one action flag")
}
Expand Down Expand Up @@ -155,6 +156,7 @@ func runUpdatePrDescription(c *cobra.Command, _ []string) {
readCampaignActivity := logger.StartActivity("Reading campaign data (%s)", repoFile)
options := campaign.NewCampaignOptions()
options.RepoFilename = repoFile
options.PrDescriptionFilename = prDescriptionFile
dir, err := campaign.OpenCampaign(options)
if err != nil {
readCampaignActivity.EndWithFailure(err)
Expand Down
27 changes: 24 additions & 3 deletions cmd/updateprs/updateprs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ func TestItLogsUpdateDescriptionErrorsButContinuesToTryAll(t *testing.T) {

testsupport.PrepareTempCampaign(true, "org/repo1", "org/repo2")

out, err := runUpdateDescriptionCommandAuto()
out, err := runUpdateDescriptionCommandAuto("README.md")
assert.NoError(t, err)
assert.Contains(t, out, "Updating PR description in org/repo1")
assert.Contains(t, out, "Updating PR description in org/repo2")
Expand All @@ -113,7 +113,7 @@ func TestItUpdatesDescriptionsSuccessfully(t *testing.T) {

testsupport.PrepareTempCampaign(true, "org/repo1", "org/repo2")

out, err := runUpdateDescriptionCommandAuto()
out, err := runUpdateDescriptionCommandAuto("README.md")
assert.NoError(t, err)
assert.Contains(t, out, "Updating PR description in org/repo1")
assert.Contains(t, out, "Updating PR description in org/repo2")
Expand All @@ -126,6 +126,26 @@ func TestItUpdatesDescriptionsSuccessfully(t *testing.T) {
})
}

func TestItUpdatesDescriptionsFromAlternativeFile(t *testing.T) {
fakeGitHub := github.NewAlwaysSucceedsFakeGitHub()
gh = fakeGitHub

testsupport.PrepareTempCampaign(true, "org/repo1", "org/repo2")
testsupport.CreateAnotherPrDescriptionFile("custom.md", "custom PR title", "custom PR body")

out, err := runUpdateDescriptionCommandAuto("custom.md")
assert.NoError(t, err)
assert.Contains(t, out, "Updating PR description in org/repo1")
assert.Contains(t, out, "Updating PR description in org/repo2")
assert.Contains(t, out, "turbolift update-prs completed")
assert.Contains(t, out, "2 OK, 0 skipped")

fakeGitHub.AssertCalledWith(t, [][]string{
{"work/org/repo1", "custom PR title", "custom PR body"},
{"work/org/repo2", "custom PR title", "custom PR body"},
})
}

func TestItDoesNotUpdateDescriptionsIfNotConfirmed(t *testing.T) {
fakeGitHub := github.NewAlwaysSucceedsFakeGitHub()
gh = fakeGitHub
Expand Down Expand Up @@ -170,10 +190,11 @@ func runCloseCommandConfirm() (string, error) {
return outBuffer.String(), nil
}

func runUpdateDescriptionCommandAuto() (string, error) {
func runUpdateDescriptionCommandAuto(descriptionFile string) (string, error) {
cmd := NewUpdatePRsCmd()
updateDescriptionFlag = true
yesFlag = true
prDescriptionFile = descriptionFile
outBuffer := bytes.NewBufferString("")
cmd.SetOut(outBuffer)
err := cmd.Execute()
Expand Down
1 change: 0 additions & 1 deletion internal/github/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ func (r *RealGitHub) ClosePullRequest(output io.Writer, workingDir string, branc
}

func (r *RealGitHub) UpdatePRDescription(output io.Writer, workingDir string, title string, body string) error {
// todo: check whether we need to GetPR and specify it in the command like in ClosePullRequest
return execInstance.Execute(output, workingDir, "gh", "pr", "edit", "--title", title, "--body", body)
}

Expand Down

0 comments on commit a866392

Please sign in to comment.