Skip to content

Feature/fork repo to org#3608

Closed
g14a wants to merge 7 commits intocli:trunkfrom
g14a:feature/forkRepo-to-org
Closed

Feature/fork repo to org#3608
g14a wants to merge 7 commits intocli:trunkfrom
g14a:feature/forkRepo-to-org

Conversation

@g14a
Copy link
Contributor

@g14a g14a commented May 9, 2021

This commit adds functionality to fork a repository into an organization.

Closes #1247

@g14a
Copy link
Contributor Author

g14a commented May 9, 2021

@mislav I'd like some insight on how I can simulate a 403 response when the user doesn't have WRITE permission on the organization. I'm stuck at that last test case. Would be helpful if you gave some advice. Thank you :)

Copy link
Contributor

@mislav mislav left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for doing this!

I've left code review comments, but I do not expect you to address them. I've been doing cleanups myself as I was reviewing the code and I've opened another PR (as this one doesn't let me push to it) #3611

path := fmt.Sprintf("repos/%s/forks", ghrepo.FullName(repo))
body := bytes.NewBufferString(`{}`)
if org != "" {
orgBody := fmt.Sprintf(`{ "organization": "%s" }`, org)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's use JSON encoding functionality instead of writing it by hand.

var httpErr HTTPError
if errors.As(err, &httpErr) {
if httpErr.StatusCode == http.StatusForbidden {
return nil, fmt.Errorf("Must have admin rights to Repository")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I appreciate you adding this special case, but I think it might be premature optimization. The 401 error will be reported to the terminal via our usual error handling and I don't think we need to add anything on top of that. If the user doesn't have write access to their org, the fork command will fail with a visible 401 and it will be enough information for them to go on.

Comment on lines +468 to +469
if tt.toOrg {
defer reg.StubWithFixturePath(200, "./orgForkResult.json")()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of switching stubs based on a boolean in the test case, consider letting the test case define its own stub.

Comment on lines +482 to +483
if tt.toOrg {
r := regexp.MustCompile(`Created fork.*batmanshome/REPO`)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here: consider letting the test case define its own expected output.

"Added remote.*fork")
}

func TestRepoFork_in_parent_org_survey_no(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I appreciate you adding many extra tests, but all of these extra tests are completely unnecessary. The feature you've added is just unconditionally passing one extra parameter to the fork function. A single tests above is enough to exercise this functionality.

@mislav mislav closed this May 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

gh repo fork cannot fork to org

2 participants