Skip to content

Commit c0bb2fd

Browse files
committed
manual merge
2 parents c59c99f + f436a7e commit c0bb2fd

8 files changed

Lines changed: 164 additions & 12 deletions

File tree

helm/safe-settings/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ A Helm chart for Kubernetes
3737
| nodeSelector | object | `{}` | |
3838
| podAnnotations | object | `{}` | |
3939
| podSecurityContext | object | `{}` | |
40+
| priorityClassName | string | `""` | Priority class name for the pod. |
4041
| replicaCount | int | `1` | |
4142
| resources | object | `{}` | |
4243
| securityContext.allowPrivilegeEscalation | bool | `false` | |

helm/safe-settings/templates/deployment.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,3 +77,6 @@ spec:
7777
tolerations:
7878
{{- toYaml . | nindent 8 }}
7979
{{- end }}
80+
{{- if .Values.priorityClassName }}
81+
priorityClassName: {{ .Values.priorityClassName }}
82+
{{- end }}

helm/safe-settings/values.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,8 @@ tolerations: []
118118

119119
affinity: {}
120120

121+
priorityClassName: ""
122+
121123
deploymentConfig:
122124
restrictedRepos:
123125
# You can exclude certain repos from safe-settings processing

lib/settings.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -949,14 +949,19 @@ class Settings {
949949
const RepoPlugin = Settings.PLUGINS.repository
950950

951951
const archivePlugin = new Archive(this.nop, this.github, repo, repoConfig, this.log)
952-
const { shouldArchive, shouldUnarchive } = await archivePlugin.getState()
952+
const { isArchived, shouldArchive, shouldUnarchive } = await archivePlugin.getState()
953953

954954
if (shouldUnarchive) {
955955
this.log.debug(`Unarchiving repo ${repo.repo}`)
956956
const unArchiveResults = await archivePlugin.sync()
957957
this.appendToResults(unArchiveResults)
958958
}
959959

960+
if (isArchived && !shouldUnarchive) {
961+
this.log.debug(`Skipping repo/child plugin updates for archived repo ${repo.repo}`)
962+
return
963+
}
964+
960965
const repoResults = await new RepoPlugin(this.nop, this.github, repo, repoConfig, this.installation_id, this.log, this.errors).sync()
961966
this.appendToResults(repoResults)
962967

package-lock.json

Lines changed: 14 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
"eslint-plugin-promise": "^6.6.0",
5050
"http-status-codes": "^2.2.0",
5151
"jest": "^29.5.0",
52-
"jest-junit": "^16.0.0",
52+
"jest-junit": "^17.0.0",
5353
"jest-when": "^3.5.2",
5454
"lockfile-lint": "^4.14.0",
5555
"nock": "^14.0.1",

test/unit/lib/plugins/archive.test.js

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,56 @@ describe('Archive Plugin', () => {
9393
})
9494
})
9595

