Skip to content

Commit 0509cd2

Browse files
committed
feat(config): add support for repository-specific assignees and reviewers configuration
1 parent 8b92be3 commit 0509cd2

File tree

3 files changed

+120
-33
lines changed

3 files changed

+120
-33
lines changed

README.md

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,66 @@ You can tell [repo-file-sync-action](https://github.com/BetaHuhn/repo-file-sync-
399399
TEAM_REVIEWERS: engineering
400400
```
401401

402+
### Repository-specific assignees and reviewers
403+
404+
You can configure different assignees, reviewers, and team reviewers for different target repositories. There are two ways to specify these:
405+
406+
1. In a group configuration:
407+
408+
**.github/sync.yml**
409+
410+
```yml
411+
group:
412+
repos:
413+
- name: user/repo1
414+
assignees:
415+
- user1
416+
reviewers:
417+
- user2
418+
team_reviewers:
419+
- team1
420+
- name: user/repo2
421+
assignees:
422+
- user3
423+
reviewers:
424+
- user4
425+
team_reviewers:
426+
- team2
427+
files:
428+
- source: path/to/file.txt
429+
dest: path/to/file.txt
430+
```
431+
432+
2. In a direct repository configuration:
433+
434+
**.github/sync.yml**
435+
436+
```yml
437+
user/repo1:
438+
assignees:
439+
- user1
440+
reviewers:
441+
- user2
442+
team_reviewers:
443+
- team1
444+
files:
445+
- source: path/to/file.txt
446+
dest: path/to/file.txt
447+
448+
user/repo2:
449+
assignees:
450+
- user3
451+
reviewers:
452+
- user4
453+
team_reviewers:
454+
- team2
455+
files:
456+
- source: path/to/file.txt
457+
dest: path/to/file.txt
458+
```
459+
460+
Repository-specific configurations take precedence over the global configuration provided in the workflow file.
461+
402462
### Custom GitHub Enterprise Host
403463

404464
If your target repository is hosted on a GitHub Enterprise Server you can specify a custom host name like this:

src/config.js

Lines changed: 48 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,35 @@ const parseFiles = (files) => {
198198
})
199199
}
200200

201+
const parseRepoConfig = (repoItem) => {
202+
let repoName = repoItem
203+
let repoConfig = {}
204+
205+
if (typeof repoItem === 'object' && repoItem !== null) {
206+
repoName = repoItem.name
207+
if (repoItem.assignees) repoConfig.assignees = Array.isArray(repoItem.assignees) ? repoItem.assignees : [repoItem.assignees]
208+
if (repoItem.reviewers) repoConfig.reviewers = Array.isArray(repoItem.reviewers) ? repoItem.reviewers : [repoItem.reviewers]
209+
if (repoItem.team_reviewers) repoConfig.team_reviewers = Array.isArray(repoItem.team_reviewers) ? repoItem.team_reviewers : [repoItem.team_reviewers]
210+
}
211+
212+
return { repoName, repoConfig }
213+
}
214+
215+
const addRepoToResult = (result, repoName, repoConfig, files) => {
216+
const repo = parseRepoName(repoName)
217+
218+
if (result[repo.uniqueName] !== undefined) {
219+
result[repo.uniqueName].files.push(...files)
220+
return
221+
}
222+
223+
result[repo.uniqueName] = {
224+
repo,
225+
files,
226+
...repoConfig
227+
}
228+
}
229+
201230
export async function parseConfig() {
202231
const fileContent = await fs.promises.readFile(context.CONFIG_PATH)
203232

@@ -213,35 +242,30 @@ export async function parseConfig() {
213242

214243
groups.forEach((group) => {
215244
const repos = typeof group.repos === 'string' ? group.repos.split('\n').map((n) => n.trim()).filter((n) => n) : group.repos
245+
const files = parseFiles(group.files)
216246

217-
repos.forEach((name) => {
218-
const files = parseFiles(group.files)
219-
const repo = parseRepoName(name)
220-
221-
if (result[repo.uniqueName] !== undefined) {
222-
result[repo.uniqueName].files.push(...files)
223-
return
224-
}
225-
226-
result[repo.uniqueName] = {
227-
repo,
228-
files
229-
}
247+
repos.forEach((repoItem) => {
248+
const { repoName, repoConfig } = parseRepoConfig(repoItem)
249+
addRepoToResult(result, repoName, repoConfig, files)
230250
})
231251
})
232252
} else {
233-
const files = parseFiles(configObject[key])
234-
const repo = parseRepoName(key)
235-
236-
if (result[repo.uniqueName] !== undefined) {
237-
result[repo.uniqueName].files.push(...files)
238-
return
239-
}
240-
241-
result[repo.uniqueName] = {
242-
repo,
243-
files
253+
let repoName = key
254+
let repoConfig = {}
255+
let repoFiles = configObject[key]
256+
257+
if (typeof configObject[key] === 'object' && configObject[key] !== null && configObject[key].files) {
258+
repoFiles = configObject[key].files
259+
const config = {
260+
name: repoName,
261+
...configObject[key]
262+
}
263+
const { repoConfig: parsedConfig } = parseRepoConfig(config)
264+
repoConfig = parsedConfig
244265
}
266+
267+
const files = parseFiles(repoFiles)
268+
addRepoToResult(result, repoName, repoConfig, files)
245269
}
246270
})
247271

src/index.js

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -179,19 +179,22 @@ async function run() {
179179
await git.addPrLabels(PR_LABELS)
180180
}
181181

182-
if (ASSIGNEES !== undefined && ASSIGNEES.length > 0 && !FORK) {
183-
core.info(`Adding assignee(s) "${ ASSIGNEES.join(', ') }" to PR`)
184-
await git.addPrAssignees(ASSIGNEES)
182+
const repoAssignees = item.assignees || ASSIGNEES
183+
if (repoAssignees !== undefined && repoAssignees.length > 0 && !FORK) {
184+
core.info(`Adding assignee(s) "${ repoAssignees.join(', ') }" to PR`)
185+
await git.addPrAssignees(repoAssignees)
185186
}
186187

187-
if (REVIEWERS !== undefined && REVIEWERS.length > 0 && !FORK) {
188-
core.info(`Adding reviewer(s) "${ REVIEWERS.join(', ') }" to PR`)
189-
await git.addPrReviewers(REVIEWERS)
188+
const repoReviewers = item.reviewers || REVIEWERS
189+
if (repoReviewers !== undefined && repoReviewers.length > 0 && !FORK) {
190+
core.info(`Adding reviewer(s) "${ repoReviewers.join(', ') }" to PR`)
191+
await git.addPrReviewers(repoReviewers)
190192
}
191193

192-
if (TEAM_REVIEWERS !== undefined && TEAM_REVIEWERS.length > 0 && !FORK) {
193-
core.info(`Adding team reviewer(s) "${ TEAM_REVIEWERS.join(', ') }" to PR`)
194-
await git.addPrTeamReviewers(TEAM_REVIEWERS)
194+
const repoTeamReviewers = item.team_reviewers || TEAM_REVIEWERS
195+
if (repoTeamReviewers !== undefined && repoTeamReviewers.length > 0 && !FORK) {
196+
core.info(`Adding team reviewer(s) "${ repoTeamReviewers.join(', ') }" to PR`)
197+
await git.addPrTeamReviewers(repoTeamReviewers)
195198
}
196199
}
197200

0 commit comments

Comments
 (0)