pr comments

This commit is contained in:
Daniel Foad 2020-05-04 23:47:47 +01:00
parent 09157f1fc7
commit e7e3a4f9b1
No known key found for this signature in database
GPG key ID: BF35612F9C708C17
2 changed files with 2 additions and 24 deletions

View file

@ -73,28 +73,17 @@ func prStatus(cmd *cobra.Command, args []string) error {
return err
}
remotes, err := ctx.Remotes()
if err != nil {
return err
}
currentUser, err := ctx.AuthLogin()
if err != nil {
return err
}
repoOverride, _ := cmd.Flags().GetString("repo")
remoteContext, err := context.ResolveRemotesToRepos(remotes, apiClient, repoOverride)
if err != nil {
return err
}
baseRepo, err := determineBaseRepo(cmd, ctx)
if err != nil {
return err
}
repoOverride, _ := cmd.Flags().GetString("repo")
currentPRNumber, currentPRHeadRef, err := prSelectorForCurrentBranch(ctx, baseRepo)
if err != nil && repoOverride == "" && err.Error() != "git: not on any branch" {
return fmt.Errorf("could not query for pull request for current branch: %w", err)
@ -114,10 +103,9 @@ func prStatus(cmd *cobra.Command, args []string) error {
printHeader(out, "Current branch")
currentPR := prPayload.CurrentPR
currentBranch, _ := ctx.Branch()
remoteRepo, _ := remoteContext.BaseRepo()
noPRMessage := fmt.Sprintf(" There is no pull request associated with %s", utils.Cyan("["+currentPRHeadRef+"]"))
if currentPR != nil {
if remoteRepo.DefaultBranchRef.Name == currentBranch && currentPR.State != "OPEN" {
if baseRepo.(*api.Repository).DefaultBranchRef.Name == currentBranch && currentPR.State != "OPEN" {
printMessage(out, noPRMessage)
} else {
printPrs(out, 0, *currentPR)

View file

@ -77,7 +77,6 @@ func TestPRStatus(t *testing.T) {
initBlankContext("", "OWNER/REPO", "blueberries")
http := initFakeHTTP()
http.StubRepoResponse("OWNER", "REPO")
http.StubRepoResponse("OWNER", "REPO")
jsonFile, _ := os.Open("../test/fixtures/prStatus.json")
defer jsonFile.Close()
@ -106,7 +105,6 @@ func TestPRStatus_fork(t *testing.T) {
initBlankContext("", "OWNER/REPO", "blueberries")
http := initFakeHTTP()
http.StubForkedRepoResponse("OWNER/REPO", "PARENT/REPO")
http.StubForkedRepoResponse("OWNER/REPO", "PARENT/REPO")
jsonFile, _ := os.Open("../test/fixtures/prStatusFork.json")
defer jsonFile.Close()
@ -137,7 +135,6 @@ func TestPRStatus_reviewsAndChecks(t *testing.T) {
initBlankContext("", "OWNER/REPO", "blueberries")
http := initFakeHTTP()
http.StubRepoResponse("OWNER", "REPO")
http.StubRepoResponse("OWNER", "REPO")
jsonFile, _ := os.Open("../test/fixtures/prStatusChecks.json")
defer jsonFile.Close()
@ -165,7 +162,6 @@ func TestPRStatus_currentBranch_showTheMostRecentPR(t *testing.T) {
initBlankContext("", "OWNER/REPO", "blueberries")
http := initFakeHTTP()
http.StubRepoResponse("OWNER", "REPO")
http.StubRepoResponse("OWNER", "REPO")
jsonFile, _ := os.Open("../test/fixtures/prStatusCurrentBranch.json")
defer jsonFile.Close()
@ -198,7 +194,6 @@ func TestPRStatus_currentBranch_defaultBranch(t *testing.T) {
initBlankContext("", "OWNER/REPO", "blueberries")
http := initFakeHTTP()
http.StubRepoResponseWithDefaultBranch("OWNER", "REPO", "blueberries")
http.StubRepoResponse("OWNER", "REPO")
jsonFile, _ := os.Open("../test/fixtures/prStatusCurrentBranch.json")
defer jsonFile.Close()
@ -220,7 +215,6 @@ func TestPRStatus_currentBranch_Closed(t *testing.T) {
initBlankContext("", "OWNER/REPO", "blueberries")
http := initFakeHTTP()
http.StubRepoResponse("OWNER", "REPO")
http.StubRepoResponse("OWNER", "REPO")
jsonFile, _ := os.Open("../test/fixtures/prStatusCurrentBranchClosed.json")
defer jsonFile.Close()
@ -242,7 +236,6 @@ func TestPRStatus_currentBranch_Closed_defaultBranch(t *testing.T) {
initBlankContext("", "OWNER/REPO", "blueberries")
http := initFakeHTTP()
http.StubRepoResponseWithDefaultBranch("OWNER", "REPO", "blueberries")
http.StubRepoResponse("OWNER", "REPO")
jsonFile, _ := os.Open("../test/fixtures/prStatusCurrentBranchClosed.json")
defer jsonFile.Close()
@ -264,7 +257,6 @@ func TestPRStatus_currentBranch_Merged(t *testing.T) {
initBlankContext("", "OWNER/REPO", "blueberries")
http := initFakeHTTP()
http.StubRepoResponse("OWNER", "REPO")
http.StubRepoResponse("OWNER", "REPO")
jsonFile, _ := os.Open("../test/fixtures/prStatusCurrentBranchMerged.json")
defer jsonFile.Close()
@ -286,7 +278,6 @@ func TestPRStatus_currentBranch_Merged_defaultBranch(t *testing.T) {
initBlankContext("", "OWNER/REPO", "blueberries")
http := initFakeHTTP()
http.StubRepoResponseWithDefaultBranch("OWNER", "REPO", "blueberries")
http.StubRepoResponse("OWNER", "REPO")
jsonFile, _ := os.Open("../test/fixtures/prStatusCurrentBranchMerged.json")
defer jsonFile.Close()
@ -308,7 +299,6 @@ func TestPRStatus_blankSlate(t *testing.T) {
initBlankContext("", "OWNER/REPO", "blueberries")
http := initFakeHTTP()
http.StubRepoResponse("OWNER", "REPO")
http.StubRepoResponse("OWNER", "REPO")
http.StubResponse(200, bytes.NewBufferString(`
{ "data": {} }