Skip to content

Commit

Permalink
fix(discord: commands): init - fix allowing multiple inits of same repo
Browse files Browse the repository at this point in the history
  • Loading branch information
dsevillamartin committed Oct 12, 2017
1 parent c62d258 commit a2a3fdf
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions lib/Discord/Commands/GitlabInit.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ class GitlabInitCommand extends Command {

if (!repository.isGitlab || isPrivate) {
// GitlabCache.add(repository.repo);
let conf = ChannelConfig.FindByChannel(channelid);
let doc = conf && conf.repos ? conf.repos.includes(repoFullName) : false;
if (doc) return this.commandError(msg, `Repository \`${repository.repo}\` is already initialized in this channel`);
const conf = ChannelConfig.FindByChannel(channelid);
const exists = conf && conf.repos && conf.repos.includes(repoFullName);
if (exists) return this.commandError(msg, `Repository \`${repository.repo}\` is already initialized in this channel`);
return ChannelConfig.AddRepoToChannel(channelid, repoFullName)
.then(() => {
let embed = this._successMessage(repository.repo);
Expand All @@ -58,14 +58,12 @@ class GitlabInitCommand extends Command {
}

return Gitlab.getRepo(repository.repo).then(res => {
const repoInfo = res.body;
const repoActualName = repoInfo.path_with_namespace;
const conf = ChannelConfig.FindByChannel(channelid);
const doc = conf && conf.repos ? conf.repos.includes(repoActualName) : false;
if (doc) return this.commandError(msg, `Repository \`${repoActualName}\` is already initialized in this channel`);
const exists = conf && conf.repos && conf.repos.includes(repoFullName);
if (exists) return this.commandError(msg, `Repository \`${repository.repo}\` is already initialized in this channel`);
return ChannelConfig.AddRepoToChannel(channelid, repoFullName)
.then(() => {
let embed = this._successMessage(repoActualName);
let embed = this._successMessage(repository.repo);
return workingMsg.edit({ embed });
});
}).catch(err => {
Expand Down

0 comments on commit a2a3fdf

Please sign in to comment.