Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: client syntax to match modern Gofer #58

Merged
merged 3 commits into from
Mar 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,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
153 changes: 88 additions & 65 deletions lib/github/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,87 +32,110 @@

'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, pkg.name);
}

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 },
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
pathParams: { pullId },
pathParams: { pullId },
endpointName: 'pull.get',

ideally, stick endpointName on all of these (one downside of the class syntax)

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

get labels() {
return {
create: function create(label) {
return request('/repos/{owner}/{repo}/labels', {
method: 'POST',
/**
*
* @param {string} label
* @return {Promise<any>}
*/
create: label =>
this.post('/repos/{owner}/{repo}/labels', {
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', {
method: 'PUT',
pathParams: {
issueId,
},
endpointName: 'labels.create',
}).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 },
endpointName: 'labels.listByIssue',
}).json(),

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

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

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

Github.forRepository = function forRepository(repository) {
const repoInfo = parseRepository(repository);
Expand Down
88 changes: 52 additions & 36 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,19 +48,19 @@
"gofer": "^5.1.0",
"minimist": "^1.2.5",
"rc": "^1.2.8",
"semver": "^7.3.4",
"semver": "^7.3.5",
"string.prototype.replaceall": "^1.0.5"
},
"devDependencies": {
"c8": "^7.6.0",
"eslint": "^7.20.0",
"eslint": "^7.22.0",
"eslint-config-groupon": "^10.0.2",
"eslint-plugin-import": "^2.22.1",
"eslint-plugin-mocha": "^8.0.0",
"eslint-plugin-mocha": "^8.1.0",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-prettier": "^3.3.1",
"mocha": "^8.3.0",
"mkdirp": "^1.0.4",
"mocha": "^8.3.2",
"prettier": "^2.2.1"
},
"author": {
Expand Down