Giter Club home page Giter Club logo

jira-connector's Introduction

Thanks All!

I no longer have the time, energy or interest to maintain this project, so I'm going to be archiving it.

As an alternative to jira-connector, try: https://github.com/MrRefactoring/jira.js

JavaScript Jira API Wrapper for NodeJS

Node.JS module which provides easy-to-use access to the Jira REST API.

Important Change in Version 1.0.0

Starting with version 1.0.0, all functions and parameters utilize xxxId instead of xxxID. Prior to this update, this naming convention was inconsistent and easily confused.

Please update your code accordingly.

Installation

Install with npm:

    $ npm install jira-connector

Install via Git clone:

    $ git clone https://github.com/floralvikings/jira-connector.git
    $ cd jira-connector
    $ npm install

Documentation

The documentation for jira-connector can be found in the source; If you'd like to view the source as an HTML document, you can use JSDoc to generate these pages. Simply run:

    $ jsdoc -c jsdoc.json

In the jira-connector source directory. This will create a docs directory, containing the HTML markup for the docs.

Also, the official Jira API docs are very useful; many of the functions in jira-connector use the exact same format as the request bodies of these endpoints.

Example

Retrieve an issue from Jira, and print its summary to the console.

// ES5
var JiraClient = require("jira-connector");

// ES6 or Typescript
import JiraClient from "jira-connector";

// Initialize
var jira = new JiraClient({
  host: "jenjinstudios.atlassian.net",
  strictSSL: true // One of optional parameters
});

// ES5
jira.issue.getIssue(
  {
    issueKey: "JWR-19"
  },
  function(error, issue) {
    console.log(issue.fields.summary);
  }
);

// ES6
jira.issue
  .getIssue((issueKey: "JWR-19"))
  .then(issue => {
    console.log(issue.fields.summary);
  })
  .catch(error => throw error);

// ES8 or Typescript. NodeJS 7.6.0 or higher
const issue = await jira.issue.getIssue({ issueKey: "JWR-19" });

First, the JiraApi class is imported from the jira-connector module. This class provides access to the Jira REST endpoints, organized into related classes.

The issue property of the JiraApi class is used to retrieve and modify Jira Issues.

All of the methods in the jira-connector API classes take two arguments; the opts and callback.

  • The opts argument specifies the options that will be used when communicating with the Jira API. For a detailed list of options, see the documentation for the method into which you are passing the options.
  • The callback argument should be a function expecting two arguments; and error, and the results of the API request.

Authentication

Depending on the Jira instance to which you are connecting, authentication may or may not be required for various API calls.

jira-connector supports two forms of authentication:

Basic Authentication (Deprecated)

Deprecated. It will require you to provide a username and password each time you connect to the Jira instance. However, jira-connector supports it for users who are unable to use OAuth.

Example:

var JiraClient = require("jira-connector");

var jira = new JiraClient({
  host: "jenjinstudios.atlassian.net",
  basic_auth: {
    username: "SirUserOfName",
    password: "Password123"
  }
});

Basic Authentication With API Token

This is not recommended; it will require you to provide a email and api_token each time you connect to the Jira instance. However, jira-connector supports it for users who are unable to use OAuth.

Example:

var JiraClient = require("jira-connector");

var jira = new JiraClient({
  host: "jenjinstudios.atlassian.net",
  basic_auth: {
    email: "[email protected]",
    api_token: "api-token"
  }
});

Basic Authentication (Base64)

Also not recommended, but slightly better than the above; it will require you to provide a Base64 encoded username and password or email and api_token (a Base64 encoding in the format of "username:password", or "email:api_token") each time you connect to the Jira instance.

More examples here.

Example:

var JiraClient = require("jira-connector");

var jira = new JiraClient({
  host: "jenjinstudios.atlassian.net",
  basic_auth: {
    base64: "U2lyVXNlck9mTmFtZTpQYXNzd29yZDEyMw=="
  }
});

// Base64 encoding of 'SirUserOfName:Password123' (for legacy server version) or 'email:api_token' (jira cloud)

OAuth Authentication

This should be the preferred method of authentication; it is more secure and does not require disclosing your password.

However, setting up OAuth access in Jira can be somewhat complicated; first the Jira administrator must create an Application Link; for instructions on how to do this, see Linking to Another Application.

This example may also be helpful in configuring OAuth Access.

Once the Application Link has been created, you will need the private key that corresponds to the public key used to create the link, and the consumer key that was provided when the link was created.

Once you have this data, you will need to generate an OAuth token and secret for your account; jira-connector provides helper functions for exactly this purpose:

var JiraClient = require("jira-connector");

JiraClient.oauth_util.getAuthorizeURL(
  {
    host: "jenjinstudios.atlassian.net",
    oauth: {
      consumer_key: "your-consumer-key",
      private_key: "-----BEGIN RSA PRIVATE KEY-----\n" + "SomePrivateKeyHere\n" + "-----END RSA PRIVATE KEY-----"
    }
  },
  function(error, oauth) {
    console.log(oauth);
  }
);

This will output something similar to the following:

{
    url: 'https://jenjinstudios.atlassian.net/plugins/servlet/oauth/authorize?oauth_token=some-token-here',
    token: 'some-token-here',
    token_secret: 'some-secret-here'
}

