Skip to content

Commit

Permalink
fix(github): published broken links (#269)
Browse files Browse the repository at this point in the history
  • Loading branch information
leocabeza authored Aug 11, 2020
1 parent 36d2312 commit 9ccc2f0
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 35 deletions.
8 changes: 5 additions & 3 deletions api/_utils/github/feed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@ interface RepoConfig {

const handleGithubFeed = async (
repoConfig: RepoConfig,
tags: string[],
urls: string[],
): Promise<void> => {
if (MAIN_GROUP_ID) {
const promises: Promise<void>[] = [];
const repoMainUrl = repoConfig.feed.replace('releases.atom', '');

tags.forEach(tag => {
urls.forEach(url => {
const tag = url.match(/[\w.-]+$/gi)![0];

const promise = sendMessage({
chatId: Number(MAIN_GROUP_ID),
text: messages.githubRelease
Expand All @@ -27,7 +29,7 @@ const handleGithubFeed = async (
'#{url}',
repoConfig.hasChangelog
? `${repoMainUrl}blob/master/CHANGELOG.md`
: `https://github.com/${repoConfig.name}/releases/tag/${tag}`,
: url,
),
});

Expand Down
8 changes: 4 additions & 4 deletions api/superfeedr/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Sentry.init({ dsn: SENTRY_DSN });

// Taken from https://documentation.superfeedr.com/schema.html
interface Item {
title: string;
permalinkUrl: string;
}

/**
Expand Down Expand Up @@ -56,12 +56,12 @@ export default async (request: NowRequest, response: NowResponse) => {
const repoConfig = config.githubFeeds.find(
({ feed }) => feed === updatedFeed,
);
const tags = request.body.items.map(
(item: Item) => item.title,
const urls = request.body.items.map(
(item: Item) => item.permalinkUrl,
);

if (repoConfig) {
await handleGithubFeed(repoConfig, tags);
await handleGithubFeed(repoConfig, urls);
}
} else {
// If it isn't a github feed, it's a blog feed
Expand Down
64 changes: 38 additions & 26 deletions package-lock.json

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

6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,11 @@
"twitter-autohook": "^1.7.2"
},
"devDependencies": {
"@semantic-release/changelog": "^5.0.1",
"@types/node": "^14.0.27",
"@types/node-fetch": "^2.5.7",
"@typescript-eslint/eslint-plugin": "^3.8.0",
"@typescript-eslint/parser": "^3.8.0",
"@typescript-eslint/eslint-plugin": "^3.9.0",
"@typescript-eslint/parser": "^3.9.0",
"eslint": "^7.6.0",
"eslint-config-prettier": "^6.11.0",
"eslint-plugin-prettier": "^3.1.4",
Expand Down Expand Up @@ -77,6 +78,7 @@
}
],
"@semantic-release/release-notes-generator",
"@semantic-release/changelog",
"@semantic-release/github"
]
}
Expand Down

0 comments on commit 9ccc2f0

Please sign in to comment.