@gitkraken/provider-apis 0.12.4 → 0.13.0
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 +10 -0
- package/dist/index.js +122 -87
- package/dist/providers/azureDevops/azureDevOps.d.ts +20 -0
- package/dist/providers/github/github.d.ts +10 -1
- package/dist/providers/gitlab/gitlab.d.ts +9 -0
- package/dist/providers/issueProvider.d.ts +1 -1
- package/dist/providers/jira/jira.d.ts +21 -0
- package/dist/providers/trello/trello.d.ts +12 -0
- package/package.json +2 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.13.0
|
|
4
|
+
|
|
5
|
+
- added `getAccountsForRepo` (GitHub, GitLab)
|
|
6
|
+
- added `getAzureProjectScopeDescriptor` (Azure DevOps)
|
|
7
|
+
- added `getAccountsForAzureProject` (Azure DevOps)
|
|
8
|
+
- ⚠️ This adds `js-base64` as a dependency
|
|
9
|
+
- added `getAccountsForJiraProject` (Jira)
|
|
10
|
+
- added `getAccountsForTrelloBoard` (Trello)
|
|
11
|
+
- improved efficiency of `getPullRequestsAssociatedWithUser` (GitHub)
|
|
12
|
+
|
|
3
13
|
## 0.12.4
|
|
4
14
|
|
|
5
15
|
- added `mergeStrategy` argument to `mergePullRequest` (Azure, BitBucket, GitHub, GitLab)
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";var Ye=Object.create;var K=Object.defineProperty;var et=Object.getOwnPropertyDescriptor;var tt=Object.getOwnPropertyNames;var rt=Object.getPrototypeOf,st=Object.prototype.hasOwnProperty;var x=(e,r)=>{for(var t in r)K(e,t,{get:r[t],enumerable:!0})},Oe=(e,r,t,s)=>{if(r&&typeof r=="object"||typeof r=="function")for(let n of tt(r))!st.call(e,n)&&n!==t&&K(e,n,{get:()=>r[n],enumerable:!(s=et(r,n))||s.enumerable});return e};var nt=(e,r,t)=>(t=e!=null?Ye(rt(e)):{},Oe(r||!e||!e.__esModule?K(t,"default",{value:e,enumerable:!0}):t,e)),at=e=>Oe(K({},"__esModule",{value:!0}),e);var sr={};x(sr,{AzureDevOps:()=>B,AzureDevopsUtils:()=>te,Bitbucket:()=>j,BitbucketServer:()=>F,BitbucketServerUtils:()=>se,BitbucketUtils:()=>re,GitHub:()=>M,GitHubUtils:()=>ne,GitLab:()=>W,GitLabUtils:()=>ae,Jira:()=>J,JiraUtils:()=>oe,Trello:()=>V,TrelloUtils:()=>ie,Utils:()=>rr,default:()=>tr});module.exports=at(sr);var S=100;var ke=nt(require("node-fetch")),_e=globalThis.fetch||ke.default;var Ne=e=>e.name==="fetch";var ot=async e=>{let r=e.headers.get("content-type")||"",t=null;if(r.startsWith("application/json")){let n=await e.text();t=n.trim().length>0?JSON.parse(n):null}else if(r.startsWith("text/"))t=await e.text();else throw new Error(`Unsupported content-type: ${r}`);let s={body:t,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},le=e=>Ne(e)?async({url:r,...t})=>{let s=await e(r,t);return ot(s)}:e;var $=class{constructor(r){this.config={...r,request:le((r==null?void 0:r.request)||_e)}}updateConfig(r){this.config={...this.config,...r,request:r.request?le(r.request):this.config.request}}},T=class extends ${};var m=(e,r)=>{let t={};return e&&(t.Authorization=`${r?"Basic":"Bearer"} ${e}`),t};var w=(e,r={})=>m(r.token||e.token,r.isPAT||e.isPAT),Qe=e=>e.url.replace("/_apis/git/repositories/","/_git/").replace(`/${e.repository.project.id}/`,`/${encodeURIComponent(e.repository.project.name)}/`).replace(`/${e.repository.id}/`,`/${encodeURIComponent(e.repository.name)}/`).replace("/pullRequests/","/pullrequest/");var Be="https://app.vssps.visualstudio.com/_apis",E="https://dev.azure.com",it={active:"OPEN",completed:"MERGED",abandoned:"CLOSED"},ut={10:"APPROVED",5:"APPROVED",0:"REVIEW_REQUESTED",[-5]:"CHANGES_REQUESTED",[-10]:"CHANGES_REQUESTED"},pe=e=>({id:e.id,name:e.displayName,username:e.uniqueName||e.displayName,email:null,avatarUrl:e.imageUrl}),X=e=>e.startsWith("refs/heads/")?e.replace("refs/heads/",""):e,je=e=>{var r;return{id:e.pullRequestId.toString(),title:e.title,number:e.codeReviewId,state:it[e.status],isDraft:e.isDraft,commentCount:null,upvoteCount:null,author:pe(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:X(e.targetRefName),oid:e.lastMergeTargetCommit.commitId},headRef:{name:X(e.sourceRefName),oid:e.lastMergeSourceCommit.commitId},url:Qe(e),assignees:e.reviewers.map(pe),reviews:e.reviewers.filter(t=>t.vote!==0).map(t=>({reviewer:pe(t),state:ut[t.vote]||"REVIEW_REQUESTED"})),additions:null,deletions:null,fileCount:null,commitCount:null,headRepository:null,mergeableState:"UNKNOWN",labels:((r=e.labels)==null?void 0:r.map(t=>({color:null,description:null,id:t.id,name:t.name})))??[]}},Fe=(e,r)=>({id:r.id,name:r.name,namespace:e,project:r.project.name,webUrl:r.webUrl,httpsUrl:r.remoteUrl,sshUrl:r.sshUrl,defaultBranch:r.defaultBranch?{name:X(r.defaultBranch)}:null,permission:null}),lt=(e,r)=>{var i,u;let t=e.fields,s=t["System.AssignedTo"],n=t["System.State"],o=t["System.WorkItemType"],a;return n&&o&&(a=(i=r[o])==null?void 0:i[n]),{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:s?[{avatarUrl:s._links.avatar.href,email:null,id:s.id,name:s.uniqueName,username:s.displayName}]:[],description:null,state:{name:(a==null?void 0:a.title)||n,color:null},type:t["System.WorkItemType"],repository:null,upvoteCount:0,labels:((u=e.fields["System.Tags"])==null?void 0:u.split(";").map(l=>({color:null,description:null,id:null,name:l.trim()})))??[]}},B=class extends ${async getCurrentUser(r={}){if(r.isPAT||this.config.isPAT)throw new Error("Azure DevOps does not support PATs for this function.");let t=await this.config.request({url:`${Be}/profile/profiles/me`,headers:w(this.config,r)});return{data:{id:t.body.id,name:t.body.displayName,username:t.body.displayName,email:t.body.emailAddress,avatarUrl:null}}}async getCurrentUserForInstance(r,t={}){let n=(await this.config.request({url:`${E}/${encodeURIComponent(r.namespace)}/_apis/ConnectionData`,headers:w(this.config,t)})).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(r,t={}){if(!r.repo.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let n=(await this.config.request({url:`${E}/${encodeURIComponent(r.repo.namespace)}/${encodeURIComponent(r.repo.project)}/_apis/git/repositories/${encodeURIComponent(r.repo.name)}/commits/${r.oid}`,headers:w(this.config,t)})).body.author;return{data:{name:n.name,email:n.email,avatarUrl:n.imageUrl}}}async getOrgsForUser(r,t={}){return{data:(await this.config.request({url:`${Be}/accounts?memberId=${r.userId}&api-version=6.0`,headers:w(this.config,t)})).body.value.map(n=>({id:n.accountId,name:n.accountName}))}}async getAzureProjects(r,t={}){let s=new URL(`${E}/${encodeURIComponent(r.namespace)}/_apis/projects`);s.searchParams.set("$top",S.toString()),r.cursor&&s.searchParams.set("$skip",r.cursor);let n=await this.config.request({url:s.toString(),headers:w(this.config,t)}),o=n.headers["x-ms-continuationtoken"];return{pageInfo:{hasNextPage:!!o,endCursor:o||null},data:n.body.value.map(a=>({id:a.id,name:a.name,namespace:r.namespace}))}}async getRepo(r,t={}){if(!r.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let s=await this.config.request({url:`${E}/${encodeURIComponent(r.namespace)}/${encodeURIComponent(r.project)}/_apis/git/repositories/${encodeURIComponent(r.name)}`,headers:w(this.config,t)});return{data:Fe(r.namespace,s.body)}}async getRepos(r,t={}){let s=[],n=[];return await Promise.all(r.map(async o=>{try{let a=await this.getRepo(o,t);s.push(a.data)}catch(a){n.push({input:o,error:a})}})),{data:s,errors:n}}async getReposForAzureProject(r,t={}){if(!r.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');return{data:(await this.config.request({url:`${E}/${encodeURIComponent(r.namespace)}/${encodeURIComponent(r.project)}/_apis/git/repositories`,headers:w(this.config,t)})).body.value.map(n=>Fe(r.namespace,n))}}async getRefs(r,t,s={}){if(!t.repo.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let n=new URL(`${E}/${encodeURIComponent(t.repo.namespace)}/${encodeURIComponent(t.repo.project)}/_apis/git/repositories/${encodeURIComponent(t.repo.name)}/refs`);n.searchParams.set("filter",r),n.searchParams.set("$top",S.toString()),t.cursor&&n.searchParams.set("continuationToken",t.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:X(i.name),commit:{oid:i.objectId,authoredDate:null,committedDate:null}}))}}async getBranches(r,t={}){return this.getRefs("heads",r,t)}async getTags(r,t={}){return this.getRefs("tags",r,t)}async getPullRequestsForRepoBase(r,t={},s=100){let{page:n,repo:o,assigneeLogins:a,authorLogin:i}=r||{},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:`${t.baseUrl||E}/${encodeURIComponent(o.namespace)}/${encodeURIComponent(o.project||"")}/_apis/git/repositories/${encodeURIComponent(o.name)}/pullRequests?${l}&%24top=${s}&%24skip=${(u-1)*s}`,headers:w(this.config,t)})}async getPullRequestsForRepo(r,t={}){let n=r.page||1,o=await this.getPullRequestsForRepoBase(r,t,100);return{pageInfo:{hasNextPage:o.body.value.length===100,nextPage:n+1},data:o.body.value.map(je)}}async getPullRequestsForRepos(r,t={}){if(!r.repos.every(o=>o.project))throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let{repos:s}=r||{},n=[];return await Promise.all(s.map(async o=>{try{(await this.getPullRequestsForRepoBase({repo:o,...r},t)).body.value.forEach(i=>{n.push(je(i))})}catch(a){if(a.statusCode!==404&&a.statusCode!==401)throw a}})),{data:n}}async updatePullRequest(r,t,s,n){let{namespace:o,project:a,name:i}=r;return await this.config.request({method:"PATCH",url:`${n.baseUrl||E}/${encodeURIComponent(o)}/${encodeURIComponent(a||"")}/_apis/git/repositories/${i}/pullrequests/${t}?api-version=6.0`,body:s,headers:{...w(this.config,n),"Content-Type":"application/json"}})}async closePullRequest(r,t={}){if(!r.repo.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let{repo:s,pullRequestId:n}=r,o={status:"abandoned"};if(!(await this.updatePullRequest(s,n,JSON.stringify(o),t)).body.status)throw new Error("Could not close pull request")}async mergePullRequest(r,t={}){if(!r.repo.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let{repo:s,pullRequestId:n,expectedSourceSha:o,mergeStrategy:a}=r,i;switch(a){case"MERGE_COMMIT":{i="noFastForward";break}case"REBASE":{i="rebase";break}case"REBASE_THEN_MERGE_COMMIT":{i="rebaseMerge";break}case"SQUASH":{i="squash";break}}let u={completionOptions:{mergeStrategy:i},lastMergeSourceCommit:{commitId:o},status:"completed"};if(!(await this.updatePullRequest(s,n,JSON.stringify(u),t)).body.status)throw new Error("Could not merge pull request")}async setPullRequestAsDraft(r,t={}){if(!r.repo.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let{repo:s,pullRequestId:n,isDraft:o}=r,a={isDraft:o};if(!(await this.updatePullRequest(s,n,JSON.stringify(a),t)).body.status)throw new Error("Could not set the pull request as draft")}async getIssuesForAzureProject(r,t={}){let{page:s,assigneeLogins:n,authorLogin:o,mentionLogin:a,statusByWorkItemIdByStatusId:i}=r||{},u=s||1,l=200,p=["[Microsoft.VSTS.Common.ClosedDate] = ''","[System.TeamProject] = @project","[Microsoft.VSTS.Common.ResolvedDate] = ''"];o&&p.push(`[System.CreatedBy] = '${o.replace("'","''")}'`),n&&n[0]&&p.push(`[System.AssignedTo] = '${n[0].replace("'","''")}'`),a&&p.push("[System.Id] IN (@recentMentions)");let d=`Select [Microsoft.VSTS.Common.ClosedDate], [Microsoft.VSTS.Common.ResolvedDate] From WorkItems Where ${p.join(" AND ")} order by [System.CreatedDate] desc`,g=await this.config.request({url:`${t.baseUrl||E}/${encodeURIComponent(r.namespace)}/${encodeURIComponent(r.project)}/_apis/wit/wiql?api-version=6.0`,body:JSON.stringify({query:d}),method:"POST",headers:{...w(this.config,t),"Content-Type":"application/json"}}),c=g.body.workItems.slice((u-1)*l,l*u).map(I=>I.id);if(c.length==0)return{pageInfo:{hasNextPage:!1,nextPage:null},data:[]};let R=await this.config.request({url:`${t.baseUrl||E}/${encodeURIComponent(r.namespace)}/${encodeURIComponent(r.project)}/_apis/wit/workitemsbatch?api-version=6.0`,body:JSON.stringify({ids:c,$expand:"Links"}),method:"POST",headers:{...w(this.config,t),"Content-Type":"application/json"}});return{pageInfo:{hasNextPage:g.body.workItems.length>l*u,nextPage:u+1},data:R.body.value.map(I=>lt(I,i||{}))}}async setIssueStatus(r,t={}){var l;if(!r.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let{namespace:s,project:n,issueId:o,status:a}=r,i=[{op:"add",path:"/fields/System.State",value:a}];if(!((l=(await this.config.request({method:"PATCH",url:`${t.baseUrl||E}/${encodeURIComponent(s)}/${encodeURIComponent(n||"")}/_apis/wit/workitems/${o}?api-version=6.0`,body:JSON.stringify(i),headers:{...w(this.config,t),"Content-Type":"application/json-patch+json"}})).body.fields)!=null&&l["System.State"]))throw new Error("Could not set issue status")}async getIssueTypesForAzureProject(r,t={}){if(!r.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let{namespace:s,project:n}=r;return{data:(await this.config.request({url:`${t.baseUrl||E}/${encodeURIComponent(s)}/${encodeURIComponent(n||"")}/_apis/wit/workitemtypes?api-version=6.0`,headers:{...w(this.config,t)}})).body.value}}async getLabelsForProject(r,t={}){let{namespace:s,project:n}=r;return{data:(await this.config.request({url:`${t.baseUrl||E}/${encodeURIComponent(s)}/${encodeURIComponent(n||"")}/_apis/wit/tags?api-version=6.0`,headers:{...w(this.config,t)}})).body.value.map(a=>({color:null,description:null,id:a.id,name:a.name}))}}};var v=(e,r={})=>m(r.token||e.token,r.isPAT||e.isPAT);var D="https://api.bitbucket.org/2.0",pt={OPEN:"OPEN",MERGED:"MERGED",DECLINED:"CLOSED"},ze=e=>({id:e.uuid,name:e.display_name||e.nickname,username:e.nickname||e.display_name,email:null,avatarUrl:e.links.avatar.href}),Me=e=>{var r,t;return{id:e.uuid,namespace:e.workspace.slug,name:e.slug,webUrl:e.links.html.href,httpsUrl:((r=e.links.clone.find(s=>s.name==="https"))==null?void 0:r.href)??null,sshUrl:((t=e.links.clone.find(s=>s.name==="ssh"))==null?void 0:t.href)??null,defaultBranch:{name:e.mainbranch.name},permission:null}},me=e=>{let r=e.id;return{id:r.toString(),title:e.title,number:r,state:pt[e.state],isDraft:!1,commentCount:e.comment_count,upvoteCount:null,author:ze(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,oid:e.destination.commit.hash},headRef:{name:e.source.branch.name,oid:e.source.commit.hash},url:e.links.html.href,assignees:null,reviews:null,additions:null,deletions:null,fileCount:null,commitCount:null,headRepository:null,mergeableState:"UNKNOWN"}},j=class extends ${async refreshToken(r){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 ${r.base64ClientIDColonClientSecret}`},body:`grant_type=refresh_token&refresh_token=${r.refreshToken}`})).body}}async getCurrentUser(r={}){let t=await this.config.request({url:`${D}/user`,headers:v(this.config,r)});return{data:ze(t.body)}}async getUserForCommit(r,t={}){var a;let n=(await this.config.request({url:`${D}/repositories/${r.repo.namespace}/${r.repo.name}/commit/${r.oid}`,headers:v(this.config,t)})).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(r,t={}){let s=await this.config.request({url:`${D}/repositories/${r.namespace}/${r.name}`,headers:v(this.config,t)});return{data:Me(s.body)}}async getRepos(r,t={}){let s=[],n=[];return await Promise.all(r.map(async o=>{try{let a=await this.getRepo(o,t);s.push(a.data)}catch(a){n.push({input:o,error:a})}})),{data:s,errors:n}}async getReposForCurrentUser(r={},t={}){let s=new URL(`${D}/repositories`);s.searchParams.set("role","member"),s.searchParams.set("pagelen",S.toString()),r.cursor&&s.searchParams.set("after",r.cursor);let n=await this.config.request({url:s.toString(),headers:v(this.config,t)}),o=!!n.body.next,a=null;return n.body.next&&(a=new URL(n.body.next).searchParams.get("after")),{pageInfo:{hasNextPage:o,endCursor:a},data:n.body.values.map(Me)}}async getBranches(r,t={}){var a;let s=new URL(`${D}/repositories/${r.repo.namespace}/${r.repo.name}/refs/branches`);s.searchParams.set("page",((a=r.page)==null?void 0:a.toString())||"1"),s.searchParams.set("pagelen",S.toString());let n=await this.config.request({url:s.toString(),headers:v(this.config,t)}),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(r,t={}){let s=new URL(`${D}/repositories/${r.repo.namespace}/${r.repo.name}/refs/tags`);s.searchParams.set("pagelen",S.toString()),r.cursor&&s.searchParams.set("page",r.cursor);let n=await this.config.request({url:s.toString(),headers:v(this.config,t)}),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 getPullRequestsForUser(r,t={}){var a;let s=new URL(`${D}/pullrequests/${r.userId}`);s.searchParams.set("page",((a=r.page)==null?void 0:a.toString())||"1"),s.searchParams.set("pagelen","50");let n=await this.config.request({url:`${D}/pullrequests/${r.userId}`,headers:v(this.config,t)}),o=!!n.body.next;return{pageInfo:{hasNextPage:o,nextPage:o?n.body.page+1:null},data:n.body.values.map(me)}}async getPullRequestsForRepoBase(r,t={}){var n;let s=new URL(`${D}/repositories/${encodeURI(r.repo.namespace)}/${encodeURI(r.repo.name)}/pullrequests?state=OPEN`);return s.searchParams.set("page",((n=r.page)==null?void 0:n.toString())||"1"),s.searchParams.set("pagelen","50"),await this.config.request({url:s.toString(),headers:v(this.config,t)})}async getPullRequestsForRepo(r,t={}){let s=[],n=await this.getPullRequestsForRepoBase(r,t);n.body.values.forEach(a=>{if(r.authorLogin&&a.author.uuid!==r.authorLogin)return null;s.push(me(a))});let o=!!n.body.next;return{pageInfo:{hasNextPage:o,nextPage:o?n.body.page+1:null},data:s}}async getPullRequestsForRepos(r,t={}){let s=[];return await Promise.all(r.repos.map(async n=>{try{(await this.getPullRequestsForRepoBase({repo:n,...r},t)).body.values.forEach(a=>{if(r.authorLogin&&a.author.uuid!==r.authorLogin)return null;s.push(me(a))})}catch(o){if(o.statusCode!==404&&o.statusCode!==401)throw o}})),{data:s}}async closePullRequest(r,t={}){let{repo:{namespace:s,name:n},pullRequestId:o}=r;if(!(await this.config.request({method:"POST",url:`${D}/repositories/${s}/${n}/pullrequests/${o}/decline`,headers:v(this.config,t)})).body.title)throw new Error("Could not close pull request")}async mergePullRequest(r,t={}){let{repo:{namespace:s,name:n},pullRequestId:o,mergeStrategy:a}=r,i;switch(a){case"MERGE_COMMIT":{i="merge_commit";break}case"FAST_FORWARD":{i="fast_forward";break}case"SQUASH":{i="squash";break}}let u={merge_strategy:i,type:"pullrequest"};if(!(await this.config.request({method:"POST",url:`${D}/repositories/${s}/${n}/pullrequests/${o}/merge`,body:JSON.stringify(u),headers:{...v(this.config,t),"Content-Type":"application/json"}})).body.title)throw new Error("Could not merge pull request")}};var F=class extends T{getBaseUrl(r){let t=r.baseUrl||this.config.baseUrl;if(!t)throw new Error('Bitbucket Server requires "baseUrl"');return t}getRequestHeaders(r){return m(r.token||this.config.token)}async getRepo(r,t={}){var n,o,a;let s=await this.config.request({url:`${this.getBaseUrl(t)}/projects/${r.namespace}/repos/${r.name}`,headers:this.getRequestHeaders(t)});return{data:{id:s.body.id.toString(),namespace:s.body.project.key,name:s.body.slug,webUrl:((n=s.body.links.self[0])==null?void 0:n.href)??null,httpsUrl:((o=s.body.links.clone.find(i=>i.name==="https"))==null?void 0:o.href)??null,sshUrl:((a=s.body.links.clone.find(i=>i.name==="ssh"))==null?void 0:a.href)??null,defaultBranch:null,permission:null}}}async getRepos(r,t={}){let s=[],n=[];return await Promise.all(r.map(async o=>{try{let a=await this.getRepo(o,t);s.push(a.data)}catch(a){n.push({input:o,error:a})}})),{data:s,errors:n}}};var he="https://api.github.com",dt=`${he}/graphql`,Y=`
|
|
1
|
+
"use strict";var et=Object.create;var K=Object.defineProperty;var tt=Object.getOwnPropertyDescriptor;var rt=Object.getOwnPropertyNames;var st=Object.getPrototypeOf,nt=Object.prototype.hasOwnProperty;var A=(e,r)=>{for(var t in r)K(e,t,{get:r[t],enumerable:!0})},Oe=(e,r,t,s)=>{if(r&&typeof r=="object"||typeof r=="function")for(let n of rt(r))!nt.call(e,n)&&n!==t&&K(e,n,{get:()=>r[n],enumerable:!(s=tt(r,n))||s.enumerable});return e};var at=(e,r,t)=>(t=e!=null?et(st(e)):{},Oe(r||!e||!e.__esModule?K(t,"default",{value:e,enumerable:!0}):t,e)),ot=e=>Oe(K({},"__esModule",{value:!0}),e);var ar={};A(ar,{AzureDevOps:()=>B,AzureDevopsUtils:()=>re,Bitbucket:()=>F,BitbucketServer:()=>M,BitbucketServerUtils:()=>ne,BitbucketUtils:()=>se,GitHub:()=>z,GitHubUtils:()=>ae,GitLab:()=>H,GitLabUtils:()=>oe,Jira:()=>J,JiraUtils:()=>ie,Trello:()=>V,TrelloUtils:()=>ue,Utils:()=>nr,default:()=>sr});module.exports=ot(ar);var Me=require("js-base64");var S=100;var ke=at(require("node-fetch")),_e=globalThis.fetch||ke.default;var Ne=e=>e.name==="fetch";var it=async e=>{let r=e.headers.get("content-type")||"",t=null;if(r.startsWith("application/json")){let n=await e.text();t=n.trim().length>0?JSON.parse(n):null}else if(r.startsWith("text/"))t=await e.text();else throw new Error(`Unsupported content-type: ${r}`);let s={body:t,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},pe=e=>Ne(e)?async({url:r,...t})=>{let s=await e(r,t);return it(s)}:e;var v=class{constructor(r){this.config={...r,request:pe((r==null?void 0:r.request)||_e)}}updateConfig(r){this.config={...this.config,...r,request:r.request?pe(r.request):this.config.request}}},T=class extends v{};var m=(e,r)=>{let t={};return e&&(t.Authorization=`${r?"Basic":"Bearer"} ${e}`),t};var P=(e,r={})=>m(r.token||e.token,r.isPAT||e.isPAT),Qe=e=>e.url.replace("/_apis/git/repositories/","/_git/").replace(`/${e.repository.project.id}/`,`/${encodeURIComponent(e.repository.project.name)}/`).replace(`/${e.repository.id}/`,`/${encodeURIComponent(e.repository.name)}/`).replace("/pullRequests/","/pullrequest/");var je="https://app.vssps.visualstudio.com/_apis",U="https://dev.azure.com",ut={active:"OPEN",completed:"MERGED",abandoned:"CLOSED"},lt={10:"APPROVED",5:"APPROVED",0:"REVIEW_REQUESTED",[-5]:"CHANGES_REQUESTED",[-10]:"CHANGES_REQUESTED"},de=e=>({id:e.id,name:e.displayName,username:e.uniqueName||e.displayName,email:null,avatarUrl:e.imageUrl}),X=e=>e.startsWith("refs/heads/")?e.replace("refs/heads/",""):e,Be=e=>{var r;return{id:e.pullRequestId.toString(),title:e.title,number:e.codeReviewId,state:ut[e.status],isDraft:e.isDraft,commentCount:null,upvoteCount:null,author:de(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:X(e.targetRefName),oid:e.lastMergeTargetCommit.commitId},headRef:{name:X(e.sourceRefName),oid:e.lastMergeSourceCommit.commitId},url:Qe(e),assignees:e.reviewers.map(de),reviews:e.reviewers.filter(t=>t.vote!==0).map(t=>({reviewer:de(t),state:lt[t.vote]||"REVIEW_REQUESTED"})),additions:null,deletions:null,fileCount:null,commitCount:null,headRepository:null,mergeableState:"UNKNOWN",labels:((r=e.labels)==null?void 0:r.map(t=>({color:null,description:null,id:t.id,name:t.name})))??[]}},Fe=(e,r)=>({id:r.id,name:r.name,namespace:e,project:r.project.name,webUrl:r.webUrl,httpsUrl:r.remoteUrl,sshUrl:r.sshUrl,defaultBranch:r.defaultBranch?{name:X(r.defaultBranch)}:null,permission:null}),pt=(e,r)=>{var i,u;let t=e.fields,s=t["System.AssignedTo"],n=t["System.State"],o=t["System.WorkItemType"],a;return n&&o&&(a=(i=r[o])==null?void 0:i[n]),{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:s?[{avatarUrl:s._links.avatar.href,email:null,id:s.id,name:s.uniqueName,username:s.displayName}]:[],description:null,state:{name:(a==null?void 0:a.title)||n,color:null},type:t["System.WorkItemType"],repository:null,upvoteCount:0,labels:((u=e.fields["System.Tags"])==null?void 0:u.split(";").map(l=>({color:null,description:null,id:null,name:l.trim()})))??[]}},B=class extends v{async getCurrentUser(r={}){if(r.isPAT||this.config.isPAT)throw new Error("Azure DevOps does not support PATs for this function.");let t=await this.config.request({url:`${je}/profile/profiles/me`,headers:P(this.config,r)});return{data:{id:t.body.id,name:t.body.displayName,username:t.body.displayName,email:t.body.emailAddress,avatarUrl:null}}}async getCurrentUserForInstance(r,t={}){let n=(await this.config.request({url:`${U}/${encodeURIComponent(r.namespace)}/_apis/ConnectionData`,headers:P(this.config,t)})).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(r,t={}){if(!r.repo.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let n=(await this.config.request({url:`${U}/${encodeURIComponent(r.repo.namespace)}/${encodeURIComponent(r.repo.project)}/_apis/git/repositories/${encodeURIComponent(r.repo.name)}/commits/${r.oid}`,headers:P(this.config,t)})).body.author;return{data:{name:n.name,email:n.email,avatarUrl:n.imageUrl}}}async getOrgsForUser(r,t={}){return{data:(await this.config.request({url:`${je}/accounts?memberId=${r.userId}&api-version=6.0`,headers:P(this.config,t)})).body.value.map(n=>({id:n.accountId,name:n.accountName}))}}async getAzureProjects(r,t={}){let s=new URL(`${U}/${encodeURIComponent(r.namespace)}/_apis/projects`);s.searchParams.set("$top",S.toString()),r.cursor&&s.searchParams.set("$skip",r.cursor);let n=await this.config.request({url:s.toString(),headers:P(this.config,t)}),o=n.headers["x-ms-continuationtoken"];return{pageInfo:{hasNextPage:!!o,endCursor:o||null},data:n.body.value.map(a=>({id:a.id,name:a.name,namespace:r.namespace}))}}async getAzureProjectScopeDescriptor(r,t={}){let{namespace:s,projectId:n}=r;return{data:{scope:(await this.config.request({url:`https://vssps.dev.azure.com/${encodeURIComponent(s)}/_apis/graph/descriptors/${n}?api-version=6.0`,headers:P(this.config,t)})).body.value}}}async getAccountsForAzureProject(r,t={}){let{namespace:s,projectScopeDescriptor:n}=r,o=new URL(`https://vssps.dev.azure.com/${encodeURIComponent(s)}/_apis/graph/users`);return n&&o.searchParams.set("scopeDescriptor",n),{data:(await this.config.request({url:o.toString(),headers:P(this.config,t)})).body.value.map(i=>{var u;return{id:Me.Base64.decode(i.descriptor.replace(/.+?\./,"")),name:i.displayName,username:i.displayName,email:i.mailAddress,avatarUrl:(u=i._links.avatar)==null?void 0:u.href}})}}async getRepo(r,t={}){if(!r.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let s=await this.config.request({url:`${U}/${encodeURIComponent(r.namespace)}/${encodeURIComponent(r.project)}/_apis/git/repositories/${encodeURIComponent(r.name)}`,headers:P(this.config,t)});return{data:Fe(r.namespace,s.body)}}async getRepos(r,t={}){let s=[],n=[];return await Promise.all(r.map(async o=>{try{let a=await this.getRepo(o,t);s.push(a.data)}catch(a){n.push({input:o,error:a})}})),{data:s,errors:n}}async getReposForAzureProject(r,t={}){if(!r.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');return{data:(await this.config.request({url:`${U}/${encodeURIComponent(r.namespace)}/${encodeURIComponent(r.project)}/_apis/git/repositories`,headers:P(this.config,t)})).body.value.map(n=>Fe(r.namespace,n))}}async getRefs(r,t,s={}){if(!t.repo.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let n=new URL(`${U}/${encodeURIComponent(t.repo.namespace)}/${encodeURIComponent(t.repo.project)}/_apis/git/repositories/${encodeURIComponent(t.repo.name)}/refs`);n.searchParams.set("filter",r),n.searchParams.set("$top",S.toString()),t.cursor&&n.searchParams.set("continuationToken",t.cursor);let o=await this.config.request({url:n.toString(),headers:P(this.config,s)}),a=o.headers["x-ms-continuationtoken"];return{pageInfo:{hasNextPage:!!a,endCursor:a||null},data:o.body.value.map(i=>({name:X(i.name),commit:{oid:i.objectId,authoredDate:null,committedDate:null}}))}}async getBranches(r,t={}){return this.getRefs("heads",r,t)}async getTags(r,t={}){return this.getRefs("tags",r,t)}async getPullRequestsForRepoBase(r,t={},s=100){let{page:n,repo:o,assigneeLogins:a,authorLogin:i}=r||{},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:`${t.baseUrl||U}/${encodeURIComponent(o.namespace)}/${encodeURIComponent(o.project||"")}/_apis/git/repositories/${encodeURIComponent(o.name)}/pullRequests?${l}&%24top=${s}&%24skip=${(u-1)*s}`,headers:P(this.config,t)})}async getPullRequestsForRepo(r,t={}){let n=r.page||1,o=await this.getPullRequestsForRepoBase(r,t,100);return{pageInfo:{hasNextPage:o.body.value.length===100,nextPage:n+1},data:o.body.value.map(Be)}}async getPullRequestsForRepos(r,t={}){if(!r.repos.every(o=>o.project))throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let{repos:s}=r||{},n=[];return await Promise.all(s.map(async o=>{try{(await this.getPullRequestsForRepoBase({repo:o,...r},t)).body.value.forEach(i=>{n.push(Be(i))})}catch(a){if(a.statusCode!==404&&a.statusCode!==401)throw a}})),{data:n}}async updatePullRequest(r,t,s,n){let{namespace:o,project:a,name:i}=r;return await this.config.request({method:"PATCH",url:`${n.baseUrl||U}/${encodeURIComponent(o)}/${encodeURIComponent(a||"")}/_apis/git/repositories/${i}/pullrequests/${t}?api-version=6.0`,body:s,headers:{...P(this.config,n),"Content-Type":"application/json"}})}async closePullRequest(r,t={}){if(!r.repo.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let{repo:s,pullRequestId:n}=r,o={status:"abandoned"};if(!(await this.updatePullRequest(s,n,JSON.stringify(o),t)).body.status)throw new Error("Could not close pull request")}async mergePullRequest(r,t={}){if(!r.repo.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let{repo:s,pullRequestId:n,expectedSourceSha:o,mergeStrategy:a}=r,i;switch(a){case"MERGE_COMMIT":{i="noFastForward";break}case"REBASE":{i="rebase";break}case"REBASE_THEN_MERGE_COMMIT":{i="rebaseMerge";break}case"SQUASH":{i="squash";break}}let u={completionOptions:{mergeStrategy:i},lastMergeSourceCommit:{commitId:o},status:"completed"};if(!(await this.updatePullRequest(s,n,JSON.stringify(u),t)).body.status)throw new Error("Could not merge pull request")}async setPullRequestAsDraft(r,t={}){if(!r.repo.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let{repo:s,pullRequestId:n,isDraft:o}=r,a={isDraft:o};if(!(await this.updatePullRequest(s,n,JSON.stringify(a),t)).body.status)throw new Error("Could not set the pull request as draft")}async getIssuesForAzureProject(r,t={}){let{page:s,assigneeLogins:n,authorLogin:o,mentionLogin:a,statusByWorkItemIdByStatusId:i}=r||{},u=s||1,l=200,p=["[Microsoft.VSTS.Common.ClosedDate] = ''","[System.TeamProject] = @project","[Microsoft.VSTS.Common.ResolvedDate] = ''"];o&&p.push(`[System.CreatedBy] = '${o.replace("'","''")}'`),n&&n[0]&&p.push(`[System.AssignedTo] = '${n[0].replace("'","''")}'`),a&&p.push("[System.Id] IN (@recentMentions)");let d=`Select [Microsoft.VSTS.Common.ClosedDate], [Microsoft.VSTS.Common.ResolvedDate] From WorkItems Where ${p.join(" AND ")} order by [System.CreatedDate] desc`,c=await this.config.request({url:`${t.baseUrl||U}/${encodeURIComponent(r.namespace)}/${encodeURIComponent(r.project)}/_apis/wit/wiql?api-version=6.0`,body:JSON.stringify({query:d}),method:"POST",headers:{...P(this.config,t),"Content-Type":"application/json"}}),g=c.body.workItems.slice((u-1)*l,l*u).map(f=>f.id);if(g.length==0)return{pageInfo:{hasNextPage:!1,nextPage:null},data:[]};let I=await this.config.request({url:`${t.baseUrl||U}/${encodeURIComponent(r.namespace)}/${encodeURIComponent(r.project)}/_apis/wit/workitemsbatch?api-version=6.0`,body:JSON.stringify({ids:g,$expand:"Links"}),method:"POST",headers:{...P(this.config,t),"Content-Type":"application/json"}});return{pageInfo:{hasNextPage:c.body.workItems.length>l*u,nextPage:u+1},data:I.body.value.map(f=>pt(f,i||{}))}}async setIssueStatus(r,t={}){var l;if(!r.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let{namespace:s,project:n,issueId:o,status:a}=r,i=[{op:"add",path:"/fields/System.State",value:a}];if(!((l=(await this.config.request({method:"PATCH",url:`${t.baseUrl||U}/${encodeURIComponent(s)}/${encodeURIComponent(n||"")}/_apis/wit/workitems/${o}?api-version=6.0`,body:JSON.stringify(i),headers:{...P(this.config,t),"Content-Type":"application/json-patch+json"}})).body.fields)!=null&&l["System.State"]))throw new Error("Could not set issue status")}async getIssueTypesForAzureProject(r,t={}){if(!r.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let{namespace:s,project:n}=r;return{data:(await this.config.request({url:`${t.baseUrl||U}/${encodeURIComponent(s)}/${encodeURIComponent(n||"")}/_apis/wit/workitemtypes?api-version=6.0`,headers:{...P(this.config,t)}})).body.value}}async getLabelsForProject(r,t={}){let{namespace:s,project:n}=r;return{data:(await this.config.request({url:`${t.baseUrl||U}/${encodeURIComponent(s)}/${encodeURIComponent(n||"")}/_apis/wit/tags?api-version=6.0`,headers:{...P(this.config,t)}})).body.value.map(a=>({color:null,description:null,id:a.id,name:a.name}))}}};var E=(e,r={})=>m(r.token||e.token,r.isPAT||e.isPAT);var D="https://api.bitbucket.org/2.0",dt={OPEN:"OPEN",MERGED:"MERGED",DECLINED:"CLOSED"},We=e=>({id:e.uuid,name:e.display_name||e.nickname,username:e.nickname||e.display_name,email:null,avatarUrl:e.links.avatar.href}),ze=e=>{var r,t;return{id:e.uuid,namespace:e.workspace.slug,name:e.slug,webUrl:e.links.html.href,httpsUrl:((r=e.links.clone.find(s=>s.name==="https"))==null?void 0:r.href)??null,sshUrl:((t=e.links.clone.find(s=>s.name==="ssh"))==null?void 0:t.href)??null,defaultBranch:{name:e.mainbranch.name},permission:null}},he=e=>{let r=e.id;return{id:r.toString(),title:e.title,number:r,state:dt[e.state],isDraft:!1,commentCount:e.comment_count,upvoteCount:null,author:We(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,oid:e.destination.commit.hash},headRef:{name:e.source.branch.name,oid:e.source.commit.hash},url:e.links.html.href,assignees:null,reviews:null,additions:null,deletions:null,fileCount:null,commitCount:null,headRepository:null,mergeableState:"UNKNOWN"}},F=class extends v{async refreshToken(r){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 ${r.base64ClientIDColonClientSecret}`},body:`grant_type=refresh_token&refresh_token=${r.refreshToken}`})).body}}async getCurrentUser(r={}){let t=await this.config.request({url:`${D}/user`,headers:E(this.config,r)});return{data:We(t.body)}}async getUserForCommit(r,t={}){var a;let n=(await this.config.request({url:`${D}/repositories/${r.repo.namespace}/${r.repo.name}/commit/${r.oid}`,headers:E(this.config,t)})).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(r,t={}){let s=await this.config.request({url:`${D}/repositories/${r.namespace}/${r.name}`,headers:E(this.config,t)});return{data:ze(s.body)}}async getRepos(r,t={}){let s=[],n=[];return await Promise.all(r.map(async o=>{try{let a=await this.getRepo(o,t);s.push(a.data)}catch(a){n.push({input:o,error:a})}})),{data:s,errors:n}}async getReposForCurrentUser(r={},t={}){let s=new URL(`${D}/repositories`);s.searchParams.set("role","member"),s.searchParams.set("pagelen",S.toString()),r.cursor&&s.searchParams.set("after",r.cursor);let n=await this.config.request({url:s.toString(),headers:E(this.config,t)}),o=!!n.body.next,a=null;return n.body.next&&(a=new URL(n.body.next).searchParams.get("after")),{pageInfo:{hasNextPage:o,endCursor:a},data:n.body.values.map(ze)}}async getBranches(r,t={}){var a;let s=new URL(`${D}/repositories/${r.repo.namespace}/${r.repo.name}/refs/branches`);s.searchParams.set("page",((a=r.page)==null?void 0:a.toString())||"1"),s.searchParams.set("pagelen",S.toString());let n=await this.config.request({url:s.toString(),headers:E(this.config,t)}),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(r,t={}){let s=new URL(`${D}/repositories/${r.repo.namespace}/${r.repo.name}/refs/tags`);s.searchParams.set("pagelen",S.toString()),r.cursor&&s.searchParams.set("page",r.cursor);let n=await this.config.request({url:s.toString(),headers:E(this.config,t)}),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 getPullRequestsForUser(r,t={}){var a;let s=new URL(`${D}/pullrequests/${r.userId}`);s.searchParams.set("page",((a=r.page)==null?void 0:a.toString())||"1"),s.searchParams.set("pagelen","50");let n=await this.config.request({url:`${D}/pullrequests/${r.userId}`,headers:E(this.config,t)}),o=!!n.body.next;return{pageInfo:{hasNextPage:o,nextPage:o?n.body.page+1:null},data:n.body.values.map(he)}}async getPullRequestsForRepoBase(r,t={}){var n;let s=new URL(`${D}/repositories/${encodeURI(r.repo.namespace)}/${encodeURI(r.repo.name)}/pullrequests?state=OPEN`);return s.searchParams.set("page",((n=r.page)==null?void 0:n.toString())||"1"),s.searchParams.set("pagelen","50"),await this.config.request({url:s.toString(),headers:E(this.config,t)})}async getPullRequestsForRepo(r,t={}){let s=[],n=await this.getPullRequestsForRepoBase(r,t);n.body.values.forEach(a=>{if(r.authorLogin&&a.author.uuid!==r.authorLogin)return null;s.push(he(a))});let o=!!n.body.next;return{pageInfo:{hasNextPage:o,nextPage:o?n.body.page+1:null},data:s}}async getPullRequestsForRepos(r,t={}){let s=[];return await Promise.all(r.repos.map(async n=>{try{(await this.getPullRequestsForRepoBase({repo:n,...r},t)).body.values.forEach(a=>{if(r.authorLogin&&a.author.uuid!==r.authorLogin)return null;s.push(he(a))})}catch(o){if(o.statusCode!==404&&o.statusCode!==401)throw o}})),{data:s}}async closePullRequest(r,t={}){let{repo:{namespace:s,name:n},pullRequestId:o}=r;if(!(await this.config.request({method:"POST",url:`${D}/repositories/${s}/${n}/pullrequests/${o}/decline`,headers:E(this.config,t)})).body.title)throw new Error("Could not close pull request")}async mergePullRequest(r,t={}){let{repo:{namespace:s,name:n},pullRequestId:o,mergeStrategy:a}=r,i;switch(a){case"MERGE_COMMIT":{i="merge_commit";break}case"FAST_FORWARD":{i="fast_forward";break}case"SQUASH":{i="squash";break}}let u={merge_strategy:i,type:"pullrequest"};if(!(await this.config.request({method:"POST",url:`${D}/repositories/${s}/${n}/pullrequests/${o}/merge`,body:JSON.stringify(u),headers:{...E(this.config,t),"Content-Type":"application/json"}})).body.title)throw new Error("Could not merge pull request")}};var M=class extends T{getBaseUrl(r){let t=r.baseUrl||this.config.baseUrl;if(!t)throw new Error('Bitbucket Server requires "baseUrl"');return t}getRequestHeaders(r){return m(r.token||this.config.token)}async getRepo(r,t={}){var n,o,a;let s=await this.config.request({url:`${this.getBaseUrl(t)}/projects/${r.namespace}/repos/${r.name}`,headers:this.getRequestHeaders(t)});return{data:{id:s.body.id.toString(),namespace:s.body.project.key,name:s.body.slug,webUrl:((n=s.body.links.self[0])==null?void 0:n.href)??null,httpsUrl:((o=s.body.links.clone.find(i=>i.name==="https"))==null?void 0:o.href)??null,sshUrl:((a=s.body.links.clone.find(i=>i.name==="ssh"))==null?void 0:a.href)??null,defaultBranch:null,permission:null}}}async getRepos(r,t={}){let s=[],n=[];return await Promise.all(r.map(async o=>{try{let a=await this.getRepo(o,t);s.push(a.data)}catch(a){n.push({input:o,error:a})}})),{data:s,errors:n}}};var fe="https://api.github.com",ct=`${fe}/graphql`,Y=`
|
|
2
2
|
description
|
|
3
3
|
dueOn
|
|
4
4
|
id
|
|
@@ -6,12 +6,12 @@ number
|
|
|
6
6
|
state
|
|
7
7
|
title
|
|
8
8
|
url
|
|
9
|
-
`,
|
|
9
|
+
`,He=/\/api\/v\d+$/,ee=`
|
|
10
10
|
color
|
|
11
11
|
description
|
|
12
12
|
id
|
|
13
13
|
name
|
|
14
|
-
`,gt=e=>{if(e.endsWith("/api/graphql"))throw new Error("The graphql endpoint is being used as the baseUrl. This package uses both GraphQL and REST APIs, and the REST version cannot be assumed. Use the REST endpoint as the baseUrl instead.")},
|
|
14
|
+
`,gt=e=>{if(e.endsWith("/api/graphql"))throw new Error("The graphql endpoint is being used as the baseUrl. This package uses both GraphQL and REST APIs, and the REST version cannot be assumed. Use the REST endpoint as the baseUrl instead.")},mt=(e,r)=>{let t=r.baseUrl||e.baseUrl;return t?(t=t.replace(/\/$/,""),gt(t),He.test(t)&&(t=t.replace(He,"")),`${t}/api/graphql`):ct},h=(e,r,t)=>{let s=m(t.token||e.token);return s["X-Github-Next-Global-ID"]="1",s["Content-Type"]="application/json",e.request({url:mt(e,t),method:"POST",headers:s,body:JSON.stringify(r)})},ht={user:!0,"user:email":!0,"read:user":!0},O=e=>e.some(r=>ht[r]),q=(e=!1,r=!1)=>`
|
|
15
15
|
__typename
|
|
16
16
|
id
|
|
17
17
|
databaseId
|
|
@@ -19,13 +19,13 @@ name
|
|
|
19
19
|
login
|
|
20
20
|
${r?"email":""}
|
|
21
21
|
avatarUrl${e?"(size: $avatarSize)":""}
|
|
22
|
-
`,
|
|
22
|
+
`,Je=(e=!1)=>`
|
|
23
23
|
__typename
|
|
24
24
|
id
|
|
25
25
|
databaseId
|
|
26
26
|
login
|
|
27
27
|
avatarUrl${e?"(size: $avatarSize)":""}
|
|
28
|
-
`,
|
|
28
|
+
`,ft=(e,r=!1)=>`
|
|
29
29
|
id
|
|
30
30
|
databaseId
|
|
31
31
|
number
|
|
@@ -33,10 +33,10 @@ title
|
|
|
33
33
|
state
|
|
34
34
|
author {
|
|
35
35
|
... on User {
|
|
36
|
-
${
|
|
36
|
+
${q(!1,r)}
|
|
37
37
|
}
|
|
38
38
|
... on Bot {
|
|
39
|
-
${
|
|
39
|
+
${Je(!1)}
|
|
40
40
|
}
|
|
41
41
|
}
|
|
42
42
|
commits(last: 1) {
|
|
@@ -96,7 +96,7 @@ updatedAt
|
|
|
96
96
|
closedAt
|
|
97
97
|
assignees(first: 100) {
|
|
98
98
|
nodes {
|
|
99
|
-
${
|
|
99
|
+
${q(!1,r)}
|
|
100
100
|
}
|
|
101
101
|
}
|
|
102
102
|
reviewRequests(first: 100) {
|
|
@@ -104,7 +104,7 @@ reviewRequests(first: 100) {
|
|
|
104
104
|
asCodeOwner
|
|
105
105
|
requestedReviewer {
|
|
106
106
|
... on User {
|
|
107
|
-
${
|
|
107
|
+
${q(!1,r)}
|
|
108
108
|
}
|
|
109
109
|
}
|
|
110
110
|
}
|
|
@@ -113,7 +113,7 @@ latestReviews(first: 100) {
|
|
|
113
113
|
nodes {
|
|
114
114
|
author {
|
|
115
115
|
... on User {
|
|
116
|
-
${
|
|
116
|
+
${q(!1,r)}
|
|
117
117
|
}
|
|
118
118
|
}
|
|
119
119
|
state
|
|
@@ -131,16 +131,16 @@ labels(first: 100) {
|
|
|
131
131
|
${ee}
|
|
132
132
|
}
|
|
133
133
|
}
|
|
134
|
-
`,
|
|
134
|
+
`,Rt=(e=!1)=>`
|
|
135
135
|
id
|
|
136
136
|
databaseId
|
|
137
137
|
title
|
|
138
138
|
author {
|
|
139
139
|
... on User {
|
|
140
|
-
${
|
|
140
|
+
${q(!1,e)}
|
|
141
141
|
}
|
|
142
142
|
... on Bot {
|
|
143
|
-
${
|
|
143
|
+
${Je(!1)}
|
|
144
144
|
}
|
|
145
145
|
}
|
|
146
146
|
createdAt
|
|
@@ -161,7 +161,7 @@ comments {
|
|
|
161
161
|
}
|
|
162
162
|
assignees(first: 100) {
|
|
163
163
|
nodes {
|
|
164
|
-
${
|
|
164
|
+
${q(!1,e)}
|
|
165
165
|
}
|
|
166
166
|
}
|
|
167
167
|
state
|
|
@@ -173,7 +173,7 @@ labels(first: 100) {
|
|
|
173
173
|
${ee}
|
|
174
174
|
}
|
|
175
175
|
}
|
|
176
|
-
`,
|
|
176
|
+
`,It={"-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"},bt=new RegExp('(([^\\s]+:)?\\"(?:[^\\"\\\\]|\\\\.)*\\"?)|([^\\"\\s]+)',"g"),Re=e=>{let r=[];return(e.match(bt)??[]).forEach(s=>{if(s.includes(":")&&s!="is:closed"){let n=s.split(":")[0];It[n]&&r.push(s)}}),r},Ie=(e,r,t,s,n=!1)=>{let o=e==="issue";return{query:`
|
|
177
177
|
query SearchIssuesOrPullRequests($query: String! $after: String) {
|
|
178
178
|
search(type:ISSUE query:$query first:100 after:$after) {
|
|
179
179
|
pageInfo {
|
|
@@ -182,11 +182,11 @@ query SearchIssuesOrPullRequests($query: String! $after: String) {
|
|
|
182
182
|
}
|
|
183
183
|
nodes {
|
|
184
184
|
... on ${o?"Issue":"PullRequest"} {
|
|
185
|
-
${o?
|
|
185
|
+
${o?Rt(s):ft(n,s)}
|
|
186
186
|
}
|
|
187
187
|
}
|
|
188
188
|
}
|
|
189
|
-
}`,variables:{query:`is:${e} is:open ${r}`,after:t}}},
|
|
189
|
+
}`,variables:{query:`is:${e} is:open ${r}`,after:t}}},yt="Field 'isDraft' doesn't exist on type 'PullRequest'",Ve=(e=[])=>e.some(r=>(r==null?void 0:r.message)===yt);var be=`
|
|
190
190
|
id
|
|
191
191
|
databaseId
|
|
192
192
|
owner {
|
|
@@ -199,13 +199,27 @@ defaultBranchRef {
|
|
|
199
199
|
name
|
|
200
200
|
}
|
|
201
201
|
viewerPermission
|
|
202
|
-
`,
|
|
202
|
+
`,Pe={__typename:"User",id:"U_kgDNJ5k",databaseId:10137,name:"Deleted user",login:"ghost",email:"",avatarUrl:"https://avatars.githubusercontent.com/u/10137?v=4"},Pt={APPROVED:"APPROVED",CHANGES_REQUESTED:"CHANGES_REQUESTED",COMMENTED:"COMMENTED",REVIEW_REQUESTED:"REVIEW_REQUESTED"},wt={MERGEABLE:"MERGEABLE",CONFLICTING:"CONFLICTS",UNKNOWN:"UNKNOWN"},St={OPEN:"OPEN",CLOSED:"CLOSED"},we=e=>({color:e.color,description:e.description,graphQLId:e.id,id:null,name:e.name}),ye=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}),Ct={OPEN:"OPEN",CLOSED:"CLOSED",MERGED:"MERGED"},G=e=>({id:e.databaseId.toString(),graphQLId:e.id,name:e.name??e.login,username:e.login,email:e.email??null,avatarUrl:e.avatarUrl}),Ut=e=>{var l,p,d,c,g,I,f,w,y,b,C,L;let r=null;e.author?r=(e.author.__typename==="Bot",e.author):r=Pe;let t=(p=(l=e.commits.nodes)==null?void 0:l[0])==null?void 0:p.commit,s=((d=e.headRef)==null?void 0:d.target)||t,n=s==null?void 0:s.oid,o=t==null?void 0:t.oid,a=n===o?(g=(c=t==null?void 0:t.status)==null?void 0:c.contexts)==null?void 0:g[0]:null,i=(((I=e.reviewRequests)==null?void 0:I.nodes)||[]).filter($=>!$.asCodeOwner),u=(f=e.headRepository)==null?void 0:f.url;return u&&!u.endsWith(".git")&&(u=`${u}.git`),{id:e.databaseId.toString(),graphQLId:e.id,title:e.title,number:e.number,state:Ct[e.state],commentCount:e.comments.totalCount,upvoteCount:e.reactions.totalCount,author:r?G(r):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,oid:((w=e.headRef.target)==null?void 0:w.oid)??null}:null,baseRef:e.baseRef?{name:e.baseRef.name,oid:((y=e.baseRef.target)==null?void 0:y.oid)??null}: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(G):null,reviews:i.map($=>({reviewer:G($.requestedReviewer),state:"REVIEW_REQUESTED"})).concat((((b=e.latestReviews)==null?void 0:b.nodes)||[]).map($=>{let le=$.author||Pe;return{reviewer:G(le),state:Pt[$.state]}})),additions:e.additions,deletions:e.deletions,fileCount:e.changedFiles,commitCount:e.commits.totalCount,mergeableState:wt[e.mergeable],milestone:e.milestone?Se(e.milestone):null,labels:((L=(C=e.labels)==null?void 0:C.nodes)==null?void 0:L.map(we))??[]}},$t=e=>{var t,s;let r=null;return e.author?r=(e.author.__typename==="Bot",e.author):r=Pe,{id:e.databaseId.toString(),graphQLId:e.id,number:e.number,title:e.title,author:G(r),commentCount:e.comments.totalCount,createdDate:new Date(e.createdAt),description:null,state:{name:St[e.state],color:null},type: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(G):[],upvoteCount:e.reactions.totalCount,milestone:e.milestone?Se(e.milestone):null,labels:((s=(t=e.labels)==null?void 0:t.nodes)==null?void 0:s.map(we))??[]}},Se=e=>({id:e.number.toString(),graphQLId:e.id.toString(),number:e.number,title:e.title,description:e.description,isOpen:e.state=="OPEN",url:e.url,startDate:null,dueDate:e.dueOn?new Date(e.dueOn):null}),z=class extends T{constructor(){super(...arguments);this._scopesCache={}}async getScopes(t){let s=t.token||this.config.token;if(!s)return[];let n=this._scopesCache[s];if(!n){let a=(await h(this.config,{query:"query { rateLimit(dryRun: true) { __typename } }"},t)).headers["x-oauth-scopes"];n=a?a.split(", "):[],this._scopesCache[s]=n}return n}getEnterpriseAvatarUrlIfNeeded(t,s,n){let o=n.baseUrl||this.config.baseUrl;return!o||o.startsWith(fe)?t:s?`https://avatars.githubusercontent.com/u/e?email=${encodeURIComponent(s)}`:""}async getCurrentUser(t={}){var a;let s=await this.getScopes(t),o=(a=(await h(this.config,{query:`
|
|
203
203
|
query getCurrentUser {
|
|
204
204
|
viewer {
|
|
205
|
-
${
|
|
205
|
+
${q(!1,O(s))}
|
|
206
206
|
}
|
|
207
207
|
}
|
|
208
|
-
`},t)).body.data)==null?void 0:a.viewer;if(!o)throw new Error("Current user not found.");return{data:
|
|
208
|
+
`},t)).body.data)==null?void 0:a.viewer;if(!o)throw new Error("Current user not found.");return{data:G(o)}}async getAccountsForRepo(t,s={}){var l,p,d,c,g,I;let n=await this.getScopes(s),{repo:{namespace:o,name:a},cursor:i}=t,u=await h(this.config,{query:`
|
|
209
|
+
query getAccountsForRepo($owner: String!, $name: String! $cursor: String, $first: Int!) {
|
|
210
|
+
repository(owner: $owner, name: $name) {
|
|
211
|
+
assignableUsers(first: $first, after: $cursor) {
|
|
212
|
+
nodes {
|
|
213
|
+
${q(!1,O(n))}
|
|
214
|
+
}
|
|
215
|
+
pageInfo {
|
|
216
|
+
endCursor
|
|
217
|
+
hasNextPage
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
`,variables:{owner:o,name:a,cursor:i,first:S}},s);if(!u.body.data)throw new Error(((l=u.body.errors)==null?void 0:l[0].message)||u.statusText||"Unknown error");return{pageInfo:((d=(p=u.body.data.repository)==null?void 0:p.assignableUsers)==null?void 0:d.pageInfo)??{endCursor:null,hasNextPage:!1},data:((I=(g=(c=u.body.data.repository)==null?void 0:c.assignableUsers)==null?void 0:g.nodes)==null?void 0:I.map(G))??[]}}async getUserForCommit(t,s={}){var i,u;let o=(i=(await h(this.config,{query:`
|
|
209
223
|
query getUserForCommit(
|
|
210
224
|
$owner: String!
|
|
211
225
|
$name: String!
|
|
@@ -229,18 +243,18 @@ query getAccountForEmail($query: String! $avatarSize: Int) {
|
|
|
229
243
|
search(query: $query, type: USER, first: 1) {
|
|
230
244
|
nodes {
|
|
231
245
|
... on User {
|
|
232
|
-
${
|
|
246
|
+
${q(!0,O(n))}
|
|
233
247
|
}
|
|
234
248
|
}
|
|
235
249
|
}
|
|
236
250
|
}
|
|
237
|
-
`,variables:{query:`in:email ${t.email}`,avatarSize:t.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:
|
|
251
|
+
`,variables:{query:`in:email ${t.email}`,avatarSize:t.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:G({...a,avatarUrl:this.getEnterpriseAvatarUrlIfNeeded(a.avatarUrl,a.email,s)})}}async getAccountForUsername(t,s={}){var i;let n=await this.getScopes(s),a=(i=(await h(this.config,{query:`
|
|
238
252
|
query getUserForUsername($login: String! $avatarSize: Int) {
|
|
239
253
|
user(login: $login) {
|
|
240
|
-
${
|
|
254
|
+
${q(!0,O(n))}
|
|
241
255
|
}
|
|
242
256
|
}
|
|
243
|
-
`,variables:{login:t.username,avatarSize:t.avatarSize}},s)).body.data)==null?void 0:i.user;if(!a)throw new Error("User not found.");return{data:
|
|
257
|
+
`,variables:{login:t.username,avatarSize:t.avatarSize}},s)).body.data)==null?void 0:i.user;if(!a)throw new Error("User not found.");return{data:G({...a,avatarUrl:this.getEnterpriseAvatarUrlIfNeeded(a.avatarUrl,a.email,s)})}}async getOrgsForCurrentUser(t={},s={}){var a,i;let n=await h(this.config,{query:`
|
|
244
258
|
query getOrgsForCurrentUser($cursor: String, $first: Int!) {
|
|
245
259
|
viewer {
|
|
246
260
|
organizations(first: $first after: $cursor) {
|
|
@@ -262,19 +276,19 @@ query getOrgsForCurrentUser($cursor: String, $first: Int!) {
|
|
|
262
276
|
`,variables:{cursor:t.cursor,first:S}},s);if(!((a=n.body.data)!=null&&a.viewer.organizations))throw new Error(((i=n.body.errors)==null?void 0:i[0].message)||n.statusText||"Unknown error");let o=n.body.data.viewer.organizations.nodes||[];return{pageInfo:n.body.data.viewer.organizations.pageInfo,data:o.map(u=>({id:u.databaseId.toString(),graphQLId:u.id,username:u.login,name:u.name||null,email:u.email||null,avatarUrl:u.avatarUrl}))}}async getRepo(t,s={}){var o;let n=await h(this.config,{query:`
|
|
263
277
|
query getRepo($owner: String!, $name: String!) {
|
|
264
278
|
repository(owner: $owner, name: $name) {
|
|
265
|
-
${
|
|
279
|
+
${be}
|
|
266
280
|
}
|
|
267
281
|
}
|
|
268
|
-
`,variables:{owner:t.namespace,name:t.name}},s);if(!((o=n.body.data)!=null&&o.repository))throw new Error(`Repository ${t.namespace}/${t.name} not found`);return{data:
|
|
282
|
+
`,variables:{owner:t.namespace,name:t.name}},s);if(!((o=n.body.data)!=null&&o.repository))throw new Error(`Repository ${t.namespace}/${t.name} not found`);return{data:ye(n.body.data.repository)}}async getRepos(t,s={}){let n=t.map(({namespace:u,name:l},p)=>`
|
|
269
283
|
getRepo_${p}: repository(owner: "${u}", name: "${l}") {
|
|
270
|
-
${
|
|
284
|
+
${be}
|
|
271
285
|
}
|
|
272
286
|
`).join(`
|
|
273
287
|
`),o=await h(this.config,{query:`
|
|
274
288
|
query batchGetRepos {
|
|
275
289
|
${n}
|
|
276
290
|
}
|
|
277
|
-
`},s);if(!o.body.data)throw new Error(o.statusText||"Unknown error");let a=[],i=[];return t.forEach((u,l)=>{let p=o.body.data[`getRepo_${l}`];p?a.push(
|
|
291
|
+
`},s);if(!o.body.data)throw new Error(o.statusText||"Unknown error");let a=[],i=[];return t.forEach((u,l)=>{let p=o.body.data[`getRepo_${l}`];p?a.push(ye(p)):i.push({input:u})}),{data:a,errors:i}}async getReposForUsernames(t,s={}){var a;if(!t.usernames.length)return{pageInfo:{endCursor:null,hasNextPage:!1},data:[]};let n=await h(this.config,{query:`
|
|
278
292
|
query getReposForUsernames($query: String!, $cursor: String, $first: Int!) {
|
|
279
293
|
search(query: $query, type: REPOSITORY, first: $first, after: $cursor) {
|
|
280
294
|
pageInfo {
|
|
@@ -283,12 +297,12 @@ query getReposForUsernames($query: String!, $cursor: String, $first: Int!) {
|
|
|
283
297
|
}
|
|
284
298
|
nodes {
|
|
285
299
|
... on Repository {
|
|
286
|
-
${
|
|
300
|
+
${be}
|
|
287
301
|
}
|
|
288
302
|
}
|
|
289
303
|
}
|
|
290
304
|
}
|
|
291
|
-
`,variables:{query:`fork:true ${t.usernames.map(i=>`user:${i}`).join(" ")}`,cursor:t.cursor,first:S}},s);if(!n.body.data)throw new Error(((a=n.body.errors)==null?void 0:a[0].message)||n.statusText||"Unknown error");let o=n.body.data.search.nodes||[];return{pageInfo:n.body.data.search.pageInfo,data:o.map(
|
|
305
|
+
`,variables:{query:`fork:true ${t.usernames.map(i=>`user:${i}`).join(" ")}`,cursor:t.cursor,first:S}},s);if(!n.body.data)throw new Error(((a=n.body.errors)==null?void 0:a[0].message)||n.statusText||"Unknown error");let o=n.body.data.search.nodes||[];return{pageInfo:n.body.data.search.pageInfo,data:o.map(ye)}}async getReposForOwners(t,s={}){return this.getReposForUsernames({usernames:t.owners.filter(n=>n.username).map(n=>n.username),cursor:t.cursor},s)}async getRefs(t,s,n={}){var u;let a=(u=(await h(this.config,{query:`
|
|
292
306
|
query getRefs($owner: String!, $name: String!, $refPrefix: String!, $cursor: String, $first: Int!) {
|
|
293
307
|
repository(owner: $owner, name: $name) {
|
|
294
308
|
refs(refPrefix: $refPrefix first: $first after: $cursor) {
|
|
@@ -348,13 +362,13 @@ query getBlame($owner: String!, $name: String!, $ref: String!, $path: String!) {
|
|
|
348
362
|
}
|
|
349
363
|
}
|
|
350
364
|
}
|
|
351
|
-
`,variables:{owner:t.repo.namespace,name:t.repo.name,ref:t.ref,path:t.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(p=>p.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 searchPullRequests(t,s={}){var l,p;let n=await this.getScopes(s),o=
|
|
365
|
+
`,variables:{owner:t.repo.namespace,name:t.repo.name,ref:t.ref,path:t.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(p=>p.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 searchPullRequests(t,s={}){var l,p;let n=await this.getScopes(s),o=O(n),a=d=>{let c=d&&typeof t.isDraft=="boolean"?`${t.query} draft:${t.isDraft}`:t.query;return Ie("pr",c,t.cursor,o,d)},i=await h(this.config,a(!0),s);i.body.errors&&Ve(i.body.errors)&&(this.config.baseUrl||s.baseUrl)&&(i=await h(this.config,a(!1),s));let{data:u}=i.body;if(!u)throw new Error(((l=i.body.errors)==null?void 0:l[0].message)||i.statusText||"Unknown error");return{pageInfo:{hasNextPage:u.search.pageInfo.hasNextPage,endCursor:u.search.pageInfo.endCursor},data:((p=u.search.nodes)==null?void 0:p.map(Ut))||[]}}async searchIssues(t,s={}){var u,l;let n=await this.getScopes(s),o=O(n),a=await h(this.config,Ie("issue",t.query,t.cursor,o),s),{data:i}=a.body;if(!i)throw new Error(((u=a.body.errors)==null?void 0:u[0].message)||a.statusText||"Unknown error");return{pageInfo:{hasNextPage:i.search.pageInfo.hasNextPage,endCursor:i.search.pageInfo.endCursor},data:((l=i.search.nodes)==null?void 0:l.map($t))||[]}}async getPullRequestsAssociatedWithUser(t,s={}){return this.searchPullRequests({query:`involves:${t.username}`,cursor:t.cursor},s)}async getPullRequestsForRepos(t,s={}){let{assigneeLogins:n,updatedBefore:o,authorLogin:a,repos:i,reviewRequestedLogin:u,startQuery:l,mentionLogin:p}=t,d=Re(l||"");return i.forEach(c=>{d.push(`repo:${c.namespace}/${c.name}`)}),n&&n.forEach(c=>{d.push(`assignee:${c}`)}),o&&d.push(`updated:<${o}`),a&&d.push(`author:${a}`),u&&d.push(`review-requested:${u}`),p&&d.push(`mentions:${p}`),this.searchPullRequests({query:`sort:updated ${d.join(" ")}`,isDraft:t.isDraft,cursor:t.cursor},s)}async closePullRequest(t,s={}){var i,u,l;let{pullRequestGraphQLId:n}=t,o=`mutation ClosePullRequest($pullRequestGraphQLId: ID!) {
|
|
352
366
|
closePullRequest(input: { pullRequestId: $pullRequestGraphQLId }) {
|
|
353
367
|
pullRequest {
|
|
354
368
|
id
|
|
355
369
|
}
|
|
356
370
|
}
|
|
357
|
-
}`;if(!((l=(u=(i=(await h(this.config,{query:`${o}`,variables:{pullRequestGraphQLId:n}},s)).body.data)==null?void 0:i.closePullRequest)==null?void 0:u.pullRequest)!=null&&l.id))throw new Error("Could not close pull request")}async mergePullRequest(t,s={}){var p,d,
|
|
371
|
+
}`;if(!((l=(u=(i=(await h(this.config,{query:`${o}`,variables:{pullRequestGraphQLId:n}},s)).body.data)==null?void 0:i.closePullRequest)==null?void 0:u.pullRequest)!=null&&l.id))throw new Error("Could not close pull request")}async mergePullRequest(t,s={}){var p,d,c;let{pullRequestGraphQLId:n,expectedSourceSha:o,mergeStrategy:a}=t,i;switch(a){case"MERGE_COMMIT":{i="MERGE";break}case"REBASE":{i="REBASE";break}case"SQUASH":{i="SQUASH";break}}let u=`mutation MergePullRequest(
|
|
358
372
|
$pullRequestGraphQLId: ID!,
|
|
359
373
|
$expectedSourceSha: GitObjectID!,
|
|
360
374
|
$mergeStrategy: PullRequestMergeMethod,
|
|
@@ -368,7 +382,7 @@ query getBlame($owner: String!, $name: String!, $ref: String!, $path: String!) {
|
|
|
368
382
|
id
|
|
369
383
|
}
|
|
370
384
|
}
|
|
371
|
-
}`;if(!((
|
|
385
|
+
}`;if(!((c=(d=(p=(await h(this.config,{query:`${u}`,variables:{pullRequestGraphQLId:n,expectedSourceSha:o,mergeStrategy:i}},s)).body.data)==null?void 0:p.mergePullRequest)==null?void 0:d.pullRequest)!=null&&c.id))throw new Error("Could not merge pull request")}async setPullRequestMilestone(t,s={}){var u,l,p;let{pullRequestGraphQLId:n,milestoneGraphQLId:o}=t,a=`mutation SetPullRequestMilestone($pullRequestGraphQLId: ID!, $milestoneGraphQLId: ID) {
|
|
372
386
|
updatePullRequest(input: { pullRequestId: $pullRequestGraphQLId, milestoneId: $milestoneGraphQLId }) {
|
|
373
387
|
pullRequest {
|
|
374
388
|
id
|
|
@@ -386,7 +400,7 @@ query getBlame($owner: String!, $name: String!, $ref: String!, $path: String!) {
|
|
|
386
400
|
id
|
|
387
401
|
}
|
|
388
402
|
}
|
|
389
|
-
}`;if(!((u=(i=(a=(await h(this.config,{query:n,variables:{pullRequestGraphQLId:t}},s)).body.data)==null?void 0:a.convertPullRequestToDraft)==null?void 0:i.pullRequest)!=null&&u.id))throw new Error("Could not convert pull request to draft")}async setPullRequestAsDraft(t,s={}){let{pullRequestGraphQLId:n,isDraft:o}=t;if(o){await this.convertPullRequestToDraft(n,s);return}await this.markPullRequestReadyForReview(n,s)}async getIssuesAssociatedWithUser(t,s={}){var d;let[n,o]=((d=t.cursor)==null?void 0:d.split(";"))||[void 0,void 0];if(t.cursor&&n==="null"&&o==="null")return{pageInfo:{hasNextPage:!1,endCursor:"null;null"},data:[]};let[a,i]=await Promise.all([this.searchIssues({query:`author:${t.username}`,cursor:n},s),this.searchIssues({query:`assignee:${t.username}`,cursor:o},s)]),u={},l=[],p=
|
|
403
|
+
}`;if(!((u=(i=(a=(await h(this.config,{query:n,variables:{pullRequestGraphQLId:t}},s)).body.data)==null?void 0:a.convertPullRequestToDraft)==null?void 0:i.pullRequest)!=null&&u.id))throw new Error("Could not convert pull request to draft")}async setPullRequestAsDraft(t,s={}){let{pullRequestGraphQLId:n,isDraft:o}=t;if(o){await this.convertPullRequestToDraft(n,s);return}await this.markPullRequestReadyForReview(n,s)}async getIssuesAssociatedWithUser(t,s={}){var d;let[n,o]=((d=t.cursor)==null?void 0:d.split(";"))||[void 0,void 0];if(t.cursor&&n==="null"&&o==="null")return{pageInfo:{hasNextPage:!1,endCursor:"null;null"},data:[]};let[a,i]=await Promise.all([this.searchIssues({query:`author:${t.username}`,cursor:n},s),this.searchIssues({query:`assignee:${t.username}`,cursor:o},s)]),u={},l=[],p=c=>{u[c.id]||(u[c.id]=!0,l.push(c))};return a.data.forEach(p),i.data.forEach(p),{pageInfo:{hasNextPage:a.pageInfo.hasNextPage||i.pageInfo.hasNextPage,endCursor:`${(a==null?void 0:a.pageInfo.hasNextPage)&&(a==null?void 0:a.pageInfo.endCursor)||"null"};${(i==null?void 0:i.pageInfo.hasNextPage)&&(i==null?void 0:i.pageInfo.endCursor)||"null"}`},data:l}}async getIssuesForRepos(t,s={}){let n=Re(t.startQuery||""),{cursor:o,assigneeLogins:a,updatedBefore:i,authorLogin:u,mentionLogin:l}=t;return t.repos.forEach(p=>{n.push(`repo:${p.namespace}/${p.name}`)}),a&&a.forEach(p=>{n.push(`assignee:${p}`)}),i&&n.push(`updated:<${i}`),u&&n.push(`author:${u}`),l&&n.push(`mentions:${l}`),this.searchIssues({query:`sort:updated ${n.join(" ")}`,cursor:o},s)}async closeIssueWithReason(t,s,n){var i,u,l;let o=`mutation CloseIssueWithReason($issueGraphQLId: ID!, $closeReason: IssueClosedStateReason!) {
|
|
390
404
|
closeIssue(input: { issueId: $issueGraphQLId, stateReason: $closeReason }) {
|
|
391
405
|
issue {
|
|
392
406
|
id
|
|
@@ -424,7 +438,7 @@ query getLabelsForRepo($owner: String!, $name: String! $cursor: String, $first:
|
|
|
424
438
|
}
|
|
425
439
|
}
|
|
426
440
|
}
|
|
427
|
-
`,variables:{owner:n,name:o,cursor:a,first:S}},s);if(!i.body.data)throw new Error(((u=i.body.errors)==null?void 0:u[0].message)||i.statusText||"Unknown error");return{pageInfo:((l=i.body.data.repository.milestones)==null?void 0:l.pageInfo)??{endCursor:null,hasNextPage:!1},data:((d=(p=i.body.data.repository.milestones)==null?void 0:p.nodes)==null?void 0:d.map(
|
|
441
|
+
`,variables:{owner:n,name:o,cursor:a,first:S}},s);if(!i.body.data)throw new Error(((u=i.body.errors)==null?void 0:u[0].message)||i.statusText||"Unknown error");return{pageInfo:((l=i.body.data.repository.milestones)==null?void 0:l.pageInfo)??{endCursor:null,hasNextPage:!1},data:((d=(p=i.body.data.repository.milestones)==null?void 0:p.nodes)==null?void 0:d.map(Se))??[]}}async getLabelsForRepo(t,s={}){var u,l,p,d;let{repo:{namespace:n,name:o},cursor:a}=t,i=await h(this.config,{query:`
|
|
428
442
|
query getLabelsForRepo($owner: String!, $name: String! $cursor: String, $first: Int!) {
|
|
429
443
|
repository(owner: $owner, name: $name) {
|
|
430
444
|
labels(first: $first, after: $cursor) {
|
|
@@ -438,7 +452,7 @@ query getLabelsForRepo($owner: String!, $name: String! $cursor: String, $first:
|
|
|
438
452
|
}
|
|
439
453
|
}
|
|
440
454
|
}
|
|
441
|
-
`,variables:{owner:n,name:o,cursor:a,first:S}},s);if(!i.body.data)throw new Error(((u=i.body.errors)==null?void 0:u[0].message)||i.statusText||"Unknown error");return{pageInfo:((l=i.body.data.repository.labels)==null?void 0:l.pageInfo)??{endCursor:null,hasNextPage:!1},data:((d=(p=i.body.data.repository.labels)==null?void 0:p.nodes)==null?void 0:d.map(
|
|
455
|
+
`,variables:{owner:n,name:o,cursor:a,first:S}},s);if(!i.body.data)throw new Error(((u=i.body.errors)==null?void 0:u[0].message)||i.statusText||"Unknown error");return{pageInfo:((l=i.body.data.repository.labels)==null?void 0:l.pageInfo)??{endCursor:null,hasNextPage:!1},data:((d=(p=i.body.data.repository.labels)==null?void 0:p.nodes)==null?void 0:d.map(we))??[]}}};var vt="https://gitlab.com/api/v4",Et="https://gitlab.com/api/graphql",Ke=/\/api\/v\d+$/,Xe=e=>{if(e.endsWith("/api/graphql"))throw new Error("The graphql endpoint is being used as the baseUrl. This package uses both GraphQL and REST APIs, and the REST version cannot be assumed. Use the REST endpoint as the baseUrl instead.")},Ce=(e,r)=>{let t=r.baseUrl||e.baseUrl;return t?(t=t.replace(/\/$/,""),Xe(t),t):vt},Dt=(e,r)=>{let t=r.baseUrl||e.baseUrl;return t?(t=t.replace(/\/$/,""),Xe(t),Ke.test(t)&&(t=t.replace(Ke,"")),`${t}/api/graphql`):Et},R=(e,r,t)=>{let s=m(t.token||e.token);return e.request({url:Dt(e,t),method:"POST",headers:{...s,"Content-Type":"application/json"},body:JSON.stringify(r)})};var Ze=e=>e.split("/").slice(0,-1).join("/"),Q=e=>({namespace:Ze(e.fullPath),name:e.path,webUrl:e.webUrl}),qt={assigned:"assignedMergeRequests",authored:"authoredMergeRequests",reviewRequested:"reviewRequestedMergeRequests"},Gt={CAN_BE_MERGED:"MERGEABLE",CANNOT_BE_MERGED:"CONFLICTS",CANNOT_BE_MERGED_RECHECK:"UNKNOWN",UNCHECKED:"UNKNOWN",CHECKING:"UNKNOWN"},Ge="gid://gitlab/User/",W="gid://gitlab/Project/",Lt="gid://gitlab/MergeRequest/",xt="gid://gitlab/Issue/",At="gid://gitlab/ProjectLabel/",Ye="gid://gitlab/Milestone/",Le=`
|
|
442
456
|
description
|
|
443
457
|
dueDate
|
|
444
458
|
id
|
|
@@ -447,7 +461,7 @@ startDate
|
|
|
447
461
|
state
|
|
448
462
|
title
|
|
449
463
|
webPath
|
|
450
|
-
`,
|
|
464
|
+
`,Ue=`
|
|
451
465
|
id
|
|
452
466
|
path
|
|
453
467
|
fullPath
|
|
@@ -457,24 +471,24 @@ sshUrlToRepo
|
|
|
457
471
|
repository {
|
|
458
472
|
rootRef
|
|
459
473
|
}
|
|
460
|
-
`,
|
|
474
|
+
`,x=`
|
|
461
475
|
id
|
|
462
476
|
name
|
|
463
477
|
username
|
|
464
478
|
publicEmail
|
|
465
479
|
avatarUrl
|
|
466
|
-
`,
|
|
480
|
+
`,xe=`
|
|
467
481
|
color
|
|
468
482
|
description
|
|
469
483
|
id
|
|
470
484
|
title
|
|
471
|
-
|
|
485
|
+
`,$e=`
|
|
472
486
|
author {
|
|
473
|
-
${
|
|
487
|
+
${x}
|
|
474
488
|
}
|
|
475
489
|
assignees {
|
|
476
490
|
nodes {
|
|
477
|
-
${
|
|
491
|
+
${x}
|
|
478
492
|
}
|
|
479
493
|
}
|
|
480
494
|
createdAt
|
|
@@ -484,7 +498,7 @@ id
|
|
|
484
498
|
iid
|
|
485
499
|
labels {
|
|
486
500
|
nodes {
|
|
487
|
-
${
|
|
501
|
+
${xe}
|
|
488
502
|
}
|
|
489
503
|
}
|
|
490
504
|
state
|
|
@@ -495,13 +509,13 @@ upvotes
|
|
|
495
509
|
userNotesCount
|
|
496
510
|
webUrl
|
|
497
511
|
milestone {
|
|
498
|
-
${
|
|
512
|
+
${Le}
|
|
499
513
|
}
|
|
500
|
-
`,
|
|
514
|
+
`,ve=(e,r)=>`
|
|
501
515
|
id
|
|
502
516
|
state
|
|
503
517
|
author {
|
|
504
|
-
${
|
|
518
|
+
${x}
|
|
505
519
|
}
|
|
506
520
|
diffRefs {
|
|
507
521
|
baseSha
|
|
@@ -526,12 +540,12 @@ targetBranch
|
|
|
526
540
|
sourceBranch
|
|
527
541
|
assignees {
|
|
528
542
|
nodes {
|
|
529
|
-
${
|
|
543
|
+
${x}
|
|
530
544
|
}
|
|
531
545
|
}
|
|
532
546
|
reviewers {
|
|
533
547
|
nodes {
|
|
534
|
-
${
|
|
548
|
+
${x}
|
|
535
549
|
mergeRequestInteraction {
|
|
536
550
|
approved
|
|
537
551
|
reviewState
|
|
@@ -541,18 +555,18 @@ reviewers {
|
|
|
541
555
|
mergeStatusEnum
|
|
542
556
|
labels {
|
|
543
557
|
nodes {
|
|
544
|
-
${
|
|
558
|
+
${xe}
|
|
545
559
|
}
|
|
546
560
|
}
|
|
547
561
|
${e?"project { path fullPath webUrl }":""}
|
|
548
|
-
${r?`milestone { ${
|
|
549
|
-
`,
|
|
562
|
+
${r?`milestone { ${Le} }`:""}
|
|
563
|
+
`,k=e=>`${e.namespace}/${e.name}`,Tt=e=>`${e.namespace}/${e.name}`,Ee=e=>{var r;return{id:e.id.replace(W,""),graphQLId:e.id,namespace:Ze(e.fullPath),name:e.path,webUrl:e.webUrl,httpsUrl:e.httpUrlToRepo,sshUrl:e.sshUrlToRepo,defaultBranch:(r=e.repository)!=null&&r.rootRef?{name:e.repository.rootRef}:null,permission:null}},Ot={opened:"OPEN",merged:"MERGED",closed:"CLOSED"},_=e=>({id:e.id.replace(Ge,""),graphQLId:e.id,name:e.name,username:e.username,email:e.publicEmail,avatarUrl:e.avatarUrl}),Ae=e=>({color:e.color,description:e.description,id:e.id.replace(At,""),graphQLId:e.id,name:e.title}),De=(e,r)=>{var t,s,n,o,a,i,u,l,p;return{id:e.id.replace(Lt,""),graphQLId:e.id,title:e.title,number:parseInt(e.iid,10),state:Ot[e.state],commentCount:e.userNotesCount||0,upvoteCount:e.upvotes,author:e.author?_(e.author):null,createdDate:new Date(e.createdAt),isDraft:e.draft,repository:{name:r.name,owner:{login:r.namespace}},headRepository:null,headCommit:{buildStatus:null},baseRef:{name:e.targetBranch,oid:((t=e.diffRefs)==null?void 0:t.baseSha)??null},headRef:{name:e.sourceBranch,oid:((s=e.diffRefs)==null?void 0:s.headSha)??null},url:e.webUrl,updatedDate:new Date(e.updatedAt),closedDate:e.mergedAt?new Date(e.mergedAt):null,assignees:(n=e.assignees)!=null&&n.nodes?e.assignees.nodes.map(_):null,reviews:(o=e.reviewers)!=null&&o.nodes?e.reviewers.nodes.map(d=>{var c,g;return{reviewer:_(d),state:(c=d.mergeRequestInteraction)!=null&&c.approved?"APPROVED":((g=d.mergeRequestInteraction)==null?void 0:g.reviewState)==="REVIEWED"?"CHANGES_REQUESTED":"CHANGES_REQUESTED"}}):null,additions:((a=e.diffStatsSummary)==null?void 0:a.additions)||0,deletions:((i=e.diffStatsSummary)==null?void 0:i.deletions)||0,fileCount:((u=e.diffStatsSummary)==null?void 0:u.fileCount)||0,commitCount:e.commitCount||0,mergeableState:Gt[e.mergeStatusEnum],milestone:e.milestone?Te(e.milestone,r.webUrl):null,labels:((p=(l=e.labels)==null?void 0:l.nodes)==null?void 0:p.map(Ae))??[]}},qe=(e,r)=>{var t,s;return{author:{avatarUrl:e.author.avatarUrl,email:null,graphQLId:e.author.id,id:e.author.id.replace(Ge,""),name:e.author.name,username:e.author.username},assignees:e.assignees.nodes.map(n=>({avatarUrl:n.avatarUrl,email:null,graphQLId:n.id,id:n.id.replace(Ge,""),name:n.name,username:n.username})),commentCount:e.userNotesCount,createdDate:new Date(e.createdAt),description:e.description,graphQLId:e.id,id:e.id.replace(xt,""),labels:((s=(t=e.labels)==null?void 0:t.nodes)==null?void 0:s.map(Ae))??[],number:e.iid,repository:{name:r.name,owner:{login:r.namespace}},updatedDate:new Date(e.updatedAt),upvoteCount:e.upvotes,state:{name:e.state,color:null},type:e.type,title:e.title,url:e.webUrl,milestone:e.milestone?Te(e.milestone,r.webUrl):null}},Te=(e,r)=>({id:e.id.replace(Ye,""),graphQLId:e.id,number:parseInt(e.iid,10),title:e.title,description:e.description,isOpen:e.state==="active",url:`${r}/-/${e.webPath.replace(/.+?\/-\//,"")}`,startDate:e.startDate?new Date(e.startDate):null,dueDate:e.dueDate?new Date(e.dueDate):null}),H=class extends T{async getCurrentUser(r={}){var n;let s=(n=(await R(this.config,{query:`
|
|
550
564
|
query getCurrentUser {
|
|
551
565
|
currentUser {
|
|
552
|
-
${
|
|
566
|
+
${x}
|
|
553
567
|
}
|
|
554
568
|
}
|
|
555
|
-
`},r)).body.data)==null?void 0:n.currentUser;if(!s)throw new Error("Current user not found.");return{data:
|
|
569
|
+
`},r)).body.data)==null?void 0:n.currentUser;if(!s)throw new Error("Current user not found.");return{data:_(s)}}async getUserForCommit(r,t={}){var a,i,u,l;let s=k(r.repo),o=(l=(u=(i=(a=(await R(this.config,{query:`
|
|
556
570
|
query getUserForCommit($fullPath: ID!, $oid: String!) {
|
|
557
571
|
project(fullPath: $fullPath) {
|
|
558
572
|
repository {
|
|
@@ -566,36 +580,57 @@ query getUserForCommit($fullPath: ID!, $oid: String!) {
|
|
|
566
580
|
}
|
|
567
581
|
}
|
|
568
582
|
}
|
|
569
|
-
`,variables:{fullPath:s,oid:r.oid}},t)).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(r,t={}){var o,a,i;let n=(i=(a=(o=(await
|
|
583
|
+
`,variables:{fullPath:s,oid:r.oid}},t)).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(r,t={}){var o,a,i;let n=(i=(a=(o=(await R(this.config,{query:`
|
|
570
584
|
query getAccountForEmail($email: String!) {
|
|
571
585
|
users(search: $email) {
|
|
572
586
|
nodes {
|
|
573
|
-
${
|
|
587
|
+
${x}
|
|
574
588
|
}
|
|
575
589
|
}
|
|
576
590
|
}
|
|
577
|
-
`,variables:{email:r.email}},t)).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:
|
|
591
|
+
`,variables:{email:r.email}},t)).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:_(n)}}async getAccountForUsername(r,t={}){var o;let n=(o=(await R(this.config,{query:`
|
|
578
592
|
query getAccountForUsername($username: String!) {
|
|
579
593
|
user(username: $username) {
|
|
580
|
-
${
|
|
594
|
+
${x}
|
|
595
|
+
}
|
|
596
|
+
}
|
|
597
|
+
`,variables:{username:r.username}},t)).body.data)==null?void 0:o.user;if(!n)throw new Error("User not found.");return{data:_(n)}}async getAccountsForRepo(r,t={}){var u,l,p,d,c,g,I;let{repo:{namespace:s,name:n},cursor:o}=r,a=await R(this.config,{query:`
|
|
598
|
+
query getAccountsForRepo(
|
|
599
|
+
$fullPath: ID!
|
|
600
|
+
$after: String
|
|
601
|
+
) {
|
|
602
|
+
project(
|
|
603
|
+
fullPath: $fullPath
|
|
604
|
+
) {
|
|
605
|
+
projectMembers(after: $after) {
|
|
606
|
+
nodes {
|
|
607
|
+
user {
|
|
608
|
+
${x}
|
|
609
|
+
}
|
|
610
|
+
}
|
|
611
|
+
pageInfo {
|
|
612
|
+
endCursor
|
|
613
|
+
hasNextPage
|
|
614
|
+
}
|
|
615
|
+
}
|
|
581
616
|
}
|
|
582
617
|
}
|
|
583
|
-
`,variables:{
|
|
618
|
+
`,variables:{fullPath:`${s}/${n}`,after:o}},t),i=(d=(p=(l=(u=a.body.data)==null?void 0:u.project)==null?void 0:l.projectMembers)==null?void 0:p.nodes)==null?void 0:d.map(f=>f.user).filter(f=>f!==null);return{pageInfo:((I=(g=(c=a.body.data)==null?void 0:c.project)==null?void 0:g.projectMembers)==null?void 0:I.pageInfo)??{endCursor:null,hasNextPage:!1},data:(i==null?void 0:i.map(_))??[]}}async getRepo(r,t={}){var o;let s=k(r),n=await R(this.config,{query:`
|
|
584
619
|
query getRepo($fullPath: ID!) {
|
|
585
620
|
project(fullPath: $fullPath) {
|
|
586
|
-
${
|
|
621
|
+
${Ue}
|
|
587
622
|
}
|
|
588
623
|
}
|
|
589
|
-
`,variables:{fullPath:s}},t);if(!((o=n.body.data)!=null&&o.project))throw new Error(`Repository ${s} not found`);return{data
|
|
624
|
+
`,variables:{fullPath:s}},t);if(!((o=n.body.data)!=null&&o.project))throw new Error(`Repository ${s} not found`);return{data:Ee(n.body.data.project)}}async getRepos(r,t={}){let n=r.map(k).map((u,l)=>`
|
|
590
625
|
getRepo_${l}: project(fullPath: "${u}") {
|
|
591
|
-
${
|
|
626
|
+
${Ue}
|
|
592
627
|
}
|
|
593
628
|
`).join(`
|
|
594
|
-
`),o=await
|
|
629
|
+
`),o=await R(this.config,{query:`
|
|
595
630
|
query batchGetRepos {
|
|
596
631
|
${n}
|
|
597
632
|
}
|
|
598
|
-
`},t);if(!o.body.data)throw new Error(o.statusText||"Unknown error");let a=[],i=[];return r.forEach((u,l)=>{let p=o.body.data[`getRepo_${l}`];p?a.push(
|
|
633
|
+
`},t);if(!o.body.data)throw new Error(o.statusText||"Unknown error");let a=[],i=[];return r.forEach((u,l)=>{let p=o.body.data[`getRepo_${l}`];p?a.push(Ee(p)):i.push({input:u})}),{data:a,errors:i}}async getReposForCurrentUser(r={},t={}){var o,a,i,u,l,p;let s=await R(this.config,{query:`
|
|
599
634
|
query getReposForCurrentUser($after: String) {
|
|
600
635
|
projects(membership: true first: 100 after: $after) {
|
|
601
636
|
pageInfo {
|
|
@@ -603,11 +638,11 @@ query getReposForCurrentUser($after: String) {
|
|
|
603
638
|
hasNextPage
|
|
604
639
|
}
|
|
605
640
|
nodes {
|
|
606
|
-
${
|
|
641
|
+
${Ue}
|
|
607
642
|
}
|
|
608
643
|
}
|
|
609
644
|
}
|
|
610
|
-
`,variables:{after:r.cursor}},t);if(!((o=s.body.data)!=null&&o.projects))throw new Error(((a=s.body.errors)==null?void 0:a[0].message)||s.statusText||"Unknown error");let n=((u=(i=s.body.data)==null?void 0:i.projects)==null?void 0:u.nodes)||[];return{pageInfo:(p=(l=s.body.data)==null?void 0:l.projects)==null?void 0:p.pageInfo,data:n.map(
|
|
645
|
+
`,variables:{after:r.cursor}},t);if(!((o=s.body.data)!=null&&o.projects))throw new Error(((a=s.body.errors)==null?void 0:a[0].message)||s.statusText||"Unknown error");let n=((u=(i=s.body.data)==null?void 0:i.projects)==null?void 0:u.nodes)||[];return{pageInfo:(p=(l=s.body.data)==null?void 0:l.projects)==null?void 0:p.pageInfo,data:n.map(Ee)}}async getRefs(r,t,s={}){var u;let n=k(t.repo),o=new URL(`${Ce(this.config,s)}/projects/${encodeURIComponent(n)}/repository/${r}`);o.searchParams.set("page",((u=t.page)==null?void 0:u.toString())||"1"),o.searchParams.set("per_page",S.toString());let a=await this.config.request({url:o.toString(),headers:m(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(r,t={}){return this.getRefs("branches",r,t)}async getTags(r,t={}){return this.getRefs("tags",r,t)}async getBlame(r,t={}){let s=k(r.repo),n=new URL(`${Ce(this.config,t)}/projects/${encodeURIComponent(s)}/repository/files/${encodeURIComponent(r.path)}/blame`);n.searchParams.set("ref",r.ref);let o=await this.config.request({url:n.toString(),headers:m(t.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}}})}}}async getPullRequestsForUser(r,t={}){var a,i;let s=qt[r.association],n=await R(this.config,{query:`
|
|
611
646
|
query getPullRequestsForUser($username: String! $cursor: String) {
|
|
612
647
|
user(username: $username) {
|
|
613
648
|
${s}(state:opened first:100 after:$cursor) {
|
|
@@ -616,12 +651,12 @@ query getPullRequestsForUser($username: String! $cursor: String) {
|
|
|
616
651
|
hasNextPage
|
|
617
652
|
}
|
|
618
653
|
nodes {
|
|
619
|
-
${
|
|
654
|
+
${ve(!0,!0)}
|
|
620
655
|
}
|
|
621
656
|
}
|
|
622
657
|
}
|
|
623
658
|
}
|
|
624
|
-
`,variables:{username:r.username,cursor:r.cursor}},t);if(!n.body.data)throw new Error(((a=n.body.errors)==null?void 0:a[0].message)||n.statusText||"Unknown error");if(!n.body.data.user)throw new Error("User not found");let o=n.body.data.user[s];if(!o)throw new Error("Unexpected response");return{pageInfo:o.pageInfo,data:((i=o.nodes)==null?void 0:i.map(u=>
|
|
659
|
+
`,variables:{username:r.username,cursor:r.cursor}},t);if(!n.body.data)throw new Error(((a=n.body.errors)==null?void 0:a[0].message)||n.statusText||"Unknown error");if(!n.body.data.user)throw new Error("User not found");let o=n.body.data.user[s];if(!o)throw new Error("Unexpected response");return{pageInfo:o.pageInfo,data:((i=o.nodes)==null?void 0:i.map(u=>De(u,Q(u.project))))||[]}}async getPullRequestsAssociatedWithUser(r,t={}){var c;let[s,n,o]=((c=r.cursor)==null?void 0:c.split(";"))||[void 0,void 0,void 0];if(r.cursor&&s==="null"&&n==="null"&&o==="null")return{pageInfo:{hasNextPage:!1,endCursor:"null;null;null"},data:[]};let[a,i,u]=await Promise.all([this.getPullRequestsForUser({username:r.username,association:"authored",cursor:s},t),this.getPullRequestsForUser({username:r.username,association:"assigned",cursor:n},t),this.getPullRequestsForUser({username:r.username,association:"reviewRequested",cursor:o},t)]),l={},p=[],d=g=>{l[g.id]||(l[g.id]=!0,p.push(g))};return a.data.forEach(d),i.data.forEach(d),u.data.forEach(d),{pageInfo:{hasNextPage:a.pageInfo.hasNextPage||i.pageInfo.hasNextPage||u.pageInfo.hasNextPage,endCursor:`${(a==null?void 0:a.pageInfo.hasNextPage)&&(a==null?void 0:a.pageInfo.endCursor)||"null"};${(i==null?void 0:i.pageInfo.hasNextPage)&&(i==null?void 0:i.pageInfo.endCursor)||"null"};${(u==null?void 0:u.pageInfo.hasNextPage)&&(u==null?void 0:u.pageInfo.endCursor)||"null"}`},data:p}}getVariablesForPullRequests(r){let{updatedBefore:t,isDraft:s,authorLogin:n,assigneeLogins:o,reviewRequestedLogin:a}=r||{},i={},u=[],l=[],p=(d,c,g)=>{u.push(`$${d}: ${g}`),l.push(`${d}: $${d}`),i[d]=c};return t&&p("updatedBefore",t,"Time"),n&&p("authorUsername",n,"String"),o&&p("assigneeUsername",o[0],"String"),s!=null&&p("draft",s,"Boolean"),a&&p("reviewerUsername",a,"String"),{variables:i,variableTypes:u,mergeRequestArguments:l}}async getPullRequestsForRepo(r,t={}){var f,w,y;let{cursor:s,repo:n}=r||{},o=k(n),{variables:a,variableTypes:i,mergeRequestArguments:u}=this.getVariablesForPullRequests(r),l={fullPath:o,...a},p=await R(this.config,{query:`
|
|
625
660
|
query getPullRequestsForRepo(
|
|
626
661
|
$fullPath: ID!
|
|
627
662
|
$after: String
|
|
@@ -645,12 +680,12 @@ query getPullRequestsForRepo(
|
|
|
645
680
|
hasNextPage
|
|
646
681
|
}
|
|
647
682
|
nodes {
|
|
648
|
-
${
|
|
683
|
+
${ve(!1,!0)}
|
|
649
684
|
}
|
|
650
685
|
}
|
|
651
686
|
}
|
|
652
687
|
}
|
|
653
|
-
`,variables:{...l,after:s}},t),d=[],
|
|
688
|
+
`,variables:{...l,after:s}},t),d=[],c=(f=p.body.data)==null?void 0:f.project,g=Q(c||{fullPath:"",path:"",webUrl:""});return(((w=c==null?void 0:c.mergeRequests)==null?void 0:w.nodes)||[]).forEach(b=>{d.push(De(b,g))}),{pageInfo:(y=c==null?void 0:c.mergeRequests)==null?void 0:y.pageInfo,data:d}}async getPullRequestsForRepos(r,t={}){var c,g,I,f,w;let{cursor:s}=r||{},n=r.repoIds.map(y=>y.toString().startsWith(W)?y:`${W}${y}`),{variables:o,variableTypes:a,mergeRequestArguments:i}=this.getVariablesForPullRequests(r),u={projectIds:n,...o},l=await R(this.config,{query:`
|
|
654
689
|
query getPullRequests(
|
|
655
690
|
$projectIds: [ID!]
|
|
656
691
|
$after: String
|
|
@@ -675,20 +710,20 @@ query getPullRequests(
|
|
|
675
710
|
${i.length?i.join(" "):""}
|
|
676
711
|
) {
|
|
677
712
|
nodes {
|
|
678
|
-
${
|
|
713
|
+
${ve(!1,!1)}
|
|
679
714
|
}
|
|
680
715
|
}
|
|
681
716
|
}
|
|
682
717
|
}
|
|
683
718
|
}
|
|
684
|
-
`,variables:{...u,after:s}},t),p=[];return(((
|
|
719
|
+
`,variables:{...u,after:s}},t),p=[];return(((g=(c=l.body.data)==null?void 0:c.projects)==null?void 0:g.nodes)||[]).forEach(y=>{var L;let b=Q(y);(((L=y.mergeRequests)==null?void 0:L.nodes)||[]).forEach($=>{p.push(De($,b))})}),{pageInfo:(w=(f=(I=l.body)==null?void 0:I.data)==null?void 0:f.projects)==null?void 0:w.pageInfo,data:p}}async closePullRequest(r,t={}){var l,p,d;let{repo:{namespace:s,name:n},pullRequestId:o}=r,a=`mutation ClosePullRequest($fullPath: ID!, $pullRequestId: String!) {
|
|
685
720
|
mergeRequestUpdate(input: { projectPath: $fullPath, iid: $pullRequestId, state: CLOSED }) {
|
|
686
721
|
errors,
|
|
687
722
|
mergeRequest {
|
|
688
723
|
id
|
|
689
724
|
}
|
|
690
725
|
}
|
|
691
|
-
}`,u=(l=(await
|
|
726
|
+
}`,u=(l=(await R(this.config,{query:a,variables:{fullPath:`${s}/${n}`,pullRequestId:o}},t)).body.data)==null?void 0:l.mergeRequestUpdate;if(!((p=u==null?void 0:u.mergeRequest)!=null&&p.id)||((d=u==null?void 0:u.errors)==null?void 0:d.length)!==0)throw new Error("Could not close pull request")}async mergePullRequest(r,t={}){var d,c,g;let{repo:{namespace:s,name:n},pullRequestId:o,expectedSourceSha:a,mergeStrategy:i}=r,u=`mutation MergePullRequest(
|
|
692
727
|
$fullPath: ID!,
|
|
693
728
|
$pullRequestId: String!,
|
|
694
729
|
$expectedSourceSha: String!,
|
|
@@ -705,32 +740,32 @@ query getPullRequests(
|
|
|
705
740
|
id
|
|
706
741
|
}
|
|
707
742
|
}
|
|
708
|
-
}`,p=(d=(await
|
|
743
|
+
}`,p=(d=(await R(this.config,{query:u,variables:{fullPath:`${s}/${n}`,pullRequestId:o,expectedSourceSha:a,squash:i==="SQUASH"}},t)).body.data)==null?void 0:d.mergeRequestAccept;if(!((c=p==null?void 0:p.mergeRequest)!=null&&c.id)||((g=p==null?void 0:p.errors)==null?void 0:g.length)!==0)throw new Error("Could not merge pull request")}async setPullRequestMilestone(r,t={}){var p,d,c;let{repo:{namespace:s,name:n},pullRequestId:o,milestoneGraphQLId:a}=r,i=`mutation SetPullRequestMilestone($fullPath: ID!, $pullRequestId: String!, $milestoneGraphQLId: MilestoneID) {
|
|
709
744
|
mergeRequestSetMilestone(input: { projectPath: $fullPath, iid: $pullRequestId, milestoneId: $milestoneGraphQLId }) {
|
|
710
745
|
errors,
|
|
711
746
|
mergeRequest {
|
|
712
747
|
id
|
|
713
748
|
}
|
|
714
749
|
}
|
|
715
|
-
}`,u=await
|
|
750
|
+
}`,u=await R(this.config,{query:i,variables:{fullPath:`${s}/${n}`,pullRequestId:o,milestoneGraphQLId:a}},t),l=(p=u.body.data)==null?void 0:p.mergeRequestSetMilestone;if(!((d=l==null?void 0:l.mergeRequest)!=null&&d.id)||u.body.errors||((c=l==null?void 0:l.errors)==null?void 0:c.length)!==0)throw new Error("Could not set milestone of pull request")}async setPullRequestAsDraft(r,t={}){var p,d,c;let{repo:{namespace:s,name:n},pullRequestId:o,isDraft:a}=r,i=`mutation MergeRequestSetDraft($fullPath: ID!, $pullRequestId: String!, $isDraft: Boolean!) {
|
|
716
751
|
mergeRequestSetDraft(input: { projectPath: $fullPath, iid: $pullRequestId, draft: $isDraft }) {
|
|
717
752
|
errors,
|
|
718
753
|
mergeRequest {
|
|
719
754
|
id
|
|
720
755
|
}
|
|
721
756
|
}
|
|
722
|
-
}`,l=(p=(await
|
|
757
|
+
}`,l=(p=(await R(this.config,{query:i,variables:{fullPath:`${s}/${n}`,pullRequestId:o,isDraft:a}},t)).body.data)==null?void 0:p.mergeRequestSetDraft;if(!((d=l==null?void 0:l.mergeRequest)!=null&&d.id)||((c=l==null?void 0:l.errors)==null?void 0:c.length)!==0)throw new Error("Could not set pull request as draft")}async getIssue(r,t={}){var o,a,i;let s=Tt(r),n=await R(this.config,{query:`
|
|
723
758
|
query GetSingleIssue($projectId: ID!, $issueId: String!) {
|
|
724
759
|
project(fullPath: $projectId) {
|
|
725
760
|
path
|
|
726
761
|
fullPath
|
|
727
762
|
webUrl
|
|
728
763
|
issue(iid: $issueId) {
|
|
729
|
-
${
|
|
764
|
+
${$e}
|
|
730
765
|
}
|
|
731
766
|
}
|
|
732
767
|
}
|
|
733
|
-
`,variables:{issueId:r.id,projectId:s}},t);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 ${r.id} not found`);return{data:
|
|
768
|
+
`,variables:{issueId:r.id,projectId:s}},t);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 ${r.id} not found`);return{data:qe(n.body.data.project.issue,Q(n.body.data.project))}}getVariablesForIssues(r){let{updatedBefore:t,authorLogin:s,assigneeLogins:n}=r||{},o={},a=[],i=[],u=(l,p,d)=>{a.push(`$${l}: ${d}`),i.push(`${l}: $${l}`),o[l]=p};return t&&u("updatedBefore",t,"Time"),s&&u("authorUsername",s,"String"),n&&u("assigneeUsername",n[0],"String"),{variables:o,variableTypes:a,issueArguments:i}}async getIssuesForRepo(r,t={}){var w,y,b;let{cursor:s,repo:n}=r||{},o=k(n),{variables:a,variableTypes:i,issueArguments:u}=this.getVariablesForIssues(r),l={fullPath:o,...a},p=`
|
|
734
769
|
query GetIssuesFromProject(
|
|
735
770
|
$fullPath: ID!
|
|
736
771
|
$after: String
|
|
@@ -750,7 +785,7 @@ query GetSingleIssue($projectId: ID!, $issueId: String!) {
|
|
|
750
785
|
${u.length?u.join(" "):""}
|
|
751
786
|
) {
|
|
752
787
|
nodes {
|
|
753
|
-
${
|
|
788
|
+
${$e}
|
|
754
789
|
}
|
|
755
790
|
pageInfo {
|
|
756
791
|
endCursor
|
|
@@ -758,7 +793,7 @@ query GetSingleIssue($projectId: ID!, $issueId: String!) {
|
|
|
758
793
|
}
|
|
759
794
|
}
|
|
760
795
|
}
|
|
761
|
-
}`,d=await
|
|
796
|
+
}`,d=await R(this.config,{query:p,variables:{...l,after:s}},t),c=[],g=(w=d.body.data)==null?void 0:w.project,I=Q(g||{fullPath:"",path:"",webUrl:""});return(((y=g==null?void 0:g.issues)==null?void 0:y.nodes)||[]).forEach(C=>{c.push(qe(C,I))}),{pageInfo:(b=g==null?void 0:g.issues)==null?void 0:b.pageInfo,data:c.sort((C,L)=>(C.updatedDate||C.createdDate).getTime()-(L.updatedDate||L.createdDate).getTime())}}async getIssuesForRepos(r,t={}){var g,I,f,w,y;let{cursor:s}=r||{},n=r.repoIds.map(b=>b.toString().startsWith(W)?b:`${W}${b}`),{variables:o,variableTypes:a,mergeRequestArguments:i}=this.getVariablesForPullRequests(r),u={projectIds:n,...o},l=`
|
|
762
797
|
query GetIssuesFromProject(
|
|
763
798
|
$projectIds: [ID!]
|
|
764
799
|
$after: String
|
|
@@ -783,18 +818,18 @@ query GetSingleIssue($projectId: ID!, $issueId: String!) {
|
|
|
783
818
|
${i.length?i.join(" "):""}
|
|
784
819
|
) {
|
|
785
820
|
nodes {
|
|
786
|
-
${
|
|
821
|
+
${$e}
|
|
787
822
|
}
|
|
788
823
|
}
|
|
789
824
|
}
|
|
790
825
|
}
|
|
791
|
-
}`,p=await
|
|
826
|
+
}`,p=await R(this.config,{query:l,variables:{...u,after:s}},t),d=[];return(((I=(g=p.body.data)==null?void 0:g.projects)==null?void 0:I.nodes)||[]).forEach(b=>{var $;let C=Q(b);((($=b.issues)==null?void 0:$.nodes)||[]).forEach(le=>d.push(qe(le,C)))}),{pageInfo:(y=(w=(f=p.body)==null?void 0:f.data)==null?void 0:w.projects)==null?void 0:y.pageInfo,data:d.sort((b,C)=>(b.updatedDate||b.createdDate).getTime()-(C.updatedDate||C.createdDate).getTime())}}async setIssueStatus(r,t={}){var l,p,d;let{repo:{namespace:s,name:n},issueId:o,status:a}=r,i=`mutation SetIssueState($fullPath: ID!, $issueId: String!, $status: IssueStateEvent!) {
|
|
792
827
|
updateIssue(input: { projectPath: $fullPath, iid: $issueId, stateEvent: $status }) {
|
|
793
828
|
issue {
|
|
794
829
|
id
|
|
795
830
|
}
|
|
796
831
|
}
|
|
797
|
-
}`;if(!((d=(p=(l=(await
|
|
832
|
+
}`;if(!((d=(p=(l=(await R(this.config,{query:i,variables:{fullPath:`${s}/${n}`,issueId:o,status:a}},t)).body.data)==null?void 0:l.updateIssue)==null?void 0:p.issue)!=null&&d.id))throw new Error("Could not set issue status")}async setIssueMilestone(r,t={}){var p,d,c,g;let{repo:{namespace:s,name:n},issueId:o}=r,a=((p=r.milestoneGraphQLId)==null?void 0:p.replace(Ye,""))??"",i=`mutation SetIssueMilestone($fullPath: ID!, $issueId: String!, $milestoneGraphQLId: ID) {
|
|
798
833
|
updateIssue(input: { projectPath: $fullPath, iid: $issueId, milestoneId: $milestoneGraphQLId }) {
|
|
799
834
|
errors
|
|
800
835
|
issue {
|
|
@@ -804,7 +839,7 @@ query GetSingleIssue($projectId: ID!, $issueId: String!) {
|
|
|
804
839
|
}
|
|
805
840
|
}
|
|
806
841
|
}
|
|
807
|
-
}`,u=await
|
|
842
|
+
}`,u=await R(this.config,{query:i,variables:{fullPath:`${s}/${n}`,issueId:o,milestoneGraphQLId:a}},t),l=(d=u.body.data)==null?void 0:d.updateIssue;if(!((c=l==null?void 0:l.issue)!=null&&c.id)||u.body.errors||((g=l==null?void 0:l.errors)==null?void 0:g.length)!==0)throw new Error("Could not set milestone of issue")}async getMilestonesForRepo(r,t={}){var i,u,l,p,d,c,g;let{repo:{namespace:s,name:n},cursor:o}=r,a=await R(this.config,{query:`
|
|
808
843
|
query getLabelsForRepo(
|
|
809
844
|
$fullPath: ID!
|
|
810
845
|
$after: String
|
|
@@ -815,7 +850,7 @@ query getLabelsForRepo(
|
|
|
815
850
|
webUrl
|
|
816
851
|
milestones(after: $after) {
|
|
817
852
|
nodes {
|
|
818
|
-
${
|
|
853
|
+
${Le}
|
|
819
854
|
}
|
|
820
855
|
pageInfo {
|
|
821
856
|
endCursor
|
|
@@ -824,7 +859,7 @@ query getLabelsForRepo(
|
|
|
824
859
|
}
|
|
825
860
|
}
|
|
826
861
|
}
|
|
827
|
-
`,variables:{fullPath:`${s}/${n}`,after:o}},t);return{pageInfo:((l=(u=(i=a.body.data)==null?void 0:i.project)==null?void 0:u.milestones)==null?void 0:l.pageInfo)??{endCursor:null,hasNextPage:!1},data:((
|
|
862
|
+
`,variables:{fullPath:`${s}/${n}`,after:o}},t);return{pageInfo:((l=(u=(i=a.body.data)==null?void 0:i.project)==null?void 0:u.milestones)==null?void 0:l.pageInfo)??{endCursor:null,hasNextPage:!1},data:((g=(c=(d=(p=a.body.data)==null?void 0:p.project)==null?void 0:d.milestones)==null?void 0:c.nodes)==null?void 0:g.map(I=>{var f,w;return Te(I,((w=(f=a.body.data)==null?void 0:f.project)==null?void 0:w.webUrl)||"")}))??[]}}async getLabelsForRepo(r,t={}){var i,u,l,p,d,c,g;let{repo:{namespace:s,name:n},cursor:o}=r,a=await R(this.config,{query:`
|
|
828
863
|
query getLabelsForRepo(
|
|
829
864
|
$fullPath: ID!
|
|
830
865
|
$after: String
|
|
@@ -834,7 +869,7 @@ query getLabelsForRepo(
|
|
|
834
869
|
) {
|
|
835
870
|
labels(after: $after) {
|
|
836
871
|
nodes {
|
|
837
|
-
${
|
|
872
|
+
${xe}
|
|
838
873
|
}
|
|
839
874
|
pageInfo {
|
|
840
875
|
endCursor
|
|
@@ -843,4 +878,4 @@ query getLabelsForRepo(
|
|
|
843
878
|
}
|
|
844
879
|
}
|
|
845
880
|
}
|
|
846
|
-
`,variables:{fullPath:`${s}/${n}`,after:o}},t);return{pageInfo:((l=(u=(i=a.body.data)==null?void 0:i.project)==null?void 0:u.labels)==null?void 0:l.pageInfo)??{endCursor:null,hasNextPage:!1},data:((c=(g=(d=(p=a.body.data)==null?void 0:p.project)==null?void 0:d.labels)==null?void 0:g.nodes)==null?void 0:c.map(xe))??[]}}};var H="https://api.atlassian.com/ex/jira",Ae=100,Ot=e=>{var t,s,n,o,a,i;let r=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:r?[{id:r.accountId,name:r.displayName,email:r.emailAddress,avatarUrl:r.avatarUrls["32x32"],username:r.displayName}]:[],description:null,repository:null,state:{name:(t=e.fields.status)==null?void 0:t.name,color:(n=(s=e.fields.status)==null?void 0:s.statusCategory)==null?void 0:n.colorName},statusTransitions:((o=e.transitions)==null?void 0:o.map(kt))??[],type:e.fields.issuetype.name,upvoteCount:((a=e.fields.votes)==null?void 0:a.votes)||0,labels:((i=e.fields.labels)==null?void 0:i.map(u=>({color:null,description:null,id:null,name:u})))??[]}},kt=e=>({name:e.name,id:e.id}),J=class extends ${async getCurrentUserForResource(r,t={}){let s=await this.config.request({url:`${t.baseUrl||H}/${r.resourceId}/rest/api/2/myself`,headers:m(t.token||this.config.token)});return{data:{name:s.body.displayName,email:s.body.emailAddress,avatarUrl:s.body.avatarUrls["48x48"],id:s.body.accountId,username:s.body.displayName}}}async getJiraResourcesForCurrentUser(r={}){return{data:(await this.config.request({url:`${r.baseUrl||"https://api.atlassian.com/"}/oauth/token/accessible-resources`,headers:m(r.token||this.config.token)})).body.map(s=>({avatarUrl:s.avatarUrl,id:s.id,name:s.name}))}}async getJiraProjectsForResource(r,t={}){let s=new URL(`${t.baseUrl||H}/${r.resourceId}/rest/api/2/project/search`);s.searchParams.set("maxResults",Ae.toString()),r.cursor&&s.searchParams.set("startAt",r.cursor);let n=await this.config.request({url:s.toString(),headers:m(t.token||this.config.token)});return{pageInfo:{hasNextPage:n.body.values.length!==0,endCursor:(n.body.startAt+n.body.values.length).toString()},data:n.body.values.map(o=>({id:o.id,name:o.name,resourceId:r.resourceId}))}}async getJiraProjectsForResources(r,t={}){let s=[];return await Promise.all(r.resourceIds.map(async n=>{let o=await this.getJiraProjectsForResource({resourceId:n},t);s.push(...o.data)})),{data:s}}async getIssuesForProject(r,t={}){let{assigneeLogins:s,authorLogin:n,mentionLogin:o,project:a}=r||{},i=[`project = "${a}"`];return n&&i.push(`creator in ("${n}")`),s&&s.length!==0&&i.push(`assignee in ("${s.join('", "')}")`),o&&i.push(`comment ~ "${o}"`),{data:(await this.config.request({url:`${t.baseUrl||H}/${r.resourceId}/rest/api/2/search?jql=${i.join(" AND ")}&startAt=0&maxResults=${Ae}&fields=${["assignee","comment","summary","created","creator","updated","votes","issuetype","status","labels"].join(",")}&expand=transitions`,headers:m(t.token||this.config.token)})).body.issues.map(Ot)}}async setIssueStatus(r,t={}){let{resourceId:s,issueId:n,status:o}=r,a={transition:{id:o}};await this.config.request({method:"POST",url:`${t.baseUrl||H}/${s}/rest/api/2/issue/${n}/transitions`,body:JSON.stringify(a),headers:{...m(t.token||this.config.token),"Content-Type":"application/json"}})}async getLabelsForResource(r,t={}){let{resourceId:s,cursor:n}=r,o=new URL(`${t.baseUrl||H}/${s}/rest/api/2/label`);o.searchParams.set("maxResults",Ae.toString()),n&&o.searchParams.set("startAt",n);let a=await this.config.request({url:o.toString(),headers:m(t.token||this.config.token)});return{pageInfo:{hasNextPage:!a.body.isLast,endCursor:(a.body.startAt+a.body.values.length).toString()},data:a.body.values.map(i=>({color:null,description:null,id:null,name:i}))}}};var Q="https://api.trello.com",_t=1e3,Nt=(e,r)=>{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(s=>({id:s,username:null,name:null,email:null,avatarUrl:null})),description:null,state:r[e.idList??""]?{name:r[e.idList].name,color:null}:null,type:null,repository:null,upvoteCount:e.badges.votes,labels:e.labels.map(s=>({color:s.color,description:null,id:s.id,name:s.name}))}},V=class extends ${async getCurrentUser(r,t={}){let s=await this.config.request({url:`${t.baseUrl||Q}/1/members/me?key=${r.appKey}&token=${t.token||this.config.token}`,headers:m(t.token||this.config.token)});return{data:{name:s.body.fullName,email:s.body.email,avatarUrl:s.body.avatarHash?`https://trello-members.s3.amazonaws.com/${s.body.id}/${s.body.avatarHash}/50.png`:null,id:s.body.id,username:s.body.username}}}async getBoardsForCurrentUser(r,t={}){return{data:(await this.config.request({url:`${t.baseUrl||Q}/1/members/me/boards?fields=name&key=${r.appKey}&token=${t.token||this.config.token}&filter=open`,headers:m(t.token||this.config.token)})).body.map(n=>({id:n.id,name:n.name}))}}async getListsForTrelloBoard(r,t={}){let{appKey:s,boardId:n}=r;return{data:(await this.config.request({url:`${t.baseUrl||Q}/1/boards/${n}/lists?key=${s}&token=${t.token||this.config.token}`,headers:m(t.token||this.config.token)})).body}}async getIssuesForBoard(r,t={}){let s=["-is:archived","sort:edited"],{appKey:n,boardId:o,filterText:a,assigneeLogins:i,trelloBoardListsById:u}=r||{};i&&s.push("@me");let l=`${a?`${a}`:""}${s.join(" ")} board:${o}`;return{data:(await this.config.request({url:`${t.baseUrl||Q}/1/search?key=${n}&query=${l}&cards_limit=${_t}&token=${t.token||this.config.token}`,headers:m(t.token||this.config.token)})).body.cards.map(d=>Nt(d,u||{}))}}async setIssueStatus(r,t={}){let{appKey:s,cardId:n,status:o}=r;if(!(await this.config.request({method:"PUT",url:`${t.baseUrl||Q}/1/cards/${n}?key=${s}&token=${t.token||this.config.token}&idList=${o}`,headers:m(t.token||this.config.token)})).body.id)throw new Error("Could not set issue status")}async getLabelsForBoard(r,t={}){let{appKey:s,boardId:n}=r;return{data:(await this.config.request({url:`${t.baseUrl||Q}/1/boards/${n}/labels?key=${s}&token=${t.token||this.config.token}`,headers:m(t.token||this.config.token)})).body.map(a=>({color:a.color,description:null,id:a.id,name:a.name}))}}};var te={};x(te,{getIssueUniqueId:()=>Qt,getPullRequestUniqueId:()=>Bt});var Qt=(e,r,t,s="")=>{let n=[];return n.push(s),n.push(e),n.push(r),n.push(t),JSON.stringify(n)},Bt=(e,r,t,s,n="")=>{let o=[];return o.push(n),o.push(e),o.push(r),o.push(t),o.push(s),JSON.stringify(o)};var re={};x(re,{getIssueUniqueId:()=>jt,getPullRequestUniqueId:()=>Ft});var jt=(e,r)=>JSON.stringify(["",e,r]),Ft=(e,r)=>JSON.stringify(["",e,r]);var se={};x(se,{getIssueUniqueId:()=>Mt,getPullRequestUniqueId:()=>zt});var Mt=(e,r,t)=>JSON.stringify([t,e,r]),zt=(e,r,t)=>JSON.stringify([t,e,r]);var ne={};x(ne,{getIssueUniqueId:()=>Wt,getPullRequestRank:()=>Jt,getPullRequestUniqueId:()=>Ht});var Wt=(e,r="")=>{let t=[];return t.push(r),t.push(e),JSON.stringify(t)},Ht=(e,r="")=>{let t=[];return t.push(r),t.push(e),JSON.stringify(t)},Jt=(e,r,t)=>{var a,i,u;let s=0,n,o;return(a=e.reviews)==null||a.forEach(l=>{l.reviewer.id===r&&(n=l.state),l.state==="CHANGES_REQUESTED"?o="CHANGES_REQUESTED":l.state==="APPROVED"&&o!=="CHANGES_REQUESTED"&&(o="APPROVED")}),o||(o="REVIEW_REQUESTED"),((i=e.author)==null?void 0:i.id)===r?s+=1e3:(u=e.assignees)!=null&&u.find(l=>l.id===r)?s+=900:n==="REVIEW_REQUESTED"?s+=800:t&&(s+=700),o==="APPROVED"?e.mergeableState==="MERGEABLE"?s+=100:e.mergeableState==="CONFLICTS"?s+=90:s+=80:o=="CHANGES_REQUESTED"&&(s+=70),s};var ae={};x(ae,{getIssueUniqueId:()=>Vt,getPullRequestUniqueId:()=>Kt});var Vt=(e,r="")=>{let t=[];return t.push(r),t.push(e),JSON.stringify(t)},Kt=(e,r="")=>{let t=[];return t.push(r),t.push(e),JSON.stringify(t)};var oe={};x(oe,{getIssueUniqueId:()=>Xt,getJiraServerIssueUniqueId:()=>Zt});var Xt=(e,r,t)=>{let s=[];return s.push(""),s.push(e),s.push(r),s.push(t),JSON.stringify(s)},Zt=(e,r,t)=>{let s=[];return s.push(t),s.push(""),s.push(e),s.push(r),JSON.stringify(s)};var ie={};x(ie,{getIssueUniqueId:()=>Yt});var Yt=(e,r,t,s="")=>{let n=[];return n.push(s),n.push(e),n.push(r),n.push(t),JSON.stringify(n)};var er=e=>{let r={request:e==null?void 0:e.request};return{azureDevOps:new B({...r,...e==null?void 0:e.azureDevOps}),bitbucket:new j({...r,...e==null?void 0:e.bitbucket}),bitbucketServer:new F({...r,...e==null?void 0:e.bitbucketServer}),github:new M({...r,...e==null?void 0:e.github}),gitlab:new W({...r,...e==null?void 0:e.gitlab}),jira:new J({...r,...e==null?void 0:e.jira}),trello:new V({...r,...e==null?void 0:e.trello})}},tr=er;var rr={azureDevOps:te,bitbucket:re,bitbucketServer:se,github:ne,gitlab:ae,jira:oe,trello:ie};
|
|
881
|
+
`,variables:{fullPath:`${s}/${n}`,after:o}},t);return{pageInfo:((l=(u=(i=a.body.data)==null?void 0:i.project)==null?void 0:u.labels)==null?void 0:l.pageInfo)??{endCursor:null,hasNextPage:!1},data:((g=(c=(d=(p=a.body.data)==null?void 0:p.project)==null?void 0:d.labels)==null?void 0:c.nodes)==null?void 0:g.map(Ae))??[]}}};var j="https://api.atlassian.com/ex/jira",te=100,kt=(e,r)=>{var s,n,o,a,i,u;let t=e.fields.assignee;return{id:e.id,commentCount:e.fields.comment.comments.length,number:e.key,title:e.fields.summary,url:r?`${r}/browse/${e.key}`:null,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:{name:(s=e.fields.status)==null?void 0:s.name,color:(o=(n=e.fields.status)==null?void 0:n.statusCategory)==null?void 0:o.colorName},statusTransitions:((a=e.transitions)==null?void 0:a.map(_t))??[],type:e.fields.issuetype.name,upvoteCount:((i=e.fields.votes)==null?void 0:i.votes)||0,labels:((u=e.fields.labels)==null?void 0:u.map(l=>({color:null,description:null,id:null,name:l})))??[]}},_t=e=>({name:e.name,id:e.id}),Nt=e=>({id:e.accountId,name:e.displayName,email:e.emailAddress,avatarUrl:e.avatarUrls["48x48"],username:e.displayName}),J=class extends v{constructor(){super(...arguments);this._resourceUrlCache={}}async getResourceUrl(t,s={}){var a;let n=s.token||this.config.token;if(!n)return null;let o=this._resourceUrlCache[n];return o?o[t.resourceId]??null:(await this.getJiraResourcesForCurrentUser(s),((a=this._resourceUrlCache[n])==null?void 0:a[t.resourceId])??null)}async getCurrentUserForResource(t,s={}){let n=await this.config.request({url:`${s.baseUrl||j}/${t.resourceId}/rest/api/2/myself`,headers:m(s.token||this.config.token)});return{data:{name:n.body.displayName,email:n.body.emailAddress,avatarUrl:n.body.avatarUrls["48x48"],id:n.body.accountId,username:n.body.displayName}}}async getJiraResourcesForCurrentUser(t={}){let s=await this.config.request({url:`${t.baseUrl||"https://api.atlassian.com/"}/oauth/token/accessible-resources`,headers:m(t.token||this.config.token)}),n=t.token||this.config.token,o=n?this._resourceUrlCache[n]||{}:void 0,a=s.body.map(i=>(o&&(o[i.id]=i.url),{avatarUrl:i.avatarUrl,id:i.id,name:i.name,url:i.url}));return n&&(this._resourceUrlCache[n]=o),{data:a}}async getJiraProjectsForResource(t,s={}){let n=new URL(`${s.baseUrl||j}/${t.resourceId}/rest/api/2/project/search`);n.searchParams.set("maxResults",te.toString()),t.cursor&&n.searchParams.set("startAt",t.cursor);let o=await this.config.request({url:n.toString(),headers:m(s.token||this.config.token)});return{pageInfo:{hasNextPage:o.body.values.length!==0,endCursor:(o.body.startAt+o.body.values.length).toString()},data:o.body.values.map(a=>({id:a.id,key:a.key,name:a.name,resourceId:t.resourceId}))}}async getJiraProjectsForResources(t,s={}){let n=[];return await Promise.all(t.resourceIds.map(async o=>{let a=await this.getJiraProjectsForResource({resourceId:o},s);n.push(...a.data)})),{data:n}}async getAccountsForJiraProject(t,s={}){let{resourceId:n,projectKey:o,cursor:a}=t,i=new URL(`${s.baseUrl||j}/${n}/rest/api/2/user/assignable/search`);i.searchParams.set("maxResults",te.toString()),a&&i.searchParams.set("startAt",a),i.searchParams.set("project",o);let u=await this.config.request({url:i.toString(),headers:m(s.token||this.config.token)});return{pageInfo:{hasNextPage:u.body.length!==0,endCursor:((a?parseInt(a):0)+u.body.length).toString()},data:u.body.filter(l=>l.accountType!=="app"&&l.active).map(Nt)}}async getIssuesForProject(t,s={}){let{assigneeLogins:n,authorLogin:o,mentionLogin:a,project:i}=t||{},u=[`project = "${i}"`];o&&u.push(`creator in ("${o}")`),n&&n.length!==0&&u.push(`assignee in ("${n.join('", "')}")`),a&&u.push(`comment ~ "${a}"`);let l=await this.config.request({url:`${s.baseUrl||j}/${t.resourceId}/rest/api/2/search?jql=${u.join(" AND ")}&startAt=0&maxResults=${te}&fields=${["assignee","comment","summary","created","creator","updated","votes","issuetype","status","labels"].join(",")}&expand=transitions`,headers:m(s.token||this.config.token)}),p=await this.getResourceUrl({resourceId:t.resourceId},s);return{data:l.body.issues.map(d=>kt(d,p))}}async setIssueStatus(t,s={}){let{resourceId:n,issueId:o,status:a}=t,i={transition:{id:a}};await this.config.request({method:"POST",url:`${s.baseUrl||j}/${n}/rest/api/2/issue/${o}/transitions`,body:JSON.stringify(i),headers:{...m(s.token||this.config.token),"Content-Type":"application/json"}})}async getLabelsForResource(t,s={}){let{resourceId:n,cursor:o}=t,a=new URL(`${s.baseUrl||j}/${n}/rest/api/2/label`);a.searchParams.set("maxResults",te.toString()),o&&a.searchParams.set("startAt",o);let i=await this.config.request({url:a.toString(),headers:m(s.token||this.config.token)});return{pageInfo:{hasNextPage:!i.body.isLast,endCursor:(i.body.startAt+i.body.values.length).toString()},data:i.body.values.map(u=>({color:null,description:null,id:null,name:u}))}}};var N="https://api.trello.com",Qt=1e3,jt=(e,r)=>{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(s=>({id:s,username:null,name:null,email:null,avatarUrl:null})),description:null,state:r[e.idList??""]?{name:r[e.idList].name,color:null}:null,type:null,repository:null,upvoteCount:e.badges.votes,labels:e.labels.map(s=>({color:s.color,description:null,id:s.id,name:s.name}))}},V=class extends v{async getCurrentUser(r,t={}){let s=await this.config.request({url:`${t.baseUrl||N}/1/members/me?key=${r.appKey}&token=${t.token||this.config.token}`,headers:m(t.token||this.config.token)});return{data:{name:s.body.fullName,email:s.body.email,avatarUrl:s.body.avatarHash?`https://trello-members.s3.amazonaws.com/${s.body.id}/${s.body.avatarHash}/50.png`:null,id:s.body.id,username:s.body.username}}}async getBoardsForCurrentUser(r,t={}){return{data:(await this.config.request({url:`${t.baseUrl||N}/1/members/me/boards?fields=name&key=${r.appKey}&token=${t.token||this.config.token}&filter=open`,headers:m(t.token||this.config.token)})).body.map(n=>({id:n.id,name:n.name}))}}async getListsForTrelloBoard(r,t={}){let{appKey:s,boardId:n}=r;return{data:(await this.config.request({url:`${t.baseUrl||N}/1/boards/${n}/lists?key=${s}&token=${t.token||this.config.token}`,headers:m(t.token||this.config.token)})).body}}async getAccountsForTrelloBoard(r,t={}){let{appKey:s,boardId:n}=r;return{data:(await this.config.request({url:`${t.baseUrl||N}/1/boards/${n}/members?key=${s}&token=${t.token||this.config.token}`,headers:m(t.token||this.config.token)})).body.map(a=>({id:a.id,name:a.fullName,username:a.username,email:null,avatarUrl:null}))}}async getIssuesForBoard(r,t={}){let s=["-is:archived","sort:edited"],{appKey:n,boardId:o,filterText:a,assigneeLogins:i,trelloBoardListsById:u}=r||{};i&&s.push("@me");let l=`${a?`${a}`:""}${s.join(" ")} board:${o}`;return{data:(await this.config.request({url:`${t.baseUrl||N}/1/search?key=${n}&query=${l}&cards_limit=${Qt}&token=${t.token||this.config.token}`,headers:m(t.token||this.config.token)})).body.cards.map(d=>jt(d,u||{}))}}async setIssueStatus(r,t={}){let{appKey:s,cardId:n,status:o}=r;if(!(await this.config.request({method:"PUT",url:`${t.baseUrl||N}/1/cards/${n}?key=${s}&token=${t.token||this.config.token}&idList=${o}`,headers:m(t.token||this.config.token)})).body.id)throw new Error("Could not set issue status")}async getLabelsForBoard(r,t={}){let{appKey:s,boardId:n}=r;return{data:(await this.config.request({url:`${t.baseUrl||N}/1/boards/${n}/labels?key=${s}&token=${t.token||this.config.token}`,headers:m(t.token||this.config.token)})).body.map(a=>({color:a.color,description:null,id:a.id,name:a.name}))}}};var re={};A(re,{getIssueUniqueId:()=>Bt,getPullRequestUniqueId:()=>Ft});var Bt=(e,r,t,s="")=>{let n=[];return n.push(s),n.push(e),n.push(r),n.push(t),JSON.stringify(n)},Ft=(e,r,t,s,n="")=>{let o=[];return o.push(n),o.push(e),o.push(r),o.push(t),o.push(s),JSON.stringify(o)};var se={};A(se,{getIssueUniqueId:()=>Mt,getPullRequestUniqueId:()=>zt});var Mt=(e,r)=>JSON.stringify(["",e,r]),zt=(e,r)=>JSON.stringify(["",e,r]);var ne={};A(ne,{getIssueUniqueId:()=>Wt,getPullRequestUniqueId:()=>Ht});var Wt=(e,r,t)=>JSON.stringify([t,e,r]),Ht=(e,r,t)=>JSON.stringify([t,e,r]);var ae={};A(ae,{getIssueUniqueId:()=>Jt,getPullRequestRank:()=>Kt,getPullRequestUniqueId:()=>Vt});var Jt=(e,r="")=>{let t=[];return t.push(r),t.push(e),JSON.stringify(t)},Vt=(e,r="")=>{let t=[];return t.push(r),t.push(e),JSON.stringify(t)},Kt=(e,r,t)=>{var a,i,u;let s=0,n,o;return(a=e.reviews)==null||a.forEach(l=>{l.reviewer.id===r&&(n=l.state),l.state==="CHANGES_REQUESTED"?o="CHANGES_REQUESTED":l.state==="APPROVED"&&o!=="CHANGES_REQUESTED"&&(o="APPROVED")}),o||(o="REVIEW_REQUESTED"),((i=e.author)==null?void 0:i.id)===r?s+=1e3:(u=e.assignees)!=null&&u.find(l=>l.id===r)?s+=900:n==="REVIEW_REQUESTED"?s+=800:t&&(s+=700),o==="APPROVED"?e.mergeableState==="MERGEABLE"?s+=100:e.mergeableState==="CONFLICTS"?s+=90:s+=80:o=="CHANGES_REQUESTED"&&(s+=70),s};var oe={};A(oe,{getIssueUniqueId:()=>Xt,getPullRequestUniqueId:()=>Zt});var Xt=(e,r="")=>{let t=[];return t.push(r),t.push(e),JSON.stringify(t)},Zt=(e,r="")=>{let t=[];return t.push(r),t.push(e),JSON.stringify(t)};var ie={};A(ie,{getIssueUniqueId:()=>Yt,getJiraServerIssueUniqueId:()=>er});var Yt=(e,r,t)=>{let s=[];return s.push(""),s.push(e),s.push(r),s.push(t),JSON.stringify(s)},er=(e,r,t)=>{let s=[];return s.push(t),s.push(""),s.push(e),s.push(r),JSON.stringify(s)};var ue={};A(ue,{getIssueUniqueId:()=>tr});var tr=(e,r,t,s="")=>{let n=[];return n.push(s),n.push(e),n.push(r),n.push(t),JSON.stringify(n)};var rr=e=>{let r={request:e==null?void 0:e.request};return{azureDevOps:new B({...r,...e==null?void 0:e.azureDevOps}),bitbucket:new F({...r,...e==null?void 0:e.bitbucket}),bitbucketServer:new M({...r,...e==null?void 0:e.bitbucketServer}),github:new z({...r,...e==null?void 0:e.github}),gitlab:new H({...r,...e==null?void 0:e.gitlab}),jira:new J({...r,...e==null?void 0:e.jira}),trello:new V({...r,...e==null?void 0:e.trello})}},sr=rr;var nr={azureDevOps:re,bitbucket:se,bitbucketServer:ne,github:ae,gitlab:oe,jira:ie,trello:ue};
|
|
@@ -64,6 +64,26 @@ export declare class AzureDevOps extends Provider implements GitProvider {
|
|
|
64
64
|
getAzureProjects(input: {
|
|
65
65
|
namespace: string;
|
|
66
66
|
} & CursorPageInput, options?: Options): Promise<PagedResult<AzureProject>>;
|
|
67
|
+
getAzureProjectScopeDescriptor(input: {
|
|
68
|
+
namespace: string;
|
|
69
|
+
projectId: string;
|
|
70
|
+
}, options?: Options): Promise<{
|
|
71
|
+
data: {
|
|
72
|
+
scope: string;
|
|
73
|
+
};
|
|
74
|
+
}>;
|
|
75
|
+
getAccountsForAzureProject(input: {
|
|
76
|
+
namespace: string;
|
|
77
|
+
projectScopeDescriptor?: string;
|
|
78
|
+
}, options?: Options): Promise<{
|
|
79
|
+
data: {
|
|
80
|
+
id: string;
|
|
81
|
+
name: string;
|
|
82
|
+
username: string;
|
|
83
|
+
email: string;
|
|
84
|
+
avatarUrl: string | undefined;
|
|
85
|
+
}[];
|
|
86
|
+
}>;
|
|
67
87
|
getRepo(input: AzureGetRepoInput, options?: Options): Promise<{
|
|
68
88
|
data: GitRepository;
|
|
69
89
|
}>;
|
|
@@ -9,6 +9,15 @@ export declare class GitHub extends EnterpriseProvider implements GitProvider {
|
|
|
9
9
|
getCurrentUser(options?: EnterpriseOptions): Promise<{
|
|
10
10
|
data: Account;
|
|
11
11
|
}>;
|
|
12
|
+
getAccountsForRepo(input: {
|
|
13
|
+
repo: GetRepoInput;
|
|
14
|
+
} & CursorPageInput, options?: EnterpriseOptions): Promise<{
|
|
15
|
+
pageInfo: {
|
|
16
|
+
endCursor: string | null;
|
|
17
|
+
hasNextPage: boolean;
|
|
18
|
+
};
|
|
19
|
+
data: Account[];
|
|
20
|
+
}>;
|
|
12
21
|
getUserForCommit(input: {
|
|
13
22
|
repo: GetRepoInput;
|
|
14
23
|
oid: string;
|
|
@@ -166,7 +175,7 @@ export declare class GitHub extends EnterpriseProvider implements GitProvider {
|
|
|
166
175
|
} & CursorPageInput, options?: EnterpriseOptions): Promise<{
|
|
167
176
|
pageInfo: {
|
|
168
177
|
hasNextPage: boolean;
|
|
169
|
-
endCursor: string;
|
|
178
|
+
endCursor: string | null;
|
|
170
179
|
};
|
|
171
180
|
data: GitPullRequest[];
|
|
172
181
|
}>;
|
|
@@ -27,6 +27,15 @@ export declare class GitLab extends EnterpriseProvider implements GitProvider, I
|
|
|
27
27
|
}, options?: EnterpriseOptions): Promise<{
|
|
28
28
|
data: Account;
|
|
29
29
|
}>;
|
|
30
|
+
getAccountsForRepo(input: {
|
|
31
|
+
repo: GetRepoInput;
|
|
32
|
+
} & CursorPageInput, options?: EnterpriseOptions): Promise<{
|
|
33
|
+
pageInfo: {
|
|
34
|
+
endCursor: string | null;
|
|
35
|
+
hasNextPage: boolean;
|
|
36
|
+
};
|
|
37
|
+
data: Account[];
|
|
38
|
+
}>;
|
|
30
39
|
getRepo(input: GetRepoInput, options?: EnterpriseOptions): Promise<{
|
|
31
40
|
data: GitRepository;
|
|
32
41
|
}>;
|
|
@@ -5,14 +5,18 @@ import { Provider } from '../provider';
|
|
|
5
5
|
export interface JiraResource {
|
|
6
6
|
id: string;
|
|
7
7
|
name: string;
|
|
8
|
+
url: string;
|
|
8
9
|
avatarUrl: string;
|
|
9
10
|
}
|
|
10
11
|
export interface JiraProject {
|
|
11
12
|
id: string;
|
|
13
|
+
key: string;
|
|
12
14
|
name: string;
|
|
13
15
|
resourceId: string;
|
|
14
16
|
}
|
|
15
17
|
export declare class Jira extends Provider {
|
|
18
|
+
private _resourceUrlCache;
|
|
19
|
+
private getResourceUrl;
|
|
16
20
|
getCurrentUserForResource(input: {
|
|
17
21
|
resourceId: string;
|
|
18
22
|
}, options?: EnterpriseOptions): Promise<{
|
|
@@ -34,6 +38,7 @@ export declare class Jira extends Provider {
|
|
|
34
38
|
};
|
|
35
39
|
data: {
|
|
36
40
|
id: string;
|
|
41
|
+
key: string;
|
|
37
42
|
name: string;
|
|
38
43
|
resourceId: string;
|
|
39
44
|
}[];
|
|
@@ -41,6 +46,22 @@ export declare class Jira extends Provider {
|
|
|
41
46
|
getJiraProjectsForResources(input: {
|
|
42
47
|
resourceIds: string[];
|
|
43
48
|
}, options?: EnterpriseOptions): Promise<Result<JiraProject[]>>;
|
|
49
|
+
getAccountsForJiraProject(input: {
|
|
50
|
+
resourceId: string;
|
|
51
|
+
projectKey: string;
|
|
52
|
+
} & CursorPageInput, options?: EnterpriseOptions): Promise<{
|
|
53
|
+
pageInfo: {
|
|
54
|
+
hasNextPage: boolean;
|
|
55
|
+
endCursor: string;
|
|
56
|
+
};
|
|
57
|
+
data: {
|
|
58
|
+
id: string;
|
|
59
|
+
name: string;
|
|
60
|
+
email: string;
|
|
61
|
+
avatarUrl: string;
|
|
62
|
+
username: string;
|
|
63
|
+
}[];
|
|
64
|
+
}>;
|
|
44
65
|
getIssuesForProject(input: {
|
|
45
66
|
project: string;
|
|
46
67
|
resourceId: string;
|
|
@@ -45,6 +45,18 @@ export declare class Trello extends Provider {
|
|
|
45
45
|
}, options?: EnterpriseOptions): Promise<{
|
|
46
46
|
data: TrelloList[];
|
|
47
47
|
}>;
|
|
48
|
+
getAccountsForTrelloBoard(input: {
|
|
49
|
+
appKey: string;
|
|
50
|
+
boardId: string;
|
|
51
|
+
}, options?: EnterpriseOptions): Promise<{
|
|
52
|
+
data: {
|
|
53
|
+
id: string;
|
|
54
|
+
name: string;
|
|
55
|
+
username: string;
|
|
56
|
+
email: null;
|
|
57
|
+
avatarUrl: null;
|
|
58
|
+
}[];
|
|
59
|
+
}>;
|
|
48
60
|
getIssuesForBoard(input: {
|
|
49
61
|
appKey: string;
|
|
50
62
|
boardId: string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gitkraken/provider-apis",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.13.0",
|
|
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",
|
|
@@ -29,6 +29,7 @@
|
|
|
29
29
|
"watch": "yarn clean && node ./scripts/build.mjs --watch & tsc -w"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
+
"js-base64": "3.7.5",
|
|
32
33
|
"node-fetch": "2.7.0"
|
|
33
34
|
},
|
|
34
35
|
"devDependencies": {
|