@gitkraken/provider-apis 0.6.1
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 +112 -0
- package/LICENSE +19 -0
- package/README.md +78 -0
- package/dist/defaults.d.ts +6 -0
- package/dist/fetchWrapper.d.ts +2 -0
- package/dist/index.d.ts +27 -0
- package/dist/index.js +552 -0
- package/dist/providers/azureDevops/azureDevOps.d.ts +116 -0
- package/dist/providers/azureDevops/azureDevOpsHelpers.d.ts +3 -0
- package/dist/providers/azureDevops/azureDevOpsTypes.d.ts +198 -0
- package/dist/providers/bitbucket/bitbucket.d.ts +107 -0
- package/dist/providers/bitbucket/bitbucketHelpers.d.ts +3 -0
- package/dist/providers/bitbucket/bitbucketTypes.d.ts +181 -0
- package/dist/providers/gitProvider.d.ts +166 -0
- package/dist/providers/github/github.d.ts +122 -0
- package/dist/providers/github/githubHelpers.d.ts +19 -0
- package/dist/providers/github/githubTypes.d.ts +159 -0
- package/dist/providers/gitlab/gitlab.d.ts +157 -0
- package/dist/providers/gitlab/gitlabHelpers.d.ts +4 -0
- package/dist/providers/gitlab/gitlabTypes.d.ts +33 -0
- package/dist/providers/issueProvider.d.ts +37 -0
- package/dist/providers/jira/jira.d.ts +14 -0
- package/dist/providers/provider.d.ts +6 -0
- package/dist/providers/trello/trello.d.ts +13 -0
- package/dist/types.d.ts +76 -0
- package/dist/utils.d.ts +1 -0
- package/package.json +59 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,552 @@
|
|
|
1
|
+
"use strict";var Pe=Object.create;var Q=Object.defineProperty;var ve=Object.getOwnPropertyDescriptor;var Se=Object.getOwnPropertyNames;var we=Object.getPrototypeOf,Ce=Object.prototype.hasOwnProperty;var Ue=(e,t)=>{for(var r in t)Q(e,r,{get:t[r],enumerable:!0})},ne=(e,t,r,s)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of Se(t))!Ce.call(e,n)&&n!==r&&Q(e,n,{get:()=>t[n],enumerable:!(s=ve(t,n))||s.enumerable});return e};var De=(e,t,r)=>(r=e!=null?Pe(we(e)):{},ne(t||!e||!e.__esModule?Q(r,"default",{value:e,enumerable:!0}):r,e)),$e=e=>ne(Q({},"__esModule",{value:!0}),e);var at={};Ue(at,{AzureDevOps:()=>O,Bitbucket:()=>k,GitHub:()=>j,GitLab:()=>N,default:()=>nt});module.exports=$e(at);var ae=De(require("node-fetch")),oe=globalThis.fetch||ae.default;var ie=e=>e.name==="fetch";var Le=async e=>{let t=e.headers.get("content-type")||"",r=null;if(t.startsWith("application/json"))r=await e.json();else if(t.startsWith("text/"))r=await e.text();else throw new Error(`Unsupported content-type: ${t}`);let s={body:r,headers:Object.fromEntries(e.headers.entries()),status:e.status,statusText:e.statusText};if(!e.ok){let n=new Error(e.statusText);throw Object.assign(n,{response:s}),n}return s},W=e=>ie(e)?async({url:t,...r})=>{let s=await e(t,r);return Le(s)}:e;var S=class{constructor(t){this.config={...t,request:W((t==null?void 0:t.request)||oe)}}updateConfig(t){this.config={...this.config,...t,request:t.request?W(t.request):this.config.request}}};var G=class extends S{},z=class extends G{},$=100;var y=(e,t)=>{let r={};return e&&(r.Authorization=`${t?"Basic":"Bearer"} ${e}`),r};var w=(e,t={})=>y(t.token||e.token,t.isPAT||e.isPAT);var Ae="https://app.vssps.visualstudio.com/_apis",A="https://dev.azure.com",Ee={active:"OPEN",completed:"MERGED",abandoned:"CLOSED"},Ge={10:"APPROVED",5:"APPROVED",0:"REVIEW_REQUESTED",[-5]:"CHANGES_REQUESTED",[-10]:"CHANGES_REQUESTED"},X=e=>({id:e.id,name:e.displayName,username:e.uniqueName||e.displayName,email:null,avatarUrl:e.imageUrl}),M=e=>e.startsWith("refs/heads/")?e.replace("refs/heads/",""):e,ue=e=>({id:e.pullRequestId.toString(),title:e.title,number:e.codeReviewId,state:Ee[e.status],isDraft:e.isDraft,commentCount:null,upvoteCount:null,author:X(e.createdBy),createdDate:new Date(e.creationDate),updatedDate:new Date(e.closedDate||e.creationDate),closedDate:e.closedDate?new Date(e.closedDate):null,repository:{name:e.repository.name,owner:{login:void 0}},headCommit:{buildStatus:null},baseRef:{name:M(e.targetRefName)},headRef:{name:M(e.sourceRefName)},url:null,assignees:e.reviewers.map(X),reviews:e.reviewers.filter(t=>t.vote!==0).map(t=>({reviewer:X(t),state:Ge[t.vote]||"REVIEW_REQUESTED"})),additions:null,deletions:null,fileCount:null,commitCount:null,headRepository:null}),le=(e,t)=>({id:t.id,name:t.name,namespace:e,project:t.project.name,webUrl:t.webUrl,httpsUrl:t.remoteUrl,sshUrl:t.sshUrl,defaultBranch:t.defaultBranch?{name:M(t.defaultBranch)}:null,permission:null}),Te=e=>{let t=e.fields,r=t["System.AssignedTo"];return{id:e.id.toString(),number:e.id.toString(),title:t["System.Title"],commentCount:t["System.CommentCount"],author:{avatarUrl:t["System.CreatedBy"]._links.avatar.href,email:null,id:t["System.CreatedBy"].id,name:t["System.CreatedBy"].uniqueName,username:t["System.CreatedBy"].displayName},createdDate:new Date(t["System.CreatedDate"]),updatedDate:new Date(t["System.ChangedDate"]),url:e._links.html.href,assignees:r?[{avatarUrl:r._links.avatar.href,email:null,id:r.id,name:r.uniqueName,username:r.displayName}]:[],description:null,state:null,repository:null,upvoteCount:0}},O=class extends G{async getCurrentUser(t={}){if(t.isPAT||this.config.isPAT)throw new Error("Azure DevOps does not support PATs for this function.");let r=await this.config.request({url:`${Ae}/profile/profiles/me`,headers:w(this.config,t)});return{data:{id:r.body.id,name:r.body.displayName,username:r.body.displayName,email:r.body.emailAddress,avatarUrl:null}}}async getCurrentUserForInstance(t,r={}){let n=(await this.config.request({url:`${A}/${encodeURIComponent(t.namespace)}/_apis/ConnectionData`,headers:w(this.config,r)})).body.authorizedUser;if(n.providerDisplayName==="Anonymous")throw new Error("Current user not found.");return{data:{id:n.id,name:n.providerDisplayName,username:n.providerDisplayName,email:n.properties.Account.$value,avatarUrl:null}}}async getUserForCommit(t,r={}){if(!t.repo.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let n=(await this.config.request({url:`${A}/${encodeURIComponent(t.repo.namespace)}/${encodeURIComponent(t.repo.project)}/_apis/git/repositories/${encodeURIComponent(t.repo.name)}/commits/${t.oid}`,headers:w(this.config,r)})).body.author;return{data:{name:n.name,email:n.email,avatarUrl:n.imageUrl}}}async getRepo(t,r={}){if(!t.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let s=await this.config.request({url:`${A}/${encodeURIComponent(t.namespace)}/${encodeURIComponent(t.project)}/_apis/git/repositories/${encodeURIComponent(t.name)}`,headers:w(this.config,r)});return{data:le(t.namespace,s.body)}}async getRepos(t,r={}){return{data:(await Promise.all(t.map(n=>this.getRepo(n,r)))).map(n=>n.data)}}async getReposForAzureProject(t,r={}){if(!t.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');return{data:(await this.config.request({url:`${A}/${encodeURIComponent(t.namespace)}/${encodeURIComponent(t.project)}/_apis/git/repositories`,headers:w(this.config,r)})).body.value.map(n=>le(t.namespace,n))}}async getRefs(t,r,s={}){if(!r.repo.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let n=new URL(`${A}/${encodeURIComponent(r.repo.namespace)}/${encodeURIComponent(r.repo.project)}/_apis/git/repositories/${encodeURIComponent(r.repo.name)}/refs`);n.searchParams.set("filter",t),n.searchParams.set("$top",$.toString()),r.cursor&&n.searchParams.set("continuationToken",r.cursor);let o=await this.config.request({url:n.toString(),headers:w(this.config,s)}),a=o.headers["x-ms-continuationtoken"];return{pageInfo:{hasNextPage:!!a,endCursor:a||null},data:o.body.value.map(i=>({name:M(i.name),commit:{oid:i.objectId,authoredDate:null,committedDate:null}}))}}async getBranches(t,r={}){return this.getRefs("heads",t,r)}async getTags(t,r={}){return this.getRefs("tags",t,r)}async getPullRequestsForRepoBase(t,r={},s=100){let{page:n,repo:o,assigneeLogins:a,authorLogin:i}=t||{},u=n||1;if(!o.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let l="searchCriteria.status=1";return a&&a.length&&(l+=`&searchCriteria.reviewerId=${a[0]}`),i&&(l+=`&searchCriteria.creatorId=${i}`),await this.config.request({url:`${r.baseUrl||A}/${encodeURIComponent(o.namespace)}/${encodeURIComponent(o.project||"")}/_apis/git/repositories/${encodeURIComponent(o.name)}/pullRequests?${l}&%24top=${s}&%24skip=${(u-1)*s}`,headers:w(this.config,r)})}async getPullRequestsForRepo(t,r={}){let n=t.page||1,o=await this.getPullRequestsForRepoBase(t,r,100);return{pageInfo:{hasNextPage:o.body.value.length===100,nextPage:n+1},data:o.body.value.map(ue)}}async getPullRequestsForRepos(t,r={}){if(!t.repos.every(o=>o.project))throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let{repos:s}=t||{},n=[];return await Promise.all(s.map(async o=>{try{(await this.getPullRequestsForRepoBase({repo:o,...t},r)).body.value.forEach(i=>{n.push(ue(i))})}catch(a){if(a.statusCode!==404&&a.statusCode!==401)throw a}})),{data:n}}async getIssuesForAzureProject(t,r={}){let{page:s,assigneeLogins:n,authorLogin:o,mentionLogin:a}=t||{},i=s||1,u=200,l=["[Microsoft.VSTS.Common.ClosedDate] = ''","[System.TeamProject] = @project","[Microsoft.VSTS.Common.ResolvedDate] = ''"];o&&l.push(`[System.CreatedBy] = '${o.replace("'","''")}'`),n&&n[0]&&l.push(`[System.AssignedTo] = '${n[0].replace("'","''")}'`),a&&l.push("[System.Id] IN (@recentMentions)");let d=`Select [Microsoft.VSTS.Common.ClosedDate], [Microsoft.VSTS.Common.ResolvedDate] From WorkItems Where ${l.join(" AND ")} order by [System.CreatedDate] desc`,m=await this.config.request({url:`${r.baseUrl||A}/${encodeURIComponent(t.namespace)}/${encodeURIComponent(t.project)}/_apis/wit/wiql?api-version=6.0`,body:JSON.stringify({query:d}),method:"POST",headers:{...w(this.config,r),"Content-Type":"application/json"}}),c=m.body.workItems.slice((i-1)*u,u*i).map(g=>g.id),p=await this.config.request({url:`${r.baseUrl||A}/${encodeURIComponent(t.namespace)}/${encodeURIComponent(t.project)}/_apis/wit/workitemsbatch?api-version=6.0`,body:JSON.stringify({ids:c,$expand:"Links"}),method:"POST",headers:{...w(this.config,r),"Content-Type":"application/json"}});return{pageInfo:{hasNextPage:m.body.workItems.length>u*i,nextPage:i+1},data:p.body.value.map(Te)}}};var T=(e,t={})=>y(t.token||e.token,t.isPAT||e.isPAT);var q="https://api.bitbucket.org/2.0",xe={OPEN:"OPEN",MERGED:"MERGED",DECLINED:"CLOSED"},me=e=>({id:e.uuid,name:e.display_name||e.nickname,username:e.nickname||e.display_name,email:null,avatarUrl:e.links.avatar.href}),pe=e=>{let t=e.id;return{id:t.toString(),title:e.title,number:t,state:xe[e.state],isDraft:!1,commentCount:e.comment_count,upvoteCount:null,author:me(e.author),createdDate:new Date(e.created_on),updatedDate:new Date(e.updated_on),closedDate:null,repository:{name:e.source.repository.name,owner:{login:void 0}},headCommit:{buildStatus:null},baseRef:{name:e.destination.branch.name},headRef:{name:e.source.branch.name},url:e.links.html.href,assignees:null,reviews:null,additions:null,deletions:null,fileCount:null,commitCount:null,headRepository:null}},k=class extends G{async refreshToken(t){return{data:(await this.config.request({url:"https://bitbucket.org/site/oauth2/access_token",method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded",Authorization:`Basic ${t.base64ClientIDColonClientSecret}`},body:`grant_type=refresh_token&refresh_token=${t.refreshToken}`})).body}}async getCurrentUser(t={}){let r=await this.config.request({url:`${q}/user`,headers:T(this.config,t)});return{data:me(r.body)}}async getUserForCommit(t,r={}){var a;let n=(await this.config.request({url:`${q}/repositories/${t.repo.namespace}/${t.repo.name}/commit/${t.oid}`,headers:T(this.config,r)})).body.author,o=n.raw.match(/([^<]+)<(.+)>/);return{data:{name:o?o[1].trim():null,email:o?o[2]:null,avatarUrl:((a=n.user)==null?void 0:a.links.avatar.href)||null}}}async getRepo(t,r={}){var n,o;let s=await this.config.request({url:`${q}/repositories/${t.namespace}/${t.name}`,headers:T(this.config,r)});return{data:{id:s.body.uuid,namespace:s.body.workspace.slug,name:s.body.slug,webUrl:s.body.links.html.href,httpsUrl:((n=s.body.links.clone.find(a=>a.name==="https"))==null?void 0:n.href)??null,sshUrl:((o=s.body.links.clone.find(a=>a.name==="ssh"))==null?void 0:o.href)??null,defaultBranch:{name:s.body.mainbranch.name},permission:null}}}async getRepos(t,r={}){return{data:(await Promise.all(t.map(n=>this.getRepo(n,r)))).map(n=>n.data)}}async getBranches(t,r={}){var a;let s=new URL(`${q}/repositories/${t.repo.namespace}/${t.repo.name}/refs/branches`);s.searchParams.set("page",((a=t.page)==null?void 0:a.toString())||"1"),s.searchParams.set("pagelen",$.toString());let n=await this.config.request({url:s.toString(),headers:T(this.config,r)}),o=!!n.body.next;return{pageInfo:{hasNextPage:o,nextPage:o?n.body.page+1:null},data:n.body.values.map(i=>{let u=new Date(i.target.date);return{name:i.name,commit:{oid:i.target.hash,authoredDate:u,committedDate:u}}})}}async getTags(t,r={}){let s=new URL(`${q}/repositories/${t.repo.namespace}/${t.repo.name}/refs/tags`);s.searchParams.set("pagelen",$.toString()),t.cursor&&s.searchParams.set("page",t.cursor);let n=await this.config.request({url:s.toString(),headers:T(this.config,r)}),o=!!n.body.next,a=null;return n.body.next&&(a=new URL(n.body.next).searchParams.get("page")),{pageInfo:{hasNextPage:o,endCursor:a},data:n.body.values.map(i=>{let u=new Date(i.target.date);return{name:i.name,commit:{oid:i.target.hash,authoredDate:u,committedDate:u}}})}}async getPullRequestsForRepoBase(t,r={}){var n;let s=new URL(`${r.baseUrl||q}/repositories/${encodeURI(t.repo.namespace)}/${encodeURI(t.repo.name)}/pullrequests?state=OPEN`);return s.searchParams.set("page",((n=t.page)==null?void 0:n.toString())||"1"),s.searchParams.set("pagelen","50"),await this.config.request({url:s.toString(),headers:T(this.config,r)})}async getPullRequestsForRepo(t,r={}){let s=[],n=await this.getPullRequestsForRepoBase(t,r);n.body.values.forEach(a=>{if(t.authorLogin&&a.author.uuid!==t.authorLogin)return null;s.push(pe(a))});let o=!!n.body.next;return{pageInfo:{hasNextPage:o,nextPage:o?n.body.page+1:null},data:s}}async getPullRequestsForRepos(t,r={}){let s=[];return await Promise.all(t.repos.map(async n=>{try{(await this.getPullRequestsForRepoBase({repo:n,...t},r)).body.values.forEach(a=>{if(t.authorLogin&&a.author.uuid!==t.authorLogin)return null;s.push(pe(a))})}catch(o){if(o.statusCode!==404&&o.statusCode!==401)throw o}})),{data:s}}};var Z="https://api.github.com",qe=`${Z}/graphql`,_e=/\/api\/v3\/?$/,Be=e=>e?e.replace(_e,"/api/graphql"):qe,P=(e,t,r)=>{let s=y(r.token||e.token);return s["X-Github-Next-Global-ID"]="1",s["Content-Type"]="application/json",e.request({url:Be(r.baseUrl||e.baseUrl),method:"POST",headers:s,body:JSON.stringify(t)})},Oe={user:!0,"user:email":!0,"read:user":!0},_=e=>e.some(t=>Oe[t]),C=(e=!1,t=!1)=>`
|
|
2
|
+
id
|
|
3
|
+
databaseId
|
|
4
|
+
name
|
|
5
|
+
login
|
|
6
|
+
${t?"email":""}
|
|
7
|
+
avatarUrl${e?"(size: $avatarSize)":""}
|
|
8
|
+
`,ke=(e,t=!1)=>`
|
|
9
|
+
id
|
|
10
|
+
databaseId
|
|
11
|
+
number
|
|
12
|
+
title
|
|
13
|
+
state
|
|
14
|
+
author {
|
|
15
|
+
... on User {
|
|
16
|
+
${C(!1,t)}
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
commits(last: 1) {
|
|
20
|
+
totalCount
|
|
21
|
+
nodes {
|
|
22
|
+
commit {
|
|
23
|
+
... on Commit {
|
|
24
|
+
oid
|
|
25
|
+
status {
|
|
26
|
+
contexts {
|
|
27
|
+
context
|
|
28
|
+
state
|
|
29
|
+
description
|
|
30
|
+
targetUrl
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
baseRef {
|
|
38
|
+
name
|
|
39
|
+
target {
|
|
40
|
+
oid
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
headRef {
|
|
44
|
+
name
|
|
45
|
+
target {
|
|
46
|
+
oid
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
repository {
|
|
50
|
+
name
|
|
51
|
+
owner {
|
|
52
|
+
login
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
headRepository {
|
|
56
|
+
name
|
|
57
|
+
owner {
|
|
58
|
+
login
|
|
59
|
+
}
|
|
60
|
+
url
|
|
61
|
+
sshUrl
|
|
62
|
+
}
|
|
63
|
+
${e?"isDraft":""}
|
|
64
|
+
url
|
|
65
|
+
createdAt
|
|
66
|
+
comments {
|
|
67
|
+
totalCount
|
|
68
|
+
}
|
|
69
|
+
reactions(content: THUMBS_UP) {
|
|
70
|
+
totalCount
|
|
71
|
+
}
|
|
72
|
+
updatedAt
|
|
73
|
+
closedAt
|
|
74
|
+
assignees(first: 100) {
|
|
75
|
+
nodes {
|
|
76
|
+
${C(!1,t)}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
reviewRequests(first: 100) {
|
|
80
|
+
nodes {
|
|
81
|
+
asCodeOwner
|
|
82
|
+
requestedReviewer {
|
|
83
|
+
... on User {
|
|
84
|
+
${C(!1,t)}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
latestReviews(first: 100) {
|
|
90
|
+
nodes {
|
|
91
|
+
author {
|
|
92
|
+
... on User {
|
|
93
|
+
${C(!1,t)}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
state
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
additions
|
|
100
|
+
deletions
|
|
101
|
+
changedFiles
|
|
102
|
+
`,je={"-linked":"-linked",archived:"archived",assignee:"assignee",author:"author",base:"base",closed:"closed",commenter:"commenter",comments:"comments",created:"created",draft:"draft",head:"head",label:"label",language:"language",linked:"linked",in:"in",interactions:"interactions",involves:"involves",is:"is",mentions:"mentions",merged:"merged",milestone:"milestone",no:"no",org:"org",project:"project",reactions:"reactions",repo:"repo",review:"review","reviewed-by":"reviewed-by","review-requested":"review-requested",state:"state",status:"status",team:"team","team-review-requested":"team-review-requested",type:"type",updated:"updated",user:"user","user-review-requested":"user-review-requested"},Fe=new RegExp('(([^\\s]+:)?\\"(?:[^\\"\\\\]|\\\\.)*\\"?)|([^\\"\\s]+)',"g"),K=e=>{let t=[];return(e.match(Fe)??[]).forEach(s=>{if(s.includes(":")&&s!="is:closed"){let n=s.split(":")[0];je[n]&&t.push(s)}}),t},Y=async(e,t,r,s=!0,n=!1)=>{let{cursor:o,assigneeLogins:a,updatedBefore:i,isDraft:u,authorLogin:l,repos:d,reviewRequestedLogin:m,startQuery:c,mentionLogin:p}=t||{},g=K(c||"");d.forEach(f=>{g.push(`repo:${f.namespace}/${f.name}`)}),a&&a.forEach(f=>{g.push(`assignee:${f}`)}),i&&g.push(`updated:<${i}`),s&&u!=null&&u!=null&&g.push(`draft:${String(u)}`),l&&g.push(`author:${l}`),m&&g.push(`review-requested:${m}`),p&&g.push(`mentions:${p}`);let b=`
|
|
103
|
+
query (
|
|
104
|
+
$after: String
|
|
105
|
+
$search: String!
|
|
106
|
+
) {
|
|
107
|
+
search(
|
|
108
|
+
type: ISSUE
|
|
109
|
+
first: 100
|
|
110
|
+
after: $after
|
|
111
|
+
query: $search
|
|
112
|
+
) {
|
|
113
|
+
nodes {
|
|
114
|
+
... on PullRequest {
|
|
115
|
+
${ke(s,n)}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
pageInfo {
|
|
119
|
+
endCursor
|
|
120
|
+
hasNextPage
|
|
121
|
+
startCursor
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
`;return P(e,{query:`${b}`,variables:{after:o??null,search:`sort:updated type:pr state:open ${g.join(" ")}`}},r)};var ce=`
|
|
126
|
+
id
|
|
127
|
+
databaseId
|
|
128
|
+
owner {
|
|
129
|
+
login
|
|
130
|
+
}
|
|
131
|
+
name
|
|
132
|
+
url
|
|
133
|
+
sshUrl
|
|
134
|
+
defaultBranchRef {
|
|
135
|
+
name
|
|
136
|
+
}
|
|
137
|
+
viewerPermission
|
|
138
|
+
`,ee={id:"U_kgDNJ5k",databaseId:10137,name:"Deleted user",login:"ghost",email:"",avatarUrl:"https://avatars.githubusercontent.com/u/10137?v=4"},Ne={APPROVED:"APPROVED",CHANGES_REQUESTED:"CHANGES_REQUESTED",COMMENTED:"COMMENTED",REVIEW_REQUESTED:"REVIEW_REQUESTED"},ge=e=>({id:e.databaseId.toString(),graphQLId:e.id,namespace:e.owner.login,name:e.name,webUrl:e.url,httpsUrl:e.url.endsWith(".git")?e.url:`${e.url}.git`,sshUrl:e.sshUrl,defaultBranch:e.defaultBranchRef,permission:e.viewerPermission}),Qe={OPEN:"OPEN",CLOSED:"CLOSED",MERGED:"MERGED"},L=e=>({id:e.databaseId.toString(),graphQLId:e.id,name:e.name,username:e.login,email:e.email??null,avatarUrl:e.avatarUrl}),ze=e=>{var l,d,m,c,p,g,b,f;let t=e.author?e.author.id?e.author:null:ee,r=(d=(l=e.commits.nodes)==null?void 0:l[0])==null?void 0:d.commit,s=((m=e.headRef)==null?void 0:m.target)||r,n=s==null?void 0:s.oid,o=r==null?void 0:r.oid,a=n===o?(p=(c=r==null?void 0:r.status)==null?void 0:c.contexts)==null?void 0:p[0]:null,i=(((g=e.reviewRequests)==null?void 0:g.nodes)||[]).filter(h=>!h.asCodeOwner),u=(b=e.headRepository)==null?void 0:b.url;return u&&!u.endsWith(".git")&&(u=`${u}.git`),{id:e.databaseId.toString(),graphQLId:e.id,title:e.title,number:e.number,state:Qe[e.state],commentCount:e.comments.totalCount,upvoteCount:e.reactions.totalCount,author:t?L(t):null,createdDate:new Date(e.createdAt),isDraft:e.isDraft,repository:{name:e.repository.name,owner:{login:e.repository.owner.login}},headRepository:e.headRepository?{name:e.headRepository.name,owner:{login:e.headRepository.owner.login},remoteInfo:{cloneUrlHTTPS:u,cloneUrlSSH:e.headRepository.sshUrl}}:null,headCommit:{buildStatus:a||null},headRef:e.headRef?{name:e.headRef.name}:null,baseRef:e.baseRef?{name:e.baseRef.name}:null,url:e.url,updatedDate:new Date(e.updatedAt),closedDate:e.closedAt?new Date(e.closedAt):null,assignees:e.assignees.nodes?e.assignees.nodes.map(L):null,reviews:i.map(h=>({reviewer:L(h.requestedReviewer),state:"REVIEW_REQUESTED"})).concat((((f=e.latestReviews)==null?void 0:f.nodes)||[]).map(h=>{let R=h.author||ee;return{reviewer:L(R),state:Ne[h.state]}})),additions:e.additions,deletions:e.deletions,fileCount:e.changedFiles,commitCount:e.commits.totalCount}},Me=e=>{var r;let t=(r=e.author)!=null&&r.id?e.author:ee;return{id:e.databaseId.toString(),graphQLId:e.id,number:e.number,title:e.title,author:L(t),commentCount:e.comments.totalCount,createdDate:new Date(e.createdAt),description:null,state:null,repository:{name:e.repository.name,owner:{login:e.repository.owner.login}},url:e.url,updatedDate:new Date(e.updatedAt),assignees:e.assignees.nodes?e.assignees.nodes.map(L):[],upvoteCount:e.reactions.totalCount}},j=class extends z{constructor(){super(...arguments);this._scopesCache={}}async getScopes(r){let s=r.token||this.config.token;if(!s)return[];let n=this._scopesCache[s];if(!n){let a=(await P(this.config,{query:"query { rateLimit(dryRun: true) { __typename } }"},r)).headers["x-oauth-scopes"];n=a?a.split(", "):[],this._scopesCache[s]=n}return n}getEnterpriseAvatarUrlIfNeeded(r,s,n){let o=n.baseUrl||this.config.baseUrl;return!o||o.startsWith(Z)?r:s?`https://avatars.githubusercontent.com/u/e?email=${encodeURIComponent(s)}`:""}async getCurrentUser(r={}){var a;let s=await this.getScopes(r),o=(a=(await P(this.config,{query:`
|
|
139
|
+
query getCurrentUser {
|
|
140
|
+
viewer {
|
|
141
|
+
${C(!1,_(s))}
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
`},r)).body.data)==null?void 0:a.viewer;if(!o)throw new Error("Current user not found.");return{data:L(o)}}async getUserForCommit(r,s={}){var i,u;let o=(i=(await P(this.config,{query:`
|
|
145
|
+
query getUserForCommit(
|
|
146
|
+
$owner: String!
|
|
147
|
+
$name: String!
|
|
148
|
+
$oid: GitObjectID!
|
|
149
|
+
$avatarSize: Int
|
|
150
|
+
) {
|
|
151
|
+
repository(owner: $owner, name: $name) {
|
|
152
|
+
object(oid: $oid) {
|
|
153
|
+
... on Commit {
|
|
154
|
+
author {
|
|
155
|
+
name
|
|
156
|
+
email
|
|
157
|
+
avatarUrl(size: $avatarSize)
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
`,variables:{owner:r.repo.namespace,name:r.repo.name,oid:r.oid,avatarSize:r.avatarSize}},s)).body.data)==null?void 0:i.repository;if(!o)throw new Error("Repository not found.");let a=(u=o.object)==null?void 0:u.author;if(!a)throw new Error("Commit not found.");return{data:{name:a.name,email:a.email,avatarUrl:this.getEnterpriseAvatarUrlIfNeeded(a.avatarUrl,a.email,s)}}}async getAccountForEmail(r,s={}){var i,u,l;let n=await this.getScopes(s),a=(l=(u=(i=(await P(this.config,{query:`
|
|
164
|
+
query getAccountForEmail($query: String! $avatarSize: Int) {
|
|
165
|
+
search(query: $query, type: USER, first: 1) {
|
|
166
|
+
nodes {
|
|
167
|
+
... on User {
|
|
168
|
+
${C(!0,_(n))}
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
`,variables:{query:`in:email ${r.email}`,avatarSize:r.avatarSize}},s)).body.data)==null?void 0:i.search)==null?void 0:u.nodes)==null?void 0:l[0];if(!a)throw new Error("User not found.");return{data:L({...a,avatarUrl:this.getEnterpriseAvatarUrlIfNeeded(a.avatarUrl,a.email,s)})}}async getAccountForUsername(r,s={}){var i;let n=await this.getScopes(s),a=(i=(await P(this.config,{query:`
|
|
174
|
+
query getUserForUsername($login: String! $avatarSize: Int) {
|
|
175
|
+
user(login: $login) {
|
|
176
|
+
${C(!0,_(n))}
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
`,variables:{login:r.username,avatarSize:r.avatarSize}},s)).body.data)==null?void 0:i.user;if(!a)throw new Error("User not found.");return{data:L({...a,avatarUrl:this.getEnterpriseAvatarUrlIfNeeded(a.avatarUrl,a.email,s)})}}async getRepo(r,s={}){var o;let n=await P(this.config,{query:`
|
|
180
|
+
query getRepo($owner: String!, $name: String!) {
|
|
181
|
+
repository(owner: $owner, name: $name) {
|
|
182
|
+
${ce}
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
`,variables:{owner:r.namespace,name:r.name}},s);if(!((o=n.body.data)!=null&&o.repository))throw new Error(`Repository ${r.namespace}/${r.name} not found`);return{data:ge(n.body.data.repository)}}async getRepos(r,s={}){let n=r.map(({namespace:a,name:i},u)=>`
|
|
186
|
+
getRepo_${u}: repository(owner: "${a}", name: "${i}") {
|
|
187
|
+
${ce}
|
|
188
|
+
}
|
|
189
|
+
`).join(`
|
|
190
|
+
`),o=await P(this.config,{query:`
|
|
191
|
+
query batchGetRepos {
|
|
192
|
+
${n}
|
|
193
|
+
}
|
|
194
|
+
`},s);if(!o.body.data)throw new Error(o.statusText||"Unknown error");return{data:r.map(({namespace:a,name:i},u)=>{let l=o.body.data[`getRepo_${u}`];if(!l)throw new Error(`Repository ${a}/${i} not found`);return ge(l)})}}async getRefs(r,s,n={}){var u;let a=(u=(await P(this.config,{query:`
|
|
195
|
+
query getRefs($owner: String!, $name: String!, $refPrefix: String!, $cursor: String, $first: Int!) {
|
|
196
|
+
repository(owner: $owner, name: $name) {
|
|
197
|
+
refs(refPrefix: $refPrefix first: $first after: $cursor) {
|
|
198
|
+
pageInfo {
|
|
199
|
+
endCursor
|
|
200
|
+
hasNextPage
|
|
201
|
+
}
|
|
202
|
+
nodes {
|
|
203
|
+
name
|
|
204
|
+
target {
|
|
205
|
+
...on Commit {
|
|
206
|
+
oid
|
|
207
|
+
authoredDate
|
|
208
|
+
committedDate
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
`,variables:{owner:s.repo.namespace,name:s.repo.name,refPrefix:r,cursor:s.cursor,first:$}},n)).body.data)==null?void 0:u.repository;if(!a)throw new Error("Repository not found.");let i=a.refs;return i?{pageInfo:i.pageInfo,data:(i.nodes||[]).map(l=>{var m;let d=(m=l.target)!=null&&m.oid?l.target:null;return{name:l.name,commit:d?{oid:d.oid,authoredDate:new Date(d.authoredDate),committedDate:new Date(d.committedDate)}:null}})}:{pageInfo:{endCursor:null,hasNextPage:!1},data:[]}}async getBranches(r,s={}){return this.getRefs("refs/heads/",r,s)}async getTags(r,s={}){return this.getRefs("refs/tags/",r,s)}async getBlame(r,s={}){var i;let o=(i=(await P(this.config,{query:`
|
|
216
|
+
query getBlame($owner: String!, $name: String!, $ref: String!, $path: String!) {
|
|
217
|
+
repository(owner: $owner, name: $name) {
|
|
218
|
+
object(expression: $ref) {
|
|
219
|
+
... on Commit {
|
|
220
|
+
blame(path: $path) {
|
|
221
|
+
ranges {
|
|
222
|
+
startingLine
|
|
223
|
+
endingLine
|
|
224
|
+
commit {
|
|
225
|
+
oid
|
|
226
|
+
parents(first:100) {
|
|
227
|
+
nodes {
|
|
228
|
+
oid
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
authoredDate
|
|
232
|
+
committedDate
|
|
233
|
+
message
|
|
234
|
+
author {
|
|
235
|
+
name
|
|
236
|
+
email
|
|
237
|
+
avatarUrl
|
|
238
|
+
}
|
|
239
|
+
committer {
|
|
240
|
+
name
|
|
241
|
+
email
|
|
242
|
+
avatarUrl
|
|
243
|
+
}
|
|
244
|
+
additions
|
|
245
|
+
deletions
|
|
246
|
+
changedFilesIfAvailable
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
`,variables:{owner:r.repo.namespace,name:r.repo.name,ref:r.ref,path:r.path}},s)).body.data)==null?void 0:i.repository;if(!o)throw new Error("Repository not found.");let a=o.object;if(!a||!("blame"in a))throw new Error("Ref not found.");if(a.blame.ranges.length===0)throw new Error("File not found.");return{data:{ranges:a.blame.ranges.map(u=>{var l;return{startingLine:u.startingLine,endingLine:u.endingLine,commit:{oid:u.commit.oid,parentOids:((l=u.commit.parents.nodes)==null?void 0:l.map(d=>d.oid))||[],authoredDate:new Date(u.commit.authoredDate),author:u.commit.author?{name:u.commit.author.name,email:u.commit.author.email,avatarUrl:u.commit.author.avatarUrl}:null,committedDate:new Date(u.commit.committedDate),committer:u.commit.committer?{name:u.commit.committer.name,email:u.commit.committer.email,avatarUrl:u.commit.committer.avatarUrl}:null,message:u.commit.message,fileCount:u.commit.changedFilesIfAvailable,additions:u.commit.additions,deletions:u.commit.deletions}}})}}}async getPullRequestsForRepos(r,s={}){var l,d,m,c,p,g,b,f;let n=await this.getScopes(s),o=_(n),a="Field 'isDraft' doesn't exist on type 'PullRequest'",i=await Y(this.config,r,s,!0,o);if(i.body.errors){let R=((d=(l=i==null?void 0:i.body.errors)==null?void 0:l[0])==null?void 0:d.message)===a;s.baseUrl&&R&&(i=await Y(this.config,r,s,!1,o))}let u=((p=(c=(m=i.body)==null?void 0:m.data)==null?void 0:c.search)==null?void 0:p.nodes)||[];return{pageInfo:(f=(b=(g=i.body)==null?void 0:g.data)==null?void 0:b.search)==null?void 0:f.pageInfo,data:u.map(ze)}}async getIssuesForRepos(r,s={}){var b,f,h,R,I,U;let n=await this.getScopes(s),o=_(n),a=K(r.startQuery||""),{cursor:i,assigneeLogins:u,updatedBefore:l,authorLogin:d,mentionLogin:m}=r||{};r.repos.forEach(D=>{a.push(`repo:${D.namespace}/${D.name}`)}),u&&u.forEach(D=>{a.push(`assignee:${D}`)}),l&&a.push(`updated:<${l}`),d&&a.push(`author:${d}`),m&&a.push(`mentions:${m}`);let c=`
|
|
255
|
+
query (
|
|
256
|
+
$after: String
|
|
257
|
+
$search: String!
|
|
258
|
+
) {
|
|
259
|
+
search(
|
|
260
|
+
type: ISSUE
|
|
261
|
+
first: 100
|
|
262
|
+
after: $after
|
|
263
|
+
query: $search
|
|
264
|
+
) {
|
|
265
|
+
nodes {
|
|
266
|
+
... on Issue {
|
|
267
|
+
id
|
|
268
|
+
databaseId
|
|
269
|
+
title
|
|
270
|
+
author {
|
|
271
|
+
... on User {
|
|
272
|
+
${C(!1,o)}
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
createdAt
|
|
276
|
+
number
|
|
277
|
+
updatedAt
|
|
278
|
+
url
|
|
279
|
+
reactions(content: THUMBS_UP) {
|
|
280
|
+
totalCount
|
|
281
|
+
}
|
|
282
|
+
repository {
|
|
283
|
+
name
|
|
284
|
+
owner {
|
|
285
|
+
login
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
comments {
|
|
289
|
+
totalCount
|
|
290
|
+
}
|
|
291
|
+
assignees(first: 100) {
|
|
292
|
+
nodes {
|
|
293
|
+
${C(!1,o)}
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
pageInfo {
|
|
299
|
+
endCursor
|
|
300
|
+
hasNextPage
|
|
301
|
+
startCursor
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
`,p=await P(this.config,{query:`${c}`,variables:{after:i??null,search:`sort:updated type:issue state:open ${a.join(" ")}`}},s);if(!p.body.data)throw new Error(p.statusText||"Unknown error");let g=((h=(f=(b=p.body)==null?void 0:b.data)==null?void 0:f.search)==null?void 0:h.nodes)||[];return{pageInfo:(U=(I=(R=p.body)==null?void 0:R.data)==null?void 0:I.search)==null?void 0:U.pageInfo,data:g.map(Me)}}};var He="https://gitlab.com/api/graphql",v=(e,t,r)=>{let s=y(r.token||e.token);return e.request({url:He,method:"POST",headers:{...s,"Content-Type":"application/json"},body:JSON.stringify(t)})};var he="https://gitlab.com/api/v4",se="gid://gitlab/User/",F="gid://gitlab/Project/",Ve="gid://gitlab/MergeRequest/",We="gid://gitlab/Issue/",fe=`
|
|
306
|
+
id
|
|
307
|
+
namespace {
|
|
308
|
+
fullPath
|
|
309
|
+
}
|
|
310
|
+
path
|
|
311
|
+
webUrl
|
|
312
|
+
httpUrlToRepo
|
|
313
|
+
sshUrlToRepo
|
|
314
|
+
repository {
|
|
315
|
+
rootRef
|
|
316
|
+
}
|
|
317
|
+
`,E=`
|
|
318
|
+
id
|
|
319
|
+
name
|
|
320
|
+
username
|
|
321
|
+
publicEmail
|
|
322
|
+
avatarUrl
|
|
323
|
+
`,te=`
|
|
324
|
+
author {
|
|
325
|
+
${E}
|
|
326
|
+
}
|
|
327
|
+
assignees {
|
|
328
|
+
nodes {
|
|
329
|
+
${E}
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
createdAt
|
|
333
|
+
description
|
|
334
|
+
dueDate
|
|
335
|
+
id
|
|
336
|
+
iid
|
|
337
|
+
state
|
|
338
|
+
title
|
|
339
|
+
updatedAt
|
|
340
|
+
upvotes
|
|
341
|
+
userNotesCount
|
|
342
|
+
webUrl
|
|
343
|
+
`,Re=`
|
|
344
|
+
id
|
|
345
|
+
state
|
|
346
|
+
author {
|
|
347
|
+
${E}
|
|
348
|
+
}
|
|
349
|
+
diffStatsSummary {
|
|
350
|
+
additions
|
|
351
|
+
deletions
|
|
352
|
+
fileCount
|
|
353
|
+
}
|
|
354
|
+
commitCount
|
|
355
|
+
draft
|
|
356
|
+
userNotesCount
|
|
357
|
+
upvotes
|
|
358
|
+
title
|
|
359
|
+
webUrl
|
|
360
|
+
createdAt
|
|
361
|
+
updatedAt
|
|
362
|
+
mergedAt
|
|
363
|
+
iid
|
|
364
|
+
targetBranch
|
|
365
|
+
sourceBranch
|
|
366
|
+
assignees {
|
|
367
|
+
nodes {
|
|
368
|
+
${E}
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
reviewers {
|
|
372
|
+
nodes {
|
|
373
|
+
${E}
|
|
374
|
+
mergeRequestInteraction {
|
|
375
|
+
approved
|
|
376
|
+
reviewState
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
}`,x=e=>`${e.namespace}/${e.name}`,Xe=e=>`${e.namespace}/${e.name}`,be=e=>{var t;return{id:e.id.replace(F,""),graphQLId:e.id,namespace:e.namespace.fullPath.split("/").slice(0,-1).join("/"),name:e.path,webUrl:e.webUrl,httpsUrl:e.httpUrlToRepo,sshUrl:e.sshUrlToRepo,defaultBranch:(t=e.repository)!=null&&t.rootRef?{name:e.repository.rootRef}:null,permission:null}},Je={opened:"OPEN",merged:"MERGED",closed:"CLOSED"},B=e=>({id:e.id.replace(se,""),graphQLId:e.id,name:e.name,username:e.username,email:e.publicEmail,avatarUrl:e.avatarUrl}),ye=(e,t)=>{var r,s,n,o,a;return{id:e.id.replace(Ve,""),graphQLId:e.id,title:e.title,number:parseInt(e.iid,10),state:Je[e.state],commentCount:e.userNotesCount||0,upvoteCount:e.upvotes,author:e.author?B(e.author):null,createdDate:new Date(e.createdAt),isDraft:e.draft,repository:{name:t.name,owner:{login:t.owner}},headRepository:null,headCommit:{buildStatus:null},baseRef:{name:e.targetBranch},headRef:{name:e.sourceBranch},url:e.webUrl,updatedDate:new Date(e.updatedAt),closedDate:e.mergedAt?new Date(e.mergedAt):null,assignees:(r=e.assignees)!=null&&r.nodes?e.assignees.nodes.map(B):null,reviews:(s=e.reviewers)!=null&&s.nodes?e.reviewers.nodes.map(i=>{var u,l;return{reviewer:B(i),state:(u=i.mergeRequestInteraction)!=null&&u.approved?"APPROVED":((l=i.mergeRequestInteraction)==null?void 0:l.reviewState)==="REVIEWED"?"CHANGES_REQUESTED":"CHANGES_REQUESTED"}}):null,additions:((n=e.diffStatsSummary)==null?void 0:n.additions)||0,deletions:((o=e.diffStatsSummary)==null?void 0:o.deletions)||0,fileCount:((a=e.diffStatsSummary)==null?void 0:a.fileCount)||0,commitCount:e.commitCount||0}},re=(e,t)=>({author:{avatarUrl:e.author.avatarUrl,email:null,graphQLId:e.author.id,id:e.author.id.replace(se,""),name:e.author.name,username:e.author.username},assignees:e.assignees.nodes.map(r=>({avatarUrl:r.avatarUrl,email:null,graphQLId:r.id,id:r.id.replace(se,""),name:r.name,username:r.username})),commentCount:e.userNotesCount,createdDate:new Date(e.createdAt),description:e.description,graphQLId:e.id,id:e.id.replace(We,""),number:e.iid,repository:{name:t.name,owner:{login:t.owner}},updatedDate:new Date(e.updatedAt),upvoteCount:e.upvotes,state:e.state,title:e.title,url:e.webUrl}),N=class extends S{async getCurrentUser(t={}){var n;let s=(n=(await v(this.config,{query:`
|
|
380
|
+
query getCurrentUser {
|
|
381
|
+
currentUser {
|
|
382
|
+
${E}
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
`},t)).body.data)==null?void 0:n.currentUser;if(!s)throw new Error("Current user not found.");return{data:B(s)}}async getUserForCommit(t,r={}){var a,i,u,l;let s=x(t.repo),o=(l=(u=(i=(a=(await v(this.config,{query:`
|
|
386
|
+
query getUserForCommit($fullPath: ID!, $oid: String!) {
|
|
387
|
+
project(fullPath: $fullPath) {
|
|
388
|
+
repository {
|
|
389
|
+
tree(ref: $oid) {
|
|
390
|
+
lastCommit {
|
|
391
|
+
authorName
|
|
392
|
+
authorEmail
|
|
393
|
+
authorGravatar
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
`,variables:{fullPath:s,oid:t.oid}},r)).body.data)==null?void 0:a.project)==null?void 0:i.repository)==null?void 0:u.tree)==null?void 0:l.lastCommit;if(!o)throw new Error("Commit not found.");return{data:{name:o.authorName,email:o.authorEmail,avatarUrl:o.authorGravatar}}}async getAccountForEmail(t,r={}){var o,a,i;let n=(i=(a=(o=(await v(this.config,{query:`
|
|
400
|
+
query getAccountForEmail($email: String!) {
|
|
401
|
+
users(search: $email) {
|
|
402
|
+
nodes {
|
|
403
|
+
${E}
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
`,variables:{email:t.email}},r)).body.data)==null?void 0:o.users)==null?void 0:a.nodes)==null?void 0:i[0];if(!n)throw new Error("User not found.");return{data:B(n)}}async getAccountForUsername(t,r={}){var o;let n=(o=(await v(this.config,{query:`
|
|
408
|
+
query getAccountForUsername($username: String!) {
|
|
409
|
+
user(username: $username) {
|
|
410
|
+
${E}
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
`,variables:{username:t.username}},r)).body.data)==null?void 0:o.user;if(!n)throw new Error("User not found.");return{data:B(n)}}async getRepo(t,r={}){var o;let s=x(t),n=await v(this.config,{query:`
|
|
414
|
+
query getRepo($fullPath: ID!) {
|
|
415
|
+
project(fullPath: $fullPath) {
|
|
416
|
+
${fe}
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
`,variables:{fullPath:s}},r);if(!((o=n.body.data)!=null&&o.project))throw new Error(`Repository ${s} not found`);return{data:be(n.body.data.project)}}async getRepos(t,r={}){let s=t.map(x),n=s.map((a,i)=>`
|
|
420
|
+
getRepo_${i}: project(fullPath: "${a}") {
|
|
421
|
+
${fe}
|
|
422
|
+
}
|
|
423
|
+
`).join(`
|
|
424
|
+
`),o=await v(this.config,{query:`
|
|
425
|
+
query batchGetRepos {
|
|
426
|
+
${n}
|
|
427
|
+
}
|
|
428
|
+
`},r);if(!o.body.data)throw new Error(o.statusText||"Unknown error");return{data:s.map((a,i)=>{let u=o.body.data[`getRepo_${i}`];if(!u)throw new Error(`Repository ${a} not found`);return be(u)})}}async getRefs(t,r,s={}){var u;let n=x(r.repo),o=new URL(`${he}/projects/${encodeURIComponent(n)}/repository/${t}`);o.searchParams.set("page",((u=r.page)==null?void 0:u.toString())||"1"),o.searchParams.set("per_page",$.toString());let a=await this.config.request({url:o.toString(),headers:y(s.token||this.config.token)}),i=a.headers["x-next-page"];return{pageInfo:{hasNextPage:!!i,nextPage:i?parseInt(i,10):null},data:a.body.map(l=>({name:l.name,commit:{oid:l.commit.id,authoredDate:new Date(l.commit.authored_date),committedDate:new Date(l.commit.committed_date)}}))}}async getBranches(t,r={}){return this.getRefs("branches",t,r)}async getTags(t,r={}){return this.getRefs("tags",t,r)}async getBlame(t,r={}){let s=x(t.repo),n=new URL(`${he}/projects/${encodeURIComponent(s)}/repository/files/${encodeURIComponent(t.path)}/blame`);n.searchParams.set("ref",t.ref);let o=await this.config.request({url:n.toString(),headers:y(r.token||this.config.token)}),a=0;return{data:{ranges:o.body.map(i=>{let u=a+1;return a+=i.lines.length,{startingLine:u,endingLine:a,commit:{oid:i.commit.id,parentOids:i.commit.parent_ids,authoredDate:new Date(i.commit.authored_date),author:{name:i.commit.author_name,email:i.commit.author_email,avatarUrl:null},committedDate:new Date(i.commit.committed_date),committer:{name:i.commit.committer_name,email:i.commit.committer_email,avatarUrl:null},message:i.commit.message,fileCount:null,additions:null,deletions:null}}})}}}getVariablesForPullRequests(t){let{updatedBefore:r,isDraft:s,authorLogin:n,assigneeLogins:o,reviewRequestedLogin:a}=t||{},i={},u=[],l=[],d=(m,c,p)=>{u.push(`$${m}: ${p}`),l.push(`${m}: $${m}`),i[m]=c};return r&&d("updatedBefore",r,"Time"),n&&d("authorUsername",n,"String"),o&&d("assigneeUsername",o[0],"String"),s!=null&&d("draft",s,"Boolean"),a&&d("reviewerUsername",a,"String"),{variables:i,variableTypes:u,mergeRequestArguments:l}}async getPullRequestsForRepo(t,r={}){var b,f,h;let{cursor:s,repo:n}=t||{},o=x(n),{variables:a,variableTypes:i,mergeRequestArguments:u}=this.getVariablesForPullRequests(t),l={fullPath:o,...a},d=await v(this.config,{query:`
|
|
429
|
+
query getPullRequestsForRepo(
|
|
430
|
+
$fullPath: ID!
|
|
431
|
+
$after: String
|
|
432
|
+
${i.length?i.join(" "):""}
|
|
433
|
+
) {
|
|
434
|
+
project(
|
|
435
|
+
fullPath: $fullPath
|
|
436
|
+
) {
|
|
437
|
+
name
|
|
438
|
+
fullPath
|
|
439
|
+
mergeRequests(
|
|
440
|
+
first: 100
|
|
441
|
+
state: opened
|
|
442
|
+
sort: UPDATED_DESC
|
|
443
|
+
after: $after
|
|
444
|
+
${u.length?u.join(" "):""}
|
|
445
|
+
) {
|
|
446
|
+
pageInfo {
|
|
447
|
+
endCursor
|
|
448
|
+
hasNextPage
|
|
449
|
+
}
|
|
450
|
+
nodes {
|
|
451
|
+
${Re}
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
}
|
|
455
|
+
}
|
|
456
|
+
`,variables:{...l,after:s}},r),m=[],c=(b=d.body.data)==null?void 0:b.project,p={name:(c==null?void 0:c.name)||"",owner:((c==null?void 0:c.fullPath)||"").split("/").slice(0,-1).join("/")};return(((f=c==null?void 0:c.mergeRequests)==null?void 0:f.nodes)||[]).forEach(R=>{m.push(ye(R,p))}),{pageInfo:(h=c==null?void 0:c.mergeRequests)==null?void 0:h.pageInfo,data:m}}async getPullRequestsForRepos(t,r={}){var c,p,g,b,f;let{cursor:s}=t||{},n=t.repoIds.map(h=>h.toString().startsWith(F)?h:`${F}${h}`),{variables:o,variableTypes:a,mergeRequestArguments:i}=this.getVariablesForPullRequests(t),u={projectIds:n,...o},l=await v(this.config,{query:`
|
|
457
|
+
query getPullRequests(
|
|
458
|
+
$projectIds: [ID!]
|
|
459
|
+
$after: String
|
|
460
|
+
${a.length?a.join(" "):""}
|
|
461
|
+
) {
|
|
462
|
+
projects(
|
|
463
|
+
ids: $projectIds
|
|
464
|
+
after: $after
|
|
465
|
+
) {
|
|
466
|
+
pageInfo {
|
|
467
|
+
endCursor
|
|
468
|
+
hasNextPage
|
|
469
|
+
}
|
|
470
|
+
nodes {
|
|
471
|
+
name
|
|
472
|
+
fullPath
|
|
473
|
+
mergeRequests(
|
|
474
|
+
first: 100
|
|
475
|
+
state: opened
|
|
476
|
+
sort: UPDATED_DESC
|
|
477
|
+
${i.length?i.join(" "):""}
|
|
478
|
+
) {
|
|
479
|
+
nodes {
|
|
480
|
+
${Re}
|
|
481
|
+
}
|
|
482
|
+
}
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
}
|
|
486
|
+
`,variables:{...u,after:s}},r),d=[];return(((p=(c=l.body.data)==null?void 0:c.projects)==null?void 0:p.nodes)||[]).forEach(h=>{var U;let R={name:h.name,owner:h.fullPath.split("/").slice(0,-1).join("/")};(((U=h.mergeRequests)==null?void 0:U.nodes)||[]).forEach(D=>{d.push(ye(D,R))})}),{pageInfo:(f=(b=(g=l.body)==null?void 0:g.data)==null?void 0:b.projects)==null?void 0:f.pageInfo,data:d}}async getIssue(t,r={}){var o,a,i,u,l,d,m;let s=Xe(t),n=await v(this.config,{query:`
|
|
487
|
+
query GetSingleIssue($projectId: ID!, $issueId: String!) {
|
|
488
|
+
project(fullPath: $projectId) {
|
|
489
|
+
name
|
|
490
|
+
fullPath
|
|
491
|
+
issue(iid: $issueId) {
|
|
492
|
+
${te}
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
}
|
|
496
|
+
`,variables:{issueId:t.id,projectId:s}},r);if(!((o=n.body.data)!=null&&o.project))throw new Error(`Repository ${s} not found`);if(!((i=(a=n.body.data)==null?void 0:a.project)!=null&&i.issue))throw new Error(`Issue ${t.id} not found`);return{data:re((l=(u=n.body.data)==null?void 0:u.project)==null?void 0:l.issue,{name:(d=n.body.data)==null?void 0:d.project.name,owner:(m=n.body.data)==null?void 0:m.project.fullPath.split("/").slice(0,-1).join("/")})}}getVariablesForIssues(t){let{updatedBefore:r,authorLogin:s,assigneeLogins:n}=t||{},o={},a=[],i=[],u=(l,d,m)=>{a.push(`$${l}: ${m}`),i.push(`${l}: $${l}`),o[l]=d};return r&&u("updatedBefore",r,"Time"),s&&u("authorUsername",s,"String"),n&&u("assigneeUsername",n[0],"String"),{variables:o,variableTypes:a,issueArguments:i}}async getIssuesForRepo(t,r={}){var f,h,R;let{cursor:s,repo:n}=t||{},o=x(n),{variables:a,variableTypes:i,issueArguments:u}=this.getVariablesForIssues(t),l={fullPath:o,...a},d=`
|
|
497
|
+
query GetIssuesFromProject(
|
|
498
|
+
$fullPath: ID!
|
|
499
|
+
$after: String
|
|
500
|
+
${i.length?i.join(" "):""}
|
|
501
|
+
) {
|
|
502
|
+
project(
|
|
503
|
+
fullPath: $fullPath
|
|
504
|
+
) {
|
|
505
|
+
name
|
|
506
|
+
fullPath
|
|
507
|
+
issues(
|
|
508
|
+
first: 100
|
|
509
|
+
state: opened
|
|
510
|
+
sort: UPDATED_DESC
|
|
511
|
+
after: $after
|
|
512
|
+
${u.length?u.join(" "):""}
|
|
513
|
+
) {
|
|
514
|
+
nodes {
|
|
515
|
+
${te}
|
|
516
|
+
}
|
|
517
|
+
pageInfo {
|
|
518
|
+
endCursor
|
|
519
|
+
hasNextPage
|
|
520
|
+
}
|
|
521
|
+
}
|
|
522
|
+
}
|
|
523
|
+
}`,m=await v(this.config,{query:d,variables:{...l,after:s}},r),c=[],p=(f=m.body.data)==null?void 0:f.project,g={name:(p==null?void 0:p.name)||"",owner:((p==null?void 0:p.fullPath)||"").split("/").slice(0,-1).join("/")};return(((h=p==null?void 0:p.issues)==null?void 0:h.nodes)||[]).forEach(I=>{c.push(re(I,g))}),{pageInfo:(R=p==null?void 0:p.issues)==null?void 0:R.pageInfo,data:c.sort((I,U)=>(I.updatedDate||I.createdDate).getTime()-(U.updatedDate||U.createdDate).getTime())}}async getIssuesForRepos(t,r={}){var p,g,b,f,h;let{cursor:s}=t||{},n=t.repoIds.map(R=>R.toString().startsWith(F)?R:`${F}${R}`),{variables:o,variableTypes:a,mergeRequestArguments:i}=this.getVariablesForPullRequests(t),u={projectIds:n,...o},l=`
|
|
524
|
+
query GetIssuesFromProject(
|
|
525
|
+
$projectIds: [ID!]
|
|
526
|
+
$after: String
|
|
527
|
+
${a.length?a.join(" "):""}
|
|
528
|
+
) {
|
|
529
|
+
projects(
|
|
530
|
+
ids: $projectIds
|
|
531
|
+
after: $after
|
|
532
|
+
) {
|
|
533
|
+
pageInfo {
|
|
534
|
+
endCursor
|
|
535
|
+
hasNextPage
|
|
536
|
+
}
|
|
537
|
+
nodes {
|
|
538
|
+
name
|
|
539
|
+
fullPath
|
|
540
|
+
issues(
|
|
541
|
+
first: 100
|
|
542
|
+
state: opened
|
|
543
|
+
sort: UPDATED_DESC
|
|
544
|
+
${i.length?i.join(" "):""}
|
|
545
|
+
) {
|
|
546
|
+
nodes {
|
|
547
|
+
${te}
|
|
548
|
+
}
|
|
549
|
+
}
|
|
550
|
+
}
|
|
551
|
+
}
|
|
552
|
+
}`,d=await v(this.config,{query:l,variables:{...u,after:s}},r),m=[];return(((g=(p=d.body.data)==null?void 0:p.projects)==null?void 0:g.nodes)||[]).forEach(R=>{var D;let I={name:R.name,owner:R.fullPath.split("/").slice(0,-1).join("/")};(((D=R.issues)==null?void 0:D.nodes)||[]).forEach(Ie=>m.push(re(Ie,I)))}),{pageInfo:(h=(f=(b=d.body)==null?void 0:b.data)==null?void 0:f.projects)==null?void 0:h.pageInfo,data:m.sort((R,I)=>(R.updatedDate||R.createdDate).getTime()-(I.updatedDate||I.createdDate).getTime())}}};var Ze="https://api.atlassian.com/ex/jira",Ke=100,Ye=e=>{var r;let t=e.fields.assignee;return{id:e.id,commentCount:e.fields.comment.comments.length,number:e.key,title:e.fields.summary,url:e.self,createdDate:new Date(e.fields.created),author:{id:e.fields.creator.accountId,name:e.fields.creator.displayName,email:e.fields.creator.emailAddress,avatarUrl:e.fields.creator.avatarUrls["32x32"],username:e.fields.creator.displayName},updatedDate:new Date(e.fields.updated),assignees:t?[{id:t.accountId,name:t.displayName,email:t.emailAddress,avatarUrl:t.avatarUrls["32x32"],username:t.displayName}]:[],description:null,repository:null,state:null,upvoteCount:((r=e.fields.votes)==null?void 0:r.votes)||0}},H=class extends S{async getIssuesForProject(t,r={}){let{assigneeLogins:s,authorLogin:n,mentionLogin:o,project:a}=t||{},i=[`project = "${a}"`];return n&&i.push(`creator in (${n})`),s&&i.push(`assignee in (${s.join(", ")})`),o&&i.push(`comment ~ ${o}`),{data:(await this.config.request({url:`${r.baseUrl||Ze}/${t.resourceId}/rest/api/2/search?jql=${i.join(" AND ")}&startAt=0&maxResults=${Ke}&fields=${["assignee","comment","summary","created","creator","updated","votes"].join(",")}`,headers:y(r.token||this.config.token)})).body.issues.map(Ye)}}};var et="https://api.trello.com",tt=1e3,rt=e=>{let t=new Date(1e3*parseInt(e.id.substring(0,8),16));return{id:e.id,commentCount:e.badges.comments,number:e.idShort.toString(),title:e.name,url:e.url,createdDate:new Date(t.toISOString()),author:null,updatedDate:new Date(e.dateLastActivity),assignees:e.idMembers.map(r=>({id:r,username:null,name:null,email:null,avatarUrl:null})),description:null,state:null,repository:null,upvoteCount:e.badges.votes}},V=class extends S{async getIssuesForBoard(t,r={}){let s=["-is:archived","sort:edited"],{appKey:n,boardId:o,filterText:a,assigneeLogins:i}=t||{};i&&s.push("@me");let u=`${a?`${a}`:""}${s.join(" ")} board:${o}`;return{data:(await this.config.request({url:`${r.baseUrl||et}/1/search?key=${n}&query=${u}&cards_limit=${tt}&token=${r.token||this.config.token}`,headers:y(r.token||this.config.token)})).body.cards.map(rt)}}};var st=e=>{let t={request:e==null?void 0:e.request};return{azureDevOps:new O({...t,...e==null?void 0:e.azureDevOps}),bitbucket:new k({...t,...e==null?void 0:e.bitbucket}),github:new j({...t,...e==null?void 0:e.github}),gitlab:new N({...t,...e==null?void 0:e.gitlab}),jira:new H({...t,...e==null?void 0:e.jira}),trello:new V({...t,...e==null?void 0:e.trello})}},nt=st;
|