Skip to content

Commit

Permalink
added gittrack possibility
Browse files Browse the repository at this point in the history
  • Loading branch information
Zomis committed Jan 21, 2015
1 parent 725c3b8 commit e9c2520
Showing 1 changed file with 16 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.skiwi.githubhooksechatservice.mvc.controllers;

import java.time.Instant;
import java.util.Arrays;

import org.springframework.beans.factory.annotation.Autowired;
Expand All @@ -11,8 +12,9 @@
import org.springframework.web.bind.annotation.ResponseBody;

import com.skiwi.githubhooksechatservice.chatbot.ChatBot;
import com.skiwi.githubhooksechatservice.events.AnySetterJSONObject;
import com.skiwi.githubhooksechatservice.events.github.AbstractEvent;
import com.skiwi.githubhooksechatservice.mvc.beans.GithubUtils;
import com.skiwi.githubhooksechatservice.service.GithubService;

/**
*
Expand All @@ -27,6 +29,9 @@ public class BotController {
@Autowired
private GithubUtils githubUtils;

@Autowired
private GithubService githubService;

@RequestMapping(value = "/hello", method = RequestMethod.GET)
@ResponseBody
public String hello() {
Expand All @@ -37,7 +42,16 @@ public String hello() {
@RequestMapping(value = "/gittest", method = RequestMethod.GET)
@ResponseBody
public String gitScan(@RequestParam("name") String name) {
AnySetterJSONObject[] blocks = githubUtils.fetchRepoEvents(name);
AbstractEvent[] blocks = githubUtils.fetchRepoEvents(name);
return Arrays.toString(blocks);
}

@RequestMapping(value = "/gittrack", method = RequestMethod.GET)
@ResponseBody
public String gitTrack(@RequestParam("name") String name) {
AbstractEvent[] blocks = githubUtils.fetchRepoEvents(name);
long eventId = Arrays.stream(blocks).mapToLong(bl -> bl.getId()).max().orElse(0);
githubService.update(name, Instant.now().getEpochSecond(), eventId - 1);
return Arrays.toString(blocks);
}

Expand Down

0 comments on commit e9c2520

Please sign in to comment.