Home > Software design >  How to add comment and spent time in one call to Gitlab API?
How to add comment and spent time in one call to Gitlab API?

Time:12-17

I have two separate calls

addSpentTime(projectId, issueIid, duration, date) {
    const endpoint = this.apiUrl(
      `/projects/${projectId}/issues/${issueIid}/notes?body=/spend ${duration} ${date}`
    );
    return this.ajaxRequest("POST", endpoint);
}

addComment(projectId, issueIid, comment) {
    const endpoint = this.apiUrl(
      `/projects/${projectId}/issues/${issueIid}/notes?body=${comment}`
    );
    return this.ajaxRequest("POST", endpoint);
}

The first one is for sending how much time has been spent on an issue and the latter is for adding a comment to the issue.

I'd like to do both of these actions in one call like this

addSpentTimeAndComment(projectId, issueIid, duration, date, comment) {
    const endpoint = this.apiUrl(
        `/projects/${projectId}/issues/${issueIid}/notes?body=${comment}/spend ${duration} ${date}`
    );
    return this.ajaxRequest("POST", endpoint);
}

but the suffix /spend ${duration} ${date} makes it into the comment as well. It seems that the API takes literally everything that comes after body= as a part of the comment. I tried to add \n, \\n, spaces, backslashes to signify the end of the comment so that the /spend part gets evaluated as well and I also tried changing the order so that the /spend is before the comment body but nothing seemed to work. The GitLab API docs don't mention any standard way of ending the comment or maybe they do but I can't find it anywhere. Furthermore, I don't even know what it's called - delimiter, escaping symbol...?

Is there a way of signifying the ending of the comment, giving a way of appending other commands?

CodePudding user response:

As part of the comment (project note) call, append the time as a Quick Action using the /spend <time> call.

By posting that to the API with the comment, GitLab will add the time at the same time it adds the comment.

  • Related