Skip to content

Commit

Permalink
Broken promise 😱; updated readme to add the new interaction
Browse files Browse the repository at this point in the history
  • Loading branch information
mgwalker committed Aug 10, 2017
1 parent f8d15f4 commit 23e9e5e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 19 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ Charlie will exclaim about even more love, and will post in the #love channel
`@charlie opm status`
Charlie will check with OPM about whether or not DC offices are open today

`@charlie is <app> approved?`
Charlie will check if the app is approved according to the [GSA IT Standards](https://ea.gsa.gov/#!/itstandards) (also [available on Github](https://github.com/GSA/data/blob/gh-pages/enterprise-architecture/it-standards.csv))

`@charlie set tock <tock line>` or `@charlie set tock line <tock line>`
Charlie will associate the current channel to the given tock line

Expand Down
41 changes: 22 additions & 19 deletions scripts/gsa-approved-software.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,25 +54,28 @@ const getMessage = (target) => {
const lookingFor = target.toLowerCase();
return getCSV().then(body => {
const matches = [];
csv().fromString(body)
.on('csv', (item) => {
// Can't be certain the CSV is right, but we can at least
// make sure it has the right number of fields
if(item.length > 4 && item[0].toLowerCase().includes(lookingFor)) {
matches.push({ name: item[0], status: item[3], platform: item[4] })
}
}).on('done', () => {
let message = ''
if (matches.length == 0) {
message = `I didn't find anything in the GSA IT Standards for ${target}`;
} else if (matches.length <= 5) {
message = { attachments: matches.map(getAttachment) };
message.attachments[0].pretext = `Here's what I found in the GSA IT Standards`;
} else {
const finds = matches.map((item) => `*${item.name}* (${item.status})`)
message = `I found several potential matches for ${target}: ${finds.join(' | ')}`;
}
return message;

return new Promise((resolve, reject) => {
csv().fromString(body)
.on('csv', (item) => {
// Can't be certain the CSV is right, but we can at least
// make sure it has the right number of fields
if(item.length > 4 && item[0].toLowerCase().includes(lookingFor)) {
matches.push({ name: item[0], status: item[3], platform: item[4] })
}
}).on('done', () => {
let message = ''
if (matches.length == 0) {
message = `I didn't find anything in the GSA IT Standards for ${target}`;
} else if (matches.length <= 5) {
message = { attachments: matches.map(getAttachment) };
message.attachments[0].pretext = `Here's what I found in the GSA IT Standards`;
} else {
const finds = matches.map((item) => `*${item.name}* (${item.status})`)
message = `I found several potential matches for ${target}: ${finds.join(' | ')}`;
}
resolve(message);
}).on('error', err => reject(err));
});
});
};
Expand Down

0 comments on commit 23e9e5e

Please sign in to comment.