Skip to content

Commit 45a68fa

Browse files
committed
fix: prevent race conditions by creating new objects for repository configurations
Signed-off-by: Jan Bronicki <janbronicki@microsoft.com>
1 parent 829bc8b commit 45a68fa

2 files changed

Lines changed: 6 additions & 4 deletions

File tree

lib/plugins/repository.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ const ignorableFields = [
77
'id',
88
'node_id',
99
'full_name',
10+
'name',
1011
'private',
1112
'fork',
1213
'created_at',

lib/settings.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -327,11 +327,11 @@ ${this.results.reduce((x, y) => {
327327

328328
async updateRepos (repo) {
329329
this.subOrgConfigs = this.subOrgConfigs || await this.getSubOrgConfigs()
330-
// Keeping this as is instead of doing an object assign as that would cause `Cannot read properties of undefined (reading 'startsWith')` error
331-
// Copilot code review would recoommend using object assign but that would cause the error
330+
// Create a new object to avoid mutating the shared this.config.repository
331+
// This prevents race conditions when multiple repos are processed concurrently via Promise.all
332332
let repoConfig = this.config.repository
333333
if (repoConfig) {
334-
repoConfig = Object.assign(repoConfig, { name: repo.repo, org: repo.owner })
334+
repoConfig = Object.assign({}, repoConfig, { name: repo.repo, org: repo.owner })
335335
}
336336

337337
const subOrgConfig = this.getSubOrgConfig(repo.repo)
@@ -347,7 +347,8 @@ ${this.results.reduce((x, y) => {
347347
if (subOrgConfig) {
348348
let suborgRepoConfig = subOrgConfig.repository
349349
if (suborgRepoConfig) {
350-
suborgRepoConfig = Object.assign(suborgRepoConfig, { name: repo.repo, org: repo.owner })
350+
// Create a new object to avoid mutating the shared subOrgConfig.repository
351+
suborgRepoConfig = Object.assign({}, suborgRepoConfig, { name: repo.repo, org: repo.owner })
351352
repoConfig = this.mergeDeep.mergeDeep({}, repoConfig, suborgRepoConfig)
352353
}
353354
}

0 commit comments

Comments
 (0)