Skip to content

Test GitHub Actions workflow #49

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

Merged
merged 7 commits into from
Sep 1, 2024
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
29 changes: 20 additions & 9 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,25 @@ on:
jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Use Node.js
uses: actions/setup-node@v2
- uses: actions/checkout@v4

- name: Use Bun
uses: oven-sh/setup-bun@v2
with:
node-version: "20.x"
- run: npm ci
- run: npm run build --if-present
- run: npm test
- run: npm run lint
bun-version: latest

- name: Install dependencies
run: bun install

- name: Format code
run: bun run format

- name: Lint code
run: bun run lint

- name: Type check
run: bunx tsc --noEmit

- name: Build
run: bunx tsc
55 changes: 23 additions & 32 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import globals from "globals";
import path from "node:path";
import { fileURLToPath } from "node:url";
import path from "path";
import { fileURLToPath } from "url";
import js from "@eslint/js";
import tseslint from "@typescript-eslint/eslint-plugin";
import tsParser from "@typescript-eslint/parser";
import { FlatCompat } from "@eslint/eslintrc";

const __filename = fileURLToPath(import.meta.url);
Expand All @@ -15,62 +17,64 @@ const compat = new FlatCompat({
export default [
...compat.extends("eslint:recommended"),
{
ignores: ["dist/**", "node_modules/**"],
languageOptions: {
parser: tsParser,
parserOptions: {
ecmaVersion: 2021,
sourceType: "module",
},
globals: {
...globals.node,
},

ecmaVersion: 2021,
sourceType: "module", // Changed from "commonjs" to "module"
},

files: ["**/*.{ts,mts,cts}"],
plugins: {
"@typescript-eslint": tseslint,
},
rules: {
// ESLint Core Rules
"arrow-spacing": [
"warn",
{
before: true,
after: true,
},
],

"brace-style": [
"error",
"stroustrup",
"1tbs",
{
allowSingleLine: true,
},
],

"comma-dangle": ["error", "always-multiline"],
"comma-spacing": "error",
"comma-style": "error",
curly: ["error", "multi-line", "consistent"],
"dot-location": ["error", "property"],
"handle-callback-err": "off",
indent: ["error", "tab"],
indent: ["error", 2],
"keyword-spacing": "error",

"max-nested-callbacks": [
"error",
{
max: 4,
},
],

"max-statements-per-line": [
"error",
{
max: 2,
},
],

"no-console": "off",
"no-empty-function": "error",
"no-floating-decimal": "error",
"no-inline-comments": "error",
"no-lonely-if": "error",
"no-multi-spaces": "error",

"no-multiple-empty-lines": [
"error",
{
Expand All @@ -79,22 +83,19 @@ export default [
maxBOF: 0,
},
],

"no-shadow": [
"error",
{
allow: ["err", "resolve", "reject"],
},
],

"no-trailing-spaces": ["error"],
"no-var": "error",
"object-curly-spacing": ["error", "always"],
"prefer-const": "error",
quotes: ["error", "double"],
semi: ["error", "always"],
"space-before-blocks": "error",

"space-before-function-paren": [
"error",
{
Expand All @@ -103,30 +104,20 @@ export default [
asyncArrow: "always",
},
],

"space-in-parens": "error",
"space-infix-ops": "error",
"space-unary-ops": "error",
"spaced-comment": "error",
yoda: "error",

"no-unused-vars": [
"error",
{
argsIgnorePattern: "^_",
},
],

"no-use-before-define": [
"error",
{
functions: false,
classes: true,
},
],

// TypeScript-Specific Rules
"@typescript-eslint/explicit-function-return-type": "off",
"@typescript-eslint/no-explicit-any": "warn",

// Optional: Strict and Stylistic Rules
...tseslint.configs.recommended.rules,
...tseslint.configs.strict.rules,
...tseslint.configs.stylistic.rules,
},
},
];
8 changes: 6 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"start": "bun ./dist/index.js",
"watch": "bunx tsc -w",
"format": "bunx prettier --write .",
"lint": "eslint . "
"lint": "eslint . --fix "
},
"keywords": [
"canvas",
Expand All @@ -35,9 +35,13 @@
"devDependencies": {
"@eslint/eslintrc": "^3.1.0",
"@eslint/js": "^9.9.1",
"@types/eslint__js": "^8.42.3",
"@types/html-to-text": "^9.0.1",
"@typescript-eslint/eslint-plugin": "^8.3.0",
"@typescript-eslint/parser": "^8.3.0",
"eslint": "^9.9.1",
"globals": "^15.9.0",
"supabase": "^1.191.3"
"supabase": "^1.191.3",
"typescript-eslint": "^8.3.0"
}
}
2 changes: 1 addition & 1 deletion src/commands/canvas/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ export async function execute(interaction: ChatInputCommandInteraction) {

if (confirmation?.customId === "confirm") {
const schoolResponse = await axios.get(
`https://canvas.instructure.com/api/v1/accounts/search?name=long beach&per_page=5`,
"https://canvas.instructure.com/api/v1/accounts/search?name=long beach&per_page=5",
);
const schools = schoolResponse.data;
const selectedSchool = await chooseSchool(interaction, schools);
Expand Down
10 changes: 6 additions & 4 deletions src/commands/canvas/assignments.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import axios from "axios";
import {
SlashCommandBuilder,
ActionRowBuilder,
Expand All @@ -10,15 +9,18 @@ import {
} from "discord.js";
import { randomColor } from "../../helpers/colors";
import { fetchAssignments, fetchCourses } from "../../helpers/api";
import { Course } from "../../types";

export const data = new SlashCommandBuilder()
.setName("assignments")
.setDescription("Display assignments for your courses");

export async function execute(interaction: ChatInputCommandInteraction) {
const userId = interaction.user.id;
const { message, courses } = await fetchCourses(userId);

const { message, courses } = (await fetchCourses(userId)) as {
message: string;
courses: Course[];
};
if (courses.length === 0) {
await interaction.reply({ content: message, ephemeral: true });
return;
Expand All @@ -28,7 +30,7 @@ export async function execute(interaction: ChatInputCommandInteraction) {
.setCustomId("course_select")
.setPlaceholder("Select a course")
.addOptions(
courses.map((course: { name: string; id: number }) => ({
courses.map((course: Course) => ({
label: course.name,
value: course.id.toString(),
})),
Expand Down
13 changes: 7 additions & 6 deletions src/commands/canvas/missing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
SlashCommandBuilder,
} from "discord.js";
import { randomColor } from "../../helpers/colors";
import { Command, MissingAssignmentResponse } from "../../types";
import { Assignment, Command, MissingAssignmentResponse } from "../../types";
import { getAllAssignments } from "../../helpers/api";

export const data = new SlashCommandBuilder()
Expand All @@ -14,14 +14,15 @@ export const data = new SlashCommandBuilder()

export async function execute(interaction: ChatInputCommandInteraction) {
try {
const data: Command["data"] = {
const commandData: Command["data"] = {
name: "missing",
permissions: [],
aliases: [],
};
const userId: string = interaction.user.id;
const userAssignments: MissingAssignmentResponse =
await getAllAssignments(userId);
const userAssignments: MissingAssignmentResponse = await getAllAssignments(
userId,
);

if (userAssignments.courses.length === 0) {
await interaction.reply({
Expand All @@ -31,7 +32,7 @@ export async function execute(interaction: ChatInputCommandInteraction) {
return;
}

for (const course of userAssignments.courses) {
for (const course of userAssignments.courses as Assignment[]) {
const title: string = course.name;
const url: string = course.html_url;
const points: number = course.points_possible;
Expand Down Expand Up @@ -70,7 +71,7 @@ export async function execute(interaction: ChatInputCommandInteraction) {
await interaction.user.send({ embeds: [embed] });
}
await interaction.reply("Missing assignments received in DM's");
return { data };
return { data: commandData };
} catch (error) {
console.error(
"An error occurred while fetching or replying to missing assignments: ",
Expand Down
10 changes: 7 additions & 3 deletions src/deployCommands.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { REST, Routes } from "discord.js";
import {
REST,
RESTPostAPIApplicationCommandsJSONBody,
Routes,
} from "discord.js";
import { readdir } from "fs/promises";
import { join } from "path/posix";
import { Command } from "./types";
Expand Down Expand Up @@ -37,13 +41,13 @@ async function loadCommands() {
`Started refreshing ${commands.length} application (/) commands.`,
);

const data: any = await rest.put(
const data = (await rest.put(
Routes.applicationGuildCommands(
process.env.CLIENT_ID || "",
process.env.GUILD_ID || "",
),
{ body: commands },
);
)) as RESTPostAPIApplicationCommandsJSONBody[];

console.log(
`Successfully reloaded ${data.length} application (/) commands.`,
Expand Down
3 changes: 2 additions & 1 deletion src/events/assignmentChecker.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { EmbedBuilder, Client } from "discord.js";
import { randomColor } from "../helpers/colors";
import { Assignment } from "../types";

export async function postAssignment(
userId: string,
assignment: any,
assignment: Assignment,
client: Client,
): Promise<void> {
const {
Expand Down
2 changes: 1 addition & 1 deletion src/events/interactionCreate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { BotEvent } from "../types";

const clientReadyEvent: BotEvent = {
name: Events.InteractionCreate,
execute: async function (interaction) {
execute: async function(interaction) {
if (!interaction.isCommand()) return;

const command = interaction.client.commands.get(interaction.commandName);
Expand Down
7 changes: 4 additions & 3 deletions src/events/ready.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Client, Events, ActivityType } from "discord.js";
import { BotEvent } from "../types";
import { AnnouncementPost, Assignment, BotEvent } from "../types";
import { postAnnouncement } from "./announcements";
import { runChecker } from "../helpers/checker";
import { getCanvasToken } from "../helpers/supabase";
Expand All @@ -14,7 +14,7 @@ const clientReadyEvent: BotEvent = {
client?.user?.setActivity("Your Assignments", {
type: ActivityType.Watching,
});
runChecker(
runChecker<AnnouncementPost>(
client,
async (userId) => {
const token = await getCanvasToken(userId);
Expand All @@ -29,7 +29,8 @@ const clientReadyEvent: BotEvent = {
"Error fetching and posting announcements:",
24 * 60 * 60 * 1000,
);
runChecker(

runChecker<Assignment>(
client,
(userId) => fetchAssignmentChecker(userId),
postAssignment,
Expand Down
Loading