Skip to content

Commit

Permalink
fix: 🔖 v2 fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
MPThLee committed Nov 8, 2024
1 parent f1b016d commit 813401f
Show file tree
Hide file tree
Showing 9 changed files with 35,136 additions and 16,858 deletions.
10 changes: 10 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"extends": [
"plugin:github/recommended",
"plugin:@typescript-eslint/recommended"
],

"rules": {
"i18n-text/no-en": "off"
}
}
51,667 changes: 35,032 additions & 16,635 deletions dist/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

271 changes: 71 additions & 200 deletions dist/licenses.txt

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/sourcemap-register.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
"main": "lib/main.js",
"scripts": {
"build": "tsc",
"format": "prettier --write '**/*.ts'",
"format": "prettier --write src/**/*.ts",
"format-check": "prettier --check '**/*.ts'",
"lint": "eslint src/**/*.ts",
"package": "ncc build --source-map --license licenses.txt",
"all": "npm run build && npm run format && npm run lint && npm run package"
"all": "npm run format && npm run lint && npm run build && npm run package"
},
"repository": {
"type": "git",
Expand Down
12 changes: 6 additions & 6 deletions src/config.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import * as core from '@actions/core'
import {getInput, isDebug} from '@actions/core'
import {MwnOptions} from 'mwn'

export default function loadBotConfig(): MwnOptions {
const apiUrl: string = core.getInput('mediawiki_api_url')
const useragent = core.getInput('useragent')
const apiUrl: string = getInput('mediawiki_api_url')
const useragent = getInput('useragent')

const username = core.getInput('username')
const password = core.getInput('password')
const username = getInput('username')
const password = getInput('password')

return {
apiUrl,
userAgent: emptyToUndefined(useragent),
silent: !core.isDebug(),
silent: !isDebug(),

username: emptyToUndefined(username),
password: emptyToUndefined(password)
Expand Down
22 changes: 11 additions & 11 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -1,36 +1,36 @@
import {promises as fs} from 'fs'
import * as core from '@actions/core'
import * as github from '@actions/github'
import {debug, getInput, info, setFailed} from '@actions/core'
import {context} from '@actions/github'
import {Mwn} from 'mwn'
import loadBotConfig from './config'
import {stringFormatUnicorn} from './utils'

async function run(): Promise<void> {
try {
core.debug('Logging in...')
debug('Logging in...')
const bot = await Mwn.init(loadBotConfig())
core.debug('Logged in.')
debug('Logged in.')

const title = core.getInput('pagename')
const content = await fs.readFile(core.getInput('filepath'), {
const title = getInput('pagename')
const content = await fs.readFile(getInput('filepath'), {
encoding: 'utf-8'
})

if (title === '' || content === '') {
throw new Error('title or content is not provided.')
}

const summary = stringFormatUnicorn(core.getInput('summary'), {
const summary = stringFormatUnicorn(getInput('summary'), {
title,
commit: github.context.sha
commit: context.sha
})

core.debug('Save page...')
debug('Save page...')
const resp = await bot.save(title, content, summary)

core.info(`Updated ${resp.title} as ${resp.result}. (${resp.newtimestamp})`)
info(`Updated ${resp.title} as ${resp.result}. (${resp.newtimestamp})`)
} catch (error) {
if (error instanceof Error) core.setFailed(error.message)
if (error instanceof Error) setFailed(error.message)
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ function stringFormatUnicorn(
return formatted
}

for (let [key, value] of Object.entries(kv)) {
for (const [key, value] of Object.entries(kv)) {
formatted = formatted.replace(
new RegExp('\\{' + key + '\\}', 'gi'),
new RegExp(`\\{${key}\\}`, 'gi'),
value.toString()
)
}
Expand Down

0 comments on commit 813401f

Please sign in to comment.