Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: quality of life #39

Merged
merged 9 commits into from
Jun 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 0 additions & 12 deletions .github/.readmeconfig.json

This file was deleted.

13 changes: 13 additions & 0 deletions .github/readme.ijsblokje.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[project]
icon = "https://cdn.discordapp.com/avatars/1018461517408120842/fb5707cc6be7d4c0dc365fd1f775ecf1.png?size=512"
icon_width = "100px"
version = "1.0.3"

[variables]
information = "A Discord bot which makes your GitHub Discord embeds prettier ✨"
installation = [
"Want to add the bot to your server? [Click here](https://discord.com/api/oauth2/authorize?client_id=1018461517408120842&permissions=536870928&scope=bot%20applications.commands)",
"You can also install your own instance, check the .env.example for all the required environment variables.",
"### Installation Via Docker",
"```bash\ndocker run --name=gitcord -v .env:/gitcord/.env -p 3000:3000 ghcr.io/ijskoud/gitcord\n```"
]
8 changes: 4 additions & 4 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ jobs:

steps:
- name: Checkout repository
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3
uses: actions/checkout@v3

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@f6e388ebf0efc915c6c5b165b019ee61a6746a38 # v2
uses: github/codeql-action/init@v2
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
Expand All @@ -54,7 +54,7 @@ jobs:
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
uses: github/codeql-action/autobuild@f6e388ebf0efc915c6c5b165b019ee61a6746a38 # v2
uses: github/codeql-action/autobuild@v2

# ℹ️ Command-line programs to run using the OS shell.
# 📚 https://git.io/JvXDl
Expand All @@ -68,4 +68,4 @@ jobs:
# make release

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@f6e388ebf0efc915c6c5b165b019ee61a6746a38 # v2
uses: github/codeql-action/analyze@v2
52 changes: 43 additions & 9 deletions .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,40 +7,74 @@ on:
pull_request:

jobs:
Building:
Dependencies:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3
uses: actions/checkout@v3

- name: Install Node v18
uses: actions/setup-node@64ed1c7eab4cce3362f8c340dee64e5eaeef8f7c # v3
uses: actions/setup-node@v3
with:
node-version: 18
cache: yarn

- name: Install Dependencies
run: yarn install
run: yarn install --immutable

- name: Generate Prisma types
run: yarn prisma generate
Building:
runs-on: ubuntu-latest
needs: Dependencies
steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Install Node v18
uses: actions/setup-node@v3
with:
node-version: 18
cache: yarn

- name: Install Dependencies
run: yarn install --immutable

- name: Run Compiler
run: yarn run build

Linting:
runs-on: ubuntu-latest
needs: Dependencies
steps:
- name: Checkout repository
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3
uses: actions/checkout@v3

- name: Install Node v18
uses: actions/setup-node@64ed1c7eab4cce3362f8c340dee64e5eaeef8f7c # v3
uses: actions/setup-node@v3
with:
node-version: 18
cache: yarn

- name: Install Dependencies
run: yarn install
run: yarn install --immutable

- name: Run Eslint
run: yarn run lint

# Testing:
# runs-on: ubuntu-latest
# needs: Dependencies
# steps:
# - name: Checkout repository
# uses: actions/checkout@v3

# - name: Install Node v18
# uses: actions/setup-node@v3
# with:
# node-version: 18
# cache: yarn

# - name: Install Dependencies
# run: yarn install --immutable

# - name: Run Vitest
# run: yarn run test
11 changes: 5 additions & 6 deletions .github/workflows/docker-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,32 +6,31 @@ on:
- cron: "0 1 * * *"
release:
types: [prereleased]
branches: [main]

jobs:
ghcr:
name: Push Image to GitHub Packages
runs-on: ubuntu-latest
steps:
- name: Check out the repo
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3
uses: actions/checkout@v3

- name: Setup QEMU
uses: docker/setup-qemu-action@2b82ce82d56a2a04d2637cd93a637ae1b359c0a7 # v2
uses: docker/setup-qemu-action@v2

- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@ecf95283f03858871ff00b787d79c419715afc34 # v2
uses: docker/setup-buildx-action@v2

- name: Login to Github Packages
uses: docker/login-action@465a07811f14bebb1938fbed4728c6a1ff8901fc # v2
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build Docker Image
uses: docker/build-push-action@2eb1c1961a95fc15694676618e422e8ba1d63825 # v4
uses: docker/build-push-action@v4
with:
push: true
tags: ghcr.io/ijskoud/gitcord:dev
13 changes: 6 additions & 7 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,34 +4,33 @@ on:
workflow_dispatch:
release:
types: [published]
branches: [main]