You can then visit the specified URL, which will display a page asking you to allow or deny the request for access. Allowing access will display a verifier code. Once you have this code, you can swap out your current OAuth token for an Access Token with all the permissions of your account; jira-connector provides a function to help with this:

var JiraClient = require("jira-connector");

JiraClient.oauth_util.swapRequestTokenWithAccessToken(
  {
    host: "jenjinstudios.atlassian.net",
    oauth: {
      token: "your-oauth-token",
      token_secret: "your-token-secret",
      oauth_verifier: "verifier-code-from-jira",
      consumer_key: "your-consumer-key",
      private_key: "-----BEGIN RSA PRIVATE KEY-----\n" + "SomePrivateKeyHere\n" + "-----END RSA PRIVATE KEY-----"
    }
  },
  function(error, accessToken) {
    console.log(accessToken);
  }
);

This will query Jira for an Access Token, which will then be printed to the screen. Finally, you're ready to access Jira with OAuth!

var JiraClient = require("jira-connector");

var jira = new JiraClient({
  host: "jenjinstudios.atlassian.net",
  oauth: {
    consumer_key: "your-consumer-key",
    private_key: "-----BEGIN RSA PRIVATE KEY-----\n" + "SomePrivateKey\n" + "-----END RSA PRIVATE KEY-----",
    token: "your-access-token",
    token_secret: "your-token-secret"
  }
});

// Jira is now authenticated with your account!

JWT Authentication

JWT (JSON Web Token) for authenticate apps.

  • iss - The Jira app key. Can be found in the app descriptor.
  • secret - The connected shared secret as stored by the app during the installation handshake.
  • expiry_time_seconds - Optional. Token expiry time in seconds (default 180 seconds).

Example:

const JiraClient = require("jira-connector");

const jira = new JiraClient({
  host: "jenjinstudios.atlassian.net",
  jwt: {
    iss: "atlassian-connect-app",
    secret: "your-jwt-secret"
  }
});

Cookie Jar

You can also use a Cookie Jar for your request. It could be an easier way to prompt for a login only once, without the pain of setting up an OAuth method.

For example, using tough-cookie-filestore:

var JiraClient = require("jira-connector");
var FileCookieStore = require("tough-cookie-filestore");

var request = require("request");
var path = require("path");

var jar = request.jar(new FileCookieStore(path.join(__dirname, "cookies.json")));

// For the first connection
var jira = new JiraClient({
  host: "jenjinstudios.atlassian.net",
  basic_auth: {
    username: "SirUserOfName",
    password: "Password123"
  },
  cookie_jar: jar
});

// For the following connections
var jira = new JiraClient({
  host: "jenjinstudios.atlassian.net",
  cookie_jar: jar
});

In this example, all your cookies are save in a file, cookies.json. Currently, the file MUST exist, it's a limitation from tough-cookie-filestore...

You can now only use the Cookie Jar for all the following request, as long as the file exists and the cookie is still valid!

