@repository-settings/app 3.0.0-beta.1 → 3.0.0-beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,6 +2,62 @@ const Diffable = require('./diffable')
2
2
 
3
3
  const environmentRepoEndpoint = '/repos/:org/:repo/environments/:environment_name'
4
4
 
5
+ function shouldUseProtectedBranches (protectedBranches, customBranchPolicies) {
6
+ return !!(protectedBranches || customBranchPolicies === undefined || customBranchPolicies === null)
7
+ }
8
+
9
+ function attributeSorter (a, b) {
10
+ if (a.id < b.id) return -1
11
+ if (a.id > b.id) return 1
12
+ if (a.type < b.type) return -1
13
+ if (a.type > b.type) return 1
14
+ return 0
15
+ }
16
+
17
+ function reviewersToString (reviewers) {
18
+ if (reviewers === null || reviewers === undefined) {
19
+ return ''
20
+ } else {
21
+ reviewers.sort(attributeSorter)
22
+
23
+ return JSON.stringify(
24
+ reviewers.map(reviewer => {
25
+ return {
26
+ id: reviewer.id,
27
+ type: reviewer.type
28
+ }
29
+ })
30
+ )
31
+ }
32
+ }
33
+
34
+ function deploymentBranchPolicyToString (attrs) {
35
+ if (attrs === null || attrs === undefined) {
36
+ return ''
37
+ } else {
38
+ return JSON.stringify(
39
+ shouldUseProtectedBranches(attrs.protected_branches, attrs.custom_branches)
40
+ ? { protected_branches: true }
41
+ : { custom_branches: attrs.custom_branches.sort() }
42
+ )
43
+ }
44
+ }
45
+
46
+ function waitTimerHasChanged (existing, attrs) {
47
+ return (existing.wait_timer || 0) !== attrs.wait_timer
48
+ }
49
+
50
+ function reviewersHasChanged (existing, attrs) {
51
+ return reviewersToString(existing.reviewers) !== reviewersToString(attrs.reviewers)
52
+ }
53
+
54
+ function deploymentBranchPolicyHasChanged (existing, attrs) {
55
+ return (
56
+ deploymentBranchPolicyToString(existing.deployment_branch_policy) !==
57
+ deploymentBranchPolicyToString(attrs.deployment_branch_policy)
58
+ )
59
+ }
60
+
5
61
  module.exports = class Environments extends Diffable {
6
62
  constructor (...args) {
7
63
  super(...args)
@@ -21,6 +77,7 @@ module.exports = class Environments extends Diffable {
21
77
  org: this.repo.owner,
22
78
  repo: this.repo.repo
23
79
  })
80
+
24
81
  return Promise.all(
25
82
  environments.map(async environment => {
26
83
  if (environment.deployment_branch_policy) {
@@ -39,6 +96,7 @@ module.exports = class Environments extends Diffable {
39
96
  }
40
97
  }
41
98
  }
99
+
42
100
  return {
43
101
  ...environment,
44
102
  // Force all names to lowercase to avoid comparison issues.
@@ -54,17 +112,18 @@ module.exports = class Environments extends Diffable {
54
112
 
55
113
  changed (existing, attrs) {
56
114
  if (!attrs.wait_timer) attrs.wait_timer = 0
115
+
57
116
  return (
58
- (existing.wait_timer || 0) !== attrs.wait_timer ||
59
- this.reviewersToString(existing.reviewers) !== this.reviewersToString(attrs.reviewers) ||
60
- this.deploymentBranchPolicyToString(existing.deployment_branch_policy) !==
61
- this.deploymentBranchPolicyToString(attrs.deployment_branch_policy)
117
+ waitTimerHasChanged(existing, attrs) ||
118
+ reviewersHasChanged(existing, attrs) ||
119
+ deploymentBranchPolicyHasChanged(existing, attrs)
62
120
  )
63
121
  }
64
122
 
65
123
  async update (existing, attrs) {
66
124
  if (existing.deployment_branch_policy && existing.deployment_branch_policy.custom_branches) {
67
125
  const branchPolicies = await this.getDeploymentBranchPolicies(this.repo.owner, this.repo.repo, existing.name)
126
+
68
127
  await Promise.all(
69
128
  branchPolicies.map(branchPolicy =>
70
129
  this.github.request(
@@ -79,15 +138,17 @@ module.exports = class Environments extends Diffable {
79
138
  )
80
139
  )
81
140
  }
141
+
82
142
  return this.add(attrs)
83
143
  }
84
144
 
85
145
  async add (attrs) {
86
146
  await this.github.request(`PUT ${environmentRepoEndpoint}`, this.toParams({ name: attrs.name }, attrs))
147
+
87
148
  if (attrs.deployment_branch_policy && attrs.deployment_branch_policy.custom_branches) {
88
149
  await Promise.all(
89
150
  attrs.deployment_branch_policy.custom_branches.map(name =>
90
- this.github.request(`POST /repos/:org/:repo/environments/:environment_name/deployment-branch-policies`, {
151
+ this.github.request('POST /repos/:org/:repo/environments/:environment_name/deployment-branch-policies', {
91
152
  org: this.repo.owner,
92
153
  repo: this.repo.repo,
93
154
  environment_name: attrs.name,
@@ -106,40 +167,6 @@ module.exports = class Environments extends Diffable {
106
167
  })
107
168
  }
108
169
 
109
- reviewersToString (attrs) {
110
- if (attrs === null || attrs === undefined) {
111
- return ''
112
- } else {
113
- attrs.sort((a, b) => {
114
- if (a.id < b.id) return -1
115
- if (a.id > b.id) return 1
116
- if (a.type < b.type) return -1
117
- if (a.type > b.type) return 1
118
- return 0
119
- })
120
- return JSON.stringify(
121
- attrs.map(reviewer => {
122
- return {
123
- id: reviewer.id,
124
- type: reviewer.type
125
- }
126
- })
127
- )
128
- }
129
- }
130
-
131
- deploymentBranchPolicyToString (attrs) {
132
- if (attrs === null || attrs === undefined) {
133
- return ''
134
- } else {
135
- return JSON.stringify(
136
- this.shouldUseProtectedBranches(attrs.protected_branches, attrs.custom_branches)
137
- ? { protected_branches: true }
138
- : { custom_branches: attrs.custom_branches.sort() }
139
- )
140
- }
141
- }
142
-
143
170
  async getDeploymentBranchPolicies (owner, repo, environmentName) {
144
171
  const {
145
172
  data: { branch_policies: branchPolicies }
@@ -148,18 +175,20 @@ module.exports = class Environments extends Diffable {
148
175
  repo,
149
176
  environment_name: environmentName
150
177
  })
178
+
151
179
  return branchPolicies
152
180
  }
153
181
 
154
182
  toParams (existing, attrs) {
155
183
  const deploymentBranchPolicy = attrs.deployment_branch_policy
156
- ? this.shouldUseProtectedBranches(
184
+ ? shouldUseProtectedBranches(
157
185
  attrs.deployment_branch_policy.protected_branches,
158
186
  attrs.deployment_branch_policy.custom_branches
159
187
  )
160
188
  ? { protected_branches: true, custom_branch_policies: false }
161
189
  : { protected_branches: false, custom_branch_policies: true }
162
190
  : null
191
+
163
192
  return {
164
193
  environment_name: existing.name,
165
194
  repo: this.repo.repo,
@@ -169,12 +198,4 @@ module.exports = class Environments extends Diffable {
169
198
  deployment_branch_policy: deploymentBranchPolicy
170
199
  }
171
200
  }
172
-
173
- shouldUseProtectedBranches (protectedBranches, customBranchPolicies) {
174
- if (protectedBranches || customBranchPolicies === undefined || customBranchPolicies === null) {
175
- return true // Returning booleans like this to avoid unexpected datatypes that result in truthy values
176
- } else {
177
- return false
178
- }
179
- }
180
201
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@repository-settings/app",
3
- "version": "3.0.0-beta.1",
3
+ "version": "3.0.0-beta.2",
4
4
  "description": "Pull Requests for GitHub repository settings",
5
5
  "repository": "github:repository-settings/app",
6
6
  "main": "index.js",
@@ -15,8 +15,12 @@
15
15
  "lint:peer": "npm ls >/dev/null",
16
16
  "test:unit": "jest 'test/unit/'",
17
17
  "test:unit:watch": "npm run test:unit -- --watch",
18
- "test:integration": "jest 'test/integration/'",
19
- "test:integration:debug": "LOG_LEVEL=debug DEBUG=nock.* run-s test:integration",
18
+ "test:integration": "run-s 'test:integration:base -- --profile noWip'",
19
+ "test:integration:base": "NODE_OPTIONS=--enable-source-maps DEBUG=any cucumber-js test/integration",
20
+ "test:integration:debug": "DEBUG=test run-s test:integration",
21
+ "test:integration:wip": "run-s 'test:integration:base -- --profile wip'",
22
+ "test:integration:wip:debug": "DEBUG=test run-s 'test:integration:wip'",
23
+ "test:integration:focus": "run-s 'test:integration:base -- --profile focus'",
20
24
  "generate:md": "remark . --output"
21
25
  },
22
26
  "author": "Brandon Keepers",
@@ -24,9 +28,10 @@
24
28
  "dependencies": {
25
29
  "deepmerge": "4.3.1",
26
30
  "js-yaml": "4.1.0",
27
- "probot": "12.3.3"
31
+ "probot": "^13.0.2"
28
32
  },
29
33
  "devDependencies": {
34
+ "@cucumber/cucumber": "9.6.0",
30
35
  "@form8ion/remark-preset": "1.0.0",
31
36
  "@travi/any": "3.0.2",
32
37
  "http-status-codes": "2.3.0",
@@ -34,6 +39,7 @@
34
39
  "jest-when": "3.6.0",
35
40
  "lockfile-lint": "4.12.1",
36
41
  "ls-engines": "0.9.1",
42
+ "msw": "2.1.4",
37
43
  "nock": "13.5.0",
38
44
  "nodemon": "3.0.3",
39
45
  "npm-run-all2": "6.1.1",