screwdriver-request

2.0.1 • Public • Published

request

Version Downloads Build Status Open Issues License

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.

Readme

Keywords

Package Sidebar

Install

npm i screwdriver-request

Weekly Downloads

472

Version

2.0.1

License

BSD-3-Clause

Unpacked Size

7.48 kB

Total Files

7

Last publish

Collaborators

  • screwdriver