Skip to content
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

next major version #855

Merged
merged 53 commits into from
Feb 26, 2024
Merged
Show file tree
Hide file tree
Changes from 52 commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
0c32d5f
test(integration): added a cucumber test for granting team access
travi Jan 24, 2024
14ba5f7
test(integration): added a cucumber test for updating team access
travi Jan 24, 2024
0e0655a
test(integration): added a cucumber test for revoking team access
travi Jan 24, 2024
1f1632e
test(integration): removed jest integration test for teams now that c…
travi Jan 24, 2024
6194970
test(integration): migrated the integration tests of collaborators to…
travi Jan 24, 2024
0079094
test(integration): added a cucumber test for adding a label
travi Jan 26, 2024
d6c6d36
test(integration): added a cucumber test for added a label with color…
travi Jan 26, 2024
8501159
test(integration): added a cucumber test for updating a label color
travi Jan 26, 2024
0d42bfd
test(integration): added a cucumber test for removing a label
travi Jan 26, 2024
e60a151
test(integration): captured additional scenarios for labels
travi Jan 26, 2024
73c07fa
test(integration): removed jest integration test for labels
travi Jan 26, 2024
fcd5ca2
test(cucumber): downgraded to v9 to bring back v16 support for now
travi Jan 26, 2024
cba9f97
test(integration): captured more labels scenarios
travi Jan 27, 2024
3e537fe
feat(node-versions): dropped support for node v16, v17, and v19
travi Jan 27, 2024
246eb61
ci(node-versions): updated the verification matrix to match the updat…
travi Jan 27, 2024
f4136bb
Merge branch 'beta' of github.com:repository-settings/app into cucumb…
travi Jan 27, 2024
3066f06
test(integration): added a cucumber test for adding a milestone
travi Jan 27, 2024
0e78f26
test(integration): added a scenario for updating a milestone
travi Jan 30, 2024
57c7f76
test(integration): added a scenario for deleting a milestone
travi Jan 30, 2024
f7f7473
test(integration): removed the jest tests for milestones now that the…
travi Jan 30, 2024
431de8b
test(integration): removed the wip tag from the delete-milestone scen…
travi Feb 9, 2024
f039855
test(msw): reset handlers between tests
travi Feb 9, 2024
7b575a8
test(integration): defined scenarios for scenarios that do not trigge…
travi Feb 9, 2024
b8154c7
test(integration): covered the remaining scenarios that do not trigge…
travi Feb 9, 2024
59fe456
test(integration): named the repository-events steps file more clearly
travi Feb 9, 2024
cbde318
test(integration): defined basic scenarios for environments
travi Feb 9, 2024
cd98c1f
docs(environments): improved the wrapping of the environments config …
travi Feb 9, 2024
eef6dee
test(integration): pinned the behavior of updating an environment res…
travi Feb 16, 2024
349e785
test(integration): pinned the behavior of deleting a environment
travi Feb 16, 2024
fb164a5
test(integration): defined remaining scenarios for pinning environmen…
travi Feb 16, 2024
d6a259e
test(integration): pinned the behavior for defining an environment wi…
travi Feb 16, 2024
0f8b83b
test(integration): pinned the behavior of updating an environment rev…
travi Feb 16, 2024
1fa1656
test(integration): pinned the behavior of updating the id of an envir…
travi Feb 16, 2024
6e7ecfe
test(integration): pinned the behavior of defining basic repository c…
travi Feb 16, 2024
7006e29
test(integration): pinned behavior of updating repository topics
travi Feb 17, 2024
b6c971c
test(integration): pinned the behavior of enabling/disabling vulnerab…
travi Feb 17, 2024
a829cc9
test(integration): pinned the behaviors of enabling/disabling securit…
travi Feb 17, 2024
d5898ee
test(integration): pinned the behavior of adding a reviewer to an env…
travi Feb 17, 2024
405083e
test(integration): pinned behavior of removing an environment reviewer
travi Feb 19, 2024
fb8f322
test(integration): pinned creating env w/ branch policies
julekirk Feb 19, 2024
352f163
test(integration): pinned add branch policy to existing env
julekirk Feb 19, 2024
a3d1ffc
test(integration): pinned switching deployment branch policy type
julekirk Feb 19, 2024
6ab7834
Merge pull request #868 from julekirk/cucumber-msw
travi Feb 20, 2024
117188e
test(integration): pinned no sync when reviewers are already in sync
julekirk Feb 20, 2024
1b02660
test(integration): pinning deployment branch policy update avoidance
julekirk Feb 20, 2024
35d7b35
Merge pull request #870 from julekirk/cucumber-msw
travi Feb 20, 2024
39dae4f
test(integration): pinned updated avoidance for undefined wait_timer …
travi Feb 20, 2024
d7bc853
test(integration): cleaned up remaining jest details after finishing …
travi Feb 20, 2024
bdca6a3
Merge pull request #854 from repository-settings/cucumber-msw
travi Feb 21, 2024
9ebbbd2
feat(deps): upgraded to probot v13
travi Feb 21, 2024
74df26c
Merge branch 'master' of github.com:repository-settings/app into beta
travi Feb 21, 2024
7ce4ab7
chore(deps): removed nock now that it is replaced by msw
travi Feb 21, 2024
561cfeb
Merge branch 'master' of github.com:repository-settings/app into beta
travi Feb 25, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/node-ci.yml
Expand Up @@ -3,6 +3,7 @@ name: Node.js CI
push:
branches:
- master
- beta
- renovate/**
pull_request:
types:
Expand All @@ -14,9 +15,8 @@ jobs:
strategy:
matrix:
node:
- 16.0.0
- 18
- 20
- 18.17.0
- 20.6.1
steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
- name: Setup node
Expand Down
21 changes: 21 additions & 0 deletions cucumber.mjs
@@ -0,0 +1,21 @@
const base = {
formatOptions: { snippetInterface: 'async-await' },
import: ['test/integration/features/**/*.mjs']
}

