Search code examples
node.jsjira

Using Jira.js to bulk assign a version to a number of issues


I'm using the jira.js node library and have used it to successfully create versions and query issues. Now I would like to assign the version to those issues, but cannot get the desired effect after some googling and ChatGPT querying.

What I've tried is:

import { IssueProperties } from 'jira.js/out/version3'

const issuePropsUpdate = new IssueProperties(jiraClient) // I know jiraClient works
const issueIds = ['123', '456', '789']
const versionId = '101112'

  const res = await issuePropsUpdate.bulkSetIssuesProperties({
    entitiesIds: issueIds.map((issue) => Number(issue)),
    properties: {
      fixVersions: [
        {
          add: {
            id: Number(versionId),
          },
        },
      ],
    },
  })

I do get a response, and it tells me it's successful, but nothing happens to the issues. Here is the response from this request:

{
  self: 'REDACTED',
  id: 'REDACTED',
  description: 'Bulk multiple.update of Issue (matching: 33036,33895) property fixVersions',
  status: 'COMPLETE',
  message: 'Bulk update of 2 issues completed',
  result: {
    updatedTotal: 2,
    errors: { errors: {}, errorMessages: [], reasons: [] }
  },
  submittedBy: 10036,
  progress: 100,
  elapsedRuntime: 36,
  submitted: 1687879190262,
  started: 1687879190286,
  finished: 1687879190322,
  lastUpdate: 1687879190322
}

EDIT: I've asked how to do this on the github repository https://github.com/MrRefactoring/jira.js/issues/268


Solution

  • EDIT: Found a way to do this with the JIRA SDK

    import { Issues } from 'jira.js/out/version3'
    
    const issuesClient = new Issues(jiraClient) // I know jiraClient 
    works
    const issueIds = ['123', '456', '789']
    const versionId = 'NEW_FIX_VERSION'
    
    await Promise.all(
      issueIds.map(async (issueId) => {
        await issues.editIssue({
          issueIdOrKey: issueId,
          update: {
            fixVersions: [{ add: { name: release.name } }],
          },
        })
      }),
    ))
    

    Below is how you do it with axios if you'd like

    await axios.put(
      `${process.env.ATLASSIAN_API_HOST}rest/api/2/issue/${issue.key}`,
      {
        update: {
          fixVersions: [{ add: { name: version.name } }],
        },
      },
      {
        headers: {
          'Content-Type': 'application/json; charset=utf-8',
          Authorization: `Basic ${Buffer.from(
            `${process.env.ATLASSIAN_EMAIL}:${process.env.ATLASSIAN_API_TOKEN}`,
          ).toString('base64')}`,
        },
      },
    )