96+
describe('getState', () => {
97+
it('getState when repo is already archived and desired state is not set returns isArchived true shouldArchive false shouldUnarchive false', async () => {
98+
// Arrange
99+
github.rest.repos.get.mockResolvedValue({ data: { archived: true } })
100+
archive = new Archive(false, github, repo, {}, log)
101+
102+
// Act
103+
const result = await archive.getState()
104+
105+
// Assert
106+
expect(result).toEqual({
107+
isArchived: true,
108+
shouldArchive: false,
109+
shouldUnarchive: false
110+
})
111+
})
112+
113+
it('getState when repo is not archived and desired state is not set returns isArchived false shouldArchive false shouldUnarchive false', async () => {
114+
// Arrange
115+
github.rest.repos.get.mockResolvedValue({ data: { archived: false } })
116+
archive = new Archive(false, github, repo, {}, log)
117+
118+
// Act
119+
const result = await archive.getState()
120+
121+
// Assert
122+
expect(result).toEqual({
123+
isArchived: false,
124+
shouldArchive: false,
125+
shouldUnarchive: false
126+
})
127+
})
128+
129+
it('getState when repo is archived and desired state is false returns isArchived true shouldArchive false shouldUnarchive true', async () => {
130+
// Arrange
131+
github.rest.repos.get.mockResolvedValue({ data: { archived: true } })
132+
archive = new Archive(false, github, repo, { archived: false }, log)
133+
134+
// Act
135+
const result = await archive.getState()
136+
137+
// Assert
138+
expect(result).toEqual({
139+
isArchived: true,
140+
shouldArchive: false,
141+
shouldUnarchive: true
142+
})
143+
})
144+
})
145+
96146
describe('sync', () => {
97147
beforeEach(() => {
98148
archive = new Archive(false, github, repo, settings, log)

test/unit/lib/settings.test.js

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -498,4 +498,91 @@ repository:
498498
handleResultsSpy.mockRestore()
499499
})
500500
})
501+
502+
describe('updateRepos - archived repo skipping', () => {
503+
const Archive = require('../../../lib/plugins/archive')
504+
505+
let settings
506+
let mockRepoSync
507+
let originalRepoPlugin
508+
509+
beforeEach(() => {
510+
// Preserve the original RepoPlugin so it can be restored after each test
511+
originalRepoPlugin = Settings.PLUGINS.repository
512+
513+
// Replace RepoPlugin with a mock constructor whose sync() we can assert on
514+
mockRepoSync = jest.fn().mockResolvedValue([])
515+
Settings.PLUGINS.repository = jest.fn().mockImplementation(() => ({
516+
sync: mockRepoSync
517+
}))
518+
519+
// Build a Settings instance that will enter the `if (repoConfig)` branch:
520+
// config.repository must be defined so repoConfig is truthy
521+
settings = new Settings(
522+
false,
523+
stubContext,
524+
{ owner: 'test-org', repo: 'test-repo' },
525+
{ repository: { name: 'test-repo' } },
526+
'main'
527+
)
528+
529+
// Pre-set subOrgConfigs so updateRepos() does not call the async getSubOrgConfigs()
530+
settings.subOrgConfigs = {}
531+
532+
// Pre-set repoConfigs so getRepoOverrideConfig() does not throw on undefined
533+
settings.repoConfigs = {}
534+
})
535+
536+
afterEach(() => {
537+
// Restore the real RepoPlugin and all prototype spies
538+
Settings.PLUGINS.repository = originalRepoPlugin
539+
jest.restoreAllMocks()
540+
})
541+
542+
it('updateRepos when repo is already archived and not being unarchived does not call RepoPlugin sync', async () => {
543+
// Arrange
544+
jest.spyOn(Archive.prototype, 'getState').mockResolvedValue({
545+
isArchived: true,
546+
shouldArchive: false,
547+
shouldUnarchive: false
548+
})
549+
550+
// Act
551+
await settings.updateRepos({ owner: 'test-org', repo: 'test-repo' })
552+
553+
// Assert
554+
expect(mockRepoSync).not.toHaveBeenCalled()
555+
})
556+
557+
it('updateRepos when repo is archived but is being unarchived calls RepoPlugin sync', async () => {
558+
// Arrange
559+
jest.spyOn(Archive.prototype, 'getState').mockResolvedValue({
560+
isArchived: true,
561+
shouldArchive: false,
562+
shouldUnarchive: true
563+
})
564+
jest.spyOn(Archive.prototype, 'sync').mockResolvedValue([])
565+
566+
// Act
567+
await settings.updateRepos({ owner: 'test-org', repo: 'test-repo' })
568+
569+
// Assert
570+
expect(mockRepoSync).toHaveBeenCalledTimes(1)
571+
})
572+
573+
it('updateRepos when repo is not archived calls RepoPlugin sync', async () => {
574+
// Arrange
575+
jest.spyOn(Archive.prototype, 'getState').mockResolvedValue({
576+
isArchived: false,
577+
shouldArchive: false,
578+
shouldUnarchive: false
579+
})
580+
581+
// Act
582+
await settings.updateRepos({ owner: 'test-org', repo: 'test-repo' })
583+
584+
// Assert
585+
expect(mockRepoSync).toHaveBeenCalledTimes(1)
586+
})
587+
}) // updateRepos - archived repo skipping
501588
}) // Settings Tests

0 commit comments

Comments
 (0)