Skip to content

Commit

Permalink
initial
Browse files Browse the repository at this point in the history
  • Loading branch information
H1D committed Jul 9, 2024
0 parents commit c60ada9
Show file tree
Hide file tree
Showing 18 changed files with 5,312 additions and 0 deletions.
7 changes: 7 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[*]
indent_style = space
indent_size = 2
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
7 changes: 7 additions & 0 deletions .env.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
TELEGRAM_BOT_TOKEN=your-telegram-bot-token
GITHUB_TOKEN=your-github-token
GH_REPO=user/repo

# Optional
ISSUE_TAGS=from:telegram,bug
DEBUG=telegram-to-github-bot:*
54 changes: 54 additions & 0 deletions .github/workflows/push-docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: Build and Publish Docker Image

on:
workflow_run:
workflows: ["Test"]
types:
- completed

jobs:
publish:
if: ${{ github.event.workflow_run.conclusion == 'success' }}
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
repository: ${{ github.event.workflow_run.head_repository.full_name }}
ref: ${{ github.event.workflow_run.head_branch }}

- name: Set up QEMU
uses: docker/setup-qemu-action@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Log in to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract version and commit hash
id: version
run: |
echo "VERSION=$(jq -r .version < package.json)-${{ github.sha }}" >> $GITHUB_ENV
echo "SHORT_SHA=$(echo ${{ github.sha }} | head -c 8)" >> $GITHUB_ENV
- name: Lowercase GitHub repository name
run: |
echo "IMAGE_NAME=$(echo ${{ github.repository }} | tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .
file: Containerfile
platforms: linux/amd64,linux/arm64
push: true
tags: |
ghcr.io/${{ env.IMAGE_NAME }}:latest,
ghcr.io/${{ env.IMAGE_NAME }}:${{ env.VERSION }},
ghcr.io/${{ env.IMAGE_NAME }}:${{ env.VERSION }}-${{ env.SHORT_SHA }}
33 changes: 33 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Test

on:
push:
branches:
- main
- "**/feature/**"
pull_request:
branches:
- main

jobs:
test:
runs-on: ubuntu-latest

strategy:
matrix:
node-version: [20]

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

- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}

- name: Install dependencies
run: npm install

- name: Run tests
run: npm test
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.secrets
.env
node_modules
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
20
25 changes: 25 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Launch",
"skipFiles": ["<node_internals>/**"],
"runtimeArgs": ["--loader", "ts-node/esm"],
"program": "${workspaceFolder}/src/index.ts",
"envFile": "${workspaceFolder}/.env",
"outFiles": ["${workspaceFolder}/dist/**/*.js"]
},
{
"type": "node",
"request": "launch",
"name": "Debug",
"skipFiles": ["<node_internals>/**"],
"runtimeArgs": ["--loader", "ts-node/esm", "--inspect"],
"program": "${workspaceFolder}/src/index.ts",
"envFile": "${workspaceFolder}/.env",
"outFiles": ["${workspaceFolder}/dist/**/*.js"]
}
]
}
16 changes: 16 additions & 0 deletions Containerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
FROM node:lts-alpine

WORKDIR /app

# Copy package files
COPY package*.json ./

# Install all dependencies
RUN npm install

# Copy source files
COPY src ./src
COPY tsconfig.json ./
COPY .env ./

CMD ["npm", "start"]
43 changes: 43 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Telegram to GitHub Bot

---

## What It Is

Telegram bot to create GitHub issues simply by `@mentioning`. Useful for "TDD" (Telegarm Driven Development) team styles. Comparing to [annndruha/issue-github-telegram-bot](https://github.com/annndruha/issue-github-telegram-bot) needs less github permissions and is more lightweight overall.

## How to use

You'll need to create a Telegram bot and a GitHub token.

1. **Create a Telegram Bot**

- Go to ['@BotFather'](https//t.me/BotFather).
- Create a new bot via `/newbot` command.
- Follow the instructions to set up your bot. **BotFather** will give you a **token** when your bot is created.

2. **Generate a GitHub Personal Access Token**

- Go to your [GitHub settings](https://github.com/settings/tokens?type=beta).
- Click on **Generate new token**.
- Choose `Repository access` -> `Only select repositories`. Select **repo(s)** where you want to create issues.
- Add `Repository permissions` -> `Issues` -> `Read & Write`.
- Click on **Generate token** and save the token.

3. **Prepare Environment Variables**

Keep in mind – one bot instance – one repo. So if you want to create issues in multiple repos, you'll need to create multiple bots.

- Prepare env variables:
```sh
TELEGRAM_BOT_TOKEN=your-telegram-bot-token
GITHUB_TOKEN=your-github-token
GH_REPO=user/repo
```

4. **Run the bot**. Here is a local example:
```sh
docker run --env-file .env <image-repo>/telegram-to-github-bot:latest
```
5. **Add the bot to your group(s)**
6. **Start creating issues!**
13 changes: 13 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
export default {
preset: "ts-jest/presets/js-with-ts-esm",
testEnvironment: "node",
transform: {
"^.+\\.ts$": ["ts-jest", { useESM: true }],

"^.+\\.js$": "babel-jest",
},
testRegex: "(/__tests__/.*|(\\.|/)(test|spec))\\.ts?$",
moduleFileExtensions: ["ts", "js", "json", "node"],
extensionsToTreatAsEsm: [".ts"],
testPathIgnorePatterns: ["/node_modules/", "fixtures\\.ts$"],
};
Loading

0 comments on commit c60ada9

Please sign in to comment.