Skip to content

Commit

Permalink
Merge pull request #5 from elsoul/log
Browse files Browse the repository at this point in the history
update getReleaseInfoAsJson - improve 4000 limit
  • Loading branch information
POPPIN-FUMI authored Nov 8, 2023
2 parents f1151c1 + de36069 commit 040833d
Show file tree
Hide file tree
Showing 7 changed files with 114 additions and 43 deletions.
30 changes: 0 additions & 30 deletions .github/workflows/deploy.yml

This file was deleted.

41 changes: 41 additions & 0 deletions .github/workflows/discord.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: SkeetFrameworkDiscord

on:
release:
types: [created]

jobs:
build:
runs-on: ubuntu-latest

strategy:
matrix:
node-version: [18.x]

steps:
- uses: actions/checkout@v4
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
- run: npm i -g yarn
- run: yarn install
- name: Disord Notification Epics
run: yarn discord epics ${{ github.repository }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
DISCORD_TOKEN: ${{ secrets.DISCORD_TOKEN }}
DISCORD_CHANNEL_ID: ${{ secrets.DISCORD_CHANNEL_ID }}
DISCORD_CHANNEL_ID_JA: ${{ secrets.DISCORD_CHANNEL_ID_JA }}
- name: Disord Notification LABO
run: yarn discord labo ${{ github.repository }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
DISCORD_TOKEN_LABO: ${{ secrets.DISCORD_TOKEN_LABO }}
LABO_SKEET_CHANNEL_ID: ${{ secrets.LABO_SKEET_CHANNEL_ID }}
- name: Post X package update notification
if: success()
run: |
curl --location ${{ secrets.TW_ENDPOINT }} \
--header 'Content-Type: application/json' \
--data '{"repo": "${{ github.repository }}", "hey": "${{ secrets.TW_ENDPOINT_SECRET }}"}'
27 changes: 27 additions & 0 deletions .github/workflows/runDiscordChangeLog.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import dotenv from 'dotenv'
import { discordChangeLog } from '@skeet-framework/discord-utils'
dotenv.config()

type ProjectType = 'labo' | 'epics'

const run = async (project: ProjectType, repoName: string) => {
if (project === 'labo') {
console.log('labo')
const token = process.env.DISCORD_TOKEN_LABO || ''
const channelId = process.env.LABO_SKEET_CHANNEL_ID || ''
await discordChangeLog(token, repoName, [channelId])
} else if (project === 'epics') {
console.log('epics')
const token = process.env.DISCORD_TOKEN || ''
const channelId = process.env.DISCORD_CHANNEL_ID || ''
const channelIdJA = process.env.DISCORD_CHANNEL_ID_JA || ''
await discordChangeLog(token, repoName, [channelId])
await discordChangeLog(token, repoName, [channelIdJA], 'ja')
} else {
console.log('invalid project name')
}
}

const project = process.argv[2] as ProjectType
const repoArg = process.argv[3] || ''
void run(project, repoArg)
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,10 @@
"discord.js": "14.13.0"
},
"devDependencies": {
"dotenv": "16.3.1",
"@skeet-framework/discord-utils": "^0.2.2",
"@types/jest": "29.5.6",
"@types/node": "20.8.9",
"dotenv": "16.3.1",
"esbuild": "0.19.5",
"eslint": "8.52.0",
"eslint-config-prettier": "9.0.0",
Expand All @@ -55,4 +56,4 @@
"typedoc": "0.25.2",
"typescript": "5.2.2"
}
}
}
17 changes: 16 additions & 1 deletion src/lib/discordChangeLog.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { execSync } from 'child_process'
import { messageChannel } from './messageChannel'

const DISCORD_BODY_LIMIT = 4000

