Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: create a fork with Octokit given a repository name and its corresponding owner #20

Merged
merged 1 commit into from Jul 10, 2020

Conversation

TomKristie
Copy link
Contributor

@TomKristie TomKristie commented Jul 8, 2020

Given an owner and a repository, correctly invoke the create fork Octokit function.
The PR implements the basic functionality of a fork source code with basic mock test.

  • on successful fork creation, the GitHub API (wrapped by Octokit) returns the owner and name of the repository so that branches can be created with this origin address
  • on error, safely log error and returned undefined fields.

Towards #19

@TomKristie TomKristie requested a review from chingor13 July 8, 2020 22:18
@codecov
Copy link

codecov bot commented Jul 8, 2020

Codecov Report

Merging #20 into master will increase coverage by 6.28%.
The diff coverage is 46.28%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #20      +/-   ##
==========================================
+ Coverage   37.28%   43.57%   +6.28%     
==========================================
  Files           3        6       +3     
  Lines          59      179     +120     
  Branches        0        4       +4     
==========================================
+ Hits           22       78      +56     
- Misses         37      100      +63     
- Partials        0        1       +1     
Impacted Files Coverage Δ
src/github-handler/index.ts 0.00% <0.00%> (ø)
src/logger/index.ts 0.00% <0.00%> (ø)
src/types/index.ts 0.00% <0.00%> (ø)
src/github-handler/fork-handler.ts 94.91% <94.91%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b649ddc...f42a3f2. Read the comment docs.

@TomKristie TomKristie changed the title Create a fork with Octokit given a repository name and its corresponding owner feat: create a fork with Octokit given a repository name and its corresponding owner Jul 9, 2020
@chingor13 chingor13 self-assigned this Jul 9, 2020
test/fork.ts Show resolved Hide resolved
test/fork.ts Outdated Show resolved Hide resolved
package.json Outdated Show resolved Hide resolved
src/github-handler/fork-handler.ts Outdated Show resolved Hide resolved
src/github-handler/fork-handler.ts Outdated Show resolved Hide resolved
src/github-handler/fork-handler.ts Outdated Show resolved Hide resolved

import {Logger, Octokit} from '../types';

interface ForkData {
Copy link
Contributor

Choose a reason for hiding this comment

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

We could probably generalize this to be Repository with owner and repo fields. A general repository type could be used for upstream and origin elsewhere.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This specific interface is for returning 2 values from the fork function. There's not another instance in the code where just the owner and repo are passed/returned. If I move this to the general src/types then it will not be used by anything.

Copy link
Contributor

Choose a reason for hiding this comment

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

My thought is that maybe GitHubContext and/or GitHubContextParams could specify upstream: Repository rather than upstreamOwner/upstreamRepo

Copy link
Contributor

Choose a reason for hiding this comment

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

This is a non-blocker on this PR, but is something to consider later.

test/fork.ts Outdated Show resolved Hide resolved
test/fork.ts Outdated Show resolved Hide resolved

/**
* Fork the GitHub owner's repository
* If fork already exists no new fork is created and no error occurs
Copy link
Contributor

Choose a reason for hiding this comment

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

If no error is returned, what is returned?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have a @returns statement on line 29. I'll also add a commit to update this comment.

Copy link
Contributor

Choose a reason for hiding this comment

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

I meant in the case of the fork already existing. Does the GitHub API createFork return the same data if the fork already exists?

Copy link
Contributor Author

@TomKristie TomKristie Jul 9, 2020

Choose a reason for hiding this comment

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

It returns a superset of the original data. I believe it also adds a parent and source object.

Copy link
Contributor

Choose a reason for hiding this comment

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

Can you add to this note that it will return the existing fork?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just as an FYI what I originally said isn't true. It returns the exact same data each time (except for the updated_at field). It's just the GitHub docs don't include the parent/source object.

test/fork.ts Outdated Show resolved Hide resolved
Copy link
Contributor

@bcoe bcoe left a comment

Choose a reason for hiding this comment

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

Left a few initial notes. I like the library choice so far, and seems like a good start.

package.json Outdated Show resolved Hide resolved
package.json Outdated Show resolved Hide resolved
package.json Outdated Show resolved Hide resolved
data: responseData,
};
// setup
const stub = sinon
Copy link
Contributor

Choose a reason for hiding this comment

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

Are we using nock purely to disable net connect? I wonder if we could potentially get away with just using sinon for the time being.

Copy link
Contributor

Choose a reason for hiding this comment

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

I asked for that precisely for that reason. Do you have another suggestion?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes. Nock is solely used as a guarantee that we never connect to the internet. Sinon stubs definitely could do the trick, but isn't fool-proof.

@chingor13 thoughts?

@chingor13 chingor13 added the automerge Merge the pull request once unit tests and other checks pass. label Jul 10, 2020
@TomKristie TomKristie merged commit eb9047f into master Jul 10, 2020
@TomKristie TomKristie deleted the basic-fork branch July 10, 2020 15:20
@TomKristie TomKristie added the type: process A process-related concern. May include testing, release, or the like. label Jul 14, 2020
@TomKristie TomKristie added this to the Open-PR-From-Fork milestone Jul 14, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
automerge Merge the pull request once unit tests and other checks pass. type: process A process-related concern. May include testing, release, or the like.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants