Skip to content

Commit

Permalink
refactor: client syntax to match modern Gofer
Browse files Browse the repository at this point in the history
  • Loading branch information
Andreas Richter committed Feb 6, 2020
1 parent df01025 commit 84fd239
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 60 deletions.
2 changes: 1 addition & 1 deletion lib/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ if (argv.version) {
process.exit(argv.help ? 0 : 1);
} else {
const cwd = process.cwd();
const packageJsonFile = path.join(cwd, 'package.json'); // eslint-disable-next-line import/no-dynamic-require
const packageJsonFile = path.join(cwd, 'package.json');

// eslint-disable-next-line import/no-dynamic-require
const pkg = require(packageJsonFile);
Expand Down
139 changes: 80 additions & 59 deletions lib/github/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,87 +32,108 @@

'use strict';

const util = require('util');

const Gofer = require('gofer');

const pkg = require('../../package');

const parseRepository = require('./parse-repository');

function Github(config) {
Gofer.call(this, config, 'github');
}
class Github extends Gofer {
constructor(config) {
super(config, 'github', pkg.version);
}

util.inherits(Github, Gofer);
Github.prototype.registerEndpoints({
pull: function pull(request) {
get pull() {
return {
commits: function commits(pullId) {
return request('/repos/{owner}/{repo}/pulls/{pullId}/commits', {
pathParams: {
pullId,
},
}).json();
},
get: function get(pullId) {
return request('/repos/{owner}/{repo}/pulls/{pullId}', {
pathParams: {
pullId,
},
}).json();
},
/**
* @param {string} pullId
* @return {Promise<any>}
*/
get: pullId =>
this.get('/repos/{owner}/{repo}/pulls/{pullId}', {
pathParams: { pullId },
}).json(),
/**
* @param {string} pullId
* @return {Promise<any>}
*/
commits: pullId =>
this.get('/repos/{owner}/{repo}/pulls/{pullId}/commits', {
pathParams: { pullId },
}).json(),
};
},
labels: function labelsEndpoint(request) {
}

get labels() {
return {
create: function create(label) {
return request('/repos/{owner}/{repo}/labels', {
/**
*
* @param {string} label
* @return {Promise<any>}
*/
create: label =>
this.get('/repos/{owner}/{repo}/labels', {
method: 'POST',
json: label,
}).json();
},
list: function list() {
return request('/repos/{owner}/{repo}/labels', {}).json();
},
listByIssue: function listByIssue(issueId) {
return request('/repos/{owner}/{repo}/issues/{issueId}/labels', {
pathParams: {
issueId,
},
}).json();
},
setForIssue: function setForIssue(issueId, labels) {
return request('/repos/{owner}/{repo}/issues/{issueId}/labels', {
}).json(),

/**
* @return {Promise<any>}
*/
list: () => this.get('/repos/{owner}/{repo}/labels', {}).json(),

/**
* @param {string} issueId
* @return {Promise<any>}
*/
listByIssue: issueId =>
this.get('/repos/{owner}/{repo}/issues/{issueId}/labels', {
pathParams: { issueId },
}).json(),

/**
* @param {string} issueId
* @param {string[]} labels
* @return {FetchResponse}
*/
setForIssue: (issueId, labels) =>
this.get('/repos/{owner}/{repo}/issues/{issueId}/labels', {
method: 'PUT',
pathParams: {
issueId,
},
pathParams: { issueId },
json: labels,
});
},
}),
};
},
releases: function releases(request) {
}

get releases() {
return {
create: function create(release) {
return request('/repos/{owner}/{repo}/releases', {
/**
* @param release
* @return {Promise<any>}
*/
create: release =>
this.get('/repos/{owner}/{repo}/releases', {
method: 'POST',
json: release,
}).json();
},
}).json(),
};
},
tags: function tags(request) {
}

get tags() {
return {
get: function get(tag) {
return request('/repos/{owner}/{repo}/git/refs/tags/{tag}', {
/**
* @param {string} tag
* @return {Promise<any>}
*/
get: tag =>
this.get('/repos/{owner}/{repo}/git/refs/tags/{tag}', {
pathParams: {
tag,
},
}).json();
},
}).json(),
};
},
});
}
}

Github.forRepository = function forRepository(repository) {
const repoInfo = parseRepository(repository);
Expand Down

0 comments on commit 84fd239

Please sign in to comment.