github-repository-provider 7.33.37 → 7.33.38

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": "github-repository-provider",
3
- "version": "7.33.37",
3
+ "version": "7.33.38",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -45,7 +45,7 @@
45
45
  "etag-cache-leveldb": "^1.4.1",
46
46
  "leveldown": "^6.1.1",
47
47
  "levelup": "^5.1.1",
48
- "repository-provider-test-support": "^2.2.32",
48
+ "repository-provider-test-support": "^2.2.35",
49
49
  "semantic-release": "^20.0.2"
50
50
  },
51
51
  "engines": {
@@ -13,13 +13,6 @@ export class GithubPullRequest extends PullRequest {
13
13
  return new Set(["MERGE", "SQUASH", "REBASE"]);
14
14
  }
15
15
 
16
- static get attributeMapping() {
17
- return {
18
- ...super.attributeMapping,
19
- url: "api"
20
- };
21
- }
22
-
23
16
  static get attributes() {
24
17
  return {
25
18
  ...super.attributes,
@@ -33,22 +26,27 @@ export class GithubPullRequest extends PullRequest {
33
26
  * @param {Object} filter
34
27
  */
35
28
  static async *list(repository, filter = {}) {
36
- const branchName = (name, branch) =>
37
- branch === undefined
38
- ? ""
39
- : `&${name}=${branch.owner.name}:${branch.name}`;
29
+ const query = {};
30
+
31
+ if (filter.source) {
32
+ query.head = `${filter.source.owner.owner.name}:${filter.source.name}`
33
+ }
34
+
35
+ if (filter.destination) {
36
+ query.base = filter.destination.name;
37
+ }
40
38
 
41
- const head = branchName("head", filter.source);
42
- const base = branchName("base", undefined /*filter.destination*/); // TODO
39
+ for (const state of filter.states || this.defaultListStates) {
40
+ query.state = state;
43
41
 
44
- for (const state of [
45
- ...(filter.states ? filter.states : this.defaultListStates)
46
- ]) {
47
- let next = `${repository.api}/pulls?state=${state}${head}${base}`;
42
+ let next = `${repository.api}/pulls?${new URLSearchParams(
43
+ query
44
+ ).toString()}`;
48
45
 
49
46
  do {
50
47
  const provider = repository.provider;
51
48
  const { response, json } = await provider.fetchJSON(next);
49
+
52
50
  for (const node of json) {
53
51
  const [source, dest] = await Promise.all(
54
52
  [node.head, node.base].map(r =>
@@ -76,7 +74,7 @@ export class GithubPullRequest extends PullRequest {
76
74
  })) {
77
75
  return p;
78
76
  }
79
-
77
+
80
78
  const { response, json } = await destination.provider.fetchJSON(
81
79
  `${destination.repository.api}/pulls`,
82
80
  {
@@ -90,40 +88,38 @@ export class GithubPullRequest extends PullRequest {
90
88
  );
91
89
 
92
90
  if (!response.ok) {
93
- throw new Error(response.statusText + ' (' + response.status + ')');
91
+ throw new Error(response.statusText + " (" + response.status + ")");
94
92
  }
95
93
 
96
94
  return new this(source, destination, json.number, json);
97
95
  }
98
96
 
97
+ get api() {
98
+ return `${this.destination.repository.api}/pulls/${this.number}`;
99
+ }
100
+
99
101
  /**
100
102
  * {@link https://developer.github.com/v3/pulls/#merge-a-pull-request}
101
103
  */
102
104
  async _merge(method = "MERGE") {
103
- const res = await this.provider.fetch(
104
- `${this.source.repository.api}/pulls/${this.number}/merge`,
105
- {
106
- method: "PUT",
107
- body: JSON.stringify({ merge_method: method, sha: "???" })
108
- }
109
- );
105
+ const res = await this.provider.fetch(`${this.api}/merge`, {
106
+ method: "PUT",
107
+ body: JSON.stringify({ merge_method: method, sha: "???" })
108
+ });
110
109
  }
111
110
 
112
111
  /**
113
112
  *
114
113
  */
115
114
  async update() {
116
- const res = await this.provider.fetch(
117
- `${this.source.repository.api}/pulls/${this.number}`,
118
- {
119
- method: "PATCH",
120
- body: JSON.stringify({
121
- title: this.title,
122
- body: this.body,
123
- state: this.state
124
- })
125
- }
126
- );
115
+ const res = await this.provider.fetch(this.api, {
116
+ method: "PATCH",
117
+ body: JSON.stringify({
118
+ title: this.title,
119
+ body: this.body,
120
+ state: this.state
121
+ })
122
+ });
127
123
  console.log(res);
128
124
  }
129
125
  }