jobs:
ghcr:
name: Push Image to GitHub Packages
runs-on: ubuntu-latest
steps:
- name: Check out the repo
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3
uses: actions/checkout@v3

- name: Setup QEMU
uses: docker/setup-qemu-action@2b82ce82d56a2a04d2637cd93a637ae1b359c0a7 # v2
uses: docker/setup-qemu-action@v2

- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@ecf95283f03858871ff00b787d79c419715afc34 # v2
uses: docker/setup-buildx-action@v2

- name: Login to Github Packages
uses: docker/login-action@465a07811f14bebb1938fbed4728c6a1ff8901fc # v2
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build Docker Image
uses: docker/build-push-action@2eb1c1961a95fc15694676618e422e8ba1d63825 # v4
uses: docker/build-push-action@v4
with:
push: true
tags: |
ghcr.io/ijskoud/gitcord:latest
ghcr.io/ijskoud/gitcord:v1
ghcr.io/ijskoud/gitcord:latest
28 changes: 28 additions & 0 deletions .yarn/plugins/@yarnpkg/plugin-workspace-tools.cjs

Large diffs are not rendered by default.

7 changes: 6 additions & 1 deletion .yarnrc.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
yarnPath: .yarn/releases/yarn-3.6.0.cjs
nodeLinker: node-modules

plugins:
- path: .yarn/plugins/@yarnpkg/plugin-workspace-tools.cjs
spec: "@yarnpkg/plugin-workspace-tools"

yarnPath: .yarn/releases/yarn-3.6.0.cjs
45 changes: 34 additions & 11 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,19 +1,42 @@
FROM node:20-alpine
FROM node:18-alpine AS base


# --- Installer ---
FROM base AS installer
WORKDIR /gitcord

# Copy Existing Files
COPY package.json yarn.lock .yarnrc.yml tsconfig.json ./
COPY .yarn ./.yarn
COPY src ./src
COPY prisma ./prisma
RUN apk add --no-cache libc6-compat
RUN apk update

# Install dependencies & build the application
RUN yarn install --immutable
# Install dependencies
COPY . .
RUN yarn --immutable
RUN yarn prisma generate
RUN yarn build

# Register Environment Variables
# Remove dev-dependencies from node_modules
RUN yarn pinst --disable
RUN yarn workspaces focus --production --all


# --- Runner ---
FROM base AS runner
WORKDIR /gitcord

ENV NODE_ENV="production"

# Run NodeJS script
CMD ["yarn", "run", "start:docker"]
# Set the user
RUN addgroup --system --gid 1001 app
RUN adduser --system --uid 1001 app
USER app

# Copy over the application
COPY --from=installer --chown=app:app /gitcord/dist ./dist
COPY --from=installer --chown=app:app /gitcord/prisma ./prisma

# Copy over the packages
COPY --from=installer --chown=app:app /gitcord/yarn.lock yarn.lock
COPY --from=installer --chown=app:app /gitcord/package.json package.json
COPY --from=installer --chown=app:app /gitcord/node_modules node_modules

CMD yarn start
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ You can also install your own instance, check the .env.example for all the requi
docker run --name=gitcord -v .env:/gitcord/.env -p 3000:3000 ghcr.io/ijskoud/gitcord
```



## Author

👤 **ijsKoud**
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
"is-ci": "^3.0.1",
"lint-staged": "^13.2.2",
"nodemon": "^2.0.22",
"pinst": "^3.0.0",
"prettier": "^2.8.8",
"prisma": "^4.16.1",
"typescript": "5.1.3"
Expand Down
3 changes: 2 additions & 1 deletion src/github/embeds/commits/CommitComment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type { CommitCommentEvent } from "@octokit/webhooks-types";
import type { EmbedBuilder } from "discord.js";
import { ApplyOptions } from "#github/lib/embed/decorators.js";
import { EmbedLimits } from "@sapphire/discord-utilities";
import markdownParser from "#github/lib/embed/MarkdownParser.js";

@ApplyOptions<GitHubEmbedOptions>({ name: "commit_comment" })
export default class extends GitHubEmbed {
Expand All @@ -12,7 +13,7 @@ export default class extends GitHubEmbed {

embed
.setURL(event.comment.html_url)
.setDescription(event.comment.body.slice(0, EmbedLimits.MaximumDescriptionLength))
.setDescription(markdownParser(event.comment.body).slice(0, EmbedLimits.MaximumDescriptionLength))
.addFields([{ name: "On commit", value: `[\`${commit}\`](${commitUrl})` }]);