Supported API Calls

  • applicationProperties (/rest/api/2/application-properties)
    • getProperties
    • setProperty
  • attachment (/rest/api/2/attachment)
    • getAttachment
    • deleteAttachment
    • getGlobalAttachmentMetadata
  • auditing (/rest/api/2/auditing)
    • getAudits
    • createAudit
  • avatar (/rest/api/2/avatar) (Untested; use at your own peril)
    • getAvatars
    • createTemporaryAvatar
    • cropTemporaryAvatar
  • backlog (/rest/agile/1.0/backlog)
    • moveIssuesToBacklog
    • moveIssuesToBacklogForBoard
  • board (/rest/agile/1.0/board)
    • getAllBoards
    • createBoard
    • getBoardByFilterId
    • getBoard
    • deleteBoard
    • getIssuesForBacklog
    • getConfiguration
    • getEpics
    • getIssuesWithoutEpic
    • getIssuesForEpic
    • getFeaturesForBoard
    • toggleFeatures
    • getIssuesForBoard
    • moveIssuesToBoard
    • getProjects
    • getProjectsFull
    • getBoardPropertyKeys
    • getBoardProperty
    • setBoardProperty
    • deleteBoardProperty
    • getAllQuickFilters
    • getQuickFilter
    • getReportsForBoard
    • getAllSprints
    • getIssuesForSprint
    • getAllVersions
  • comment (/rest/api/2/comment)
    • getCommentPropertyKeys
    • setCommentProperty
    • getCommentProperty
    • deleteCommentProperty
  • component (/rest/api/2/component)
    • getComponent
    • createComponent
    • editComponent
    • deleteComponent
    • getRelatedIssueCount
  • customFieldOption (/rest/api/2/customFieldOptions)
    • getCustomFieldOption
  • epic (/rest/agile/1.0/epic)
    • getIssuesWithoutEpic
    • removeIssuesFromEpic
    • getEpic
    • partiallyUpdateEpic
    • getIssuesForEpic
    • moveIssuesToEpic
    • rankEpics
  • dashboard (/rest/api/2/dashboard)
    • getAllDashboards
    • getDashboard
  • developmentInformation (/rest/devinfo)
    • store
    • getRepository
    • deleteRepository
    • deleteByProperties
    • checkExists
    • deleteEntity
  • field (/rest/api/2/field)
    • getAllFields
    • createCustomField
  • filter (/rest/api/2/filter)
    • createFilter
    • getFilter
    • updateFilter
    • deleteFilter
    • getFilterColumns
    • setFilterColumns
    • resetFilterColumns
    • getDefaultShareScope
    • setDefaultShareScope
    • getFavoriteFilters
  • group (/rest/api/2/group)
    • createGroup
    • getGroup [DEPRECATED, use getMembers]
    • addUserToGroup
    • removeUserFromGroup
    • deleteGroup
    • getMembers
  • groups (/rest/api/2/groups)
    • findGroups
  • groupUserPicker (/rest/api/2/groupuserpicker)
    • findUsersAndGroups
  • issue (/rest/api/2/issue and /rest/agile/1.0/issue)
    • getIssue (agile api, set opts.agile: true)
    • getIssueEstimation (agile api)
    • setIssueEstimation (agile api)
    • setIssueRanks (agile api)
    • createIssue
    • getCreateMetadata
    • bulkCreate
    • getIssue
    • deleteIssue
    • editIssue
    • assignIssue
    • getComments
    • addComment
    • getComment
    • editComment
    • deleteComment
    • getEditMetadata
    • sendEmailNotification
    • getRemoteLinks
    • createRemoteLink
    • updateRemoteLink
    • deleteRemoteLink
    • getRemoteLinkByID
    • updateRemoteLinkByID
    • deleteRemoteLinkByID
    • getTransitions
    • transitionIssue
    • unvote
    • vote
    • getVotes
    • getWatchers
    • addWatcher
    • removeWatcher
    • getWorkLogs
    • addWorkLog
    • updateWorkLog
    • deleteWorkLog
    • addAttachment
    • getProperties
    • setProperty
    • getProperty
    • deleteProperty
    • getIssuePicker
    • getChangelog
  • issueLink (/rest/api/2/issueLink)
    • createIssueLink
    • getIssueLink
    • deleteIssueLink
  • issueLinkType (/rest/api/2/issueLinkType)
    • getAvailableTypes
    • createIssueLinkType
    • getIssueLinkType
    • deleteIssueLinkType
    • editIssueLinkType
  • issueType (/rest/api/2/issuetype)
    • getAllIssueTypes
    • getIssueType
    • createIssueType
    • deleteIssueType
    • updateIssueType
    • getAlternativeIssueTypes
  • jql (/rest/api/2/jql/autocompletedata)
    • getAutoCompleteData
  • labels (/rest/api/1.0/labels/suggest?query= and /rest/api/2/label)
    • getLabels
    • getAllLabels
  • licenseRole (/rest/api/2/licenserole)
    • getAllLicenseRoles
    • getLicenseRole
    • editLicenseRole
  • licenseValidator (/rest/api/2/licenseValidator)
    • validateLicense
  • myPermissions (/rest/api/2/mypermissions)
    • getMyPermissions
  • myPreferences (/rest/api/2/mypreferences)
    • getPreference
    • editPreference
    • deletePreference
  • myself (/rest/api/2/myself)
    • getMyself
    • editMyslef
    • changePassword
  • password (/rest/api/2/password)
    • getPasswordPolicy
  • permissions (/rest/api/2/permissions)
    • getAllPermissions
  • permissionScheme (/rest/api/2/permissionscheme)
    • getAllPermissionSchemes
    • createPermissionScheme
    • getPermissionScheme
    • editPermissionScheme
    • deletePermissionScheme
    • getPermissionSchemeGrants
    • createPermissionGrantInScheme
    • deletePermissionGrantFromScheme
    • getPermissionSchemeGrantById
  • priority (/rest/api/2/priority)
    • getAllPriorities
    • getPriority
  • project (/rest/api/2/project)
    • getAllProjects
    • getProject
    • getComponents
    • getStatuses
    • getVersions
    • getVersionsPaginated
    • getRoles
    • getRole
    • updateRole
    • updateProject
    • addToRole
  • projectCategory (/rest/api/2/projectCategory)
    • getAllProjectCategories
    • getProjectCategory
  • projectValidate (/rest/api/2/projectvalidate)
    • validateProjectKey
  • reindex (/rest/api/2/reindex)
    • doReindex
    • getReindex
  • resolution (/rest/api/2/resolution)
    • getAllResolutions
    • getResolution
  • roles (/rest/api/2/role) (a.k.a. ProjectRoles)
    • getAll
    • createRole
    • getRoleById
    • updateRole
    • deleteRole
    • getActors
    • addActors
    • removeActor
  • screens (/rest/api/2/screens)
    • getAvailableFields
    • getTabs
    • createTab
    • renameTab
    • deleteTab
    • addFieldToTab
    • getFieldsInTab
    • removeFieldFromTab
    • moveFieldOnTab
    • moveTabPosition
    • addFieldToDefaultTab
  • search (/rest/api/2/search)
    • search
  • securityLevel (/rest/api/2/securitylevel)
    • getSecurityLevel
  • serverInfo (/rest/api/2/serverInfo)
    • getServerInfo
  • settings (/rest/api/2/settings)
    • setBaseUrl
    • getIssueNavColumns
  • sprint (/rest/agile/1.0/sprint)
    • createSprint
    • getSprint
    • updateSprint
    • partiallyUpdateSprint
    • deleteSprint
    • getSprintIssues
    • moveSprintIssues
    • swapSprint
  • status (/rest/api/2/status)
    • getAllStatuses
    • getStatus
  • statusCategory (/rest/api/2/statuscategory)
    • getAllStatusCategories
    • getStatusCategory
  • user (/rest/api/2/user)
    • getUser
    • deleteUser
    • editUser
    • multiProjectSearchAssignable
    • searchAssignable
    • createTemporaryAvatar
    • convertTemporaryAvatar
    • deleteAvatar
    • getAvatars
    • getDefaultColumns
    • setDefaultColumns
    • resetDefaultColumns
    • changePassword
    • searchPermissions
    • searchPicker
    • search
    • all
    • viewIssueSearch
  • version (/rest/api/2/version)
    • createVersion
    • moveVersion
    • getVersion
    • editVersion
    • getRelatedIssueCounts
    • getUnresolvedIssueCount
    • getRemoteLinks
    • createRemoteLink
    • getRemoteLink
    • deleteRemoteLink
    • deleteVersion
    • deleteAllRemoteLinks
    • getGlobalRemoteLink
  • webhook (/rest/webhooks/1.0/webhook)
    • getAllWebhooks
    • getWebhook
    • createWebhook
    • deleteWebhook
  • workflow (/rest/api/2/workflow)
    • getWorkflows
  • workflowScheme (/rest/api/2/workflowscheme)
    • createWorkflowScheme
    • editWorkflowScheme
    • deleteWorkflowScheme
    • createDraft
    • getDefaultWorkflow
    • removeDefaultWorkflow
    • setDefaultWorkflow
    • getDraft
    • editDraft
    • deleteDraft
    • getDraftDefaultWorkflow
    • setDraftDefaultWorkflow
    • removeDraftDefaultWorkflow
    • getIssueType
    • removeIssueType
    • editIssueType
    • getDraftIssueType
    • editDraftIssueType
    • removeDraftIssueType
    • getWorkflow
    • editWorkflow
    • deleteWorkflow
    • getDraftWorkflow
    • editDraftWorkflow
    • deleteDraftWorkflow
  • worklog (/rest/api/2/worklog)
    • getWorklogDeleted
    • worklogList
    • getWorklogUpdated

