Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit fda1aa0

Browse files
authored
Merge pull request atom#1888 from atom/vy/fall-back-gitlog-users
mentionable users fall back
2 parents 7f2fe2d + f982959 commit fda1aa0

File tree

2 files changed

+26
-5
lines changed

2 files changed

+26
-5
lines changed

lib/models/user-store.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,16 @@ export default class UserStore {
100100
this.setCommitter(data.committer);
101101
const githubRemotes = Array.from(data.remotes).filter(remote => remote.isGithubRepo());
102102

103-
if (githubRemotes.length === 0) {
104-
this.addUsers(data.authors, source.GITLOG);
105-
} else {
103+
if (githubRemotes.length > 0) {
106104
await this.loadUsersFromGraphQL(githubRemotes);
105+
} else {
106+
this.addUsers(data.authors, source.GITLOG);
107+
}
108+
109+
// if for whatever reason, no committers can be added, fall back to
110+
// using git log committers as the last resort
111+
if (this.allUsers.size === 0) {
112+
this.addUsers(data.authors, source.GITLOG);
107113
}
108114
}
109115

test/models/user-store.test.js

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,21 @@ describe('UserStore', function() {
9797
assert.deepEqual(store.committer, new Author(FAKE_USER.email, FAKE_USER.name));
9898
});
9999

100+
it('falls back to local git users and committers if loadMentionableUsers cannot load any user for whatever reason', async function() {
101+
const workdirPath = await cloneRepository('multiple-commits');
102+
const repository = await buildRepository(workdirPath);
103+
104+
store = new UserStore({repository, config});
105+
sinon.stub(store, 'loadMentionableUsers').returns(undefined);
106+
107+
await store.loadUsers();
108+
await nextUpdatePromise();
109+
110+
assert.deepEqual(store.getUsers(), [
111+
new Author('[email protected]', 'Katrina Uychaco'),
112+
]);
113+
});
114+
100115
it('loads store with mentionable users from the GitHub API in a repo with a GitHub remote', async function() {
101116
await login.setToken('https://api.github.com', '1234');
102117

@@ -223,12 +238,12 @@ describe('UserStore', function() {
223238
const workdirPath = await cloneRepository('multiple-commits');
224239
const repository = await buildRepository(workdirPath);
225240
store = new UserStore({repository, config});
241+
sinon.spy(store, 'addUsers');
226242
await assert.async.lengthOf(store.getUsers(), 1);
243+
await assert.async.equal(store.addUsers.callCount, 1);
227244

228-
sinon.spy(store, 'addUsers');
229245
// make a commit with FAKE_USER as committer
230246
await repository.commit('made a new commit', {allowEmpty: true});
231-
await assert.async.equal(store.addUsers.callCount, 1);
232247

233248
// verify that FAKE_USER is in commit history
234249
const lastCommit = await repository.getLastCommit();

0 commit comments

Comments
 (0)