fix: use merge_commit_sha instead of head.sha for auto-tag#786
Open
hudeng-go wants to merge 1 commit into
Open
fix: use merge_commit_sha instead of head.sha for auto-tag#786hudeng-go wants to merge 1 commit into
hudeng-go wants to merge 1 commit into
Conversation
解决创建的tag无法找到对用的分支的问题 Log:
Contributor
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: hudeng-go The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
Contributor
deepin pr auto review你好!我是CodeGeeX。我已仔细审查了你提供的 GitHub Actions 工作流代码的 diff。本次修改将获取 Pull Request (PR) 提交 SHA 的方式从 这是一个在 CI/CD 流程中非常关键的改动,涉及到 Git 底层逻辑和 GitHub Actions 的运行机制。以下是我的详细审查意见: 1. 语法逻辑
2. 代码质量
3. 代码性能
4. 代码安全
💡 综合改进建议及代码示例为了确保代码的健壮性和安全性,建议在获取 以下是改进后的代码片段: // 确保只在 PR 成功合并时执行后续逻辑
if (!context.payload.pull_request.merged) {
core.info("PR was not merged, skipping tag creation.")
return
}
const mergeCommitSha = context.payload.pull_request.merge_commit_sha
// 增加防御性校验,防止 merge_commit_sha 为空导致 API 报错
if (!mergeCommitSha) {
core.setFailed("Error: merge_commit_sha is null. This can happen if the PR is not fully merged or in certain merge strategies.")
return
}
let data
try {
const tagResult = await github.rest.git.createTag({
repo: context.repo.repo,
owner: context.repo.owner,
tag: /* your tag variable */,
message: /* your message variable */,
object: mergeCommitSha, // 使用校验过的 mergeCommitSha
type: "commit"
})
// ... 后续逻辑
} catch (error) {
core.setFailed(`Failed to create tag: ${error.message}`)
}总结:将 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Log: