Skip to content
This repository has been archived by the owner on Mar 12, 2024. It is now read-only.

Commit

Permalink
Merge pull request #304 from watermelontools/fix/broken-deactivation-…
Browse files Browse the repository at this point in the history
…text

Fix/broken deactivation text
  • Loading branch information
baristaGeek authored Sep 20, 2023
2 parents 0e09202 + 0f4e18f commit 7fbb7af
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 6 deletions.
2 changes: 2 additions & 0 deletions types/watermelon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ export type StandardProcessedDataArray = {
link?: string;
number?: number | string;
image?: string;
created_at?: string;
author?: string;
}[];
export type StandardAPIResponse = {
data?: StandardProcessedDataArray;
Expand Down
1 change: 1 addition & 0 deletions utils/actions/getAllServices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ export default async function getAllServices({
amount: AsanaTasks,
}),
]);

return {
github,
jira,
Expand Down
5 changes: 4 additions & 1 deletion utils/actions/getGitHub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,17 @@ async function getGitHub({
type: "pr",
per_page: amount,
});

return {
fullData: issues.data?.items,
data:
issues.data?.items?.map(({ title, body, html_url: link, number }) => ({
issues.data?.items?.map(({ title, body, html_url: link, number, created_at, user }) => ({
title,
body,
link,
number,
created_at,
author: user?.login
})) || [],
};
}
Expand Down
11 changes: 6 additions & 5 deletions utils/actions/markdownHelpers/helper.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { MarkdownRequest, MarkdownResponse } from "../../../types/watermelon";
import getRelativeDate from "../../getRelativeDate";

type generalMarkdown = MarkdownRequest & {
systemName: string;
Expand All @@ -11,7 +12,7 @@ const generalMarkdownHelper = ({
systemResponseName,
}: generalMarkdown): MarkdownResponse => {
if (!value || value?.data?.length === 0) {
return `\n ${systemResponseName} deactivated by ${userLogin}`;
return `\n No results found in **${systemResponseName}** :( \n`;
}
if (value?.error?.match(/no (\w+) token/)) {
return `\n [Click here to login to ${systemName}](https://app.watermelontools.com)`;
Expand All @@ -21,12 +22,12 @@ const generalMarkdownHelper = ({
markdown = `\n #### ${systemResponseName}`;
markdown += (value?.data || [])
.map(
({ number, title, link, body }) =>
`\n - [#${number} - ${title}](${link}) \n`
({ number, title, link, body, author, created_at }) =>
`\n - [#${number} - ${title}](${link}) ${
author ? ` - By ${author}` : ""
} ${created_at ? `${getRelativeDate(created_at ?? "")}` : ""}\n`
)
.join("");
} else {
markdown += `\n No results found in **${systemResponseName}** :( \n`;
}
return markdown;
};
Expand Down
41 changes: 41 additions & 0 deletions utils/getRelativeDate.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
export default function getRelativeDate(isoDateString: string): string {

const date = new Date(isoDateString);
const now = new Date();

const diffInSeconds = (now.getTime() - date.getTime()) / 1000;

if (diffInSeconds < 60) {
return 'Just now';
}

const diffInMinutes = diffInSeconds / 60;
if (diffInMinutes < 60) {
return `${Math.floor(diffInMinutes)} minutes ago`;
}

const diffInHours = diffInMinutes / 60;
if (diffInHours < 24) {
return `${Math.floor(diffInHours)} hours ago`;
}

const diffInDays = diffInHours / 24;
if (diffInDays < 7) {
return `${Math.floor(diffInDays)} days ago`;
}

const diffInWeeks = diffInDays / 7;
if (diffInWeeks < 5) {
return `${Math.floor(diffInWeeks)} weeks ago`;
}

const diffInMonths = diffInDays / 30;
if (diffInMonths < 12) {
return `${Math.floor(diffInMonths)} months ago`;
}

const diffInYears = diffInMonths / 12;
return `${Math.floor(diffInYears)} years ago`;

}

0 comments on commit 7fbb7af

Please sign in to comment.