Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
sureness
Issues Translate Action
提交
d9ec1640
I
Issues Translate Action
项目概览
sureness
/
Issues Translate Action
通知
5
Star
3
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
I
Issues Translate Action
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
d9ec1640
编写于
11月 14, 2020
作者:
sinat_25235033
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
support issue trigger
上级
2083e22c
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
59 addition
and
35 deletion
+59
-35
.github/workflows/test.yml
.github/workflows/test.yml
+1
-0
README.md
README.md
+18
-6
dist/index.js
dist/index.js
+0
-0
dist/index.js.map
dist/index.js.map
+0
-0
src/main.ts
src/main.ts
+40
-29
未找到文件。
.github/workflows/test.yml
浏览文件 @
d9ec1640
name
:
'
build-test'
on
:
# rebuild any PRs and main branch changes
issue_comment
:
issue
:
branches
:
-
main
-
'
releases/*'
...
...
README.md
浏览文件 @
d9ec1640
...
...
@@ -6,11 +6,14 @@ The action for translating non-English issues comment content to English.
## Usage
> Use the default bot @Issues-translate-bot
#### Create a workflow from this action
````
name: 'issue-comment-translator'
on: # only support issue_comment
on: # support issue_comment issue
issue:
issue_comment:
branches:
- main
...
...
@@ -19,19 +22,28 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: tomsun28/issues-translate-action@v1
- uses: tomsun28/issues-translate-action@v1
.2
````
##
Custom
##
Advanced Custom
#### Create a workflow from this action
> Use your own bot by add BOT_GITHUB_TOKEN
>
1.
Create a new github account as your bot
2.
Use the account to generate a new token as BOT_GITHUB_TOKEN
3.
Add the Secrets BOT_GITHUB_TOKEN = ${token} in your project
4.
Create a workflow from this action
````
name: 'issue-comment-translator'
on: # only support issue_comment
on: # support issue_comment issue
issue:
issue_comment:
branches:
- main
...
...
@@ -40,7 +52,7 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: tomsun28/issues-translate-action@v1
- uses: tomsun28/issues-translate-action@v1
.2
with:
BOT_GITHUB_TOKEN: ${{ secrets.BOT_GITHUB_TOKEN }} # required, input your bot github token
# BOT_LOGIN_NAME: nameValue - not required, suggest not input, action will get name from BOT_GITHUB_TOKEN
...
...
dist/index.js
浏览文件 @
d9ec1640
此差异由.gitattributes 抑制。
dist/index.js.map
浏览文件 @
d9ec1640
此差异由.gitattributes 抑制。
src/main.ts
浏览文件 @
d9ec1640
...
...
@@ -8,7 +8,7 @@ let franc = require('franc-min')
async
function
run
():
Promise
<
void
>
{
try
{
if
(
github
.
context
.
eventName
!==
'
issue_comment
'
||
(
github
.
context
.
eventName
!==
'
issue_comment
'
&&
github
.
context
.
eventName
!=
'
issue
'
)
||
github
.
context
.
payload
.
action
!==
'
created
'
)
{
core
.
setFailed
(
...
...
@@ -16,57 +16,68 @@ async function run(): Promise<void> {
)
return
}
const
issueCommentPayload
=
github
.
context
let
issueNumber
=
null
let
originBody
=
null
let
issueUser
=
null
if
(
github
.
context
.
eventName
===
'
issue_comment
'
)
{
const
issueCommentPayload
=
github
.
context
.
payload
as
webhook
.
EventPayloads
.
WebhookPayloadIssueComment
const
issue_number
=
issueCommentPayload
.
issue
.
number
const
issue_origin_comment_body
=
issueCommentPayload
.
comment
.
body
issueNumber
=
issueCommentPayload
.
issue
.
number
issueUser
=
issueCommentPayload
.
comment
.
user
.
login
originBody
=
issueCommentPayload
.
comment
.
body
}
else
{
const
issuePayload
=
github
.
context
.
payload
as
webhook
.
EventPayloads
.
WebhookPayloadIssues
issueNumber
=
issuePayload
.
issue
.
number
issueUser
=
issuePayload
.
issue
.
user
.
login
originBody
=
issuePayload
.
issue
.
body
}
// detect comment body is english
if
(
detectIsEnglish
(
issue_origin_comment_b
ody
))
{
if
(
detectIsEnglish
(
originB
ody
))
{
core
.
info
(
'
Detect the issue comment body is english already, ignore return.
'
)
return
}
// ignore when bot comment issue himself
let
my
Token
=
core
.
getInput
(
'
BOT_GITHUB_TOKEN
'
)
let
bot
_login_n
ame
=
core
.
getInput
(
'
BOT_LOGIN_NAME
'
)
if
(
myToken
===
null
||
myToken
===
undefined
||
my
Token
===
''
)
{
let
bot
Token
=
core
.
getInput
(
'
BOT_GITHUB_TOKEN
'
)
let
bot
LoginN
ame
=
core
.
getInput
(
'
BOT_LOGIN_NAME
'
)
if
(
botToken
===
null
||
botToken
===
undefined
||
bot
Token
===
''
)
{
// use the default github bot token
const
myTokenBase64
=
'
Y2I4M2EyNjE0NThlMzIwMjA3MGJhODRlY2I5NTM0ZjBmYTEwM2ZlNg==
'
myToken
=
Buffer
.
from
(
myTokenBase64
,
'
base64
'
).
toString
()
bot_login_name
=
'
Issues-translate-bot
'
const
defaultBotTokenBase64
=
'
Y2I4M2EyNjE0NThlMzIwMjA3MGJhODRlY2I5NTM0ZjBmYTEwM2ZlNg==
'
const
defaultBotLoginName
=
'
Issues-translate-bot
'
botToken
=
Buffer
.
from
(
defaultBotTokenBase64
,
'
base64
'
).
toString
()
botLoginName
=
defaultBotLoginName
}
let
octokit
=
null
;
const
issue_user
=
issueCommentPayload
.
comment
.
user
.
login
if
(
bot_login_name
===
null
||
bot_login_name
===
undefined
||
bot_login_name
===
''
)
{
octokit
=
github
.
getOctokit
(
myToken
)
if
(
botLoginName
===
null
||
botLoginName
===
undefined
||
botLoginName
===
''
)
{
octokit
=
github
.
getOctokit
(
botToken
)
const
botInfo
=
await
octokit
.
request
(
'
GET /user
'
)
bot
_login_n
ame
=
botInfo
.
data
.
login
bot
LoginN
ame
=
botInfo
.
data
.
login
}
if
(
bot
_login_name
===
issue_u
ser
)
{
core
.
info
(
`The issue comment user is bot
${
bot
_login_n
ame
}
himself, ignore return.`
)
if
(
bot
LoginName
===
issueU
ser
)
{
core
.
info
(
`The issue comment user is bot
${
bot
LoginN
ame
}
himself, ignore return.`
)
return
}
// translate issue comment body to english
const
issue_translate_comment_b
ody
=
await
translateCommentBody
(
issue_origin_comment_body
,
issue_u
ser
const
translateB
ody
=
await
translateCommentBody
(
originBody
,
issueU
ser
)
if
(
issue_translate_comment_b
ody
===
null
||
issue_translate_comment_b
ody
===
''
||
issue_translate_comment_body
===
issue_origin_comment_b
ody
)
{
core
.
warning
(
"
The
issue_translate_comment_b
ody is null or same, ignore return.
"
)
if
(
translateB
ody
===
null
||
translateB
ody
===
''
||
translateBody
===
originB
ody
)
{
core
.
warning
(
"
The
translateB
ody is null or same, ignore return.
"
)
return
}
// create comment by bot
if
(
octokit
===
null
)
{
octokit
=
github
.
getOctokit
(
my
Token
)
octokit
=
github
.
getOctokit
(
bot
Token
)
}
await
createComment
(
issue
_number
,
issue_translate_comment_b
ody
,
octokit
)
await
createComment
(
issue
Number
,
translateB
ody
,
octokit
)
core
.
setOutput
(
'
complete time
'
,
new
Date
().
toTimeString
())
}
catch
(
error
)
{
core
.
setFailed
(
error
.
message
)
...
...
@@ -85,13 +96,13 @@ function detectIsEnglish(body: string): boolean | true {
return
detectResult
===
'
eng
'
}
async
function
translateCommentBody
(
body
:
string
,
issue
_u
ser
:
string
):
Promise
<
string
>
{
async
function
translateCommentBody
(
body
:
string
,
issue
U
ser
:
string
):
Promise
<
string
>
{
let
result
=
''
await
translate
(
body
,
{
to
:
'
en
'
})
.
then
(
res
=>
{
result
=
`
> @
${
issue
_u
ser
}
> @
${
issue
U
ser
}
> Bot detected the comment body's language is not English, translate it automatically. For the convenience of others, please use English next time👯.
----
...
...
@@ -105,13 +116,13 @@ ${res.text}
return
result
}
async
function
createComment
(
issue
Id
:
number
,
body
:
string
,
octokit
:
any
):
Promise
<
void
>
{
async
function
createComment
(
issue
Number
:
number
,
body
:
string
,
octokit
:
any
):
Promise
<
void
>
{
const
{
owner
,
repo
}
=
github
.
context
.
repo
const
issue_url
=
github
.
context
.
payload
.
issue
?.
html_url
await
octokit
.
issues
.
createComment
({
owner
,
repo
,
issue_number
:
issue
Id
,
issue_number
:
issue
Number
,
body
})
core
.
info
(
`complete to push translate issue comment:
${
body
}
in
${
issue_url
}
`
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录