repository-provider 29.2.3 → 30.0.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "repository-provider",
3
- "version": "29.2.3",
3
+ "version": "30.0.2",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -36,7 +36,7 @@
36
36
  "ava": "^4.2.0",
37
37
  "c8": "^7.11.3",
38
38
  "documentation": "^13.2.5",
39
- "repository-provider-test-support": "^2.1.19",
39
+ "repository-provider-test-support": "^2.1.20",
40
40
  "semantic-release": "^19.0.2",
41
41
  "typescript": "^4.7.2"
42
42
  },
package/src/attribute.mjs CHANGED
@@ -65,6 +65,11 @@ export function definePropertiesFromOptions(
65
65
  value = attribute.set(value);
66
66
  } else {
67
67
  switch (attribute.type) {
68
+ case "set":
69
+ if (Array.isArray(value)) {
70
+ value = new Set(value);
71
+ }
72
+ break;
68
73
  case "boolean":
69
74
  if (value !== undefined) {
70
75
  value =
@@ -120,7 +125,7 @@ export function defaultValues(attributes, object) {
120
125
  a.push([name, attribute.default]);
121
126
  } else if (attribute.get !== undefined) {
122
127
  const value = attribute.get(attribute, object);
123
- if(value !== undefined) {
128
+ if (value !== undefined) {
124
129
  a.push([name, value]);
125
130
  }
126
131
  }
@@ -191,7 +196,11 @@ export function optionJSON(
191
196
  return Object.keys(attributes || {}).reduce((a, c) => {
192
197
  const value = object[c];
193
198
  if (value !== undefined && !(value instanceof Function)) {
194
- a[c] = value;
199
+ if (value instanceof Set) {
200
+ a[c] = [...value];
201
+ } else {
202
+ a[c] = value;
203
+ }
195
204
  }
196
205
  return a;
197
206
  }, initial);
package/src/hook.mjs CHANGED
@@ -12,7 +12,8 @@ export class Hook extends OwnedObject {
12
12
  secret: { type: "string", private: true, writable: true },
13
13
  content_type: { type: "string", default: "json", writable: true },
14
14
  insecure_ssl: { type: "boolean", default: false },
15
- active: { type: "boolean", default: true, writable: true }
15
+ active: { type: "boolean", default: true, writable: true },
16
+ events: { type: "set", default: new Set(["*"]) }
16
17
  };
17
18
  }
18
19
 
@@ -20,17 +21,10 @@ export class Hook extends OwnedObject {
20
21
  return "_addHook";
21
22
  }
22
23
 
23
- constructor(owner, name, events = new Set(["*"]), options) {
24
- super(owner, name, options, {
25
- events: { value: events }
26
- });
27
- }
28
-
29
24
  /**
30
25
  * Provide name, events and all defined attributes.
31
26
  */
32
27
  toJSON() {
33
- return optionJSON(this, { name: this.name, id: this.id, events: [...this.events] });
28
+ return optionJSON(this, { name: this.name, id: this.id });
34
29
  }
35
30
  }
36
-
@@ -25,7 +25,6 @@ import { BaseProvider } from "./base-provider.mjs";
25
25
  * @property {Map<string,Milestone>} milestones
26
26
  */
27
27
  export class Repository extends OwnedObject {
28
-
29
28
  static get addMethodName() {
30
29
  return "_addRepository";
31
30
  }
@@ -128,8 +127,7 @@ export class Repository extends OwnedObject {
128
127
  * @param {Object} options
129
128
  * @return {AsyncIterator<Commit>} all matching commits in the repository
130
129
  */
131
- async *commits(options) {
132
- }
130
+ async *commits(options) {}
133
131
 
134
132
  /**
135
133
  * Urls to access the repo.
@@ -234,7 +232,7 @@ export class Repository extends OwnedObject {
234
232
  * @return {Promise<Branch>}
235
233
  */
236
234
  async branch(name) {
237
- if(name === this.defaultBranchName) {
235
+ if (name === this.defaultBranchName) {
238
236
  return this.#branches.get(name) || this.addBranch(name);
239
237
  }
240
238
 
@@ -242,8 +240,10 @@ export class Repository extends OwnedObject {
242
240
  return this.#branches.get(name);
243
241
  }
244
242
 
245
- get hasBranches()
246
- {
243
+ /**
244
+ * @return {boolean} true if there is at least one branch
245
+ */
246
+ get hasBranches() {
247
247
  return this.#branches.size > 0;
248
248
  }
249
249
 
@@ -277,7 +277,9 @@ export class Repository extends OwnedObject {
277
277
  * @return {Branch} newly created branch
278
278
  */
279
279
  addBranch(name, options) {
280
- return this.#branches.get(name) || new this.branchClass(this, name, options);
280
+ return (
281
+ this.#branches.get(name) || new this.branchClass(this, name, options)
282
+ );
281
283
  }
282
284
 
283
285
  _addBranch(branch) {
@@ -323,7 +325,7 @@ export class Repository extends OwnedObject {
323
325
  * @return {Tag} newly created tag
324
326
  */
325
327
  addTag(name, options) {
326
- return this.#tags.get(name) || new this.tagClass(this, name, options);
328
+ return this.#tags.get(name) || new this.tagClass(this, name, options);
327
329
  }
328
330
 
329
331
  _addTag(tag) {
@@ -394,11 +396,16 @@ export class Repository extends OwnedObject {
394
396
  }
395
397
 
396
398
  /**
397
- * Add a Hook.
398
- * @param {Hook} hook
399
+ * Add a new {@link Hook}.
400
+ * @param {string} name of the new hoook name
401
+ * @param {Object} options
402
+ * @return {Hook} newly created hook
399
403
  */
400
- addHook(hook) {
401
- this.#hooks.push(hook);
404
+ addHook(name, options) {
405
+ return (
406
+ this.#hooks.find(hook => hook.name == name) ||
407
+ new this.hookClass(this, name, options)
408
+ );
402
409
  }
403
410
 
404
411
  _addHook(hook) {
@@ -475,8 +482,7 @@ export class Repository extends OwnedObject {
475
482
  * @param {string} ref
476
483
  * @return {Promise<string>} sha of the ref
477
484
  */
478
- async refId(ref) {
479
- }
485
+ async refId(ref) {}
480
486
 
481
487
  /**
482
488
  * Provide name and all defined attributes