github-repository-provider 7.30.24 → 7.31.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/README.md CHANGED
@@ -34,19 +34,20 @@ console.log(entry.name);
34
34
  ### Table of Contents
35
35
 
36
36
  * [GithubBranch](#githubbranch)
37
+ * [Parameters](#parameters)
37
38
  * [writeEntry](#writeentry)
38
- * [Parameters](#parameters)
39
- * [commit](#commit)
40
39
  * [Parameters](#parameters-1)
41
- * [entry](#entry)
40
+ * [commit](#commit)
42
41
  * [Parameters](#parameters-2)
43
- * [removeEntries](#removeentries)
42
+ * [entry](#entry)
44
43
  * [Parameters](#parameters-3)
44
+ * [removeEntries](#removeentries)
45
+ * [Parameters](#parameters-4)
45
46
  * [GithubOwner](#githubowner)
46
47
  * [createRepository](#createrepository)
47
- * [Parameters](#parameters-4)
48
- * [deleteRepository](#deleterepository)
49
48
  * [Parameters](#parameters-5)
49
+ * [deleteRepository](#deleterepository)
50
+ * [Parameters](#parameters-6)
50
51
  * [attributeMapping](#attributemapping)
51
52
  * [GithubProvider](#githubprovider)
52
53
  * [Examples](#examples)
@@ -56,23 +57,23 @@ console.log(entry.name);
56
57
  * [instanceIdentifier](#instanceidentifier)
57
58
  * [GithubPullRequest](#githubpullrequest)
58
59
  * [\_merge](#\_merge)
59
- * [Parameters](#parameters-6)
60
+ * [Parameters](#parameters-7)
60
61
  * [update](#update)
61
62
  * [validMergeMethods](#validmergemethods)
62
63
  * [list](#list)
63
- * [Parameters](#parameters-7)
64
- * [open](#open)
65
64
  * [Parameters](#parameters-8)
65
+ * [open](#open)
66
+ * [Parameters](#parameters-9)
66
67
  * [GithubRepository](#githubrepository)
67
68
  * [defaultBranchName](#defaultbranchname)
68
69
  * [commits](#commits)
69
- * [Parameters](#parameters-9)
70
- * [commitForSha](#commitforsha)
71
70
  * [Parameters](#parameters-10)
72
- * [tree](#tree)
71
+ * [commitForSha](#commitforsha)
73
72
  * [Parameters](#parameters-11)
74
- * [addTree](#addtree)
73
+ * [tree](#tree)
75
74
  * [Parameters](#parameters-12)
75
+ * [addTree](#addtree)
76
+ * [Parameters](#parameters-13)
76
77
  * [initializeBranches](#initializebranches)
77
78
  * [initializeTags](#initializetags)
78
79
  * [url](#url)
@@ -81,11 +82,13 @@ console.log(entry.name);
81
82
  * [api](#api)
82
83
  * [update](#update-1)
83
84
  * [refId](#refid)
84
- * [Parameters](#parameters-13)
85
- * [setRefId](#setrefid)
86
85
  * [Parameters](#parameters-14)
87
- * [deletePullRequest](#deletepullrequest)
86
+ * [\_setRefId](#\_setrefid)
88
87
  * [Parameters](#parameters-15)
88
+ * [setRefId](#setrefid)
89
+ * [Parameters](#parameters-16)
90
+ * [deletePullRequest](#deletepullrequest)
91
+ * [Parameters](#parameters-17)
89
92
  * [initializeHooks](#initializehooks)
90
93
 
91
94
  ## GithubBranch
@@ -94,6 +97,12 @@ console.log(entry.name);
94
97
 
95
98
  Branch on GitHub.
96
99
 
100
+ ### Parameters
101
+
102
+ * `owner`
103
+ * `name`
104
+ * `options`
105
+
97
106
  ### writeEntry
98
107
 
99
108
  Writes content into the branch
@@ -356,6 +365,13 @@ Get sha of a ref.
356
365
 
357
366
  Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)<[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)>** sha of the ref
358
367
 
368
+ ### \_setRefId
369
+
370
+ #### Parameters
371
+
372
+ * `ref` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)**
373
+ * `sha` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)**
374
+
359
375
  ### setRefId
360
376
 
361
377
  <https://docs.github.com/en/github-ae@latest/rest/git/refs#update-a-reference>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "github-repository-provider",
3
- "version": "7.30.24",
3
+ "version": "7.31.2",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -32,11 +32,11 @@
32
32
  "dependencies": {
33
33
  "content-entry": "^5.0.6",
34
34
  "fetch-link-util": "^1.0.10",
35
- "fetch-rate-limit-util": "^3.0.14",
35
+ "fetch-rate-limit-util": "^3.0.16",
36
36
  "matching-iterator": "^2.0.6",
37
37
  "node-fetch": "^3.2.6",
38
38
  "one-time-execution-method": "^3.0.3",
39
- "repository-provider": "^32.0.0"
39
+ "repository-provider": "^32.0.2"
40
40
  },
41
41
  "devDependencies": {
42
42
  "ava": "^4.3.0",
@@ -45,7 +45,7 @@
45
45
  "etag-cache-leveldb": "^1.2.4",
46
46
  "leveldown": "^6.1.1",
47
47
  "levelup": "^5.1.1",
48
- "repository-provider-test-support": "^2.2.8",
48
+ "repository-provider-test-support": "^2.2.9",
49
49
  "semantic-release": "^19.0.3"
50
50
  },
51
51
  "engines": {
@@ -12,6 +12,14 @@ import {
12
12
  export class GithubBranch extends Branch {
13
13
  #entries = new Map();
14
14
 
15
+ constructor(owner, name, options) {
16
+ super(owner, name, options);
17
+
18
+ if (options && options.commit) {
19
+ owner._setRefId(this.ref, options.commit.sha);
20
+ }
21
+ }
22
+
15
23
  /**
16
24
  * Writes content into the branch
17
25
  * {@link https://developer.github.com/v3/git/blobs/#get-a-blob}
@@ -55,14 +63,10 @@ export class GithubBranch extends Branch {
55
63
  entries.map(entry => this.writeEntry(entry))
56
64
  );
57
65
 
58
- const shaLatestCommit = await this.refId;
59
- const latestCommit = await this.owner.commitForSha(shaLatestCommit);
66
+ const sha = await this.refId;
67
+ const latestCommit = await this.owner.commitForSha(sha);
60
68
  const tree = await this.owner.addTree(updates, latestCommit.tree.sha);
61
- const commit = await this.owner.addCommit(
62
- tree.sha,
63
- [shaLatestCommit],
64
- message
65
- );
69
+ const commit = await this.owner.addCommit(tree.sha, [sha], message);
66
70
 
67
71
  return this.owner.setRefId(this.ref, commit.sha, options);
68
72
  }
@@ -16,6 +16,12 @@ export class GithubOwner extends RepositoryGroup {
16
16
  };
17
17
  }
18
18
 
19
+ get reposApi() {
20
+ return this.type === "Organization"
21
+ ? `orgs/${this.name}/repos`
22
+ : "user/repos";
23
+ }
24
+
19
25
  /**
20
26
  * {@link https://developer.github.com/v3/repos/#create-a-repository-for-the-authenticated-user}
21
27
  * @param {string} name
@@ -23,20 +29,17 @@ export class GithubOwner extends RepositoryGroup {
23
29
  * @return {Repository} newly created repository
24
30
  */
25
31
  async createRepository(name, options = {}) {
26
- const response = await this.provider.fetch(
27
- this.type === "Organization" ? `orgs/${this.name}/repos` : "user/repos",
28
- {
29
- method: "POST",
30
- headers: {
31
- accept: "application/vnd.github.nebula-preview+json"
32
- },
33
- body: JSON.stringify({
34
- name,
35
- auto_init: true,
36
- ...options
37
- })
38
- }
39
- );
32
+ const response = await this.provider.fetch(this.reposApi, {
33
+ method: "POST",
34
+ headers: {
35
+ accept: "application/vnd.github.nebula-preview+json"
36
+ },
37
+ body: JSON.stringify({
38
+ name,
39
+ auto_init: true,
40
+ ...options
41
+ })
42
+ });
40
43
 
41
44
  if (response.ok) {
42
45
  this.info(`Repository ${name} created`);
@@ -259,6 +259,16 @@ export class GithubRepository extends Repository {
259
259
  return sha;
260
260
  }
261
261
 
262
+ /**
263
+ * @TODO generalize for all repos ?
264
+ * @param {string} ref
265
+ * @param {string} sha
266
+ */
267
+ _setRefId(ref, sha) {
268
+ ref = ref.replace(/^refs\//, "");
269
+ this.#refs.set(ref, sha);
270
+ }
271
+
262
272
  /**
263
273
  * {@link https://docs.github.com/en/github-ae@latest/rest/git/refs#update-a-reference}
264
274
  * @param {string} ref
@@ -266,7 +276,7 @@ export class GithubRepository extends Repository {
266
276
  * @param {Object} options
267
277
  * @returns
268
278
  *
269
- * @TODO: belongs into Ref ?
279
+ * @TODO belongs into Ref ?
270
280
  */
271
281
  async setRefId(ref, sha, options) {
272
282
  ref = ref.replace(/^refs\//, "");