Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
sureness
Issues Translate Action
提交
32b435be
I
Issues Translate Action
项目概览
sureness
/
Issues Translate Action
通知
2
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看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
32b435be
编写于
3月 21, 2021
作者:
sinat_25235033
提交者:
GitHub
3月 21, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
support modify issue title (#43)
上级
d7f080b9
变更
5
显示空白变更内容
内联
并排
Showing
5 changed file
with
89 addition
and
27 deletion
+89
-27
.github/workflows/action-test.yml
.github/workflows/action-test.yml
+3
-0
action.yml
action.yml
+2
-0
dist/index.js
dist/index.js
+0
-0
dist/index.js.map
dist/index.js.map
+0
-0
src/main.ts
src/main.ts
+84
-27
未找到文件。
.github/workflows/action-test.yml
浏览文件 @
32b435be
...
@@ -13,3 +13,6 @@ jobs:
...
@@ -13,3 +13,6 @@ jobs:
-
uses
:
./
-
uses
:
./
# with:
# with:
# BOT_GITHUB_TOKEN: ${{ secrets.BOT_GITHUB_TOKEN }}
# BOT_GITHUB_TOKEN: ${{ secrets.BOT_GITHUB_TOKEN }}
with
:
IS_MODIFY_TITLE
:
true
action.yml
浏览文件 @
32b435be
...
@@ -9,6 +9,8 @@ inputs:
...
@@ -9,6 +9,8 @@ inputs:
description
:
'
The
issue
comment
bot
GITHUB_TOKEN.'
description
:
'
The
issue
comment
bot
GITHUB_TOKEN.'
BOT_LOGIN_NAME
:
BOT_LOGIN_NAME
:
description
:
'
The
issue
comment
bot
github
login
name.'
description
:
'
The
issue
comment
bot
github
login
name.'
IS_MODIFY_TITLE
:
description
:
'
Is
need
modify
issue
title,
true
or
false,
default
false.'
runs
:
runs
:
using
:
'
node12'
using
:
'
node12'
main
:
'
dist/index.js'
main
:
'
dist/index.js'
dist/index.js
浏览文件 @
32b435be
此差异由.gitattributes 抑制。
dist/index.js.map
浏览文件 @
32b435be
此差异由.gitattributes 抑制。
src/main.ts
浏览文件 @
32b435be
...
@@ -17,28 +17,41 @@ async function run(): Promise<void> {
...
@@ -17,28 +17,41 @@ async function run(): Promise<void> {
return
return
}
}
let
issueNumber
=
null
let
issueNumber
=
null
let
originBody
=
null
let
originComment
=
null
let
originTitle
=
null
let
issueUser
=
null
let
issueUser
=
null
let
botNote
=
"
Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑🤝🧑👫🧑🏿🤝🧑🏻👩🏾🤝👨🏿👬🏿
"
let
isModifyTitle
=
core
.
getInput
(
'
IS_MODIFY_TITLE
'
)
if
(
github
.
context
.
eventName
===
'
issue_comment
'
)
{
if
(
github
.
context
.
eventName
===
'
issue_comment
'
)
{
const
issueCommentPayload
=
github
.
context
const
issueCommentPayload
=
github
.
context
.
payload
as
webhook
.
EventPayloads
.
WebhookPayloadIssueComment
.
payload
as
webhook
.
EventPayloads
.
WebhookPayloadIssueComment
issueNumber
=
issueCommentPayload
.
issue
.
number
issueNumber
=
issueCommentPayload
.
issue
.
number
issueUser
=
issueCommentPayload
.
comment
.
user
.
login
issueUser
=
issueCommentPayload
.
comment
.
user
.
login
origin
Body
=
issueCommentPayload
.
comment
.
body
origin
Comment
=
issueCommentPayload
.
comment
.
body
}
else
{
}
else
{
const
issuePayload
=
github
.
context
.
payload
as
webhook
.
EventPayloads
.
WebhookPayloadIssues
const
issuePayload
=
github
.
context
.
payload
as
webhook
.
EventPayloads
.
WebhookPayloadIssues
issueNumber
=
issuePayload
.
issue
.
number
issueNumber
=
issuePayload
.
issue
.
number
issueUser
=
issuePayload
.
issue
.
user
.
login
issueUser
=
issuePayload
.
issue
.
user
.
login
originBody
=
originComment
=
issuePayload
.
issue
.
body
originTitle
=
issuePayload
.
issue
.
title
if
(
isModifyTitle
===
'
true
'
)
{
originComment
=
issuePayload
.
issue
.
body
originTitle
=
issuePayload
.
issue
.
title
}
else
{
originComment
=
`
`
**Title:**
${
issuePayload
.
issue
.
title
}
**Title:**
${
issuePayload
.
issue
.
title
}
${
issuePayload
.
issue
.
body
}
${
issuePayload
.
issue
.
body
}
`
`
}
}
}
// detect comment body is english
let
translateOrigin
=
originComment
+
'
@====@
'
+
originTitle
if
(
detectIsEnglish
(
originBody
))
{
// detect issue title comment body is english
if
(
detectIsEnglish
(
translateOrigin
))
{
core
.
info
(
'
Detect the issue comment body is english already, ignore return.
'
)
core
.
info
(
'
Detect the issue comment body is english already, ignore return.
'
)
return
return
}
}
...
@@ -67,29 +80,67 @@ ${issuePayload.issue.body}
...
@@ -67,29 +80,67 @@ ${issuePayload.issue.body}
// translate issue comment body to english
// translate issue comment body to english
const
translateBody
=
await
translateCommentBody
(
const
translateTmp
=
await
translateIssueOrigin
(
translateOrigin
)
originBody
,
issueUser
)
if
(
translate
Body
===
null
if
(
translate
Tmp
===
null
||
translate
Body
===
''
||
translate
Tmp
===
''
||
translate
Body
===
originBody
)
{
||
translate
Tmp
===
translateOrigin
)
{
core
.
warning
(
"
The translateBody is null or same, ignore return.
"
)
core
.
warning
(
"
The translateBody is null or same, ignore return.
"
)
return
return
}
}
let
translateBody
:
string
[]
=
translateTmp
.
split
(
'
@====@
'
)
let
translateComment
=
null
let
translateTitle
=
null
if
(
translateBody
.
length
==
1
)
{
translateComment
=
translateBody
[
0
]
}
else
if
(
translateBody
.
length
==
2
)
{
translateComment
=
translateBody
[
0
]
translateTitle
=
translateBody
[
1
]
}
else
{
core
.
setFailed
(
`the translateBody is
${
translateTmp
}
`
)
}
// create comment by bot
// create comment by bot
if
(
octokit
===
null
)
{
if
(
octokit
===
null
)
{
octokit
=
github
.
getOctokit
(
botToken
)
octokit
=
github
.
getOctokit
(
botToken
)
}
}
await
createComment
(
issueNumber
,
translateBody
,
octokit
)
if
(
translateTitle
!==
null
&&
isModifyTitle
===
'
false
'
)
{
translateComment
=
`
>
${
botNote
}
----
**Title:**
${
translateTitle
}
${
translateComment
}
`
}
else
{
translateComment
=
`
>
${
botNote
}
----
${
translateComment
}
`
}
if
(
isModifyTitle
===
'
true
'
)
{
await
modifyTitle
(
issueNumber
,
translateTitle
,
octokit
)
}
await
createComment
(
issueNumber
,
translateComment
,
octokit
)
core
.
setOutput
(
'
complete time
'
,
new
Date
().
toTimeString
())
core
.
setOutput
(
'
complete time
'
,
new
Date
().
toTimeString
())
}
catch
(
error
)
{
}
catch
(
error
)
{
core
.
setFailed
(
error
.
message
)
core
.
setFailed
(
error
.
message
)
}
}
}
}
function
detectIsEnglish
(
body
:
string
):
boolean
|
true
{
function
detectIsEnglish
(
body
:
string
|
null
):
boolean
|
true
{
if
(
body
===
null
)
{
return
true
}
const
detectResult
=
franc
(
body
)
const
detectResult
=
franc
(
body
)
if
(
detectResult
===
'
und
'
if
(
detectResult
===
'
und
'
||
detectResult
===
undefined
||
detectResult
===
undefined
...
@@ -101,18 +152,12 @@ function detectIsEnglish(body: string): boolean | true {
...
@@ -101,18 +152,12 @@ function detectIsEnglish(body: string): boolean | true {
return
detectResult
===
'
eng
'
return
detectResult
===
'
eng
'
}
}
async
function
translate
CommentBody
(
body
:
string
,
issueUser
:
string
):
Promise
<
string
>
{
async
function
translate
IssueOrigin
(
body
:
string
):
Promise
<
string
>
{
let
result
=
''
let
result
=
''
await
translate
(
body
,
{
to
:
'
en
'
})
await
translate
(
body
,
{
to
:
'
en
'
})
.
then
(
res
=>
{
.
then
(
res
=>
{
if
(
res
.
text
!==
body
)
{
if
(
res
.
text
!==
body
)
{
result
=
result
=
res
.
text
`
> Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑🤝🧑👫🧑🏿🤝🧑🏻👩🏾🤝👨🏿👬🏿
----
${
res
.
text
}
`
}
}
})
})
.
catch
(
err
=>
{
.
catch
(
err
=>
{
...
@@ -122,7 +167,7 @@ ${res.text}
...
@@ -122,7 +167,7 @@ ${res.text}
return
result
return
result
}
}
async
function
createComment
(
issueNumber
:
number
,
body
:
string
,
octokit
:
any
):
Promise
<
void
>
{
async
function
createComment
(
issueNumber
:
number
,
body
:
string
|
null
,
octokit
:
any
):
Promise
<
void
>
{
const
{
owner
,
repo
}
=
github
.
context
.
repo
const
{
owner
,
repo
}
=
github
.
context
.
repo
const
issue_url
=
github
.
context
.
payload
.
issue
?.
html_url
const
issue_url
=
github
.
context
.
payload
.
issue
?.
html_url
await
octokit
.
issues
.
createComment
({
await
octokit
.
issues
.
createComment
({
...
@@ -134,4 +179,16 @@ async function createComment(issueNumber: number, body: string, octokit: any): P
...
@@ -134,4 +179,16 @@ async function createComment(issueNumber: number, body: string, octokit: any): P
core
.
info
(
`complete to push translate issue comment:
${
body
}
in
${
issue_url
}
`
)
core
.
info
(
`complete to push translate issue comment:
${
body
}
in
${
issue_url
}
`
)
}
}
async
function
modifyTitle
(
issueNumber
:
number
,
title
:
string
|
null
,
octokit
:
any
):
Promise
<
void
>
{
const
{
owner
,
repo
}
=
github
.
context
.
repo
const
issue_url
=
github
.
context
.
payload
.
issue
?.
html_url
await
octokit
.
issues
.
update
({
owner
,
repo
,
issue_number
:
issueNumber
,
title
})
core
.
info
(
`complete to modify translate issue title:
${
title
}
in
${
issue_url
}
`
)
}
run
()
run
()
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录