Skip to content

Commit

Permalink
0.2.0 Release: Comment staled Pull-request Feature
Browse files Browse the repository at this point in the history
  • Loading branch information
MalloZup committed Jul 31, 2019
1 parent 9f31a1b commit 25ab74b
Show file tree
Hide file tree
Showing 5 changed files with 97 additions and 57 deletions.
14 changes: 13 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
# Change Log

# 0.0.1
# 0.2.0

## Features:

add posibility to check staled Pull-Request, togheter with Issues.

Right now the bot comment automatically PRs and Issue.

- add logging and try/catch

- improve layout

# 0.1.0

Add initial structure. Implement old issue check
33 changes: 17 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,44 +1,45 @@
# doghub

Doghub is a Stalebot.
It monitor stale Issues and PR on GitHub for your different projects in a private and centralized manner.

# Rationale:

Other stalebot exists, but they are mainly run as service that you need to authorize on your different GitHub repos.

Doghub has 2 goals in mind:

- 1) allow maintainers to be indipendent, don't allow some X service in their repo. (instead use token and manage yourself the daemon on your server)

- 2) offer a full centralized control for list of repo you want to monitor.


Also it is data-driven, functional and concurrent by design.

# Quickstart

1) create `doghub.edn` file

```
{
:github-config {
:github-config {
:token "my-token"
}
;; a list of repository of github where you want to monitor issue and prs
:repositories ["MalloZup/missile", "MalloZup/saint-build"]
;; a list of repository of github where you want to monitor issue and prs
:repositories ["MalloZup/missile", "MalloZup/doghub"]
:issue-days 130 ;; this is the number of day you will tollerate for an issue to be inactive
:prs-days 2 ;; tollerations days for Pull-request. PR older then this will be take action.
;; this is the number of days you will tollerate for an issue to be inactive (write comments on issues older then 10 days)
:issue-days 10
;; by default doghub will create a comment on the issue or PR. you can customize the prefix message.
:prefix-msg "[autogenerated with https://github.com/MalloZup/doghub]"
;; example:
;; prefix-msg + std-msg
;; std-msg == "issue older then " issue-days "days. Please update the issue or close it"
:prefix-msg "autogenerated with https://github.com/MalloZup/doghub: "
;; the message compose of prefix-msg + std-msg. std-msg will be " the pr/issue is old then 10/X days.
;; the bot will just update the comments. RATE-LIMITING will be logged in case of exceeded
}
```

