screwdriver-request
v2.0.1
Published
Wrapper around got pkg to define a simple interface for http requests
Downloads
1,059
Readme
request
Wrapper around got pkg to define a simple interface for http requests
Usage
npm install screwdriver-request
Example:
const Hoek = require('@hapi/hoek');
const logger = require('logger');
const request = require('screwdriver-request');
async _addPrComment({ comment, prNum, scmUri }) {
try {
const pullRequestComment = await request({
method: 'POST',
url: `https://gitlab.com/v4/projects/${repoId}/merge_requests/${prNum}/notes`,
json: {
body: 'This is a comment'
},
context: {
token: this.config.commentUserToken,
caller: 'createPullRequestComment'
},
timeout: 15000
});
return {
commentId: Hoek.reach(pullRequestComment, 'body.id'),
createTime: Hoek.reach(pullRequestComment, 'body.created_at'),
username: Hoek.reach(pullRequestComment, 'body.author.username')
};
} catch (err) {
logger.error('Failed to addPRComment: ', err);
return null;
}
}
}
Testing
npm test
License
Code licensed under the BSD 3-Clause license. See LICENSE file for terms.