Skip to content

Commit

Permalink
fix: manually determine URLs for each notification type
Browse files Browse the repository at this point in the history
  • Loading branch information
Ebonsignori committed Aug 1, 2022
1 parent 1c0a146 commit c3f6d82
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 4 deletions.
23 changes: 21 additions & 2 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -221,17 +221,36 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
Object.defineProperty(exports, "__esModule", ({ value: true }));
const BASE = `https://github.com`;
function determineUrl(core, octokit, inputs, notification) {
var _a;
var _a, _b;
return __awaiter(this, void 0, void 0, function* () {
const urlResource = (_a = /[^/]*$/.exec(notification.subject.url)) === null || _a === void 0 ? void 0 : _a[0];
if (notification.subject.type === "Discussion") {
return `${BASE}/${notification.repository.full_name}/discussions?${encodeURI(notification.subject.title)}`;
}
if (notification.subject.type === "Release") {
return `${BASE}/${notification.repository.full_name}/releases/tag/${notification.subject.title}`;
}
if (notification.subject.type === "Release") {
return `${BASE}/${notification.repository.full_name}/releases/tag/${notification.subject.title}`;
}
if (notification.subject.type === "PullRequest" && urlResource) {
return `${BASE}/${notification.repository.full_name}/pull/${urlResource}`;
}
if (notification.subject.type === "Issue" && urlResource) {
return `${BASE}/${notification.repository.full_name}/issues/${urlResource}`;
}
if (notification.subject.type === "CheckSuite") {
return `${BASE}/${notification.repository.full_name}/actions`;
}
if (notification.subject.type === "CheckSuite") {
return `${BASE}/${notification.repository.full_name}/actions`;
}
// If no hard-coded method for fetching URL is defined, try .request to get the `html_url`
let notificationHtmlURL;
if (notification.subject.url) {
try {
const notificationSubject = yield octokit.request(notification.subject.url);
notificationHtmlURL = (_a = notificationSubject === null || notificationSubject === void 0 ? void 0 : notificationSubject.data) === null || _a === void 0 ? void 0 : _a.html_url;
notificationHtmlURL = (_b = notificationSubject === null || notificationSubject === void 0 ? void 0 : notificationSubject.data) === null || _b === void 0 ? void 0 : _b.html_url;
// If there still isn't an html_url, it lives on another key
if (inputs.debugLogging && !notificationHtmlURL) {
core.warning(`Unable to find URL from linked api url for notification\nid :${notification.id}\nsubject:${JSON.stringify(notification.subject, null, 2)}\subject.url request: ${JSON.stringify(notificationSubject.data, null, 2)}`);
Expand Down
2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -415,4 +415,4 @@ test("filters on filter-exclude-repositories", async (t) => {

// TODO: Test rollup-notifications
// TODO: Test timezone and date-format
// TODO: Test html URLs
// TODO: Test determined html URLs
31 changes: 31 additions & 0 deletions src/lib/determine-url.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,42 @@ export default async function determineUrl(
inputs,
notification: Endpoints["GET /notifications"]["response"]["data"][0]
) {
const urlResource = /[^/]*$/.exec(notification.subject.url)?.[0];
if (notification.subject.type === "Discussion") {
return `${BASE}/${
notification.repository.full_name
}/discussions?${encodeURI(notification.subject.title)}`;
}
if (notification.subject.type === "Release") {
return `${BASE}/${
notification.repository.full_name
}/releases/tag/${notification.subject.title}`;
}
if (notification.subject.type === "Release") {
return `${BASE}/${
notification.repository.full_name
}/releases/tag/${notification.subject.title}`;
}
if (notification.subject.type === "PullRequest" && urlResource) {
return `${BASE}/${
notification.repository.full_name
}/pull/${urlResource}`
}
if (notification.subject.type === "Issue" && urlResource) {
return `${BASE}/${
notification.repository.full_name
}/issues/${urlResource}`
}
if (notification.subject.type === "CheckSuite") {
return `${BASE}/${
notification.repository.full_name
}/actions`
}
if (notification.subject.type === "CheckSuite") {
return `${BASE}/${
notification.repository.full_name
}/actions`
}

// If no hard-coded method for fetching URL is defined, try .request to get the `html_url`
let notificationHtmlURL;
Expand Down

0 comments on commit c3f6d82

Please sign in to comment.