Timetracker for Youtrack: DIY

There is a wonderful T-REC application that allows you to track the time spent on tasks in Youtrack, and writes it to task. But the author abandoned it more than two years ago, plus old dependencies, the constant loading of one core (the electron is apparently to blame) and periodic crashes led to the fact that it became "inconvenient" to use it. I decided to write my own, with the same functionality, only on the pros, so Honsu appeared ...



The current documentation on working with Youtrack is here .

How it works:

To access Youtrack from a third-party application, you need a token to work.

  1. Log in to YouTrack in a browser
  2. Go to the profile " example.youtrack.com/users/me "
  3. Find the item “Update personal information and manage logins”
  4. Open the tab "Authentication"
  5. Click the button "New token ..."
  6. Fill in the client field "YoutrackTimerec"
  7. Choosing which subsystems we need access to - “YouTrack” first
  8. Click the Create Token button
  9. We copy the token, because it is shown only once.

Examples are in the form of cURL requests, but they are easy to shift to the desired form.

First you need to check that the entered address is correct and there is a REST API on the server side. if the service is available and the key is correct, json with accounting data will be returned

curl -X GET "https://example.myjetbrains.com/api/admin/users/me?fields=id,login,name,email"
-H "Accept: application/json"
-H "Authorization: Bearer perm:token"
-H "Cache-Control: no-cache"
-H "Content-Type: application/json"




{"login":"s.user",
"email":"s.user@example.team",
"name":"S User",
"id":"1-325",
"$type":"Me"}



What Agile without tasks? Simplified, tasks usually live in sprints, and sprints in boards. It’s just the active boards that you need to get in order to later select tasks for time tracking. The answer contains a list of available boards for a specific user:

curl -X GET "https://example.myjetbrains.com/api/agiles?fields=name,id,projects(id,shortName,name),columnSettings(columns(presentation))&$top=100"
-H "Accept: application/json"
-H "Authorization: Bearer perm:token"
-H "Cache-Control: no-cache"
-H "Content-Type: application/json"




[
   {
      "projects":[{ "shortName":"OPS", "name":"Operations",
                     "id":"04", "$type":"Project" }],
      "columnSettings":{
         "columns":[
            { "presentation":"Open", "$type":"AgileColumn"},
            { "presentation":"In Progress, Paused","$type":"AgileColumn" },
            { "presentation":"Postponed", "$type":"AgileColumn" },
            { "presentation":"Closed, Resolved", "$type":"AgileColumn" },
            { "presentation":"Feedback, On Review", "$type":"AgileColumn" }
         ],
         "$type":"ColumnSettings"
      },
      "name":"Web",
      "id":"15",
      "$type":"Agile"
   }
]



The next step is to get tasks from the

board : - `Board Some Name:` ​​the name after the space is indicated, end with `:`
- `{Current sprint}` only tasks from the current sprint
are taken - `# Unresolved` only unclosed tasks are taken Tasks will come with an array of objects , there are quite a few properties, but for accounting for time, ID fields will be needed, Summary - the header, Spent Time - the time spent in minutes, and sprint - the sprint ID, if you need to work with it.

curl -X GET "https://example.myjetbrains.com/rest/issue?filter=for:me%20Board%20Some%20Name:%7BCurrent%20sprint%7D%20%23Unresolved%20"
-H "Accept: application/json"
-H "Authorization: Bearer perm:token"
-H "Cache-Control: no-cache"
-H "Content-Type: application/json"




{
   "issue":[
      {
         "id":"38-1234", 
         "entityId":"2-12345",
         "jiraId":null,
         "field":[
            { "name":"projectShortName", "value":"38"  },
            { "name":"summary", "value":"[system] [tech] Huge hard task" },
            { "name":"created", "value":"1582624816973" },
            { "name":"Spent time", "value":[ "399" ],  "valueId":["6h 39m"],"color":null },
            { "name":"sprint", "value":[  { "value":"Value", "id":"ID" } ] }
         ],
      }]
}



The data obtained is sufficient for mappings and navigation through the task list. The main idea of ​​the application is to consider the time spent in work on a specific task. To do this, send the server the number of minutes (WorkItem), with the following query Why XML? For some reason, the test server does not accept the WorkItem as a json object. Daily task history: You can request tasks for which the Spent Time> 0 field, after processing their WorkItem, you can compile a work history. Requesting all the tasks in the current sprint. Next, we process the incoming task array, and make requests for those that have written off time. Having processed the received data, you can show it in a convenient form Where does Honsu live: github.com/dalerank/nanogui/tree/master/honsu

curl -i -X POST "https://example.myjetbrains.com/rest/issue/38-1234/timetracking/workitem" 
-H "Accept: application/json"
-H "Authorization: Bearer perm:token"
-H "Cache-Control: no-cache"
-H "Content-Type: application/xml"
-d <?xml version=\"1.0\" encoding=\"UTF-8\"?> <workItem> <date>UnixEpocTime*1000</date> <duration>10</duration> <description>added by Honsu</description> <worktype> <name>Development</name> </worktype> </workItem>











curl -X GET "https://example.myjetbrains.com/rest/issue?filter=for:me%20Board%20Some%20Name:%7BCurrent%20sprint%7D"
-H "Accept: application/json"
-H "Authorization: Bearer perm:token"
-H "Cache-Control: no-cache"
-H "Content-Type: application/json"




curl -X GET "https://example.myjetbrains.com/rest/issue/38-1234/timetracking/workitem"
-H "Accept: application/json"
-H "Authorization: Bearer perm:token"
-H "Cache-Control: no-cache"
-H "Content-Type: application/json"







It is assembled together with other examples

Or here in the form of exe (Windows): github.com/dalerank/nanogui/releases

Why this is done:

+ keep track of time spent on tasks
+ see how rest api youtrack works
+ if possible make a monoapp, without dependencies
+ interesting :)

What it can do:

+ pick up tasks from youtrack
+ shows active boards
+ mark the collected time as a workItem in the task
+ cut off downtime
+ remind about the absence of a task when activity is detected
+ show the history of time tracking by days
+ does not store locally data, except for a key and a server

What does not know how:

+ use multiple accounts
+ store the cracked time if there is no Internet
+ create new tasks inapp
+ display the color of tasks
+ build timelines +
update from the releases of the gig

What it says:

+ CMake + C ++ 11 + OpenGL (or another gapi)
+ OpenSSL
+ cpp-httplib
+ Actively supported version for Windows, on other platforms (Ubuntu \ MacOS) is built and even works

All Articles