export default base

export const wip = {
...base,
tags: '@wip and not @skip'
}

export const noWip = {
...base,
tags: 'not @skip and not @wip'
}

export const focus = {
...base,
tags: '@focus'
}
6 changes: 5 additions & 1 deletion docs/configuration.md
Expand Up @@ -103,7 +103,11 @@ collaborators:
# * `triage` - Recommended for contributors who need to proactively manage issues and pull requests without write access.

# See https://docs.github.com/en/rest/deployments/environments#create-or-update-an-environment for available options
# Note: deployment_branch_policy differs from the API for ease of use. Either protected_branches (boolean) OR custom_branches (array of strings) can be provided; this will manage the API requirements under the hood. See https://docs.github.com/en/rest/deployments/branch-policies for documentation of custom_branches. If both are provided in an unexpected manner, protected_branches will be used.
# Note: deployment_branch_policy differs from the API for ease of use.
# Either protected_branches (boolean) OR custom_branches (array of strings) can be provided;
# this will manage the API requirements under the hood.
# See https://docs.github.com/en/rest/deployments/branch-policies for documentation of custom_branches.
# If both are provided in an unexpected manner, protected_branches will be used.
# Either removing or simply not setting deployment_branch_policy will restore the default 'All branches' setting.
environments:
- name: production
Expand Down
117 changes: 69 additions & 48 deletions lib/plugins/environments.js
Expand Up @@ -2,6 +2,62 @@ const Diffable = require('./diffable')

const environmentRepoEndpoint = '/repos/:org/:repo/environments/:environment_name'

function shouldUseProtectedBranches (protectedBranches, customBranchPolicies) {
return !!(protectedBranches || customBranchPolicies === undefined || customBranchPolicies === null)
}

function attributeSorter (a, b) {
if (a.id < b.id) return -1
if (a.id > b.id) return 1
if (a.type < b.type) return -1
if (a.type > b.type) return 1
return 0
}

function reviewersToString (reviewers) {
if (reviewers === null || reviewers === undefined) {
return ''
} else {
reviewers.sort(attributeSorter)

return JSON.stringify(
reviewers.map(reviewer => {
return {
id: reviewer.id,
type: reviewer.type
}
})
)
}
}

function deploymentBranchPolicyToString (attrs) {
if (attrs === null || attrs === undefined) {
return ''
} else {
return JSON.stringify(
shouldUseProtectedBranches(attrs.protected_branches, attrs.custom_branches)
? { protected_branches: true }
: { custom_branches: attrs.custom_branches.sort() }
)
}
}

function waitTimerHasChanged (existing, attrs) {
return (existing.wait_timer || 0) !== attrs.wait_timer
}

function reviewersHasChanged (existing, attrs) {
return reviewersToString(existing.reviewers) !== reviewersToString(attrs.reviewers)
}