return embed;
Expand Down
3 changes: 2 additions & 1 deletion src/github/embeds/issues/IssueComment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type { IssueCommentEvent } from "@octokit/webhooks-types";
import type { EmbedBuilder } from "discord.js";
import { ApplyOptions } from "#github/lib/embed/decorators.js";
import { EmbedLimits } from "@sapphire/discord-utilities";
import MarkdownParser from "#github/lib/embed/MarkdownParser.js";

@ApplyOptions<GitHubEmbedOptions>({ name: "issue_comment" })
export default class extends GitHubEmbed {
Expand All @@ -15,7 +16,7 @@ export default class extends GitHubEmbed {
embed
.setTitle(`${event.repository.full_name} — ${isPr ? "Pull Request" : "Issue"} Comment Created`)
.setURL(event.comment.html_url)
.setDescription(event.comment.body.slice(0, EmbedLimits.MaximumDescriptionLength))
.setDescription(MarkdownParser(event.comment.body).slice(0, EmbedLimits.MaximumDescriptionLength))
.addFields([{ name: `On ${isPr ? "Pull Request" : "Issue"}`, value: `[${issue}](${event.issue.html_url})` }]);

return embed;
Expand Down
13 changes: 8 additions & 5 deletions src/github/embeds/issues/IssueEmbed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { ApplyOptions } from "#github/lib/embed/decorators.js";
import { EMBED_COLORS } from "#github/lib/types.js";
import _ from "lodash";
import { EmbedLimits } from "@sapphire/discord-utilities";
import MarkdownParser from "#github/lib/embed/MarkdownParser.js";

@ApplyOptions<GitHubEmbedOptions>({ name: "issues" })
export default class extends GitHubEmbed {
Expand Down Expand Up @@ -58,13 +59,15 @@ export default class extends GitHubEmbed {
private opened(event: IssuesOpenedEvent | IssuesReopenedEvent, embed: EmbedBuilder) {
embed
.setTitle(`${embed.data.title} #${event.issue.number}`)
.setDescription([`Title: **${event.issue.title}**\n`, `${event.issue.body}`].join("\n").slice(0, EmbedLimits.MaximumDescriptionLength));
.setDescription(
[`# ${event.issue.title}\n`, MarkdownParser(event.issue.body ?? "")].join("\n").slice(0, EmbedLimits.MaximumDescriptionLength)
);
}

private closed(event: IssuesClosedEvent, embed: EmbedBuilder) {
embed
.setTitle(`${embed.data.title} #${event.issue.number}`)
.setDescription([`Title: **${event.issue.title}**`, `State: ${event.issue.active_lock_reason ?? "closed"}`].join("\n"));
.setDescription([`### ${event.issue.title}`, `State: ${event.issue.active_lock_reason ?? "closed"}`].join("\n"));
}

private stageChange(event: IssuesEvent, embed: EmbedBuilder) {
Expand All @@ -79,15 +82,15 @@ export default class extends GitHubEmbed {
embed
.setColor(EMBED_COLORS.UPDATE)
.setTitle(`${event.repository.full_name} — Issue #${event.issue.number}: Stage Update`)
.setDescription(`**${event.issue.title}**\nState: **${state}**`);
.setDescription(`### ${event.issue.title}\nState: **${state}**`);
}

private assignUpdate(event: IssuesAssignedEvent | IssuesUnassignedEvent, embed: EmbedBuilder) {
embed
.setTitle(`${event.repository.full_name} — Issue #${event.issue.number}: User ${_.capitalize(event.action)}`)
.setDescription(
[
`**${event.issue.title}**`,
`### ${event.issue.title}`,
`Action: \`${_.capitalize(event.action)}\``,
`Assignee: [${event.assignee?.login}](${event.assignee?.html_url})`
].join("\n")
Expand All @@ -99,7 +102,7 @@ export default class extends GitHubEmbed {
.setTitle(`${event.repository.full_name} — Issue #${event.issue.number}`)
.setDescription(
[
`**${event.issue.title}**`,
`### ${event.issue.title}`,
`Action: \`${_.capitalize(event.action)}\``,
`Milestone: [${event.milestone.title}](${event.milestone.html_url})`
].join("\n")
Expand Down
Loading