Skip to content

Commit

Permalink
Merge branch 'repository-settings:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
rmtkcjs authored Jul 22, 2024
2 parents 04bf9c2 + 1a7a412 commit 034c850
Show file tree
Hide file tree
Showing 38 changed files with 4,328 additions and 1,441 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/node-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ jobs:
- 18.17.0
- 20.6.1
steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
- name: Setup node
uses: actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8 # v4.0.2
uses: actions/setup-node@1e60f620b9541d16bece96c5465dc8ee9832be0b # v4.0.3
with:
node-version: ${{ matrix.node }}
cache: npm
Expand All @@ -29,9 +29,9 @@ jobs:
verify-dev:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
- name: Setup node
uses: actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8 # v4.0.2
uses: actions/setup-node@1e60f620b9541d16bece96c5465dc8ee9832be0b # v4.0.3
with:
node-version-file: .nvmrc
cache: npm
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ jobs:
name: release
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
- uses: actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8 # v4.0.2
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
- uses: actions/setup-node@1e60f620b9541d16bece96c5465dc8ee9832be0b # v4.0.3
with:
node-version-file: .nvmrc
cache: npm
- run: npm clean-install
- run: corepack npm audit signatures
- run: npx semantic-release@23.0.7
- run: npx semantic-release@24.0.0
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.REPOSITORY_SETTINGS_BOT_NPM_TOKEN }}
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
20.12.1
20.15.1
6 changes: 3 additions & 3 deletions api/github/webhooks/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
const { createNodeMiddleware, createProbot } = require('probot')
import { createNodeMiddleware, createProbot } from 'probot'

const app = require('../../../')
import app from '../../../index.js'