Expand Down
26 changes: 18 additions & 8 deletions doghub.edn.example
Original file line number Diff line number Diff line change
@@ -1,19 +1,29 @@
{

:github-config {
:github-config {
:token "my-token"
}

;; a list of repository of github where you want to monitor issue and prs
:repositories ["MalloZup/missile", "MalloZup/saint-build"]
;; a list of repository of github where you want to monitor issue and prs
:repositories ["SUSE/spacewalk"]

:issue-days 130 ;; this is the number of day you will tollerate for an issue to be inactive

:prs-days 2 ;; tollerations days for Pull-request. PR older then this will be take action.




;; this is the number of days you will tollerate for an issue to be inactive (write comments on issues older then 10 days)
:issue-days 10

;; by default doghub will create a comment on the issue or PR. you can customize the prefix message.
:prefix-msg "[autogenerated with https://github.com/MalloZup/doghub]"

;; example:
;; prefix-msg + "issue older then " issue-days "days. Please update the issue or close it" (the latter is standard msg)

:prefix-msg "autogenerated with https://github.com/MalloZup/doghub: "


;; the message compose of prefix-msg + std-msg. std-msg will be " the pr/issue is old then 10/X days.

;; the bot will just update the comments. RATE-LIMITING will be logged in case of exceeded


}
2 changes: 1 addition & 1 deletion project.clj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(defproject doghub "0.1.0"
(defproject doghub "0.2.0"
:description "monitor GitHub staled PRs and issues"
:url "git@github.com:MalloZup/doghub.git"
:license {:name "GPL"}
Expand Down
79 changes: 48 additions & 31 deletions src/doghub/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -2,65 +2,82 @@
(:require [doghub.config :as c]
[tentacles.core :as t]
[tentacles.issues :as i]
[tentacles.pulls :as p]
[clj-time.core :as time]
[clj-time.format :as f]
[clojure.tools.logging :as log]
[clojure.string :as str]
[cheshire.core :refer :all])
(:gen-class))

(def github-options {:all-pages true
:oauth-token (get-in (c/get-config) [:github-config :token] )})
(def github-options {:all-pages true :oauth-token (get-in (c/get-config) [:github-config :token] )})

(defn comment-issue [full-repo issue prefix-msg options issue-days]
(let [user (first (str/split full-repo #"/"))
repo (last (str/split full-repo #"/"))
text (str prefix-msg " " "issue older then " issue-days "days. Please update the issue or close it")]
(log/info (str "commenting old issue from repo:" repo " " (:number issue) " " (:url issue)))
(i/create-comment user repo (:number issue) text options)))
text (str prefix-msg " " "issue older then " issue-days " days. Please update the issue or close it")]
(try
(log/info (str "commenting old issue from repo:" repo " " (:number issue) "" (:url issue)))
(i/create-comment user repo (:number issue) text options)
(catch Exception e (log/error (str "exception by commenting issue: " (.getMessage e)))))))

(defn get-issues [full-repo]
"get all issues given a repo"
(defn comment-pr[full-repo pr prefix-msg options t-days]
(let [user (first (str/split full-repo #"/"))
repo (last (str/split full-repo #"/"))
text (str prefix-msg " " "pr older then " t-days " days. Please update the PR or close it")]
(try
(log/info (str "commenting old pull-request from repo:" repo " " (:number pr) "" (:url pr)))
(i/create-comment user repo (:number pr) text options)
(catch Exception e (log/error (str "exception by commenting issue: " (.getMessage e)))))))


(defn get-issues [full-repo] "get all issues given a repo"
(let [user (first (str/split full-repo #"/"))
repo (last (str/split full-repo #"/"))]
(i/issues user repo github-options)))
(i/issues user repo github-options)))

(defn get-pulls [full-repo] "get all prs given a repo"
(let [user (first (str/split full-repo #"/"))
repo (last (str/split full-repo #"/"))]
(p/pulls user repo github-options)))


(def datetime-form (f/formatters :date-time-no-ms))

(defn compare-issue-with-tdays [issue-time tolleration-days]
(defn compare-issue-pr-with-tdays [issue-time tolleration-days]
"compare issue time with tollerated one, return true if issue-time is older
in this case it means write a comment on the issue/pr"
(time/before? (f/parse datetime-form issue-time) ;; issue-datetm
(time/minus (time/now) (time/days tolleration-days)) ;; tolleration-time
;; if it true, then write a comment to this issue
))
(try
(time/before? (f/parse datetime-form issue-time) ;; issue-datetime
(time/minus (time/now) (time/days tolleration-days)))
(catch Exception e (log/error (str "exception by commenting datetime of issue: " (.getMessage e))))))

(defn comment-all-old-issues []
;; itereate over all repositories from user
"given a list repos, comment all older issues"
(let [{:keys [repositories issue-days prefix-msg]} (c/get-config)]
(doseq [repo repositories]
(log/info (str "getting issues for repo: " repo))
;; get all issues from a single repo
(doseq [issue (get-issues repo)]
(log/info (str "comparing issue with tolleration time(days) :" issue-days))
;; check if issue is older then input days
(when (compare-issue-with-tdays (:updated_at issue) issue-days)
(future (comment-issue repo issue prefix-msg github-options issue-days)))))))
(log/info (str "getting issues for repo: " repo))
;; get all issues from a single repo
(doseq [issue (get-issues repo)]
(log/info (str "comparing issue with tolleration time(days) :" issue-days))
;; check if issue is older then input days
(when (compare-issue-pr-with-tdays (:updated_at issue) issue-days)
(future (comment-issue repo issue prefix-msg github-options issue-days)))))))

(defn comment-all-old-ors []
"comment all old prs"
(println "to implement")
)
(defn comment-all-old-prs []
(let [{:keys [repositories prs-days prefix-msg]} (c/get-config)]
(doseq [repo repositories]
(log/info (str "getting pulls for repo: " repo))
;; get all prs from a single repo
(doseq [pull (get-pulls repo)]
(log/info (str "comparing prs with tolleration time(days) :" prs-days))
;; check if prs is older then input days
(when (compare-issue-pr-with-tdays (:updated_at pull) prs-days)
(deref(future (comment-pr repo pull prefix-msg github-options prs-days))))))))

(defn -main []
(while true
(comment-all-old-issues)
;; todo: comment-all-old-prs (implenment that)
(comment-all-old-prs)
(log/info "sleeping for 5 minutes")
(Thread/sleep (* 5 60 1000))
)
)

;; (.getTime (java.util.Date.))
(Thread/sleep (* 5 60 1000))))

0 comments on commit 25ab74b

Please sign in to comment.