License

MIT license

jira-connector's People

Contributors

adwylie avatar apla avatar asakapab0i avatar bchownwt avatar dev-z avatar floralvikings avatar g-rath avatar gierappa avatar itamarm avatar kevinbowman-sbg avatar konrad-garus avatar kylefarris avatar mattpardee avatar mrrefactoring avatar ngotchac avatar okhomenko avatar oleg-codaio avatar optilude avatar patgaunt avatar pjuchniewicz avatar rocampana avatar roman-acumen avatar sebon1980 avatar shafua avatar songgao avatar tgmcclen avatar tharindu-wj avatar tomasbruckner avatar vladimirpal avatar william-olson avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

jira-connector's Issues

How to set a property in an issue in order to move it

Hello,

I'm trying to do this

jira.issue.setProperty({ id, propertyKey, propertyValue }, cb)

In order to move an issue from one column to another. However it doesn't, and I can see the properties I set like this remain as some kind of custom properties that don't affect the actual issue. Which propertyKey/propertyValue could I use to do this?

Thanks

Support multiple users with a single jira client

I am trying to write a basic jira system , and need to have the appropriate user information logged in jira - so this obviously means that I have to pass the appropriate auth to each request

After looking at the code, it seems to me that I have to have a jira instance for each potential user.

I had hoped to pass in a jar property on the option to each method call, but I can see that in a lot of places, the makebuildrequest is not used and the function builds it's own options object to pass to makeRequest

So, the ways I see to implement my requirement are these

#1 have a jira client for each user (ok for small amount of users, potentially troublesome for a large number of users)
#2 modify all methods to use a jar parameter if supplied
#3 add a pre-request hook so that the request can be modified before being sent to jira

to me, #3 is the most practical and easiest to implement . Any other comments ?

Confirm OAuth Authentication works with JIRA Cloud?

Hello; I am stuck at the "oauth_problem=signature_invalid", trying to connect with JIRA Cloud. Before I spend hours digging in, can someone confirm that floralvikings/jira-connector (and really, the OAuth module underneath) works correctly with JIRA Cloud?

user.getUser broken when using expand param

This commit adds the expand param ea53fd8 but that causes an authentication issue when hitting jira.

This is because the docs say to provide an expand object. This is similar to getIssue but it gets iterated and parsed into a string over there. https://github.com/floralvikings/jira-connector/blob/master/api/issue.js#L995

The user methods do not have a buildRequestOptions function so I've fixed this by just iterating over the expand fields in the getUser function. https://github.com/rjgoldsborough/jira-connector/tree/fix-user-expand.

Let me know if you'd prefer a buildRequestOptions in the user file or maybe it's time to move it to the jiraClient file like the makeRequest function.

How to fetch total list of issues ??

Right I see there was privilege to fetch a particular issue by passing its key , where as how would i fetch
the list of total issues from the selected project ? referred official API documentation but no luck , is there any such privilege , please suggest me ..

Inconsistency in capitalisation of ID

Some options use ID and some use Id

e.g.

     * @method getWorkLog
     * @memberOf IssueClient#
     * @param {Object} opts The options to pass to the API.  Note that this object must contain EITHER an issueID or
     *     issueKey property; issueID will be used over issueKey if both are present.
     * @param {string} [opts.issueID] The ID of the issue.  EX: 10002
     * @param {string} [opts.issueKey] The Key of the issue.  EX: JWR-3
     * @param {string} opts.worklogId The id of the work log to retrieve.

