Skip to content
This repository has been archived by the owner on Dec 15, 2022. It is now read-only.

Fix bug where pull request cannot be viewed if pullRequest.headRepository is null. #1828

Merged
merged 2 commits into from
Dec 6, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions lib/controllers/issueish-detail-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,12 @@ export class BareIssueishDetailController extends React.Component {
return this.checkoutOp.disable(checkoutStates.DISABLED, 'Checking out...');
}

// determine if pullRequest.headRepository is null
// this can happen if a repository has been deleted.
if (!pullRequest.headRepository) {
return this.checkoutOp.disable(checkoutStates.DISABLED, 'Pull request head repository does not exist');
}

// Determine if we already have this PR checked out.

const headPush = this.props.branches.getHeadBranch().getPush();
Expand Down
9 changes: 9 additions & 0 deletions test/controllers/issueish-detail-controller.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,15 @@ describe('IssueishDetailController', function() {
assert.isFalse(op1.isEnabled());
assert.strictEqual(op1.getMessage(), 'Rebase in progress');
});
it('is disabled if pullRequest.headRepository is null', function() {
const props = issueishDetailControllerProps({}, {});
props.repository.pullRequest.headRepository = null;
Copy link
Author

Choose a reason for hiding this comment

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

I...I don't love this, but also, the way the test factories are currently set up, you can't supply a parameter to our test factories that makes an entire nested part of the Relay response null. We should probably come up with a better pattern for these factories.

const wrapper = shallow(buildApp({}, {...props}));
const op = wrapper.find('Relay(BarePullRequestDetailView)').prop('checkoutOp');
assert.isFalse(op.isEnabled());
assert.strictEqual(op.getMessage(), 'Pull request head repository does not exist');
});


it('is disabled if the current branch already corresponds to the pull request', function() {
const upstream = Branch.createRemoteTracking('remotes/origin/feature', 'origin', 'refs/heads/feature');
Expand Down