Skip to content

Commit

Permalink
feat(rulesets): initial support repository rulesets (semi-dark releas…
Browse files Browse the repository at this point in the history
…e with the potential for breaking changes) (#1029)
  • Loading branch information
travi authored Sep 17, 2024
1 parent 33c8d29 commit 74919bf
Show file tree
Hide file tree
Showing 9 changed files with 327 additions and 38 deletions.
59 changes: 59 additions & 0 deletions docs/plugins/rulesets.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# Repository Rulesets

> [!WARNING]
> Support for Repository Rulesets is still under development.
> Details may still change, like how the configuration is defined in the `settings.yml`.
> Please follow [#732](https://github.com/repository-settings/app/issues/732) for progress updates.
> Feedback is appreciated, but adopt cautiously, with the expectation of breaking changes until support is fully released.
See https://docs.github.com/en/rest/repos/rules#update-a-repository-ruleset for
all available ruleset properties and a description of each.

```yaml
rulesets:
- name: prevent destruction of the default branch
target: branch
enforcement: active
conditions:
ref_name:
include:
- "~DEFAULT_BRANCH"
rules:
- type: deletion
- type: non_fast_forward

- name: verification must pass
target: branch
enforcement: active
conditions:
ref_name:
include:
- "~DEFAULT_BRANCH"
rules:
- type: required_status_checks
parameters:
required_status_checks:
- context: test
integration_id: 123456
bypass_actors:
- actor_id: 5
actor_type: RepositoryRole
bypass_mode: pull_request

- name: changes must be reviewed
target: branch
enforcement: active
conditions:
ref_name:
include:
- "~DEFAULT_BRANCH"
rules:
- type: pull_request
parameters:
required_approving_review_count: 1
require_code_owner_review: true
bypass_actors:
- actor_id: 654321
actor_type: Integration
bypass_mode: always
```
4 changes: 1 addition & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,5 @@ export default (robot, _, Settings = SettingsApp) => {
return syncSettings(context)
})

robot.on('repository.created', async context => {
return syncSettings(context)
})
robot.on('repository.created', async context => syncSettings(context))
}
31 changes: 31 additions & 0 deletions lib/plugins/rulesets.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import deepEqual from 'deep-equal'

import Diffable from './diffable.js'

export default class Rulesets extends Diffable {
async find () {
const { data: rulesets } = await this.github.repos.getRepoRulesets(this.repo)

return rulesets
}

comparator (existing, attrs) {
return existing.name === attrs.name
}

changed (existing, attrs) {
return !deepEqual(existing, attrs)
}

update (existing, attrs) {
return this.github.repos.updateRepoRuleset({ ...this.repo, ruleset_id: existing.ruleset_id, ...attrs })
}

remove (existing) {
return this.github.repos.deleteRepoRuleset({ ...this.repo, ruleset_id: existing.ruleset_id })
}

async add (attrs) {
await this.github.repos.createRepoRuleset({ ...this.repo, ...attrs })
}
}
4 changes: 3 additions & 1 deletion lib/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import Teams from './plugins/teams.js'
import Milestones from './plugins/milestones.js'
import Branches from './plugins/branches.js'
import Environments from './plugins/environments.js'
import Rulesets from './plugins/rulesets.js'

export default class Settings {
static sync (github, repo, config) {
Expand Down Expand Up @@ -49,5 +50,6 @@ Settings.PLUGINS = {
teams: Teams,
milestones: Milestones,
branches: Branches,
environments: Environments
environments: Environments,
rulesets: Rulesets
}
Loading

0 comments on commit 74919bf

Please sign in to comment.