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

Commit 2afab22

Browse files
committed
Alternate endpoint accessor that falls back to dotcom
1 parent 8c6483b commit 2afab22

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

lib/models/remote.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {getEndpoint} from './endpoint';
1+
import {getEndpoint, DOTCOM} from './endpoint';
22

33
export default class Remote {
44
constructor(name, url) {
@@ -57,6 +57,10 @@ export default class Remote {
5757
return this.domain === null ? null : getEndpoint(this.domain);
5858
}
5959

60+
getEndpointOrDotcom() {
61+
return this.getEndpoint() || DOTCOM;
62+
}
63+
6064
isPresent() {
6165
return true;
6266
}
@@ -135,6 +139,10 @@ export const nullRemote = {
135139
return null;
136140
},
137141

142+
getEndpointOrDotcom() {
143+
return DOTCOM;
144+
},
145+
138146
isPresent() {
139147
return false;
140148
},

test/models/remote.test.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ describe('Remote', function() {
7676
assert.isNull(nullRemote.getSlug());
7777
assert.strictEqual(nullRemote.getNameOr('else'), 'else');
7878
assert.isNull(nullRemote.getEndpoint());
79+
assert.strictEqual(nullRemote.getEndpointOrDotcom().getGraphQLRoot(), 'https://api.github.com/graphql');
7980
});
8081

8182
describe('getEndpoint', function() {
@@ -89,4 +90,16 @@ describe('Remote', function() {
8990
assert.isNull(elsewhere.getEndpoint());
9091
});
9192
});
93+
94+
describe('getEndpointOrDotcom', function() {
95+
it('accesses the same Endpoint for the corresponding GitHub host', function() {
96+
const remote = new Remote('origin', '[email protected]:atom/github.git');
97+
assert.strictEqual(remote.getEndpointOrDotcom().getGraphQLRoot(), 'https://api.github.com/graphql');
98+
});
99+
100+
it('returns dotcom for non-GitHub URLs', function() {
101+
const elsewhere = new Remote('mirror', 'https://[email protected]/team/repo.git');
102+
assert.strictEqual(elsewhere.getEndpointOrDotcom().getGraphQLRoot(), 'https://api.github.com/graphql');
103+
});
104+
});
92105
});

0 commit comments

Comments
 (0)