RuairiSpain / jtt

CLI for Jira Cloud time tracker using worklogs. Users Jira REST API version 3.0
MIT License
3 stars 4 forks source link

ls yields 404 (Not Found) #1

Open belljames opened 3 years ago

belljames commented 3 years ago

hi! When I run the ls command, I get a 404 error,

image

but when I copy the URL from the string and substitue the variables, I get the expected response: image

image

I'm running via WSL on a fresh node.js install.
Any troublshooting tips appreciated!

kymikoloco commented 3 years ago

Auth is working correctly, but the version on NPM is not the same as main right now. There are slightly more issues with this particular code with the latest Jira REST API, so I changed it to use version 2

Also one of the then calls is on the wrong object.

---
+++
@@ jira.js @@
  loadWorklogs: async (days = 7, issueId) => {
    return conf
       .getAuth()
       .then((auth) => {
         return got(
-           `https://${auth.domain}.atlassian.net/rest/api/3/issue/${issueId}/worklog`,
+           `https://${auth.domain}.atlassian.net/rest/api/2/issue/${issueId}/worklog`,
           {
             auth: `${auth.email}:${auth.token}`,
-            json: true,
+            responseType: 'json',
             query: {
-              startedAfter: moment().subtract(days, "days").toISOString(),
+              startedAfter: moment().subtract(days, "days").valueOf(),
             },
-          }
-        );
-      })
-      .then((response) => {
-        return response.body;
+          })
+        .then((response) => JSON.parse(response.body))
+        .catch(err => console.error(err));;
       });
   },
--- 
+++ 
@@ worklog.js @@
       },
       (argv) => {
         jira
           .loadWorklogs(argv.days, argv.issue)
           .then((logs) => {
             console.log(
-              logs.reduce((str, log) => {
+              logs.worklogs.reduce((str, log) => {
                 return (
                   str +
-                  `${log.issue.key}\t${moment
+                  `${argv.issue}\t${moment
                     .duration(log.timeSpentSeconds, "seconds")
                     .format("hh:mm", { trim: false })}\t${log.comment}\n\r`
                 );
-              }, `Total logs: ${logs.length}\n\r`)
+              }, `Total logs: ${logs.worklogs.length}\n\r`)
             );
           })
           .catch((e) => {
             console.error(e.toString());
             process.exit(1);
           });