export const discordChangeLog = async (
discordToken: string,
repoName: string,
Expand All @@ -11,10 +13,12 @@ export const discordChangeLog = async (
const log = getReleaseInfoAsJson(repoName)
const repo = repoName.split('/')[1]
const headLine = lang === 'ja' ? 'をリリースしました' : 'Released'
const content = `## ${repo} ${log.tag} ${headLine} 🎉
let content = `## ${repo} ${log.tag} ${headLine} 🎉
${log.whatsChanged}
`
content = trimContent(content)

for (const channelId of channelIds) {
const message = {
content,
Expand All @@ -30,6 +34,17 @@ ${log.whatsChanged}
}
}

function trimContent(content: string): string {
if (content.length > DISCORD_BODY_LIMIT) {
let lines = content.split('\n')
while (lines.join('\n').length > DISCORD_BODY_LIMIT) {
lines.pop()
}
return lines.join('\n')
}
return content
}

export type ReleaseInfo = {
tag: string
draft: boolean
Expand Down
27 changes: 18 additions & 9 deletions src/runDiscordChangeLog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,23 @@ dotenv.config()

const REPO_NAME = 'elsoul/skeet-discord-utils'

const run = async () => {
const token = process.env.DISCORD_TOKEN || ''
const channelId = process.env.DISCORD_CHANNEL_ID || ''
const channelIdJA = process.env.DISCORD_CHANNEL_ID_JA || ''
const laboSkeetChannelId = process.env.LABO_SKEET_CHANNEL_ID || ''
await discordChangeLog(token, REPO_NAME, [channelId])
await discordChangeLog(token, REPO_NAME, [channelIdJA], 'ja')
await discordChangeLog(token, REPO_NAME, [laboSkeetChannelId])
const run = async (project: 'labo' | 'epics') => {
if (project === 'labo') {
console.log('labo')
const token = process.env.DISCORD_TOKEN_LABO || ''
const channelId = process.env.LABO_SKEET_CHANNEL_ID || ''
await discordChangeLog(token, REPO_NAME, [channelId])
} else if (project === 'epics') {
console.log('epics')
const token = process.env.DISCORD_TOKEN || ''
const channelId = process.env.DISCORD_CHANNEL_ID || ''
const channelIdJA = process.env.DISCORD_CHANNEL_ID_JA || ''
await discordChangeLog(token, REPO_NAME, [channelId])
await discordChangeLog(token, REPO_NAME, [channelIdJA], 'ja')
} else {
console.log('invalid project name')
}
}

run()
const project = process.argv[2] as 'labo' | 'epics'
run(project)
10 changes: 9 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -986,6 +986,14 @@
dependencies:
"@sinonjs/commons" "^3.0.0"

"@skeet-framework/discord-utils@^0.2.2":
version "0.2.2"
resolved "https://registry.yarnpkg.com/@skeet-framework/discord-utils/-/discord-utils-0.2.2.tgz#866e46fa093ecb4ae5efcb925cb429afd1d3fbf8"
integrity sha512-kN6xmJ7IdS7kAZY3zhUX9+iyjtvwsNaqmzFe0GBtl8RhsuoWav8tzDMknIvizd93LwJkC+/0qt1IaU5o5C8g+A==
dependencies:
discord-interactions "3.4.0"
discord.js "14.13.0"

"@szmarczak/http-timer@^5.0.1":
version "5.0.1"
resolved "https://registry.npmjs.org/@szmarczak/http-timer/-/http-timer-5.0.1.tgz"
Expand Down Expand Up @@ -1815,7 +1823,7 @@ dot-prop@^6.0.1:
dependencies:
is-obj "^2.0.0"

dotenv@^16.3.1:
[email protected]:
version "16.3.1"
resolved "https://registry.yarnpkg.com/dotenv/-/dotenv-16.3.1.tgz#369034de7d7e5b120972693352a3bf112172cc3e"
integrity sha512-IPzF4w4/Rd94bA9imS68tZBaYyBWSCE47V1RGuMrB94iyTOIEwRmVL2x/4An+6mETpLrKJ5hQkB8W4kFAadeIQ==
Expand Down

0 comments on commit 040833d

Please sign in to comment.