-
Notifications
You must be signed in to change notification settings - Fork 216
feat(config): add CONFIG_REF environment variable for scheduled syncs
#1020
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
tdabasinskas
wants to merge
2
commits into
github-community-projects:main-enterprise
Choose a base branch
from
datolabs-io:feat/config-ref
base: main-enterprise
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+92
−2
Open
Changes from 1 commit
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,12 +1,13 @@ | ||
| module.exports = { | ||
| ADMIN_REPO: process.env.ADMIN_REPO || 'admin', | ||
| CONFIG_PATH: process.env.CONFIG_PATH || '.github', | ||
| CONFIG_REF: process.env.CONFIG_REF, | ||
| SETTINGS_FILE_PATH: process.env.SETTINGS_FILE_PATH || 'settings.yml', | ||
| DEPLOYMENT_CONFIG_FILE_PATH: process.env.DEPLOYMENT_CONFIG_FILE || 'deployment-settings.yml', | ||
| CREATE_PR_COMMENT: process.env.CREATE_PR_COMMENT || 'true', | ||
| CREATE_ERROR_ISSUE: process.env.CREATE_ERROR_ISSUE || 'true', | ||
| BLOCK_REPO_RENAME_BY_HUMAN: process.env.BLOCK_REPO_RENAME_BY_HUMAN || 'false', | ||
| FULL_SYNC_NOP: process.env.FULL_SYNC_NOP === 'true', | ||
| GHE_HOST: process.env.GHE_HOST, | ||
| GHE_PROTOCOL: process.env.GHE_PROTOCOL, | ||
| GHE_PROTOCOL: process.env.GHE_PROTOCOL | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| /* eslint-disable no-undef */ | ||
|
|
||
| // Tests for the syncInstallation path in index.js, which serves scheduled | ||
| // (CRON) and full-sync runs. The app factory takes Settings as an injectable | ||
| // parameter, so the sync can be observed without touching the GitHub API. | ||
| describe('syncInstallation', () => { | ||
| const installation = { id: 123, account: { login: 'test-org' } } | ||
| let robot | ||
| let settingsMock | ||
|
|
||
| function buildRobot () { | ||
| const content = Buffer.from('restrictedRepos: []').toString('base64') | ||
| const github = { | ||
| paginate: jest.fn().mockResolvedValue([installation]), | ||
| rest: { | ||
| apps: { | ||
| listInstallations: { endpoint: { merge: jest.fn().mockReturnValue({}) } }, | ||
| getAuthenticated: jest.fn().mockResolvedValue({ data: { slug: 'safe-settings' } }) | ||
| }, | ||
| repos: { | ||
| getContent: jest.fn().mockResolvedValue({ data: { content } }) | ||
| } | ||
| } | ||
| } | ||
| return { | ||
| log: Object.assign(jest.fn(), { | ||
| debug: jest.fn(), | ||
| trace: jest.fn(), | ||
| info: jest.fn(), | ||
| error: jest.fn() | ||
| }), | ||
| auth: jest.fn().mockResolvedValue(github), | ||
| on: jest.fn(), | ||
| github | ||
| } | ||
| } | ||
|
|
||
| function loadApp () { | ||
| let app | ||
| jest.isolateModules(() => { | ||
| const appFn = require('../../index') | ||
| app = appFn(robot, {}, settingsMock) | ||
| }) | ||
| return app | ||
| } | ||
|
|
||
| beforeEach(() => { | ||
| robot = buildRobot() | ||
| settingsMock = { | ||
| syncAll: jest.fn().mockResolvedValue({}), | ||
| handleError: jest.fn().mockResolvedValue({}) | ||
| } | ||
| }) | ||
|
|
||
| afterEach(() => { | ||
| delete process.env.CONFIG_REF | ||
| }) | ||
|
|
||
| describe('when CONFIG_REF is not set', () => { | ||
| it('reads the config from the default branch and passes no ref to syncAll', async () => { | ||
| const app = loadApp() | ||
|
|
||
| await app.syncInstallation() | ||
|
|
||
| expect(robot.github.rest.repos.getContent).toHaveBeenCalledWith(expect.objectContaining({ ref: undefined })) | ||
| expect(settingsMock.syncAll).toHaveBeenCalledTimes(1) | ||
| expect(settingsMock.syncAll.mock.calls[0][4]).toBeUndefined() | ||
| }) | ||
| }) | ||
|
|
||
| describe('when CONFIG_REF is set', () => { | ||
| it('reads the config from that ref and passes it through to syncAll', async () => { | ||
| process.env.CONFIG_REF = 'my-config-branch' | ||
| const app = loadApp() | ||
|
|
||
| await app.syncInstallation() | ||
|
|
||
| expect(robot.github.rest.repos.getContent).toHaveBeenCalledWith(expect.objectContaining({ ref: 'my-config-branch' })) | ||
| expect(settingsMock.syncAll).toHaveBeenCalledTimes(1) | ||
| expect(settingsMock.syncAll.mock.calls[0][4]).toBe('my-config-branch') | ||
| }) | ||
| }) | ||
| }) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.