Skip to content
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
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
- run: npm test
- name: Deploy slash commands
if: github.event_name == 'push'
run: node --loader ts-node/esm src/deploy-commands.js
run: node src/deploy-commands.js
env:
DISCORD_TOKEN: ${{ secrets.DISCORD_TOKEN }}
APPLICATION_ID: ${{ secrets.APPLICATION_ID }}
2 changes: 1 addition & 1 deletion .github/workflows/typecheck.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: TypeScript Check
name: Type Check

on:
push:
Expand Down
32 changes: 9 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,21 +43,15 @@ A Discord bot that allows you to create GitHub issues directly from Discord. Use
GITHUB_REPO=username/repository-name
```

4. **Compile TypeScript**
4. **Register slash commands**

```bash
npx tsc
node src/deploy-commands.js
```

5. **Register slash commands**

5. **Start the bot**
```bash
node dist/deploy-commands.js
```

6. **Start the bot**
```bash
node dist/index.js
node src/index.js
```

## ⚙️ Configuration
Expand Down Expand Up @@ -113,30 +107,22 @@ After successful creation, you'll receive a response like:
```
discord-github-bot/
├── src/
│ ├── deploy-commands.ts # Register slash commands
│ └── index.ts # Main bot logic
│ ├── deploy-commands.js # Register slash commands
│ └── index.js # Main bot logic
├── package.json
├── tsconfig.json
├── jsconfig.json
├── .env # Environment variables (not in Git)
└── README.md
```

## 🔧 Development

### Compile and watch TypeScript
To automatically reload the bot during development, consider using a tool like `nodemon`:

```bash
npx tsc --watch
npx nodemon src/index.js
```

### Start the bot in development mode

```bash
npm run dev
```

(Note: add `"dev": "ts-node src/index.ts"` to the npm scripts)

## 📝 Commands

### `/issue`
Expand Down
3 changes: 2 additions & 1 deletion jsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
"checkJs": true,
"allowJs": true,
"target": "ES2022",
"module": "ESNext"
"module": "NodeNext",
"moduleResolution": "nodenext"
},
"include": ["src", "test"]
}
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
"description": "",
"main": "index.js",
"scripts": {
"test": "NODE_ENV=test node --loader ts-node/esm --test test/*.test.js",
"typecheck": "tsc --noEmit"
"test": "NODE_ENV=test node --test test/*.test.js",
"typecheck": "tsc --noEmit -p jsconfig.json"
},
"keywords": [],
"author": "",
Expand Down
11 changes: 6 additions & 5 deletions test/index.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { test } from 'node:test';
import assert from 'node:assert/strict';
process.env.NODE_ENV = 'test';
import { handleIssueInteraction, handleMessageCreate } from '../src/index.ts';
import { handleIssueInteraction, handleMessageCreate } from '../src/index.js';
import axios from 'axios';

function createInteraction({ title = 'T', body = 'B' } = {}) {
Expand Down Expand Up @@ -38,7 +38,7 @@ test('skips if not chat input command', async () => {
interaction.isChatInputCommand = () => false;
let called = false;
const orig = axios.post;
axios.post = async () => { called = true; };
/** @type {any} */ (axios).post = async () => { called = true; };
await handleIssueInteraction(interaction);
axios.post = orig;
assert.equal(called, false);
Expand All @@ -50,7 +50,7 @@ test('skips if command name differs', async () => {
interaction.commandName = 'other';
let called = false;
const orig = axios.post;
axios.post = async () => { called = true; };
/** @type {any} */ (axios).post = async () => { called = true; };
await handleIssueInteraction(interaction);
axios.post = orig;
assert.equal(called, false);
Expand All @@ -61,9 +61,10 @@ test('creates issue and replies with url', async () => {
const interaction = createInteraction({ title: 'hi', body: 'desc' });
process.env.GITHUB_REPO = 'a/b';
process.env.GITHUB_TOKEN = 't';
/** @type {{url?: string, payload?: any}} */
let received;
const orig = axios.post;
axios.post = async (url, payload) => {
/** @type {any} */ (axios).post = async (url, payload) => {
received = { url, payload };
return { data: { html_url: 'https://example.com/1' } };
};
Expand All @@ -78,7 +79,7 @@ test('creates issue and replies with url', async () => {
test('handles axios error', async () => {
const interaction = createInteraction();
const orig = axios.post;
axios.post = async () => { throw new Error('fail'); };
/** @type {any} */ (axios).post = async () => { throw new Error('fail'); };
await handleIssueInteraction(interaction);
axios.post = orig;
assert.equal(interaction._replies.message, '❌ Fehler beim Erstellen des Issues. Wende dich direkt an Jonas.');
Expand Down