2014-11-18 21:14:12 +03:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, you can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
2014-02-27 04:54:27 +04:00
|
|
|
/**
|
|
|
|
@fileoverview
|
|
|
|
|
|
|
|
Utilities for converting github pull requests to resultsets.
|
|
|
|
|
|
|
|
@module mozilla-treeherder/github
|
|
|
|
*/
|
|
|
|
var assert = require('assert');
|
|
|
|
var factory = require('./factory/github');
|
|
|
|
var Promise = require('promise');
|
2014-05-16 11:16:05 +04:00
|
|
|
var Github = require('github');
|
2014-02-27 04:54:27 +04:00
|
|
|
|
2014-03-28 08:26:26 +04:00
|
|
|
/*
|
2014-02-27 04:54:27 +04:00
|
|
|
@param {String} repository for pull request result in treeherder.
|
|
|
|
@param {Object} options to configure pull request -> resultset.
|
|
|
|
@param {Object} options.github object from the `github` module.
|
|
|
|
@param {String} options.repo repository of the github project.
|
|
|
|
@param {String} options.user user/org which owns the repository.
|
|
|
|
@param {String} options.number of the pull request to generate results for.
|
2014-05-16 11:16:05 +04:00
|
|
|
@param {String} options.token for your github user.
|
2014-02-27 04:54:27 +04:00
|
|
|
*/
|
|
|
|
function pull(repository, options) {
|
|
|
|
assert(options.repo, 'github repo is required');
|
|
|
|
assert(options.user, 'github user is required');
|
|
|
|
assert(options.number, 'github number is required');
|
|
|
|
|
2014-05-16 11:16:05 +04:00
|
|
|
var github = new Github({ version: '3.0.0' });
|
|
|
|
if (options.token) {
|
|
|
|
github.authenticate({ type: 'oauth', token: options.token });
|
|
|
|
}
|
|
|
|
|
2014-02-27 04:54:27 +04:00
|
|
|
// github api glue
|
2014-05-16 11:16:05 +04:00
|
|
|
var pr = github.pullRequests;
|
2014-02-27 04:54:27 +04:00
|
|
|
var prGet = Promise.denodeify(pr.get.bind(pr));
|
|
|
|
var prCommits = Promise.denodeify(pr.getCommits.bind(pr));
|
|
|
|
|
|
|
|
// treeherder results
|
|
|
|
var resulset;
|
|
|
|
|
|
|
|
return prGet({
|
|
|
|
user: options.user,
|
|
|
|
repo: options.repo,
|
|
|
|
number: options.number
|
|
|
|
}).then(function(prResult) {
|
|
|
|
resulset = factory.pull(repository, prResult);
|
|
|
|
return prCommits({
|
|
|
|
user: options.user,
|
|
|
|
repo: options.repo,
|
|
|
|
number: options.number
|
|
|
|
});
|
|
|
|
}).then(function(commits) {
|
2014-03-28 08:26:26 +04:00
|
|
|
resulset.revisions = factory.pullCommits(repository, commits);
|
2014-02-27 04:54:27 +04:00
|
|
|
return resulset;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports.pull = pull;
|