@gitkraken/provider-apis 0.22.4 → 0.22.6

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/CHANGELOG.md CHANGED
@@ -1,4 +1,13 @@
1
1
  # Changelog
2
+
3
+ ## 0.22.6
4
+
5
+ - exclude data from archived repos in the results of functions that return PRs: `getPullRequestsForUser`, `getPullRequestsAssociatedWithUser` (GitLab)
6
+
7
+ ## 0.22.5
8
+
9
+ - exclude data from archived repos in the results of functions that return PRs and issues: `searchPullRequests`, `getPullRequestsAssociatedWithUser`, `getPullRequestsForRepos`, `searchIssues`, `getIssuesAssociatedWithUser`, `getIssuesForRepos` (GitHub)
10
+
2
11
  ## 0.22.4
3
12
 
4
13
  - added `key` to `Issue.project` object (Jira, Jira Server)
@@ -21,15 +30,17 @@
21
30
  ## 0.22.0
22
31
 
23
32
  ### ⚠️ Breaking Changes
33
+
24
34
  ```ts
25
35
  import { EntityIdentifier } from '@gitkraken/provider-apis';
26
36
  ```
37
+
27
38
  is now:
39
+
28
40
  ```ts
29
41
  import { EntityIdentifierUtils } from '@gitkraken/provider-apis';
30
42
  ```
31
43
 
32
-
33
44
  - `EntityProviderType` and `EntityType` are now names instead of numbers
34
45
  - EntityIdentifier `encode` and `decode` now optionally takes in more specific provider entity types
35
46
  - Fix trello entityIdentifier error message
@@ -40,15 +51,17 @@ import { EntityIdentifierUtils } from '@gitkraken/provider-apis';
40
51
 
41
52
  Added new entity ID API for encoding/decoding entity IDs (previously known as unique IDs). This API replaces the `getPullRequestUniqueId` and `getIssueUniqueId` utility functions in older versions of this library.
42
53
 
43
- The `EntityIdentifier` type represents a particular pull request or issue for a particular provider. The information stored in this type is enough to query the provider's REST or GraphQL API to fetch additional information about the entity (i.e. title, description, assignees, etc) or mutate the entity. `EntityIdentifier` is designed to be
54
+ The `EntityIdentifier` type represents a particular pull request or issue for a particular provider. The information stored in this type is enough to query the provider's REST or GraphQL API to fetch additional information about the entity (i.e. title, description, assignees, etc) or mutate the entity. `EntityIdentifier` is designed to be
44
55
  serialized so we can send it to our backend services, giving us a portable way to communicate about pull requests or issues.
45
56
 
46
57
  These are the new functions provided by the API:
58
+
47
59
  - `validate`: takes an `EntityIdentifier` as input and validates that it is correctly formed
48
60
  - `encode`: takes an `EntityIdentifier` as input and encodes it to an array of strings, which can be serialized and sent to our REST APIs
49
61
  - `decode`: takes an array string and decodes it to an `EntityIdentifier`
50
62
 
51
63
  Conversion guide:
64
+
52
65
  ```ts
53
66
  const pullRequest: GitPullRequest = { /* ... pr from somewhere ... */ };
54
67
  const githubEnterpriseDomain: string | undefined = ...; // undefined if this PR exists on https://github.com
@@ -88,6 +101,7 @@ encode({
88
101
  - changed `pullRequests` argument type from `GitPullRequest[]` to `PullRequestWithUniqueID[]` (groupPullRequestsIntoBuckets)
89
102
 
90
103
  We re-organized provider-specific types into a new directory structure. The types that were moved will have broken imports, but they can be fixed by importing the type from "@gitkraken/provider-apis". Example
104
+
91
105
  ```ts
92
106
  // provider-specific type import that is broken by v0.20.0
93
107
  import type { WorkItemState } from '@gitkraken/provider-apis/dist/providers/azureDevops/azureDevOpsTypes';
