Skip to content

Commit

Permalink
Merge pull request thelounge#9 from thelounge/fix-search
Browse files Browse the repository at this point in the history
Fix github searching
  • Loading branch information
Max Leiter authored May 12, 2017
2 parents 0ad9c26 + 2821d11 commit 2b6bf3e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
8 changes: 6 additions & 2 deletions plugins/github.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,13 @@ var commands = function(bot, options, action) {
issue: arg
});
} else {
query = action.nick + ": invalid issue/PR ID.";
if (arg === "search") {
query = "Search query cannot be empty";
} else {
query = action.nick + ": invalid issue/PR ID";
}
}
} else if (message.length === 2) { // should be !gh search <query>
} else if (message.length >= 2) { // should be !gh search <query>
if (arg === "search") {
message.shift(); // remove 'search'
query = helper.searchGithub({
Expand Down
5 changes: 3 additions & 2 deletions plugins/github_helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,19 +85,20 @@ function getIssueInformation(options) {

function searchGithub(options) {
const { repo = config.githubRepo, user = config.githubUser, terms } = options;
let status = null;
const url = `https://api.github.com/search/issues?q=repo:${user}/${repo}+${ terms.join("+") }`;
return fetch(url)
.then(res => res.json())
.then(function(res) {
if (res.items[0].state) {
const status = res.items[0].state;
status = res.items[0].state;
} else {
return "No issue found";
}
const title = res.items[0].title;
const link = res.items[0].html_url;
const issueNumber = res.items[0].number;
const type = "";
let type = "";
if(link.indexOf("issues") > -1) {
type = "Issue";
} else {
Expand Down

0 comments on commit 2b6bf3e

Please sign in to comment.