Compare commits

...

10 Commits

5 changed files with 2381 additions and 4677 deletions

View File

@@ -1,14 +1,14 @@
FROM node:lts-alpine AS build
WORKDIR /app
COPY package*.json ./
RUN npm ci
RUN npm i
COPY . .
RUN npm run build
FROM node:lts-alpine AS runtime
USER node
WORKDIR /app
ENV NODE_ENV production
USER node
COPY --chown=node:node package*.json ./
RUN npm ci --omit=dev
COPY --from=build --chown=node:node /app/dist ./dist

View File

@@ -2,6 +2,8 @@
GitHub bot that automatically verifies pull requests with new playlist entries for [spotify-playlist-archive](https://github.com/mackorone/spotify-playlist-archive) repo.
[Example of a validated pull request](https://github.com/mackorone/spotify-playlist-archive/pull/408)
## Development
### Prerequisites

View File

@@ -8,8 +8,6 @@ import { getPlaylistIdFromUrl } from './getPlaylistIdFromUrl';
type ReviewEvent = 'REQUEST_CHANGES' | 'COMMENT' | 'APPROVE';
const appFn: ApplicationFunction = (app: Probot, { getRouter }) => {
getRouter!('/ping').get('/pong', (_, res) => res.sendStatus(200));
app.on(
['pull_request.opened', 'pull_request.synchronize'],
async ({ payload, octokit, log }) => {
@@ -132,7 +130,11 @@ const appFn: ApplicationFunction = (app: Probot, { getRouter }) => {
if (found) {
const html = await spotifyResponse.text();
const { author: authorUrl, description } = await getMetaData({
const {
// author: authorUrl,
description,
title
} = await getMetaData({
html,
customRules: {
author: {
@@ -146,32 +148,39 @@ const appFn: ApplicationFunction = (app: Probot, { getRouter }) => {
}
});
let authorName = (authorUrl as string).endsWith('/user/spotify')
? 'Spotify'
: '';
// let authorName = (authorUrl as string).endsWith('/user/spotify')
// ? 'Spotify'
// : '';
if (authorName === '') {
const playlistAuthorResponse = await fetch(authorUrl as string);
// if (authorName === '') {
// const playlistAuthorResponse = await fetch(authorUrl as string);
if (!playlistAuthorResponse.ok)
throw new Error(
`Received ${playlistAuthorResponse.status} status code from ${authorUrl}`
);
// if (!playlistAuthorResponse.ok)
// throw new Error(
// `Received ${playlistAuthorResponse.status} status code from ${authorUrl}`
// );
const authorPageHtml = await playlistAuthorResponse.text();
const { title: authorPageTitle } = await getMetaData({
html: authorPageHtml
});
// const authorPageHtml = await playlistAuthorResponse.text();
// const { title: authorPageTitle } = await getMetaData({
// html: authorPageHtml
// });
authorName = authorPageTitle as string;
}
// authorName = authorPageTitle as string;
// }
const playlistMeta = (description || '')
.split(' · ')
.filter((text) => text !== 'Playlist')
.concat(authorName as string);
// const playlistMeta = (description || '')
// .split(' · ')
// .filter((text) => text !== 'Playlist')
// .concat(authorName as string);
details = playlistMeta.join(' · ');
// details = playlistMeta.join(' · ');
details = (
title +
' · ' +
description!.replace('Playlist · ', '')
)
.replace(/\s+/g, ' ')
.trim();
}
numProcessedEntries++;
@@ -236,7 +245,7 @@ const appFn: ApplicationFunction = (app: Probot, { getRouter }) => {
if (urlFilenameEntries.length > 0) {
successText = '';
const forkPageUrl = payload.pull_request.head.repo.html_url;
const forkPageUrl = payload.pull_request.head.repo?.html_url;
const httpsDirUrl = `${forkPageUrl}/tree/main/playlists/registry/https:`;
const baseCreateUrl = `${forkPageUrl}/new/main/playlists/registry/FOO`;

6995
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -17,16 +17,16 @@
},
"homepage": "https://github.com/maciejpedzich/mackorone-playlist-pr-bot#readme",
"dependencies": {
"metadata-scraper": "^0.2.60",
"probot": "^12.3.3",
"metadata-scraper": "^0.2.61",
"probot": "^13.4.5",
"promise-throttle-all": "^1.1.1"
},
"engines": {
"node": ">=18"
},
"devDependencies": {
"@types/node": "^20.14.11",
"@types/node": "^22.15.29",
"ts-node-dev": "^2.0.0",
"typescript": "^4.8.3"
"typescript": "^5.8.3"
}
}