UNPKG

gaunt-sloth-assistant

Version:

> ⚠️ **`gaunt-sloth-assistant` has been renamed to [`gaunt-sloth`](https://www.npmjs.com/package/gaunt-sloth).** > The `1.5.x` series is the final release under the old name — active development continues under > the new package. To switch: > > ```bash >

53 lines 2.29 kB
import { getJiraCredentials, jiraRequest } from '@gaunt-sloth/review/helpers/jira/jiraClient.js'; import { displayError, displaySuccess } from '@gaunt-sloth/core/utils/consoleUtils.js'; export default async function jiraLogWork(config, jiraId, timeInSeconds, comment = 'Work logged', startedAt = new Date()) { try { // Use provided config or empty config (will use environment variables) const credentials = getJiraCredentials(config); const bodyData = { comment: { content: [ { content: [ { text: comment, type: 'text', }, ], type: 'paragraph', }, ], type: 'doc', version: 1, }, started: startedAt.toISOString().replace('Z', '+0000'), timeSpentSeconds: timeInSeconds, }; /** * https://developer.atlassian.com/cloud/jira/platform/rest/v3/api-group-issue-worklogs/#api-rest-api-3-issue-issueidorkey-worklog-post * Needs: * Classic RECOMMENDED:write:jira-work * * OR * * write:issue-worklog:jira, write:issue-worklog.property:jira, read:avatar:jira, read:group:jira, * read:issue-worklog:jira, read:project-role:jira, read:user:jira, read:issue-worklog.property:jira */ await jiraRequest(credentials, `/rest/api/3/issue/${jiraId}/worklog`, { method: 'POST', body: JSON.stringify(bodyData), }); const hours = Math.floor(timeInSeconds / 3600); const minutes = Math.floor((timeInSeconds % 3600) / 60); const timeStr = hours > 0 ? `${hours}h ${minutes}m` : `${minutes}m`; const successMessage = `Logged ${timeStr} to ${jiraId}`; displaySuccess(successMessage); return successMessage; } catch (error) { const errorMessage = `Failed to log work to Jira: ${error instanceof Error ? error.message : String(error)}`; displayError(errorMessage); return errorMessage; } } //# sourceMappingURL=jiraLogWork.js.map