issueID vs worklogId

small syntax error in board.js/getBoard

On working with the npm module, i find out that there is a small syntax error at the uri which returns 404 on executing
Function "getBoard" is member of the AgileBoardClient but doesn't build an AgileUrl

@ line 58:
is written -- uri: this.jiraClient.buildURL('/board/' + opts.boardId),
must be --- uri: this.jiraClient.buildAgileURL('/board/' + opts.boardId),

utf-8 needed for german charcters

I use component.createComponent from jiraClient and need utf-8 for some german characters in the description (รค, รผ, รถ, ...)
How can i do this?

Does anyone has an example of creating a version?

I've been trying to create a version but I can't get anything but undefined not sure why I'm missing, this is my code:

var JiraClient = require('jira-connector');
var config = require('config');

// Create jira client
const jira = new JiraClient({
  host: config.get('JiraConfig.host'),
  basic_auth: {
    username: config.get('JiraConfig.username'),
    password: config.get('JiraConfig.password')
    }
});

jira.version.createVersion({
  description: "An excellent version",
  name: "New Version 1",
  userReleaseDate: "5/Jul/2010",
  project: "SQA",
  archived: false,
  released: true,
  projectId: 10000
}, function(error, version) {
  if( null !== version ) {
    console.log("version created", version);
  } else {
    console.log(error);
  }
});

Sprint issues or RapidView issues?

I can connect and get good responses from the requests. Very nice library by the way.

However, I am trying to figure out if there is a way to get all issues, or all issues for a given sprint.

I did not see any Sprint or RapidView clients in the code. Is this possible?

If not is there a way I can go about this with this library?

Thanks in advance.

Return JQL search result

Hi there,

Non-coder here trying to dig into this stuff, and I'm pretty lost. I was able to write code to return values for a single issue, but I can't seem to find the right resources to write the code to return values based upon a JQL search. I tried something basic here, but I'm not sure what I'm doing wrong. Any guidance would be much appreciated, it would be huge to get this working for my company!

var JiraClient = require('jira-connector');
 
var jira = new JiraClient( {
    host: (removed for security purposes),
    basic_auth: {
        base64: (removed for security purposes)
    }
});

jira.search.search({
   jql: 'type = bug'
}).then(issues => {
   // list issues for your search 
   function(error, issue) {
    console.log(issue.fields.issueKey, issue.fields.issuetype.name, issue.fields.summary, issue.fields.status.name, issue.fields.resolution.name, issue.fields.labels, issue.fields.customfield_12600, issue.fields.customfield_14212, issue.fields.customfield_10009, issue.fields.customfield_14200, issue.fields.customfield_14205, issue.fields.customfield_14203, issue.fields.customfield_14204, issue.fields.customfield_10004);
}
});

Search with GET instead of POST

Hi,

I have a search that uses expand="changelog". I'm porting some code from a Python script, where it so happens that the search API abstraction chooses to use a GET request. In jira-connector, the search.search() method uses POST.

I think JIRA allows both and treats them more or less equally, but with POST, trying two different JIRA instances with very different data, I get a server-side error back. This may be a bug in the JIRA REST API, I'm not sure.

The error is: Can not deserialize instance of java.util.ArrayList out of VALUE_STRING token

So, small request: can we allow the method to be specified in the options passed to search()?

I tried very quickly to hack the code to use method: 'GET', but I don't think the parameters are actually marshalled to the query string so that returned a lot of issues! :)

Martin

Client not working via http://ip:port

Hi,

My jira url is http://ip:8080 I can not get the connect to jira use this library,when connecting,it always use port 443 ,i cant change it.

let jira = new JiraClient({ 
        host: '192.168.1.111',
        port: '8080',
        basic_auth: {  
                username: process.env.HUBOT_JIRA_USER,
                password: process.env.HUBOT_JIRA_PASS
        }
});

when i run it

ERROR!
{ Error: connect ECONNREFUSED 192.168.1.111:443
  at Object.exports._errnoException (util.js:1008:11)
  at exports._exceptionWithHostPort (util.js:1031:20)
  at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1080:14)

  code: 'ECONNREFUSED',
  errno: 'ECONNREFUSED',
  syscall: 'connect',
  address: '192.168.1.111',
  port: 443 }

please help.

fs is no longer available

Hello,
jira-connector depends on fs and it seems that package is no longer available.
see npm message

ERROR in .//jira-connector/api/issue.js
Module not found: Error: Cannot resolve module 'fs' in
Portal.Client\node_modules\jira-connector\api
@ ./
/jira-connector/api/issue.js 4:9-22

Client not working via https

Hi,

I can not get the library to connect via https:

var JiraClient = require('./index.js');

var jira = new JiraClient({
    host: 'jira.foo.bar',
    oauth: {
        consumer_key: '...',
        token: '...',
        token_secret: '...',
        private_key: '-----BEGIN RSA PRIVATE KEY-----\n' +
        '...\n' +
        '-----END RSA PRIVATE KEY-----'
    }
});

jira.issue.getIssue({
    issueKey: 'T-1'
}, function(error, issue) {
    console.log(issue.fields.summary);
});

