Skip to content

Commit

Permalink
Fix: prune shows with no destinations from the DB (fixes #12) (#13)
Browse files Browse the repository at this point in the history
  • Loading branch information
cbackas committed Aug 4, 2023
1 parent 860a897 commit 0f35d1b
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 22 deletions.
56 changes: 52 additions & 4 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,66 @@
name: Pull Request

on:
pull_request:
branches:
- main

types:
- opened
- edited
- synchronize
jobs:
pr-title:
runs-on: ubuntu-latest
steps:
- name: Check PR Title
uses: deepakputhraya/action-pr-title@master
with:
allowed_prefixes: 'Breaking:,Fix:,Update:,New:,Build:,Upgrade:,Chore:,NoBuild:'
prefix_case_sensitive: true
lint:
runs-on: ubuntu-latest
steps:
# pull the repo
- name: Check out Git repository
uses: actions/checkout@v2
# setup node
- name: Setup Node.js 18
uses: actions/setup-node@v2
with:
node-version: 18
# install dependencies
- name: Install Node.js dependencies
run: npm ci
# run eslint
- name: Run linters
uses: wearerequired/lint-action@master
with:
auto_fix: false
eslint: true
eslint_fix: false
eslint_extensions: "js,ts"
build:
runs-on: ubuntu-latest

steps:
# pull the repo
- name: Check out Git repository
uses: actions/checkout@v2
# setup node
- name: Setup Node.js 18
uses: actions/setup-node@v2
with:
node-version: 18
# install dependencies
- name: Install Node.js dependencies
run: npm ci
# build the app
- name: Build TVBot
run: npm run build
build_docker:
runs-on: ubuntu-latest
steps:
# pull the repo
- name: Checkout
uses: actions/checkout@v3

# just check that it builds, dont push it anywhere cuz whatever
- name: Build and push
uses: docker/build-push-action@v3
Expand Down
37 changes: 21 additions & 16 deletions .github/workflows/push.yml
Original file line number Diff line number Diff line change
@@ -1,41 +1,46 @@
name: SemanticRelease

name: Push
on:
workflow_dispatch:
push:
branches:
- main

tags:
- '*.*.*'
jobs:
build:
release:
name: Semantic Release
runs-on: ubuntu-latest

if: startsWith(github.ref, 'refs/heads/')
steps:
- name: Checkout
uses: actions/checkout@v3
with:
persist-credentials: false

- name: Setup Node.js 18
uses: actions/setup-node@v2
with:
node-version: 18

- name: Install Semantic Release
run: npm install semantic-release @codedependant/semantic-release-docker conventional-changelog-eslint

- name: Semantic Release
env:
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
DOCKER_REGISTRY_USER: ${{ github.actor }}
DOCKER_REGISTRY_PASSWORD: ${{ secrets.GHCR_TOKEN }}
run: npx semantic-release

- name: Slack Notification
uses: rtCamp/action-slack-notify@v2
notify:
name: Discord Notify
runs-on: ubuntu-latest
if: startsWith(github.ref, 'refs/tags/')
steps:
- name: Check out code
uses: actions/checkout@v2
- name: Extract tag name
id: tag
run: echo "TAG_NAME=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV
- name: Discord notification
uses: Ilshidur/action-discord@master
env:
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK_URL }}
SLACK_ICON: https://avatars.githubusercontent.com/u/9919?s=200&v=4
SLACK_USERNAME: GitHub Actions
SLACK_COLOR: ${{ job.status }}
SLACK_FOOTER: ""
DISCORD_WEBHOOK: ${{ secrets.DISCORD_WEBHOOK }}
with:
args: 'Version {{ TAG_NAME }} of {{ EVENT_PAYLOAD.repository.full_name }} has been released!'
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"scripts": {
"build": "node esbuild.mjs",
"dev": "export NODE_ENV=development; node --enable-source-maps esbuild.mjs",
"lint": "eslint 'src/**'",
"db:migrate": "prisma migrate dev",
"db:studio": "prisma studio"
},
Expand Down
2 changes: 2 additions & 0 deletions src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ export class App {
// run initial scheduled activities
setTVDBLoadingActivity(user)
if (process.env.UPDATE_SHOWS !== 'false') await checkForAiringEpisodes()
await pruneUnsubscribedShows()
void scheduleAiringMessages(this)
void setRandomShowActivity(user)

Expand All @@ -70,6 +71,7 @@ export class App {
schedule.scheduleJob('lifecycle:4hours:fetchEpisoded', '0 */4 * * *', async () => {
setTVDBLoadingActivity(user)
await checkForAiringEpisodes()
await pruneUnsubscribedShows()
await scheduleAiringMessages(this)
void setRandomShowActivity(user)
})
Expand Down
3 changes: 3 additions & 0 deletions src/commands/unlink.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { type CommandV2 } from '../interfaces/command'
import { type App } from '../app'
import { ProgressError } from '../interfaces/error'
import { ProgressMessageBuilder } from '../lib/progressMessages'
import { pruneUnsubscribedShows } from 'src/lib/shows'

export const command: CommandV2 = {
slashCommand: {
Expand Down Expand Up @@ -113,6 +114,8 @@ export const command: CommandV2 = {
}
})

await pruneUnsubscribedShows()

return await interaction.editReply({ content: `Unlinked ${s.count} shows from <#${channelId}>`, components: [] })
}
}
4 changes: 2 additions & 2 deletions src/lib/shows.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,13 +234,13 @@ export async function removeAllSubscriptions (id: string, idType: keyof Destinat
* removes all shows that have no destinations
*/
export async function pruneUnsubscribedShows (): Promise<void> {
await client.show.deleteMany({
const result = await client.show.deleteMany({
where: {
destinations: {
isEmpty: true
}
}
})

console.info('Pruned shows with no destinations')
console.info(`Pruned shows ${result.count} with no destinations`)
}

0 comments on commit 0f35d1b

Please sign in to comment.