Skip to content

Commit

Permalink
config: Update githubRepository to target
Browse files Browse the repository at this point in the history
Part of the preparation for #11.
  • Loading branch information
Bland, Mike committed Nov 5, 2017
1 parent 52a5a31 commit cfbf8d3
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 35 deletions.
2 changes: 1 addition & 1 deletion config/slack-emoji-issues.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"rules": [
{
"reactionName": "book",
"githubRepository": "slack-emoji-issues"
"target": "slack-emoji-issues"
}
]
}
6 changes: 3 additions & 3 deletions lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ var schema = {
},
requiredRulesFields: {
reactionName: 'name of the reaction emoji triggering the rule',
githubRepository: 'GitHub repository to which to post issues'
target: 'Repository name or other issue tracking system identifier'
},
optionalRulesFields: {
channelNames: 'names of the Slack channels triggering the rules; ' +
Expand Down Expand Up @@ -183,7 +183,7 @@ function checkChannelNamesAreSorted(rules, reactionName, errors) {
}

function checkForDuplicateRepositories(rules, reactionName, errors) {
var duplicateRepos = rules.map(function(r) { return r.githubRepository })
var duplicateRepos = rules.map(function(r) { return r.target })
.sort()
.filter(detectDuplicates)

Expand Down Expand Up @@ -225,7 +225,7 @@ function checkForDuplicateAllChannelRules(rules, reactionName, errors) {
function compareRules(lhs, rhs) {
return lhs.reactionName.localeCompare(rhs.reactionName) ||
compareChannelNames(lhs.channelNames, rhs.channelNames) ||
lhs.githubRepository.localeCompare(rhs.githubRepository)
lhs.target.localeCompare(rhs.target)
}

function compareChannelNames(lhs, rhs) {
Expand Down
6 changes: 3 additions & 3 deletions lib/reaction-issue-filer.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ Impl.prototype.getReactions = function() {

Impl.prototype.fileIssue = function(getReactionsResponse) {
var metadata,
githubRepository = this.rule.githubRepository
target = this.rule.target

if (this.alreadyProcessed(getReactionsResponse)) {
this.logger.info(this.msgId, 'already processed')
Expand All @@ -168,9 +168,9 @@ Impl.prototype.fileIssue = function(getReactionsResponse) {

metadata = parseMetadata(getReactionsResponse, this.channel)
this.logger.info(this.msgId, 'filing GitHub issue in ' +
this.githubClient.collection + '/' + githubRepository)
this.githubClient.collection + '/' + target)

return this.githubClient.fileNewIssue(metadata, githubRepository)
return this.githubClient.fileNewIssue(metadata, target)
.catch(this.abort('failed to create a GitHub issue'))
}

Expand Down
4 changes: 2 additions & 2 deletions lib/rule.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ module.exports = Rule

function Rule(configRule) {
this.reactionName = configRule.reactionName
this.githubRepository = configRule.githubRepository
this.target = configRule.target
this.channelNames = configRule.channelNames
}

Rule.prototype.toLogString = function() {
var properties = [
'reactionName: ' + this.reactionName,
'githubRepository: ' + this.githubRepository
'target: ' + this.target
]

if (this.channelNames) {
Expand Down
36 changes: 18 additions & 18 deletions tests/config-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ describe('Config', function() {
configData.rules[0].xyzzy = 'plugh'
configData.rules.push({
'reactionName': 'smiley',
'githubRepository': 'mbland/slack-emoji-issues',
'target': 'mbland/slack-emoji-issues',
'channelNames': ['hub'],
'quux': {}
})
Expand All @@ -71,12 +71,12 @@ describe('Config', function() {
var configData = helpers.baseConfig(),
errors = [
'rule 0 missing reactionName',
'rule 2 missing githubRepository'
'rule 2 missing target'
],
errorMessage = 'Invalid configuration:\n ' + errors.join('\n ')

delete configData.rules[0].reactionName
delete configData.rules[2].githubRepository
delete configData.rules[2].target

expect(function() { return new Config(configData) })
.to.throw(Error, errorMessage)
Expand Down Expand Up @@ -150,14 +150,14 @@ describe('Config', function() {

configData.rules = [
{ reactionName: 'smiley',
githubRepository: 'hubot-slack-github-issues'
target: 'hubot-slack-github-issues'
},
{ reactionName: 'evergreen_tree',
githubRepository: 'slack-emoji-issues',
target: 'slack-emoji-issues',
channelNames: ['bot-dev']
},
{ reactionName: 'evergreen_tree',
githubRepository: 'handbook'
target: 'handbook'
}
]
errorMessage = 'Invalid configuration:\n' +
Expand All @@ -176,14 +176,14 @@ describe('Config', function() {

configData.rules = [
{ reactionName: 'evergreen_tree',
githubRepository: 'handbook'
target: 'handbook'
},
{ reactionName: 'evergreen_tree',
githubRepository: 'slack-emoji-issues',
target: 'slack-emoji-issues',
channelNames: ['bot-dev']
},
{ reactionName: 'smiley',
githubRepository: 'hubot-slack-github-issues'
target: 'hubot-slack-github-issues'
}
]
errorMessage = 'Invalid configuration:\n' +
Expand All @@ -203,15 +203,15 @@ describe('Config', function() {

correctConfig.rules = [
{ reactionName: 'evergreen_tree',
githubRepository: 'handbook',
target: 'handbook',
channelNames: ['handbook']
},
{ reactionName: 'evergreen_tree',
githubRepository: 'hub',
target: 'hub',
channelNames: ['hub']
},
{ reactionName: 'smiley',
githubRepository: 'hubot-slack-github-issues'
target: 'hubot-slack-github-issues'
}
]

Expand All @@ -234,9 +234,9 @@ describe('Config', function() {
var configData = helpers.baseConfig(),
errorMessage

configData.rules[0].githubRepository = 'guides'
configData.rules[0].target = 'guides'
configData.rules[0].channelNames = ['wg-testing', 'wg-documentation']
configData.rules[1].githubRepository = 'handbook'
configData.rules[1].target = 'handbook'
configData.rules[1].channelNames = ['hub', 'handbook']
errorMessage = 'Invalid configuration:\n' +
' channelNames for evergreen_tree rule 0 are not sorted; expected:\n' +
Expand All @@ -254,7 +254,7 @@ describe('Config', function() {
errorMessage

configData.rules.forEach(function(rule) {
rule.githubRepository = 'handbook'
rule.target = 'handbook'
})
errorMessage = 'Invalid configuration:\n' +
' duplicate repositories for evergreen_tree rules:\n' +
Expand All @@ -268,7 +268,7 @@ describe('Config', function() {
errorMessage

configData.rules.forEach(function(rule) {
rule.githubRepository = 'handbook'
rule.target = 'handbook'
rule.channelNames = ['hub']
})

Expand All @@ -287,9 +287,9 @@ describe('Config', function() {
var configData = helpers.baseConfig(),
errorMessage

configData.rules[0].githubRepository = 'handbook'
configData.rules[0].target = 'handbook'
delete configData.rules[0].channelNames
configData.rules[1].githubRepository = 'hub'
configData.rules[1].target = 'hub'

errorMessage = 'Invalid configuration:\n' +
' multiple all-channel rules defined for evergreen_tree'
Expand Down
6 changes: 3 additions & 3 deletions tests/helpers/test-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@
"rules": [
{
"reactionName": "evergreen_tree",
"githubRepository": "slack-emoji-issues",
"target": "slack-emoji-issues",
"channelNames": ["bot-dev"]
},

{
"reactionName": "evergreen_tree",
"githubRepository": "handbook"
"target": "handbook"
},

{
"reactionName": "smiley",
"githubRepository": "hubot-slack-github-issues"
"target": "hubot-slack-github-issues"
}
]
}
2 changes: 1 addition & 1 deletion tests/integration-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ describe('Integration test', function() {
apiServerDefaults, reactionAddedMessage, patchListenerImpl, sendReaction,
initLogMessages, wrapInfoMessages,
matchingRule = 'reactionName: evergreen_tree, ' +
'githubRepository: slack-emoji-issues, ' +
'target: slack-emoji-issues, ' +
'channelNames: bot-dev'

before(function() {
Expand Down
2 changes: 1 addition & 1 deletion tests/reaction-issue-filer-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ describe('ReactionIssueFiler', function() {
result = reactor.findMatchingRule(message, channelName)

result.reactionName.should.equal(expected.reactionName)
result.githubRepository.should.equal(expected.githubRepository)
result.target.should.equal(expected.target)
result.should.not.have.property('channelName')
})

Expand Down
6 changes: 3 additions & 3 deletions tests/rule-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ describe('Rule', function() {
var makeConfigRule = function() {
return {
reactionName: 'evergreen_tree',
githubRepository: 'slack-emoji-issues',
target: 'slack-emoji-issues',
channelNames: ['bot-dev']
}
}
Expand All @@ -34,7 +34,7 @@ describe('Rule', function() {
configRule.channelNames.push('general')
expect(new Rule(configRule).toLogString())
.to.eql('reactionName: evergreen_tree, ' +
'githubRepository: slack-emoji-issues, ' +
'target: slack-emoji-issues, ' +
'channelNames: bot-dev,general')
})

Expand All @@ -43,7 +43,7 @@ describe('Rule', function() {
delete configRule.channelNames
expect(new Rule(configRule).toLogString())
.to.eql('reactionName: evergreen_tree, ' +
'githubRepository: slack-emoji-issues')
'target: slack-emoji-issues')
})
})

Expand Down

0 comments on commit cfbf8d3

Please sign in to comment.