Add API failure handling/logging (#92)
* Add API failure handling/logging
This commit is contained in:
parent
c72e3d7ff2
commit
d7468118d7
|
@ -8755,6 +8755,7 @@ class IssueProcessor {
|
||||||
listIssueComments(issueNumber, sinceDate) {
|
listIssueComments(issueNumber, sinceDate) {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
// find any comments since date on the given issue
|
// find any comments since date on the given issue
|
||||||
|
try {
|
||||||
const comments = yield this.client.issues.listComments({
|
const comments = yield this.client.issues.listComments({
|
||||||
owner: github.context.repo.owner,
|
owner: github.context.repo.owner,
|
||||||
repo: github.context.repo.repo,
|
repo: github.context.repo.repo,
|
||||||
|
@ -8762,11 +8763,17 @@ class IssueProcessor {
|
||||||
since: sinceDate
|
since: sinceDate
|
||||||
});
|
});
|
||||||
return comments.data;
|
return comments.data;
|
||||||
|
}
|
||||||
|
catch (error) {
|
||||||
|
core.error(`List issue comments error: ${error.message}`);
|
||||||
|
return Promise.resolve([]);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
// grab issues from github in baches of 100
|
// grab issues from github in baches of 100
|
||||||
getIssues(page) {
|
getIssues(page) {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
|
try {
|
||||||
const issueResult = yield this.client.issues.listForRepo({
|
const issueResult = yield this.client.issues.listForRepo({
|
||||||
owner: github.context.repo.owner,
|
owner: github.context.repo.owner,
|
||||||
repo: github.context.repo.repo,
|
repo: github.context.repo.repo,
|
||||||
|
@ -8776,6 +8783,11 @@ class IssueProcessor {
|
||||||
page
|
page
|
||||||
});
|
});
|
||||||
return issueResult.data;
|
return issueResult.data;
|
||||||
|
}
|
||||||
|
catch (error) {
|
||||||
|
core.error(`Get issues for repo error: ${error.message}`);
|
||||||
|
return Promise.resolve([]);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
// Mark an issue as stale with a comment and a label
|
// Mark an issue as stale with a comment and a label
|
||||||
|
@ -8791,18 +8803,28 @@ class IssueProcessor {
|
||||||
if (this.options.debugOnly) {
|
if (this.options.debugOnly) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
try {
|
||||||
yield this.client.issues.createComment({
|
yield this.client.issues.createComment({
|
||||||
owner: github.context.repo.owner,
|
owner: github.context.repo.owner,
|
||||||
repo: github.context.repo.repo,
|
repo: github.context.repo.repo,
|
||||||
issue_number: issue.number,
|
issue_number: issue.number,
|
||||||
body: staleMessage
|
body: staleMessage
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
catch (error) {
|
||||||
|
core.error(`Error creating a comment: ${error.message}`);
|
||||||
|
}
|
||||||
|
try {
|
||||||
yield this.client.issues.addLabels({
|
yield this.client.issues.addLabels({
|
||||||
owner: github.context.repo.owner,
|
owner: github.context.repo.owner,
|
||||||
repo: github.context.repo.repo,
|
repo: github.context.repo.repo,
|
||||||
issue_number: issue.number,
|
issue_number: issue.number,
|
||||||
labels: [staleLabel]
|
labels: [staleLabel]
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
catch (error) {
|
||||||
|
core.error(`Error adding a label: ${error.message}`);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
// Close an issue based on staleness
|
// Close an issue based on staleness
|
||||||
|
@ -8814,12 +8836,17 @@ class IssueProcessor {
|
||||||
if (this.options.debugOnly) {
|
if (this.options.debugOnly) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
try {
|
||||||
yield this.client.issues.update({
|
yield this.client.issues.update({
|
||||||
owner: github.context.repo.owner,
|
owner: github.context.repo.owner,
|
||||||
repo: github.context.repo.repo,
|
repo: github.context.repo.repo,
|
||||||
issue_number: issue.number,
|
issue_number: issue.number,
|
||||||
state: 'closed'
|
state: 'closed'
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
catch (error) {
|
||||||
|
core.error(`Error updating an issue: ${error.message}`);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
// Remove a label from an issue
|
// Remove a label from an issue
|
||||||
|
@ -8831,12 +8858,17 @@ class IssueProcessor {
|
||||||
if (this.options.debugOnly) {
|
if (this.options.debugOnly) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
try {
|
||||||
yield this.client.issues.removeLabel({
|
yield this.client.issues.removeLabel({
|
||||||
owner: github.context.repo.owner,
|
owner: github.context.repo.owner,
|
||||||
repo: github.context.repo.repo,
|
repo: github.context.repo.repo,
|
||||||
issue_number: issue.number,
|
issue_number: issue.number,
|
||||||
name: encodeURIComponent(label) // A label can have a "?" in the name
|
name: encodeURIComponent(label) // A label can have a "?" in the name
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
catch (error) {
|
||||||
|
core.error(`Error removing a label: ${error.message}`);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
// returns the creation date of a given label on an issue (or nothing if no label existed)
|
// returns the creation date of a given label on an issue (or nothing if no label existed)
|
||||||
|
|
|
@ -268,28 +268,38 @@ export class IssueProcessor {
|
||||||
sinceDate: string
|
sinceDate: string
|
||||||
): Promise<Comment[]> {
|
): Promise<Comment[]> {
|
||||||
// find any comments since date on the given issue
|
// find any comments since date on the given issue
|
||||||
|
try {
|
||||||
const comments = await this.client.issues.listComments({
|
const comments = await this.client.issues.listComments({
|
||||||
owner: github.context.repo.owner,
|
owner: github.context.repo.owner,
|
||||||
repo: github.context.repo.repo,
|
repo: github.context.repo.repo,
|
||||||
issue_number: issueNumber,
|
issue_number: issueNumber,
|
||||||
since: sinceDate
|
since: sinceDate
|
||||||
});
|
});
|
||||||
|
|
||||||
return comments.data;
|
return comments.data;
|
||||||
|
} catch (error) {
|
||||||
|
core.error(`List issue comments error: ${error.message}`);
|
||||||
|
return Promise.resolve([]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// grab issues from github in baches of 100
|
// grab issues from github in baches of 100
|
||||||
private async getIssues(page: number): Promise<Issue[]> {
|
private async getIssues(page: number): Promise<Issue[]> {
|
||||||
const issueResult: OctoKitIssueList = await this.client.issues.listForRepo({
|
try {
|
||||||
|
const issueResult: OctoKitIssueList = await this.client.issues.listForRepo(
|
||||||
|
{
|
||||||
owner: github.context.repo.owner,
|
owner: github.context.repo.owner,
|
||||||
repo: github.context.repo.repo,
|
repo: github.context.repo.repo,
|
||||||
state: 'open',
|
state: 'open',
|
||||||
labels: this.options.onlyLabels,
|
labels: this.options.onlyLabels,
|
||||||
per_page: 100,
|
per_page: 100,
|
||||||
page
|
page
|
||||||
});
|
}
|
||||||
|
);
|
||||||
return issueResult.data;
|
return issueResult.data;
|
||||||
|
} catch (error) {
|
||||||
|
core.error(`Get issues for repo error: ${error.message}`);
|
||||||
|
return Promise.resolve([]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Mark an issue as stale with a comment and a label
|
// Mark an issue as stale with a comment and a label
|
||||||
|
@ -313,19 +323,27 @@ export class IssueProcessor {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
await this.client.issues.createComment({
|
await this.client.issues.createComment({
|
||||||
owner: github.context.repo.owner,
|
owner: github.context.repo.owner,
|
||||||
repo: github.context.repo.repo,
|
repo: github.context.repo.repo,
|
||||||
issue_number: issue.number,
|
issue_number: issue.number,
|
||||||
body: staleMessage
|
body: staleMessage
|
||||||
});
|
});
|
||||||
|
} catch (error) {
|
||||||
|
core.error(`Error creating a comment: ${error.message}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
await this.client.issues.addLabels({
|
await this.client.issues.addLabels({
|
||||||
owner: github.context.repo.owner,
|
owner: github.context.repo.owner,
|
||||||
repo: github.context.repo.repo,
|
repo: github.context.repo.repo,
|
||||||
issue_number: issue.number,
|
issue_number: issue.number,
|
||||||
labels: [staleLabel]
|
labels: [staleLabel]
|
||||||
});
|
});
|
||||||
|
} catch (error) {
|
||||||
|
core.error(`Error adding a label: ${error.message}`);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Close an issue based on staleness
|
// Close an issue based on staleness
|
||||||
|
@ -342,12 +360,16 @@ export class IssueProcessor {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
await this.client.issues.update({
|
await this.client.issues.update({
|
||||||
owner: github.context.repo.owner,
|
owner: github.context.repo.owner,
|
||||||
repo: github.context.repo.repo,
|
repo: github.context.repo.repo,
|
||||||
issue_number: issue.number,
|
issue_number: issue.number,
|
||||||
state: 'closed'
|
state: 'closed'
|
||||||
});
|
});
|
||||||
|
} catch (error) {
|
||||||
|
core.error(`Error updating an issue: ${error.message}`);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remove a label from an issue
|
// Remove a label from an issue
|
||||||
|
@ -364,12 +386,16 @@ export class IssueProcessor {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
await this.client.issues.removeLabel({
|
await this.client.issues.removeLabel({
|
||||||
owner: github.context.repo.owner,
|
owner: github.context.repo.owner,
|
||||||
repo: github.context.repo.repo,
|
repo: github.context.repo.repo,
|
||||||
issue_number: issue.number,
|
issue_number: issue.number,
|
||||||
name: encodeURIComponent(label) // A label can have a "?" in the name
|
name: encodeURIComponent(label) // A label can have a "?" in the name
|
||||||
});
|
});
|
||||||
|
} catch (error) {
|
||||||
|
core.error(`Error removing a label: ${error.message}`);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// returns the creation date of a given label on an issue (or nothing if no label existed)
|
// returns the creation date of a given label on an issue (or nothing if no label existed)
|
||||||
|
|
Loading…
Reference in New Issue