@@ -122,7 +136,9 @@ This version refactors all of the mutation functions for all providers. The muta
122
136
  Examples of how to call the new functions:
123
137
 
124
138
  ```ts
125
- const pullRequest: GitPullRequest = { /* ... some PR object from your app's state ... */ };
139
+ const pullRequest: GitPullRequest = {
140
+ /* ... some PR object from your app's state ... */
141
+ };
126
142
 
127
143
  // pre-v0.18.0 way of merging a pull request for gitlab
128
144
  await gitlab.mergePullRequest({
@@ -143,8 +159,14 @@ await gitlab.mergePullRequest({
143
159
  ```
144
160
 
145
161
  ```ts
146
- const issue: Issue = { /* ... some issue object from your app's state ... */ };
147
- const labels: GitLabel[] = [{ /* ... some label objects from your app's state ... */ }];
162
+ const issue: Issue = {
163
+ /* ... some issue object from your app's state ... */
164
+ };
165
+ const labels: GitLabel[] = [
166
+ {
167
+ /* ... some label objects from your app's state ... */
168
+ },
169
+ ];
148
170
 
149
171
  // pre-v0.18.0 way of setting issue labels for gitlab
150
172
  await gitlab.setIssueLabels({
@@ -181,18 +203,19 @@ interface GitProvider {
181
203
 
182
204
  The `Set*Input` interfaces are designed to take their corresponding provider library object. `SetPullRequestInput` is designed to take a `GitPullRequest` object. `SetMilestoneInput` is designed to take a `GitMilestone` object. Here's a quick reference of the various `Set*Input` interfaces and the objects that they are designed to take:
183
205
 
184
- |`Set*Input` interface|Provider library object |
185
- |---------------------|-------------------------------------------|
186
- |SetPullRequestInput |GitPullRequest |
187
- |SetIssueInput |Issue |
188
- |SetMilestoneInput |GitMilestone |
189
- |SetAccountInput |Account |
190
- |SetLabelInput |GitLabel |
191
- |SetStatusInput |IssueTransition, TrelloBoard, WorkItemState|
206
+ | `Set*Input` interface | Provider library object |
207
+ | --------------------- | ------------------------------------------- |
208
+ | SetPullRequestInput | GitPullRequest |
209
+ | SetIssueInput | Issue |
210
+ | SetMilestoneInput | GitMilestone |
211
+ | SetAccountInput | Account |
212
+ | SetLabelInput | GitLabel |
213
+ | SetStatusInput | IssueTransition, TrelloBoard, WorkItemState |
192
214
 
193
215
  Now, wih all of that explained, here's the list of updated mutation functions:
194
216
 
195
217
  Azure Dev Ops:
218
+
196
219
  - closePullRequest
197
220
  - mergePullRequest
198
221
  - addPullRequestLabel
@@ -208,16 +231,19 @@ Azure Dev Ops:
208
231
  - setPullRequestLabels **(new)**
209
232
 
210
233
  Bitbucket:
234
+
211
235
  - closePullRequest
212
236
  - mergePullRequest
213
237
  - setPullRequestReviewers
214
238
 
215
239
  Bitbucket Server:
240
+
216
241
  - closePullRequest
217
242
  - mergePullRequest
218
243
  - setPullRequestReviewers
219
244
 
220
245
  GitHub/GitHub Enterprise:
246
+
221
247
  - closePullRequest
222
248
  - mergePullRequest
223
249
  - setPullRequestMilestone
@@ -237,6 +263,7 @@ GitHub/GitHub Enterprise:
237
263
  - setIssueStatus was **removed**
238
264
 
239
265
  GitLab/GitLab Self-Managed:
266
+
240
267
  - closePullRequest
241
268
  - mergePullRequest
242
269
  - setPullRequestMilestone
@@ -256,17 +283,20 @@ GitLab/GitLab Self-Managed:
256
283
  - setIssueStatus was **removed**
257
284
 
258
285
  Jira:
286
+
259
287
  - setIssueStatus
260
288
  - setIssueAssignee
261
289
  - setIssueComponents
262
290
  - setIssueLabels
263
291
 
264
292
  Jira Server:
293
+
265
294
  - setIssueStatus
266
295
  - setIssueComponents
267
296
  - setIssueLabels
268
297
 
269
298
  Trello:
299
+
270
300
  - setIssueStatus
271
301
  - setIssueAssignees
272
302
  - setIssueLabels
package/dist/index.js CHANGED
@@ -160,7 +160,7 @@ labels(first: 100) {
160
160
  ${Re}
161
161
  }
162
162
  }
163
- ${!t||me(t,"VIEWER_CAN_MERGE_AS_ADMIN")?"viewerCanMergeAsAdmin":""}
163
+ ${!t||me(t,"VIEWER_CAN_MERGE_AS_ADMIN")?"viewerCanMergeAsAdmin":""}
164
164
  `,Nr=(s=!1)=>`
165
165
  id
166
166
  databaseId
@@ -219,7 +219,7 @@ query SearchIssuesOrPullRequests($query: String! $after: String) {
219
219
  }
220
220
  }
221
221
  }
222
- }`,variables:{query:`is:${s} is:open ${e}`,after:t}}},Br="Field 'isDraft' doesn't exist on type 'PullRequest'",be=(s=[])=>s.some(e=>(e==null?void 0:e.message)===Br),jr=/@@ -(\d+)(?:,\d+ | )\+(\d+)(?:,\d+ | )@@(?:\\n)?/,Mr=`
222
+ }`,variables:{query:`is:${s} is:open archived:false ${e}`,after:t}}},Br="Field 'isDraft' doesn't exist on type 'PullRequest'",be=(s=[])=>s.some(e=>(e==null?void 0:e.message)===Br),jr=/@@ -(\d+)(?:,\d+ | )\+(\d+)(?:,\d+ | )@@(?:\\n)?/,Mr=`
223
223
  \
224
224
  +`,er=(s,e,t,r)=>{let n=jr.exec(s);if(!n||!n[0]||!n[1])return[];let o=parseInt(n[1],10),i=parseInt(n[2],10),a=s.replace(Mr,`
225
225
  +`).split(`
@@ -752,7 +752,7 @@ labels {
752
752
  ${wt}
753
753
  }
754
754
  }
755
- ${s?"project { id httpUrlToRepo fullPath sshUrlToRepo webUrl } sourceProject { id httpUrlToRepo fullPath sshUrlToRepo webUrl }":""}
755
+ ${s?"project { id httpUrlToRepo fullPath sshUrlToRepo webUrl archived } sourceProject { id httpUrlToRepo fullPath sshUrlToRepo webUrl }":""}
756
756
  ${e?`milestone { ${bt} }`:""}
757
757
  ${t?`headPipeline { ${gs} }`:""}
758
758
  `,J=s=>`${s.namespace}/${s.name}`,ms=s=>`${s.namespace}/${s.name}`,ft=s=>{var e;return{id:s.id.replace(X,""),graphQLId:s.id,namespace:Rt(s.fullPath),name:yt(s.fullPath),webUrl:s.webUrl,httpsUrl:s.httpUrlToRepo,sshUrl:s.sshUrlToRepo,defaultBranch:(e=s.repository)!=null&&e.rootRef?{name:s.repository.rootRef}:null,permission:null}},hs={opened:"OPEN",merged:"MERGED",closed:"CLOSED"},M=(s,e)=>{let t=s.avatarUrl;return!e&&(t!=null&&t.startsWith("/"))&&(t=`https://gitlab.com${t}`),{id:s.id.replace(as,""),graphQLId:s.id,name:s.name,username:s.username,email:s.publicEmail??null,avatarUrl:t,url:s.webUrl}},Pt=s=>({color:s.color,description:s.description,id:s.id.replace(ps,""),graphQLId:s.id,name:s.title}),fs=(s,e)=>s?s==="FAILED"&&e?"WARNING":{CANCELED:"CANCELLED",CREATED:"PENDING",FAILED:"FAILED",MANUAL:"OPTIONAL_ACTION_REQUIRED",PENDING:"PENDING",PREPARING:"RUNNING",RUNNING:"RUNNING",SCHEDULED:"PENDING",SKIPPED:"SKIPPED",SUCCESS:"SUCCESS",WAITING_FOR_CALLBACK:"PENDING",WAITING_FOR_RESOURCE:"PENDING"}[s]:null,ir=(s,e,t,r)=>{var o,i,a,u,l,p,d,c,g,m,I,w;let n=(o=s.reviewers)!=null&&o.nodes?s.reviewers.nodes.map(h=>{var y,v;return{reviewer:M(h,r),state:(y=h.mergeRequestInteraction)!=null&&y.approved?"APPROVED":((v=h.mergeRequestInteraction)==null?void 0:v.reviewState)==="REVIEWED"?"CHANGES_REQUESTED":"CHANGES_REQUESTED"}}):null;return{id:s.id.replace(us,""),graphQLId:s.id,title:s.title,number:parseInt(s.iid,10),state:hs[s.state],commentCount:s.userNotesCount||0,upvoteCount:s.upvotes,author:s.author?M(s.author,r):null,createdDate:new Date(s.createdAt),isDraft:s.draft,repository:{id:e.id,graphQLId:e.graphQLId,name:e.name,owner:{login:e.namespace},remoteInfo:e.httpsUrl&&e.sshUrl?{cloneUrlHTTPS:e.httpsUrl,cloneUrlSSH:e.sshUrl}:null},headRepository:t?{id:t.id,graphQLId:t.graphQLId,name:t.name,owner:{login:t.namespace},remoteInfo:{cloneUrlHTTPS:t.httpsUrl,cloneUrlSSH:t.sshUrl}}:null,headCommit:{buildStatuses:((u=(a=(i=s.headPipeline)==null?void 0:i.stages)==null?void 0:a.nodes)==null?void 0:u.flatMap(h=>{var y,v;return((v=(y=h.jobs)==null?void 0:y.nodes)==null?void 0:v.map(C=>({completedAt:C.finishedAt?new Date(C.finishedAt):null,description:null,name:C.name??null,state:fs(C.status,C.allowFailure),stage:h.name??null,startedAt:new Date(C.createdAt),url:`${e.webUrl}/-/jobs/${C.id.replace(cs,"")}`})))??[]}))??[]},baseRef:{name:s.targetBranch,oid:((l=s.diffRefs)==null?void 0:l.baseSha)??null},headRef:{name:s.sourceBranch,oid:((p=s.diffRefs)==null?void 0:p.headSha)??null},url:s.webUrl,updatedDate:new Date(s.updatedAt),closedDate:s.mergedAt?new Date(s.mergedAt):null,mergedDate:s.mergedAt?new Date(s.mergedAt):null,assignees:(d=s.assignees)!=null&&d.nodes?s.assignees.nodes.map(h=>M(h,r)):null,reviews:n,reviewDecision:s.approved?"APPROVED":z(n),additions:((c=s.diffStatsSummary)==null?void 0:c.additions)||0,deletions:((g=s.diffStatsSummary)==null?void 0:g.deletions)||0,fileCount:((m=s.diffStatsSummary)==null?void 0:m.fileCount)||0,commitCount:s.commitCount||0,mergeableState:is[s.mergeStatusEnum],milestone:s.milestone?Et(s.milestone,e.webUrl):null,labels:((w=(I=s.labels)==null?void 0:I.nodes)==null?void 0:w.map(Pt))??[],permissions:null}},It=(s,e,t)=>{var r,n;return{author:M(s.author,t),assignees:s.assignees.nodes.map(o=>M(o,t)),commentCount:s.userNotesCount,closedDate:s.closedAt?new Date(s.closedAt):null,createdDate:new Date(s.createdAt),description:s.description,graphQLId:s.id,id:s.id.replace(ls,""),labels:((n=(r=s.labels)==null?void 0:r.nodes)==null?void 0:n.map(Pt))??[],number:s.iid,repository:{id:e.id.replace(X,""),graphQLId:e.id,name:e.name,owner:{login:e.namespace}},updatedDate:new Date(s.updatedAt),upvoteCount:s.upvotes,state:{name:s.state,color:null},type:s.type,title:s.title,url:s.webUrl,milestone:s.milestone?Et(s.milestone,e.webUrl):null}},Et=(s,e)=>({id:s.id.replace(ds,""),graphQLId:s.id,number:parseInt(s.iid,10),title:s.title,description:s.description,isOpen:s.state==="active",url:`${e}/-/${s.webPath.replace(/.+?\/-\//,"")}`,startDate:s.startDate?new Date(s.startDate):null,dueDate:s.dueDate?new Date(s.dueDate):null}),ne=class extends k{getIsSelfHosted(e){return!!e.baseUrl||!!this.config.baseUrl}async getCurrentUser(e={},t={}){var o;let n=(o=(await b(this.config,{query:`
@@ -851,7 +851,7 @@ query getPullRequestsForUser($username: String! $cursor: String) {
851
851
  }
852
852
  }
853
853
  }
854
- `,variables:{username:e.username,cursor:e.cursor}},t);if(!n.body.data)throw new Error(we(n.body.errors)||n.statusText||"Unknown error");if(!n.body.data.user)throw new Error("User not found");let o=n.body.data.user[r];if(!o)throw new Error("Unexpected response");return{pageInfo:o.pageInfo,data:((i=o.nodes)==null?void 0:i.map(a=>ir(a,nr(a.project),nr(a.sourceProject),this.getIsSelfHosted(t))))||[]}}async getPullRequestsAssociatedWithUser(e,t={}){var c;let[r,n,o]=((c=e.cursor)==null?void 0:c.split(";"))||[void 0,void 0,void 0],[i,a,u]=await Promise.all([r==="null"?null:this.getPullRequestsForUser({username:e.username,association:"authored",cursor:r},t),n==="null"?null:this.getPullRequestsForUser({username:e.username,association:"assigned",cursor:n},t),o==="null"?null:this.getPullRequestsForUser({username:e.username,association:"reviewRequested",cursor:o},t)]),l={},p=[],d=g=>{l[g.id]||(l[g.id]=!0,p.push(g))};return i==null||i.data.forEach(d),a==null||a.data.forEach(d),u==null||u.data.forEach(d),{pageInfo:{hasNextPage:(i==null?void 0:i.pageInfo.hasNextPage)||(a==null?void 0:a.pageInfo.hasNextPage)||(u==null?void 0:u.pageInfo.hasNextPage)||!1,endCursor:`${(i==null?void 0:i.pageInfo.hasNextPage)&&(i==null?void 0:i.pageInfo.endCursor)||"null"};${(a==null?void 0:a.pageInfo.hasNextPage)&&(a==null?void 0:a.pageInfo.endCursor)||"null"};${(u==null?void 0:u.pageInfo.hasNextPage)&&(u==null?void 0:u.pageInfo.endCursor)||"null"}`},data:p}}getVariablesForPullRequests(e){let{updatedBefore:t,isDraft:r,authorLogin:n,assigneeLogins:o,reviewRequestedLogin:i}=e||{},a={},u=[],l=[],p=(d,c,g)=>{u.push(`$${d}: ${g}`),l.push(`${d}: $${d}`),a[d]=c};return t&&p("updatedBefore",t,"Time"),n&&p("authorUsername",n,"String"),o&&p("assigneeUsername",o[0],"String"),r!=null&&p("draft",r,"Boolean"),i&&p("reviewerUsername",i,"String"),{variables:a,variableTypes:u,mergeRequestArguments:l}}async getPullRequestsForRepo(e,t={}){var I,w,h;let{cursor:r,repo:n}=e||{},o=J(n),{variables:i,variableTypes:a,mergeRequestArguments:u}=this.getVariablesForPullRequests(e),l={fullPath:o,...i},p=await b(this.config,{query:`
854
+ `,variables:{username:e.username,cursor:e.cursor}},t);if(!n.body.data)throw new Error(we(n.body.errors)||n.statusText||"Unknown error");if(!n.body.data.user)throw new Error("User not found");let o=n.body.data.user[r];if(!o)throw new Error("Unexpected response");return{pageInfo:o.pageInfo,data:((i=o.nodes)==null?void 0:i.filter(a=>!a.project.archived).map(a=>ir(a,nr(a.project),nr(a.sourceProject),this.getIsSelfHosted(t))))||[]}}async getPullRequestsAssociatedWithUser(e,t={}){var c;let[r,n,o]=((c=e.cursor)==null?void 0:c.split(";"))||[void 0,void 0,void 0],[i,a,u]=await Promise.all([r==="null"?null:this.getPullRequestsForUser({username:e.username,association:"authored",cursor:r},t),n==="null"?null:this.getPullRequestsForUser({username:e.username,association:"assigned",cursor:n},t),o==="null"?null:this.getPullRequestsForUser({username:e.username,association:"reviewRequested",cursor:o},t)]),l={},p=[],d=g=>{l[g.id]||(l[g.id]=!0,p.push(g))};return i==null||i.data.forEach(d),a==null||a.data.forEach(d),u==null||u.data.forEach(d),{pageInfo:{hasNextPage:(i==null?void 0:i.pageInfo.hasNextPage)||(a==null?void 0:a.pageInfo.hasNextPage)||(u==null?void 0:u.pageInfo.hasNextPage)||!1,endCursor:`${(i==null?void 0:i.pageInfo.hasNextPage)&&(i==null?void 0:i.pageInfo.endCursor)||"null"};${(a==null?void 0:a.pageInfo.hasNextPage)&&(a==null?void 0:a.pageInfo.endCursor)||"null"};${(u==null?void 0:u.pageInfo.hasNextPage)&&(u==null?void 0:u.pageInfo.endCursor)||"null"}`},data:p}}getVariablesForPullRequests(e){let{updatedBefore:t,isDraft:r,authorLogin:n,assigneeLogins:o,reviewRequestedLogin:i}=e||{},a={},u=[],l=[],p=(d,c,g)=>{u.push(`$${d}: ${g}`),l.push(`${d}: $${d}`),a[d]=c};return t&&p("updatedBefore",t,"Time"),n&&p("authorUsername",n,"String"),o&&p("assigneeUsername",o[0],"String"),r!=null&&p("draft",r,"Boolean"),i&&p("reviewerUsername",i,"String"),{variables:a,variableTypes:u,mergeRequestArguments:l}}async getPullRequestsForRepo(e,t={}){var I,w,h;let{cursor:r,repo:n}=e||{},o=J(n),{variables:i,variableTypes:a,mergeRequestArguments:u}=this.getVariablesForPullRequests(e),l={fullPath:o,...i},p=await b(this.config,{query:`
855
855
  query getPullRequestsForRepo(
856
856
  $fullPath: ID!
857
857
  $after: String
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gitkraken/provider-apis",
3
- "version": "0.22.4",
3
+ "version": "0.22.6",
4
4
  "description": "An SDK around different third-party APIs that accepts and returns data in a common format.",
5
5
  "author": "Axosoft, LLC dba GitKraken",
6
6
  "license": "SEE LICENSE IN LICENSE",