function deploymentBranchPolicyHasChanged (existing, attrs) {
return (
deploymentBranchPolicyToString(existing.deployment_branch_policy) !==
deploymentBranchPolicyToString(attrs.deployment_branch_policy)
)
}

module.exports = class Environments extends Diffable {
constructor (...args) {
super(...args)
Expand All @@ -21,6 +77,7 @@ module.exports = class Environments extends Diffable {
org: this.repo.owner,
repo: this.repo.repo
})

return Promise.all(
environments.map(async environment => {
if (environment.deployment_branch_policy) {
Expand All @@ -39,6 +96,7 @@ module.exports = class Environments extends Diffable {
}
}
}

return {
...environment,
// Force all names to lowercase to avoid comparison issues.
Expand All @@ -54,17 +112,18 @@ module.exports = class Environments extends Diffable {

changed (existing, attrs) {
if (!attrs.wait_timer) attrs.wait_timer = 0

return (
(existing.wait_timer || 0) !== attrs.wait_timer ||
this.reviewersToString(existing.reviewers) !== this.reviewersToString(attrs.reviewers) ||
this.deploymentBranchPolicyToString(existing.deployment_branch_policy) !==
this.deploymentBranchPolicyToString(attrs.deployment_branch_policy)
waitTimerHasChanged(existing, attrs) ||
reviewersHasChanged(existing, attrs) ||
deploymentBranchPolicyHasChanged(existing, attrs)
)
}

async update (existing, attrs) {
if (existing.deployment_branch_policy && existing.deployment_branch_policy.custom_branches) {
const branchPolicies = await this.getDeploymentBranchPolicies(this.repo.owner, this.repo.repo, existing.name)

await Promise.all(
branchPolicies.map(branchPolicy =>
this.github.request(
Expand All @@ -79,15 +138,17 @@ module.exports = class Environments extends Diffable {
)
)
}

return this.add(attrs)
}

async add (attrs) {
await this.github.request(`PUT ${environmentRepoEndpoint}`, this.toParams({ name: attrs.name }, attrs))

if (attrs.deployment_branch_policy && attrs.deployment_branch_policy.custom_branches) {
await Promise.all(
attrs.deployment_branch_policy.custom_branches.map(name =>
this.github.request(`POST /repos/:org/:repo/environments/:environment_name/deployment-branch-policies`, {
this.github.request('POST /repos/:org/:repo/environments/:environment_name/deployment-branch-policies', {
org: this.repo.owner,
repo: this.repo.repo,
environment_name: attrs.name,
Expand All @@ -106,40 +167,6 @@ module.exports = class Environments extends Diffable {
})
}

reviewersToString (attrs) {
if (attrs === null || attrs === undefined) {
return ''
} else {
attrs.sort((a, b) => {
if (a.id < b.id) return -1
if (a.id > b.id) return 1
if (a.type < b.type) return -1
if (a.type > b.type) return 1
return 0
})
return JSON.stringify(
attrs.map(reviewer => {
return {
id: reviewer.id,
type: reviewer.type
}
})
)
}
}

deploymentBranchPolicyToString (attrs) {
if (attrs === null || attrs === undefined) {
return ''
} else {
return JSON.stringify(
this.shouldUseProtectedBranches(attrs.protected_branches, attrs.custom_branches)
? { protected_branches: true }
: { custom_branches: attrs.custom_branches.sort() }
)
}
}

async getDeploymentBranchPolicies (owner, repo, environmentName) {
const {
data: { branch_policies: branchPolicies }
Expand All @@ -148,18 +175,20 @@ module.exports = class Environments extends Diffable {
repo,
environment_name: environmentName
})

return branchPolicies
}

toParams (existing, attrs) {
const deploymentBranchPolicy = attrs.deployment_branch_policy
? this.shouldUseProtectedBranches(
? shouldUseProtectedBranches(
attrs.deployment_branch_policy.protected_branches,
attrs.deployment_branch_policy.custom_branches
)
? { protected_branches: true, custom_branch_policies: false }
: { protected_branches: false, custom_branch_policies: true }
: null

return {
environment_name: existing.name,
repo: this.repo.repo,
Expand All @@ -169,12 +198,4 @@ module.exports = class Environments extends Diffable {
deployment_branch_policy: deploymentBranchPolicy
}
}

shouldUseProtectedBranches (protectedBranches, customBranchPolicies) {
if (protectedBranches || customBranchPolicies === undefined || customBranchPolicies === null) {
return true // Returning booleans like this to avoid unexpected datatypes that result in truthy values
} else {
return false
}
}
}