下面是我的 github 操作 ISSUE_TEMPLATE,它寻求用户的输入。
name: GH Action details
description: GH Issue form
title: "GH Action details"
assignees:
- my-devops
labels:
- "gh inventory"
body:
- type: markdown
attributes:
value: |
### Want to add?
---
Please fill out the information below
- type: input
id: repository-name
attributes:
label: Repository Name
description: Provide the name of the repository
validations:
required: true
下面是问题表单在用户评论之前和之后的样子。
我希望使用 PowerShell 提交类似的问题评论。尝试了下面的[您可以尝试使用 ISE、powershell 在您的系统上运行]:下面的 Powershell 代码:
$Token = "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"
$RepoOwner = "knowyrtech"
$RepoName = "mongomaskwinvslinux"
$IssueTitle = "GH Action Onboard inventory details"
# Create a hashtable for the input values
$inputValues = @{
"ref" = "main"
"inputs" = @{
"repository-name" = "YourRepositoryName"
}
}
# Convert the hashtable to JSON
$inputJson = $inputValues | ConvertTo-Json
$ApiUrl = "https://api.github.com/repos/$RepoOwner/$RepoName/issues"
$IssueData = @{
title = $IssueTitle
body = $inputJson
} | ConvertTo-Json
$response = Invoke-RestMethod -Uri $ApiUrl -Method Post -Headers @{
"Authorization" = "token $Token"
"Accept" = "application/vnd.github.v3+json"
} -ContentType "application/json" -Body $IssueData
$response
运行此命令会创建一条注释,但不是上面共享的所需输出快照。
我也尝试过
$inputValues = @{
"ref" = "main"
"inputs" = @{
"repository-name" = @{
"default" = 'wowo'
}
}
}
$inputJson = $inputValues | ConvertTo-Json
但是,无法评论作为输入,如下所示:
请推荐。
在您的脚本中,您正在创建一个 JSON 对象,表示操作工作流程的输入内容,并直接使用该 JSON 对象作为 GitHub 问题的正文:
$inputValues = @{
"ref" = "main"
"inputs" = @{
"repository-name" = "YourRepositoryName"
}
}
$inputJson = $inputValues | ConvertTo-Json
...
$IssueData = @{
title = $IssueTitle
body = $inputJson
} | ConvertTo-Json
由于通过 API 创建的 GitHub 问题本身并不支持以这种方式直接填充问题表单字段。 GitHub Issue Forms 和 GitHub API 分开工作; API 不提供直接填充问题表单字段的功能。
您可以尝试使用 Markdown 格式的字符串来表示问题正文,而不是尝试使用 JSON 对象来表示问题正文,其中包括您想要以结构化方式包含的默认值,在视觉上类似于 GitHub 问题表单:
$IssueBody = @"
### Want to add?
---
Please fill out the information below
**Repository Name**
$RepositoryName
"@
...
$IssueData = @{
title = $IssueTitle
body = $IssueBody
} | ConvertTo-Json
$IssueBody
变量包含一个采用 Markdown 格式的字符串,其信息结构与在 GitHub 平台上查看时的 GitHub 问题表单类似。
完整脚本:
$Token = "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"
$RepoOwner = "knowyrtech"
$RepoName = "mongomaskwinvslinux"
$IssueTitle = "GH Action Onboard inventory details"
# Define the repository name (or any other values you want to set as default)
$RepositoryName = "YourRepositoryName"
# Create a Markdown formatted string that represents the issue body
$IssueBody = @"
### Want to add?
---
Please fill out the information below
**Repository Name**
$RepositoryName
"@
$ApiUrl = "https://api.github.com/repos/$RepoOwner/$RepoName/issues"
$IssueData = @{
title = $IssueTitle
body = $IssueBody
} | ConvertTo-Json
$response = Invoke-RestMethod -Uri $ApiUrl -Method Post -Headers @{
"Authorization" = "token $Token"
"Accept" = "application/vnd.github.v3+json"
} -ContentType "application/json" -Body $IssueData
$response