When I run it:

$ node test.js

TypeError: Cannot read property 'fields' of undefined
    at /home/hubot/node_modules/hubot-jira-connector/node_modules/jira-connector/test.js:30:22
    at Request._callback (/home/hubot/node_modules/hubot-jira-connector/node_modules/jira-connector/index.js:260:24)
    at Request.self.callback (/home/hubot/node_modules/hubot-jira-connector/node_modules/jira-connector/node_modules/request/request.js:199:22)
    at Request.emit (events.js:98:17)
    at Request.<anonymous> (/home/hubot/node_modules/hubot-jira-connector/node_modules/jira-connector/node_modules/request/request.js:1036:10)
    at Request.emit (events.js:117:20)
    at IncomingMessage.<anonymous> (/home/hubot/node_modules/hubot-jira-connector/node_modules/jira-connector/node_modules/request/request.js:963:12)
    at IncomingMessage.emit (events.js:117:20)
    at _stream_readable.js:944:16
    at process._tickCallback (node.js:448:13)

however, when I use http it works fine:

var JiraClient = require('./index.js');

var jira = new JiraClient({
    host: 'jira.foo.bar',
    protocol: 'http',
    oauth: {
        consumer_key: '...',
        token: '...',
        token_secret: '...',
        private_key: '-----BEGIN RSA PRIVATE KEY-----\n' +
        '...\n' +
        '-----END RSA PRIVATE KEY-----'
    }
});

jira.issue.getIssue({
    issueKey: 'T-1'
}, function(error, issue) {
    console.log(issue.fields.summary);
});
$ node test.js
Test ticket

Curl doesn't show any certificate errors:

