-
Notifications
You must be signed in to change notification settings - Fork 0
/
jira.js
33 lines (28 loc) · 1.17 KB
/
jira.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
'use strict'
const fetch = require( 'isomorphic-fetch' )
exports = module.exports = ( {
apiVersion = 2,
host, pass, user
} ) => {
const auth = new Buffer( `${ user }:${ pass }` ).toString( 'base64' )
const headers = {
'Authorization': `Basic ${ auth }`,
'Content-Type': 'application/json'
}
const apiFetch = ( path, ... args ) => fetch( `${ host }/rest/api/${ apiVersion }/${ path }`, ... args )
.then( response => response.json( ) )
return {
readProjects: ( ) => apiFetch( 'project', { method: 'GET', headers } ),
readIssuesInProjects: ( ... projects ) =>
apiFetch( 'search', { method: 'POST', headers, body: JSON.stringify( {
jql: `project in (${ projects.join( ) }) AND issueFunction in workLogged("after 2016/09/01 before 2016/09/30 by currentUser()")`,
expand: [ 'worklog' ],
fields: [ 'summary', 'worklog' ],
maxResults: -1,
startAt: 0,
validateQuery: false
} ) } ),
readIssueWorklog: ( issueId ) =>
apiFetch( `issue/${ issueId }/worklog`, { method: 'GET', headers } )
}
}