Skip to content

Commit

Permalink
added issue search and id lookup commands
Browse files Browse the repository at this point in the history
  • Loading branch information
Zomis committed Jun 23, 2015
1 parent 5782e83 commit c1271f2
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
4 changes: 3 additions & 1 deletion grails-app/domain/net/zomis/duga/User.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@ class User {
}

def github(String apiPath) {
URL url = new URL("https://api.github.com/$apiPath?access_token=$apiKey")
char append = apiPath.contains('?') ? '&' : '?'
URL url = new URL("https://api.github.com/$apiPath${append}access_token=$apiKey")
println 'Github GET request: ' + url.toString()
URLConnection conn = url.openConnection()
// String encoding = Base64.getEncoder().encodeToString("$githubName:$apiKey".getBytes());
// conn.setRequestProperty("Authorization", "Basic " + encoding);
Expand Down
28 changes: 28 additions & 0 deletions src/main/groovy/net/zomis/duga/tasks/ChatCommandDelegate.groovy
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package net.zomis.duga.tasks

import net.zomis.duga.DugaChatListener
import net.zomis.duga.HookStringification
import net.zomis.duga.User
import net.zomis.duga.chat.WebhookParameters

Expand Down Expand Up @@ -118,6 +119,33 @@ abstract class ChatCommandDelegate extends Script {
bean
}

Map issue(String repo) {
requireUser()
[search: {String query ->
// https://api.github.com/search/issues?q=systems%20repo:Cardshifter/Cardshifter%20is:open
String q = query.replaceAll(' ', '+')
def issues = message.fetchUser().github("search/issues?q=repo:$repo+is:open+$q")
StringBuilder results = new StringBuilder(issues.total_count + ' results found. ' as String)
int count = 0
for (def json in issues.items) {
String next = HookStringification.issue(json)
if (results.length() + next.length() > 500) {
message.reply(results.toString())
results.setLength(0)
}
results.append(next)
results.append(' ')
if (++count >= 10) {
break;
}
}
message.reply(results.toString())
}, id: {int id ->
def issue = message.fetchUser().github("repos/$repo/issues/$id")
message.reply(HookStringification.issue(issue))
}]
}

def register(String githubKey) {
allowAll()
User.withNewSession {status ->
Expand Down

0 comments on commit c1271f2

Please sign in to comment.