Add github factory (initial work to generate treeherder data from github)

This commit is contained in:
James Lal 2014-02-26 15:52:21 -08:00
Родитель 9b1b7e8b89
Коммит 952ca696e4
5 изменённых файлов: 116 добавлений и 6 удалений

0
commit.js Normal file
Просмотреть файл

63
factory/github.js Normal file
Просмотреть файл

@ -0,0 +1,63 @@
/**
@fileoverview
Github factory which will convert github results into treeherder compatible
types.
@module mozilla-treeherder/factory/github
*/
/**
@private
*/
function commitToRev(repository, record) {
var author = record.commit.author;
return {
comment: record.commit.message,
revision: record.sha1,
repository: repository,
author: author.name + ' <' + author.email + '>'
};
}
/**
@example
var factory = require('mozilla-treeherder/factory/github');
var commitsFromGithub = [
// http://developer.github.com/v3/pulls/#list-commits-on-a-pull-request
]
factory.commits('gaia', commitsFromGithub);
@see http://developer.github.com/v3/pulls/#list-commits-on-a-pull-request
@param {String} repository name of the project.
@param {Array<Object>} list of github commits.
@return {Array} 'revsions' portion of a resultset collection.
*/
function commits(repository, list) {
return list.map(commitToRev.bind(this, repository));
}
module.exports.commits = commits;
/**
@param {Object} githubPr pull request object.
@see https://developer.github.com/v3/pulls/#get-a-single-pull-request
@return {Object} partial resultset from single pull request object.
*/
function pull(repository, githubPr) {
// created in seconds
var timestamp = new Date(githubPr.created_at);
timestamp = timestamp.valueOf() / 1000;
return {
revision_hash: githubPr.url,
push_timestamp: timestamp,
// XXX: not sure what the purpose of this or what other values we
// can expect...
type: 'push'
};
}
module.exports.pull = pull;

47
factory/github_test.js Normal file
Просмотреть файл

@ -0,0 +1,47 @@
suite('github', function() {
var REPO = 'gaia';
var GithubCommits = require('github-fixtures/commit');
var PullRequest = require('github-fixtures/pull_request');
var subject = require('./github');
function commitToRev(record) {
var author = record.commit.author;
return {
comment: record.commit.message,
revision: record.sha1,
repository: REPO,
author: author.name + ' <' + author.email + '>'
};
}
suite('#pull', function() {
var pr = PullRequest.create();
test('pull request', function() {
var result = subject.pull(REPO, pr);
assert.deepEqual(result, {
revision_hash: pr.url,
// created at in seconds
push_timestamp: (new Date(pr.created_at)).valueOf() / 1000,
type: 'push'
});
});
});
suite('#commits', function() {
var commits = [
GithubCommits.create(),
GithubCommits.create()
];
var expected = commits.map(commitToRev);
test('multiple commits', function() {
assert.deepEqual(
subject.commits(REPO, commits),
expected
);
});
});
});

Просмотреть файл

@ -26,15 +26,15 @@ gulp.task('doc', function() {
gulp.src([
'README.md',
'http_error.js',
'project.js'
'project.js',
'factory/github.js'
])
.pipe(jsdoc.parser())
.pipe(jsdoc.generator('./doc', tpl, opts));
});
gulp.task('watch', function() {
gulp.watch('*.js', ['doc']);
gulp.watch(['*.js', 'factory/*.js'], ['doc']);
});
gulp.task('default', ['doc']);

Просмотреть файл

@ -30,13 +30,13 @@
"nock": "~0.27.2",
"gulp": "~3.5.2",
"gulp-jsdoc": "0.0.2",
"uuid": "~1.4.1"
"uuid": "~1.4.1",
"github-fixtures": "~0.1.0"
},
"dependencies": {
"promise": "~4.0.0",
"superagent": "~0.16.0",
"superagent-promise": "0.0.0",
"oauth": "~0.9.11",
"swagger-client": "~1.0"
"oauth": "~0.9.11"
}
}