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

mentionable users fall back #1888

Merged
merged 7 commits into from Jan 8, 2019
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 9 additions & 3 deletions lib/models/user-store.js
Expand Up @@ -100,10 +100,16 @@ export default class UserStore {
this.setCommitter(data.committer);
const githubRemotes = Array.from(data.remotes).filter(remote => remote.isGithubRepo());

if (githubRemotes.length === 0) {
this.addUsers(data.authors, source.GITLOG);
} else {
if (githubRemotes.length > 0) {
await this.loadUsersFromGraphQL(githubRemotes);
} else {
this.addUsers(data.authors, source.GITLOG);
}

// if for whatever reason, no committers can be added, fall back to
// using git log committers as the last resort
if (this.allUsers.size === 0) {
this.addUsers(data.authors, source.GITLOG);
}
}

Expand Down
19 changes: 17 additions & 2 deletions test/models/user-store.test.js
Expand Up @@ -97,6 +97,21 @@ describe('UserStore', function() {
assert.deepEqual(store.committer, new Author(FAKE_USER.email, FAKE_USER.name));
});

it('falls back to local git users and committers if loadMentionableUsers cannot load any user for whatever reason', async function() {
const workdirPath = await cloneRepository('multiple-commits');
const repository = await buildRepository(workdirPath);

store = new UserStore({repository, config});
sinon.stub(store, 'loadMentionableUsers').returns(undefined);

await store.loadUsers();
await nextUpdatePromise();

assert.deepEqual(store.getUsers(), [
new Author('kuychaco@github.com', 'Katrina Uychaco'),
]);
});

it('loads store with mentionable users from the GitHub API in a repo with a GitHub remote', async function() {
await login.setToken('https://api.github.com', '1234');

Expand Down Expand Up @@ -223,12 +238,12 @@ describe('UserStore', function() {
const workdirPath = await cloneRepository('multiple-commits');
const repository = await buildRepository(workdirPath);
store = new UserStore({repository, config});
sinon.spy(store, 'addUsers');
await assert.async.lengthOf(store.getUsers(), 1);
await assert.async.equal(store.addUsers.callCount, 1);

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

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