tarides/get-activity

Feature to query GitHub activity for specific engineer

Closed this issue · 3 comments

As mentioned at the TL meeting on 15th of February, it is sometimes useful to query specific engineer's activity.
Okra uses get-activity to get GitHub activity, and it does that using the viewer API, which will provide information regarding the user who's token is used. By using the user API instead, one can specify which user's activity we want to get.

The naive change boils down to:

diff --git a/lib/contributions.ml b/lib/contributions.ml
index 92166ff..013e914 100644
--- a/lib/contributions.ml
+++ b/lib/contributions.ml
@@ -2,9 +2,9 @@ module Json = Yojson.Safe
 
 let ( / ) a b = Json.Util.member b a
 
-let query =
-  {| query($from: DateTime!, $to: DateTime!) {
-   viewer {
+let query = 
+  {| query($from: DateTime!, $to: DateTime! $login: String!) {
+  user(login: $login) {
     contributionsCollection(from: $from, to: $to) {
       user {
         login
@@ -64,8 +64,9 @@ module Fetch (C : Cohttp_lwt.S.Client) = struct
     let variables = [
           "from", `String start;
           "to", `String finish;
+          "login", `String user
       ] in
       G.exec token ~variables query
 end
 
 module Datetime = struct
@@ -165,9 +166,9 @@ type t = {
   activity : item list Repo_map.t
 }
 
let of_json ~from json =
-  let contribs = json / "data" / "viewer" / "contributionsCollection" in
-  let username = json / "data" / "viewer" / "contributionsCollection" / "user" / "login" |> Json.Util.to_string in
let of_json ~from json =
+  let contribs = json / "data" / "user" / "contributionsCollection" in
+  let username = json / "data" / "user" / "contributionsCollection" / "user" / "login" |> Json.Util.to_string in
   let items =
     read_issues  (contribs / "issueContributions") @
     read_prs     (contribs / "pullRequestContributions") @

However, the default behavior should not change, that is an engineer shouldn't have to start specifying their username. Afterall, most okra users do not need to query other engineer's activity.

As a side note, this might be a good time to fork Patrick's fork and bring it under Tarides.

What's the use case behind this ?

My primary use case has been getting activity for an external contributor not employed by Tarides and thus not providing okra reports. It has also been helpful in cases where an engineer is absent and has not provided his weeklies (yet).
To be clear, I've implemented this in my fork in a dirty way for doing precisely that.

Thanks!