module.exports = createNodeMiddleware(app, {
export default createNodeMiddleware(app, {
probot: createProbot(),
webhooksPath: '/api/github/webhooks'
})
File renamed without changes.
4 changes: 4 additions & 0 deletions docs/plugins/environments.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,8 @@ environments:
custom_branches:
- main
- dev/*
- name: release/*
type: branch
- name: v*
type: tag
```
5 changes: 3 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
const mergeArrayByName = require('./lib/mergeArrayByName')
import mergeArrayByName from './lib/mergeArrayByName.js'
import SettingsApp from './lib/settings.js'

/**
* @param {import('probot').Probot} robot
*/
module.exports = (robot, _, Settings = require('./lib/settings')) => {
export default (robot, _, Settings = SettingsApp) => {
async function syncSettings (context, repo = context.repo()) {
const config = await context.config('settings.yml', {}, { arrayMerge: mergeArrayByName })
return Settings.sync(context.octokit, repo, config)
Expand Down
6 changes: 2 additions & 4 deletions lib/mergeArrayByName.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// https://github.com/KyleAMathews/deepmerge#arraymerge

const merge = require('deepmerge')
import merge from 'deepmerge'

function findMatchingIndex (sourceItem, target) {
if (Object.prototype.hasOwnProperty.call(sourceItem, 'name')) {
Expand All @@ -10,7 +10,7 @@ function findMatchingIndex (sourceItem, target) {
}
}

function mergeByName (target, source, options) {
export default function mergeByName (target, source, options) {
const destination = target.slice()

source.forEach(sourceItem => {
Expand All @@ -24,5 +24,3 @@ function mergeByName (target, source, options) {

return destination
}

module.exports = mergeByName
2 changes: 1 addition & 1 deletion lib/plugins/branches.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const previewHeaders = {
'application/vnd.github.hellcat-preview+json,application/vnd.github.luke-cage-preview+json,application/vnd.github.zzzax-preview+json'
}

module.exports = class Branches {
export default class Branches {
constructor (github, repo, settings) {
this.github = github
this.repo = repo
Expand Down
4 changes: 2 additions & 2 deletions lib/plugins/collaborators.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const Diffable = require('./diffable')
import Diffable from './diffable.js'

module.exports = class Collaborators extends Diffable {
export default class Collaborators extends Diffable {
constructor (...args) {
super(...args)

Expand Down
2 changes: 1 addition & 1 deletion lib/plugins/diffable.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
// remove(existing) {
// }
// }
module.exports = class Diffable {
export default class Diffable {
constructor (github, repo, entries) {
this.github = github
this.repo = repo
Expand Down
26 changes: 20 additions & 6 deletions lib/plugins/environments.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const Diffable = require('./diffable')
import Diffable from './diffable.js'

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

Expand Down Expand Up @@ -38,7 +38,9 @@ function deploymentBranchPolicyToString (attrs) {
return JSON.stringify(
shouldUseProtectedBranches(attrs.protected_branches, attrs.custom_branches)
? { protected_branches: true }
: { custom_branches: attrs.custom_branches.sort() }
: {
custom_branches: attrs.custom_branches.sort((a, b) => JSON.stringify(a).localeCompare(JSON.stringify(b)))
}
)
}
}
Expand All @@ -58,14 +60,22 @@ function deploymentBranchPolicyHasChanged (existing, attrs) {
)
}

module.exports = class Environments extends Diffable {
export default class Environments extends Diffable {
constructor (...args) {
super(...args)

if (this.entries) {
// Force all names to lowercase to avoid comparison issues.
this.entries.forEach(environment => {
environment.name = environment.name.toLowerCase()
if (environment.deployment_branch_policy && environment.deployment_branch_policy.custom_branches) {
environment.deployment_branch_policy.custom_branches = environment.deployment_branch_policy.custom_branches.map(
rule => ({
name: rule.name || rule,
type: rule.type || 'branch'
})
)
}
})
}
}
Expand All @@ -88,7 +98,10 @@ module.exports = class Environments extends Diffable {
environment.name
)
environment.deployment_branch_policy = {
custom_branches: branchPolicies.map(_ => _.name)
custom_branches: branchPolicies.map(_ => ({
name: _.name,
type: _.type
}))
}
} else {
environment.deployment_branch_policy = {
Expand Down Expand Up @@ -147,12 +160,13 @@ module.exports = class Environments extends Diffable {

if (attrs.deployment_branch_policy && attrs.deployment_branch_policy.custom_branches) {
await Promise.all(
attrs.deployment_branch_policy.custom_branches.map(name =>
attrs.deployment_branch_policy.custom_branches.map(rule =>
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,
name
name: rule.name,
type: rule.type
})
)
)
Expand Down
4 changes: 2 additions & 2 deletions lib/plugins/labels.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const Diffable = require('./diffable')
import Diffable from './diffable.js'
const previewHeaders = { accept: 'application/vnd.github.symmetra-preview+json' }

module.exports = class Labels extends Diffable {
export default class Labels extends Diffable {
constructor (...args) {
super(...args)

Expand Down
4 changes: 2 additions & 2 deletions lib/plugins/milestones.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const Diffable = require('./diffable')
import Diffable from './diffable.js'

module.exports = class Milestones extends Diffable {
export default class Milestones extends Diffable {
constructor (...args) {
super(...args)

Expand Down
2 changes: 1 addition & 1 deletion lib/plugins/repository.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const enableVulnerabilityAlerts = ({ github, settings, enabled }) => {
return github.repos[methodName](args)
}

module.exports = class Repository {
export default class Repository {
constructor (github, repo, settings) {
this.github = github
this.settings = Object.assign({ mediaType: { previews: ['baptiste'] } }, settings, repo)
Expand Down
4 changes: 2 additions & 2 deletions lib/plugins/teams.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
const Diffable = require('./diffable')
import Diffable from './diffable.js'

// it is necessary to use this endpoint until GitHub Enterprise supports
// the modern version under /orgs
const teamRepoEndpoint = '/teams/:team_id/repos/:owner/:repo'

module.exports = class Teams extends Diffable {
export default class Teams extends Diffable {
find () {
return this.github.repos.listTeams(this.repo).then(res => res.data)
}
Expand Down
26 changes: 16 additions & 10 deletions lib/settings.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
class Settings {
import Repository from './plugins/repository.js'
import Labels from './plugins/labels.js'
import Collaborators from './plugins/collaborators.js'
import Teams from './plugins/teams.js'
import Milestones from './plugins/milestones.js'
import Branches from './plugins/branches.js'
import Environments from './plugins/environments.js'

export default class Settings {
static sync (github, repo, config) {
return new Settings(github, repo, config).update()
}
Expand Down Expand Up @@ -35,13 +43,11 @@ class Settings {
Settings.FILE_NAME = '.github/settings.yml'

Settings.PLUGINS = {
repository: require('./plugins/repository'),
labels: require('./plugins/labels'),
collaborators: require('./plugins/collaborators'),
environments: require('./plugins/environments'),
teams: require('./plugins/teams'),
milestones: require('./plugins/milestones'),
branches: require('./plugins/branches')
repository: Repository,
labels: Labels,
collaborators: Collaborators,
teams: Teams,
milestones: Milestones,
branches: Branches,
environments: Environments
}

module.exports = Settings
Loading

0 comments on commit 034c850

Please sign in to comment.