$ curl -v https://jira.foo.bar/rest/api/2/issue/T-1
*   Trying 54.x.x.x...
* Connected to jira.foo.bar (54.x.x.x) port 443 (#0)
* Initializing NSS with certpath: sql:/etc/pki/nssdb
*   CAfile: /etc/pki/tls/certs/ca-bundle.crt
  CApath: none
* SSL connection using TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384
* Server certificate:
*   subject: CN=*.foo.bar,O="Amazon.com, Inc.",L=Seattle,ST=Washington,C=US
*   start date: Sep 14 00:00:00 2015 GMT
*   expire date: Nov 04 23:59:59 2016 GMT
*   common name: *.foo.bar
*   issuer: CN=Symantec Class 3 Secure Server CA - G4,OU=Symantec Trust Network,O=Symantec Corporation,C=US
> GET /rest/api/2/issue/T-1 HTTP/1.1
> User-Agent: curl/7.40.0
> Host: jira.foo.bar
> Accept: */*
>
< HTTP/1.1 401 Unauthorized
< Server: nginx/1.8.1
< Date: Wed, 09 Mar 2016 08:12:09 GMT
< Content-Type: application/json;charset=UTF-8
< Transfer-Encoding: chunked
< Connection: keep-alive
< X-AREQUESTID: 492x2054338x1
< X-ASEN: SEN-4281670
< Set-Cookie: atlassian.xsrf.token=BLTD-G3C4-QIZQ-HKFG|9fd33f69c1caaecece6f5fe3f40dfca53b30daec|lout; Path=/
< X-AUSERNAME: anonymous
< Cache-Control: no-cache, no-store, no-transform
< X-Content-Type-Options: nosniff
< WWW-Authenticate: OAuth realm="http%3A%2F%2Fjira.foo.bar"
<
* Connection #0 to host jira.foo.bar left intact
{"errorMessages":["You do not have the permission to see the specified issue.","Login Required"],"errors":{}}

Any ideas what's happening here ?

Optional params are not optional

According to the JIRA docs, some of the filter- / query params are optional. But in the library you have to pass them in, even if they are null.

For Example:
https://docs.atlassian.com/jira/REST/cloud/#api/2/dashboard

Client:

    this.getAllDashboards = function (opts, callback) {
        var options = {
            uri: this.jiraClient.buildURL('/dashboard'),
            method: 'GET',
            json: true,
            followAllRedirects: true,
            qs: {
                filter: opts.filter,                                   // 
                startAt: opts.startAt,                           // you have to pass in obj, even with null values
                maxResults: opts.maxResults           //
            }
        };

        return this.jiraClient.makeRequest(options, callback);
    };

It would actually rather useful to check if options are provided and maybe fallback to some default values if they are required.

No support for issues retrieval by board id and sprint id

JIRA API has an endpoint https://developer.atlassian.com/cloud/jira/software/rest/#api-board-boardId-sprint-sprintId-issue-get
for retrieving issues based on board id and sprint id. Retrieving issues just based on sprint id causes all issues to be returned. The board may be filtering issues out so there may be issues returned that should not be.

It uses the same parameters as api/sprint.js/getSprintIssues does. The only difference is that the url needs to be this.jiraClient.buildAgileURL('/board/' + opts.boardId + '/sprint/' + opts.sprintId + '/issue')

Using Search 'fields' option returns undefined

Whenever i call the search method and pass along jql and fileds, i get a undefined.

Here the call:

jira.search.search({jql: 'issuetype in(Story,Bug,Issue) AND status not in("Resolved","Closed") AND sprint in openSprints()', fields: 'summary,status' }, function(err, res) { console.log(res);});

Whenever i omit the 'fields' option, it works like a charm.

getSprintsForBoard

Why 'getSprintsForBoard' method isn`t implemented? It is in documentation

Working with proxy

Hi! have been working with jira-connector for 2 months now. It always give error while on company network. I have a proxy for the network and I don't know how to use it with this package.

ENOENT when creating an attachment for an Issue

Hello!

Awemose library, just found it one hour ago and it's amazing! Congratulations for the good job.

I'm having a problem when adding an attachment for an Issue, and I don't know why. I get something like:

{ Error: form-data: ENOENT: no such file or directory, open 'C:\Users\Marcos\projects\mycurrentproject\__1496158180441.json'
  errno: -4058,
  code: 'ENOENT',
  syscall: 'open',
  path: 'C:\\Users\\Marcos\\projects\\mycurrentproject\\__1496158180441.json' } 

But the path is correct and the file exists, any ideas?

Running jira function for each issue in object

Hey guys,

I'm running a jira request for each issue of an object, having timing issues with it, I'm not an expert with promises so I was wondering if you can point me in the right direction

var issuesObject = ''
for (i = 0; i < issuesObject.length; i++) {
  jira.issue.getIssue({
    issueKey: 'SQA-72'
  }, function(error, issue) {
    issuesDescription += issue.fields.summary;
  });
});

console.log('run second function with issues description variable');

Basically my console log is running before the jira function, I need to wait until the jira response to run my function but can't do it inside the loop.

Any idea?

Thanks in advance.

Error: connect ECONNREFUSED

Hi, I'm getting the following error on every API call:

image

(This is when running console.log(err); )
I'm connecting to Jira v6.4.1 using basic authentication.

When already logged in the browser, I can get to the API to give me data in the browser with both the IP and the host name of the Jira server.

When logged out I get {"errorMessages":["No project could be found with key 'PROJ'."],"errors":{}} where 'PROJ' would be the project key. This part makes sense as I am not logged in. However, this is not returned to my application when I make the API calls using jira-connector (at least not visibly to me).

Also, I can connect just fine with curl using the first command outlined here: https://developer.atlassian.com/jiradev/api-reference/jira-rest-apis/jira-rest-api-tutorials/jira-rest-api-example-basic-authentication

Any help with this issue would be greatly appreciated.

Error on transitioning issue: TypeError: opts.fields.forEach is not a function

Hi,

Trying to transition an issue to be resolved as invalid.
This is my testcode where issue is the issue key:

ID 5 is "Resolve"

function resolve_invalid(issue) {
    jira.issue.transitionIssue({
        issueKey:   issue,
        transition: {id: '5'},
        fields: {resolution: {name: 'Invalid'}}
    }, function (error, data) {
        console.log(error);
        console.log(data);
    });
}

Error without the fields is 'Missing 'transition' identifier'
According to the Jira REST API, the fields object is supported.

Example:

{
    "update": {
        "comment": [
            {
                "add": {
                    "body": "Bug has been fixed."
                }
            }
        ]
    },
    "fields": {
        "assignee": {
            "name": "bob"
        },
        "resolution": {
            "name": "Fixed"
        }
    },
    "transition": {
        "id": "5"
    },
    "historyMetadata": {
        "type": "myplugin:type",
        "description": "text description",
        "descriptionKey": "plugin.changereason.i18.key",
        "activityDescription": "text description",
        "activityDescriptionKey": "plugin.activity.i18.key",
        "actor": {
            "id": "tony",
            "displayName": "Tony",
            "type": "mysystem-user",
            "avatarUrl": "http://mysystem/avatar/tony.jpg",
            "url": "http://mysystem/users/tony"
        },
        "generator": {
            "id": "mysystem-1",
            "type": "mysystem-application"
        },
        "cause": {
            "id": "myevent",
            "type": "mysystem-event"
        },
        "extraData": {
            "keyvalue": "extra data",
            "goes": "here"
        }
    }
}

Stacktrace:

TypeError: opts.fields.forEach is not a function
    at IssueClient.buildRequestOptions (c:\Users\muste\WebstormProjects\arise\node_modules\jira-connector\api\issue.js:981:25)
    at IssueClient.transitionIssue (c:\Users\muste\WebstormProjects\arise\node_modules\jira-connector\api\issue.js:580:28)

Handling Certificate with Authentications

Hi,

Nice connector by the way - This may not really an issue in terms of your connector, but I am connecting to a dev and prod instance of Jira internally and have the following challenges with certs:

  1. Dev environment: "self signed certificate in certificate chain"
  2. Prod environment: "UNABLE_TO_VERIFY_LEAF_SIGNATURE"

If I have a copy of the intermediate cert is there a way to point the connector to the location of the cert in order for it to use it in the connection?

I will try a global variable, but I don't know if it will work either: process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0'

Thanks

Andrew

issue.addComment does not allow visibility

Per the Jira api docs,

addComment can have the following payload:

    "body": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque eget venenatis elit. Duis eu justo eget augue iaculis fermentum. Sed semper quam laoreet nisi egestas at posuere augue semper.",
    "visibility": {
        "type": "role",
        "value": "Administrators"
    }

PR #25 prevents the visibility from being sent by only sending the body string. Your documentation also expects it to be an object, not a string.

Please revert #25 to its previous state.

Download attachment

It doesn't look like there's a way to download an issue's attachments.

I can call jira.issue.getIssue() to get the attachment list, and then read the URL from response.fields.attachment[x].content. But I couldn't find a way to download the file from that URL (with the necessary authentication headers), or preferably, pipe it to a writable stream.

Updates missing on npm install.

I npm unstalled this library and I noticed that the version on GitHub doesn't seem to match what npm provides even though the versions are the same.

From NPM:
...

"author": {
    "name": "Caleb Brinkman",
    "email": "[email protected]"
  },
  "bugs": {
    "url": "https://github.com/floralvikings/jira-connector/issues"
  },
  "bundleDependencies": false,
  "dependencies": {
    "oauth": "^0.9.12",
    "request": "^2.51.0"
  },
  "deprecated": false,
  "description": "Easy to use NodeJS wrapper for the Jira REST API.",
  "homepage": "https://github.com/floralvikings/jira-connector#readme",
  "keywords": [
    "JIRA",
    "REST",
    "OAuth"
  ],
  "license": "MIT",
  "main": ".",
  "name": "jira-connector",
  "repository": {
    "type": "git",
    "url": "git+ssh://[email protected]/floralvikings/jira-connector.git"
  },
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "version": "2.6.0"

Note how the Auth api is missing below:
screen shot 2017-11-12 at 6 09 09 pm

jira.search.search returning all issues

jira.search.search({
project:'My Project',
labels: 'My Label'
}, function(error, issue) {
//console.log(JSON.stringify(issue, null, 2));
});

has been returning all issues at my host. The body object appears to be empty when I console.log(options) inside of search.js.

transitionIssue example needed

I am trying to transition issue to done state using below code

jira.status.getAllStatuses({
   issueKey: task.ticket
}, function(err, statuses) {
   var doneStatus = (statuses.filter(function(status) {
      return status.name === 'Done';
   }))[0];
   jira.issue.transitionIssue({
     issueKey: task.ticket,
     transition: { id: doneStatus.statusCategory.id }
   }, function() {
     console.log(arguments);
  });
});

But this does not seem to be working. Any example would be very helpful.

Thanks in Advance.

How to get Multiple Issues of single project

Right now I am getting only single issue using this,

jira.issue.getIssue({
    issueKey: 'JWR-19'
}, function(error, issue) {
    console.log(issue.fields.summary);
});

How can I get multiple Issues list ?
Thanks in advance.

Fix assignIssue to allow `null` to unassign a user in api/issue

The following code does not permit a user to be unassigned.

    this.assignIssue = function (opts, callback) {
        if (!opts.assignee) {
            throw new Error(errorStrings.NO_ASSIGNEE_ERROR);
        }
        var options = this.buildRequestOptions(opts, '/assignee', 'PUT', {name: opts.assignee});

        this.jiraClient.makeRequest(options, callback, 'Issue Assigned');
    };

The user can be unassigned by setting the value of assignee to null.

OAuth authentication not working

The flow as described in the documentation is working fine till JiraClient.oauth_util.swapRequestTokenWithAccessToken method call. I get the access token but creating the JiraClient instance with consumer_key, private_key, token and token_secret in the 4th step gives oauth_problem=token_rejected error when making a API call.

Alternatively I tried to use the access_token return by JiraClient.oauth_util.getAuthorizeURL method call to make the API request like http://<API_path>/?access_token=<access_token> this works fine.

Can anyone help me to clarify this issues.

Getting undefined when trying to get the token

We tried this for our jira instance :

var JiraClient = require('./node_modules/jira-connector/index.js');

JiraClient.oauth_util.getAuthorizeURL({
host: 'ourjirahost.com',
oauth: {
consumer_key: 'requiredconsumerkey',
private_key: '-----BEGIN RSA PRIVATE KEY-----\n' +
'privatekey\n'
'-----END RSA PRIVATE KEY-----'
}
}, function (error, oauth) {
console.log(oauth);
});

With all the steps provided in the doc of this addon , but it gives 'undefined' in the output when we run node .js. I am exepcting to see a json like this :

{
url: 'https://jenjinstudios.atlassian.net/plugins/servlet/oauth/authorize?oauth_token=some-token-here',
token: 'some-token-here',
token_secret: 'some-secret-here'
}

Please revert back soon as to what might be the cause of this. Also is there a way to capture that output in some variable?

Any reason for the custom file store?

This is more of a question but I was curious why you chose to use tough-cookie-filestore over a straight request jar.

I mostly ask because tough-cookie-filestore is outdated and I am having trouble getting tough-cookie working but a straight request.jar() seems to work fine.

Thanks in advance.

#18 breaks transitioning fields

The fix implemented for issue #18 breaks transitioning fields.

Before I was able to also change the Resolution of the ticket. After the change it only allows it to change the status.

transition: {
            transition: {id: 5},
            fields:     {resolution: {name: 'Duplicate'}},
            update:     {
                comment: [{add: {body: util.format(CLOSEREASON.Duplicate, dupe_of)}}]
            }
        }

This changes the status to Resolved, Resolution to Duplicate and adds a comment.

After the change:

{           
        transition: {id: 5},
        fields:     {resolution: {name: 'Duplicate'}},
        update:     {
            comment: [{add: {body: util.format(CLOSEREASON.Duplicate, dupe_of)}}]
        }
}

Fields and Update get ignored, I see no way to do them.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.