fix: sync exact progress commits safely
This commit is contained in:
parent
2329fb7a5f
commit
e6552378cc
@ -74,6 +74,11 @@ export const FEATURE_RULES = [
|
||||
subject: /快递|报价|签署|协议|E\s*签|esign|cooperation|courier|signing/i,
|
||||
paths: /(?:Courier|Esign|agreement-signing|quote-management)/i,
|
||||
},
|
||||
{
|
||||
key: 'dingtalk-login', priority: 110, moduleName: '生产发布与团队协作', featureName: '钉钉账号登录与绑定',
|
||||
subject: /(?:(?:DingTalk|钉钉).*(?:login|callback|登录|回调)|(?:login|callback|登录|回调).*(?:DingTalk|钉钉))/i,
|
||||
paths: /(?:Auth\/DingTalkLogin|DingTalkIdentity|dingtalk.*callback|config\/dingtalk\.php)/i,
|
||||
},
|
||||
{
|
||||
key: 'ding-payables', priority: 100, moduleName: '快递与审批', featureName: '钉钉应付流程与状态同步',
|
||||
subject: /钉钉|应付.*流程|ding payable/i,
|
||||
@ -195,6 +200,16 @@ function git(repoRoot, args) {
|
||||
return result.stdout.trim()
|
||||
}
|
||||
|
||||
function isAncestor(repoRoot, ancestor, descendant) {
|
||||
const result = spawnSync('git', ['merge-base', '--is-ancestor', ancestor, descendant], {
|
||||
cwd: repoRoot,
|
||||
encoding: 'utf8',
|
||||
})
|
||||
if (result.status === 0) return true
|
||||
if (result.status === 1) return false
|
||||
fail(`GIT_FAILED:merge-base:${result.stderr.trim()}`)
|
||||
}
|
||||
|
||||
function getChangedFiles(repoRoot, sha) {
|
||||
const statuses = git(repoRoot, ['diff-tree', '--root', '--no-commit-id', '--name-status', '-r', '-M', sha]).split('\n').filter(Boolean)
|
||||
const nums = git(repoRoot, ['diff-tree', '--root', '--no-commit-id', '--numstat', '-r', '-M', sha]).split('\n').filter(Boolean)
|
||||
@ -315,6 +330,13 @@ export async function main(argv = process.argv.slice(2)) {
|
||||
const dryRun = flags.has('dry-run')
|
||||
const ref = values.ref || 'origin/main'
|
||||
const since = values.since || DEFAULT_SINCE
|
||||
const requestedSha = values.sha || null
|
||||
const manualModule = values.module || null
|
||||
const manualFeature = values.feature || null
|
||||
if ((manualModule || manualFeature) && (!requestedSha || !manualModule || !manualFeature)) {
|
||||
fail('MANUAL_FEATURE_REQUIRES_SHA_MODULE_AND_FEATURE')
|
||||
}
|
||||
if (requestedSha && !/^[0-9a-f]{40}$/i.test(requestedSha)) fail('INVALID_SHA')
|
||||
const limit = values.limit ? Number(values.limit) : Number.POSITIVE_INFINITY
|
||||
if (!(limit > 0)) fail('INVALID_LIMIT')
|
||||
const remoteUrl = git(repoRoot, ['config', '--get', 'remote.origin.url'])
|
||||
@ -328,7 +350,10 @@ export async function main(argv = process.argv.slice(2)) {
|
||||
})
|
||||
if (project.department !== env.DEPARTMENT) fail('PROJECT_DEPARTMENT_MISMATCH')
|
||||
const state = readState(statePath)
|
||||
const shas = git(repoRoot, ['log', ref, `--since=${since}`, '--no-merges', '--reverse', '--format=%H']).split('\n').filter(Boolean)
|
||||
const shas = requestedSha
|
||||
? [git(repoRoot, ['rev-parse', requestedSha])]
|
||||
: git(repoRoot, ['log', ref, `--since=${since}`, '--no-merges', '--reverse', '--format=%H']).split('\n').filter(Boolean)
|
||||
if (requestedSha && !isAncestor(repoRoot, shas[0], ref)) fail('SHA_NOT_IN_REF')
|
||||
const excluded = {}
|
||||
const excludedCommits = []
|
||||
const excludedAuthors = {}
|
||||
@ -346,7 +371,15 @@ export async function main(argv = process.argv.slice(2)) {
|
||||
excludedAuthors[author] = (excludedAuthors[author] || 0) + 1
|
||||
continue
|
||||
}
|
||||
const classification = classifyCommit(commit.message, commit.changed_files.map((file) => file.path))
|
||||
const classification = manualModule
|
||||
? {
|
||||
rule: {
|
||||
key: `manual:${manualModule}:${manualFeature}`,
|
||||
moduleName: manualModule,
|
||||
featureName: manualFeature,
|
||||
},
|
||||
}
|
||||
: classifyCommit(commit.message, commit.changed_files.map((file) => file.path))
|
||||
if (!classification.rule) {
|
||||
excluded[classification.reason] = (excluded[classification.reason] || 0) + 1
|
||||
excludedCommits.push({ sha: commit.sha, title: commit.message, reason: classification.reason })
|
||||
@ -368,7 +401,14 @@ export async function main(argv = process.argv.slice(2)) {
|
||||
return map
|
||||
}, {}))
|
||||
if (dryRun) {
|
||||
console.log(JSON.stringify({ mode: 'dry-run', project: project.projectName, ref, since, status, candidates: candidates.length, excluded, excludedAuthors, excludedCommits, features: featureSummary, authors: authorSummary }, null, 2))
|
||||
const commits = candidates.map(({ commit, rule }) => ({
|
||||
sha: commit.sha,
|
||||
title: commit.message,
|
||||
author: `${commit.author_name} <${commit.author_email}>`,
|
||||
module: rule.moduleName,
|
||||
feature: rule.featureName,
|
||||
}))
|
||||
console.log(JSON.stringify({ mode: 'dry-run', project: project.projectName, ref, since, status, candidates: candidates.length, excluded, excludedAuthors, excludedCommits, features: featureSummary, authors: authorSummary, commits }, null, 2))
|
||||
return
|
||||
}
|
||||
if (!candidates.length) {
|
||||
|
||||
@ -58,6 +58,9 @@ test('assigns one primary feature and stops on ambiguous feature matches', () =>
|
||||
const esign = classifyCommit('feat: add callback-free eSign status polling', ['app/Console/Commands/PollEsignSignatures.php']).rule
|
||||
assert.equal(esign.key, 'courier-esign')
|
||||
assert.equal(esign.featureName, 'E 签宝无回调状态轮询与归档')
|
||||
const dingtalkLogin = classifyCommit('feat: add DingTalk account login', ['app/Http/Controllers/Auth/DingTalkLogin.php']).rule
|
||||
assert.equal(dingtalkLogin.key, 'dingtalk-login')
|
||||
assert.equal(dingtalkLogin.featureName, '钉钉账号登录与绑定')
|
||||
assert.equal(
|
||||
classifyCommit('feat: align taobao reconciliation headers', ['resources/views/store_receivables/zhongcai_reconciliations/partials/embedded-table.blade.php']).rule.key,
|
||||
'zhongcai-reconciliation',
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user