Skip to content

Commit d689704

Browse files
committed
Consider already existing names in acknowledgements generation
This avoids repeated resolution of name-inconsistencies and preserves already applied name corrections.
1 parent 578d85a commit d689704

File tree

2 files changed

+77
-5
lines changed

2 files changed

+77
-5
lines changed
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
name: Check acknowledgements consistency
2+
on:
3+
pull_request:
4+
paths:
5+
- news/*/acknowledgements.md
6+
7+
permissions:
8+
contents: read
9+
10+
jobs:
11+
prepare:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
15+
- name: Determine changed files
16+
id: changed-files
17+
run: |
18+
changedFiles=$(git diff --name-only --diff-filter=ACMR ${{ github.event.pull_request.base.sha }} ${{ github.event.pull_request.head.sha }} | grep acknowledgements.md$)
19+
echo "Changed files: ${changedFiles}"
20+
echo "files=${changedFiles}" >> "$GITHUB_OUTPUT"
21+
- name: Check modified acknowledgements files
22+
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
23+
id: collect-contributors
24+
with:
25+
script: |
26+
const fs = require('fs')
27+
const files = '${{ steps.changed-files.outputs.files }}'.trim().split(/\r?\n/)
28+
const nameIdRegex = /\[(?<name>[^\]]+)\]\(https:\/\/github\.com\/(?<id>[^\)]+)\)/g
29+
const contributorNames = new Map()
30+
for (file of files) {
31+
let lines = fs.readFileSync(file, {encoding: 'utf8'}).split(/\r?\n/)
32+
for (line of lines) {
33+
for (match of line.matchAll(nameIdRegex)) {
34+
computeIfAbsent(contributorNames, match.groups.id, () => new Set()).add(match.groups.name)
35+
}
36+
}
37+
}
38+
let boolean hasMultipleNames = false
39+
for (const [profile, names] of contributorNames) {
40+
if (names.size > 1) {
41+
core.error('Multiple names found for profile '" + profile + "': ' + Array.from(names).join(', '))
42+
hasMultipleNames = true
43+
}
44+
}
45+
if (hasMultipleNames) {
46+
throw new Error('No selected name for profile: ' + profile)
47+
}
48+
49+
function computeIfAbsent(map, key, valueSupplier) {
50+
let value = map.get(key)
51+
if (!value) {
52+
value = valueSupplier()
53+
map.set(key, value)
54+
}
55+
return value
56+
}

.github/workflows/generateAcknowledgements.yml

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -137,15 +137,34 @@ jobs:
137137
console.log('Processed commits: ' + commitCount)
138138
}
139139
140+
// ------------------------------------------------------
141+
// Read existing names
142+
// ------------------------------------------------------
143+
const fs = require('fs')
144+
const acknowledgementsFile = 'website/news/${{ inputs.eclipse-version }}/acknowledgements.md'
145+
let lines = fs.readFileSync(acknowledgementsFile, {encoding: 'utf8'}).split(/\r?\n/)
146+
147+
const nameIdRegex = /\[(?<name>[^\]]+)\]\(https:\/\/github\.com\/(?<id>[^\)]+)\)/g
148+
const existingContributorNames = new Map()
149+
for (line of lines) {
150+
for (match of line.matchAll(nameIdRegex)) {
151+
existingContributorNames.set(match.groups.id, match.groups.name)
152+
}
153+
}
140154
// ------------------------------------------------------
141155
// Select name if multiple have been found for one contributor
142156
// ------------------------------------------------------
143157
const selectedContributorNames = new Map()
144158
const nameInconsistencies = []
145159
for (const [profile, names] of contributorNames) {
146160
// Select longest name, assuming that's correct
147-
let selectedName = [...names].reduce((n1, n2) => n1.length > n2.length ? n1 : n2)
148-
if (names.size > 1) {
161+
let selectedName = names[0]
162+
const existingName = existingContributorNames.get(profile)
163+
if (existingName && (selectedName != existingName || names.size > 1)) {
164+
selectedName = existingName
165+
console.log("Reuse existing name '" + existingName + "' for " + profile + ", instead of encountered: " + Array.from(names).join(', '))
166+
} else if (names.size > 1) {
167+
selectedName = [...names].reduce((n1, n2) => n1.length > n2.length ? n1 : n2)
149168
console.log("Multiple names encountered for " + profile + ": " + Array.from(names).join(', '))
150169
nameInconsistencies.push("@" + profile + ": " + Array.from(names).map(n => n==selectedName ? ("**`" + n + "`**") : ("`" + n + "`")).join(', '))
151170
}
@@ -155,9 +174,6 @@ jobs:
155174
// ------------------------------------------------------
156175
// Insert the list of contributors into the template file
157176
// ------------------------------------------------------
158-
const fs = require('fs')
159-
const acknowledgementsFile = 'website/news/${{ inputs.eclipse-version }}/acknowledgements.md'
160-
let lines = fs.readFileSync(acknowledgementsFile, {encoding: 'utf8'}).split(/\r?\n/)
161177
let elementsInLine = 0
162178
for (const [organization, contributors] of orgaContributors) {
163179
console.log('Insert contributors of ' + organization)

0 commit comments

Comments
 (0)