@gitkraken/provider-apis 0.13.0 → 0.13.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -0
- package/dist/index.js +65 -52
- package/dist/providers/azureDevops/azureDevOps.d.ts +7 -1
- package/dist/providers/azureDevops/azureDevOpsTypes.d.ts +8 -0
- package/dist/providers/github/github.d.ts +4 -0
- package/dist/providers/gitlab/gitlab.d.ts +5 -0
- package/dist/providers/trello/trello.d.ts +5 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.13.2
|
|
4
|
+
|
|
5
|
+
- added `setPullRequestAssignees` (GitHub and GitLab)
|
|
6
|
+
- added `setIssueArchived` (Trello)
|
|
7
|
+
- updated `getIssuesForProject` to only return open issues (Jira)
|
|
8
|
+
|
|
9
|
+
## 0.13.1
|
|
10
|
+
|
|
11
|
+
- added `getAzurePullRequestLastMergeStatus` (Azure DevOps)
|
|
12
|
+
- fixed a bug in `getIssuesAssociatedWithUser` (GitHub)
|
|
13
|
+
- fixed a bug in `getPullRequestsAssociatedWithUser` (GitLab)
|
|
14
|
+
|
|
3
15
|
## 0.13.0
|
|
4
16
|
|
|
5
17
|
- added `getAccountsForRepo` (GitHub, GitLab)
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
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=`
|
|
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})},Te=(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)):{},Te(r||!e||!e.__esModule?K(t,"default",{value:e,enumerable:!0}):t,e)),ot=e=>Te(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 U=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}}},O=class extends U{};var m=(e,r)=>{let t={};return e&&(t.Authorization=`${r?"Basic":"Bearer"} ${e}`),t};var y=(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",C="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 U{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:y(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:`${C}/${encodeURIComponent(r.namespace)}/_apis/ConnectionData`,headers:y(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:`${C}/${encodeURIComponent(r.repo.namespace)}/${encodeURIComponent(r.repo.project)}/_apis/git/repositories/${encodeURIComponent(r.repo.name)}/commits/${r.oid}`,headers:y(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:y(this.config,t)})).body.value.map(n=>({id:n.accountId,name:n.accountName}))}}async getAzureProjects(r,t={}){let s=new URL(`${C}/${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:y(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:y(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:y(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:`${C}/${encodeURIComponent(r.namespace)}/${encodeURIComponent(r.project)}/_apis/git/repositories/${encodeURIComponent(r.name)}`,headers:y(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:`${C}/${encodeURIComponent(r.namespace)}/${encodeURIComponent(r.project)}/_apis/git/repositories`,headers:y(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(`${C}/${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:y(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||C}/${encodeURIComponent(o.namespace)}/${encodeURIComponent(o.project||"")}/_apis/git/repositories/${encodeURIComponent(o.name)}/pullRequests?${l}&%24top=${s}&%24skip=${(u-1)*s}`,headers:y(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 getAzurePullRequestLastMergeStatus(r,t={}){if(!r.repo.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let{repo:{namespace:s,project:n,name:o},pullRequestId:a}=r,i=await this.config.request({url:`${t.baseUrl||C}/${encodeURIComponent(s)}/${encodeURIComponent(n||"")}/_apis/git/repositories/${o}/pullrequests/${a}?includeCommits=true?api-version=6.0`,headers:{...y(this.config,t)}});if(!i.body.mergeStatus)throw new Error("Could not fetch pull request");return{data:i.body.mergeStatus}}async updatePullRequest(r,t,s,n){let{namespace:o,project:a,name:i}=r;return await this.config.request({method:"PATCH",url:`${n.baseUrl||C}/${encodeURIComponent(o)}/${encodeURIComponent(a||"")}/_apis/git/repositories/${i}/pullrequests/${t}?api-version=6.0`,body:s,headers:{...y(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||C}/${encodeURIComponent(r.namespace)}/${encodeURIComponent(r.project)}/_apis/wit/wiql?api-version=6.0`,body:JSON.stringify({query:d}),method:"POST",headers:{...y(this.config,t),"Content-Type":"application/json"}}),g=c.body.workItems.slice((u-1)*l,l*u).map(R=>R.id);if(g.length==0)return{pageInfo:{hasNextPage:!1,nextPage:null},data:[]};let I=await this.config.request({url:`${t.baseUrl||C}/${encodeURIComponent(r.namespace)}/${encodeURIComponent(r.project)}/_apis/wit/workitemsbatch?api-version=6.0`,body:JSON.stringify({ids:g,$expand:"Links"}),method:"POST",headers:{...y(this.config,t),"Content-Type":"application/json"}});return{pageInfo:{hasNextPage:c.body.workItems.length>l*u,nextPage:u+1},data:I.body.value.map(R=>pt(R,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||C}/${encodeURIComponent(s)}/${encodeURIComponent(n||"")}/_apis/wit/workitems/${o}?api-version=6.0`,body:JSON.stringify(i),headers:{...y(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||C}/${encodeURIComponent(s)}/${encodeURIComponent(n||"")}/_apis/wit/workitemtypes?api-version=6.0`,headers:{...y(this.config,t)}})).body.value}}async getLabelsForProject(r,t={}){let{namespace:s,project:n}=r;return{data:(await this.config.request({url:`${t.baseUrl||C}/${encodeURIComponent(s)}/${encodeURIComponent(n||"")}/_apis/wit/tags?api-version=6.0`,headers:{...y(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",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 U{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: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: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: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: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(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: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(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: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(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: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 M=class extends O{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
|
|
@@ -11,7 +11,7 @@ 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.")},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},
|
|
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},k=e=>e.some(r=>ht[r]),E=(e=!1,r=!1)=>`
|
|
15
15
|
__typename
|
|
16
16
|
id
|
|
17
17
|
databaseId
|
|
@@ -33,7 +33,7 @@ title
|
|
|
33
33
|
state
|
|
34
34
|
author {
|
|
35
35
|
... on User {
|
|
36
|
-
${
|
|
36
|
+
${E(!1,r)}
|
|
37
37
|
}
|
|
38
38
|
... on Bot {
|
|
39
39
|
${Je(!1)}
|
|
@@ -96,7 +96,7 @@ updatedAt
|
|
|
96
96
|
closedAt
|
|
97
97
|
assignees(first: 100) {
|
|
98
98
|
nodes {
|
|
99
|
-
${
|
|
99
|
+
${E(!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
|
+
${E(!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
|
+
${E(!1,r)}
|
|
117
117
|
}
|
|
118
118
|
}
|
|
119
119
|
state
|
|
@@ -137,7 +137,7 @@ databaseId
|
|
|
137
137
|
title
|
|
138
138
|
author {
|
|
139
139
|
... on User {
|
|
140
|
-
${
|
|
140
|
+
${E(!1,e)}
|
|
141
141
|
}
|
|
142
142
|
... on Bot {
|
|
143
143
|
${Je(!1)}
|
|
@@ -161,7 +161,7 @@ comments {
|
|
|
161
161
|
}
|
|
162
162
|
assignees(first: 100) {
|
|
163
163
|
nodes {
|
|
164
|
-
${
|
|
164
|
+
${E(!1,e)}
|
|
165
165
|
}
|
|
166
166
|
}
|
|
167
167
|
state
|
|
@@ -199,10 +199,10 @@ defaultBranchRef {
|
|
|
199
199
|
name
|
|
200
200
|
}
|
|
201
201
|
viewerPermission
|
|
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})
|
|
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}),$t=e=>{var l,p,d,c,g,I,R,w,P,b,$,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(q=>!q.asCodeOwner),u=(R=e.headRepository)==null?void 0:R.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:((P=e.baseRef.target)==null?void 0:P.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(q=>({reviewer:G(q.requestedReviewer),state:"REVIEW_REQUESTED"})).concat((((b=e.latestReviews)==null?void 0:b.nodes)||[]).map(q=>{let le=q.author||Pe;return{reviewer:G(le),state:Pt[q.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=($=e.labels)==null?void 0:$.nodes)==null?void 0:L.map(we))??[]}},qt=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 O{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
|
+
${E(!1,k(s))}
|
|
206
206
|
}
|
|
207
207
|
}
|
|
208
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:`
|
|
@@ -210,7 +210,7 @@ query getAccountsForRepo($owner: String!, $name: String! $cursor: String, $first
|
|
|
210
210
|
repository(owner: $owner, name: $name) {
|
|
211
211
|
assignableUsers(first: $first, after: $cursor) {
|
|
212
212
|
nodes {
|
|
213
|
-
${
|
|
213
|
+
${E(!1,k(n))}
|
|
214
214
|
}
|
|
215
215
|
pageInfo {
|
|
216
216
|
endCursor
|
|
@@ -243,7 +243,7 @@ query getAccountForEmail($query: String! $avatarSize: Int) {
|
|
|
243
243
|
search(query: $query, type: USER, first: 1) {
|
|
244
244
|
nodes {
|
|
245
245
|
... on User {
|
|
246
|
-
${
|
|
246
|
+
${E(!0,k(n))}
|
|
247
247
|
}
|
|
248
248
|
}
|
|
249
249
|
}
|
|
@@ -251,7 +251,7 @@ query getAccountForEmail($query: String! $avatarSize: Int) {
|
|
|
251
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:`
|
|
252
252
|
query getUserForUsername($login: String! $avatarSize: Int) {
|
|
253
253
|
user(login: $login) {
|
|
254
|
-
${
|
|
254
|
+
${E(!0,k(n))}
|
|
255
255
|
}
|
|
256
256
|
}
|
|
257
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:`
|
|
@@ -362,7 +362,7 @@ query getBlame($owner: String!, $name: String!, $ref: String!, $path: String!) {
|
|
|
362
362
|
}
|
|
363
363
|
}
|
|
364
364
|
}
|
|
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=
|
|
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=k(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($t))||[]}}async searchIssues(t,s={}){var u,l;let n=await this.getScopes(s),o=k(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(qt))||[]}}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!) {
|
|
366
366
|
closePullRequest(input: { pullRequestId: $pullRequestGraphQLId }) {
|
|
367
367
|
pullRequest {
|
|
368
368
|
id
|
|
@@ -400,7 +400,13 @@ query getBlame($owner: String!, $name: String!, $ref: String!, $path: String!) {
|
|
|
400
400
|
id
|
|
401
401
|
}
|
|
402
402
|
}
|
|
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
|
|
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 setPullRequestAssignees(t,s={}){var u,l,p;let{pullRequestGraphQLId:n,assigneeGraphQLIds:o}=t,a=`mutation SetPullRequestAssignees($pullRequestGraphQLId: ID!, $assigneeGraphQLIds: [ID!]!) {
|
|
404
|
+
updatePullRequest(input: { pullRequestId: $pullRequestGraphQLId, assigneeIds: $assigneeGraphQLIds }) {
|
|
405
|
+
pullRequest {
|
|
406
|
+
id
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
}`;if(!((p=(l=(u=(await h(this.config,{query:a,variables:{pullRequestGraphQLId:n,assigneeGraphQLIds:o}},s)).body.data)==null?void 0:u.updatePullRequest)==null?void 0:l.pullRequest)!=null&&p.id))throw new Error("Could not set pull request assignees")}async getIssuesAssociatedWithUser(t,s={}){var d;let[n,o]=((d=t.cursor)==null?void 0:d.split(";"))||[void 0,void 0],[a,i]=await Promise.all([n==="null"?null:this.searchIssues({query:`author:${t.username}`,cursor:n},s),o==="null"?null: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==null||a.data.forEach(p),i==null||i.data.forEach(p),{pageInfo:{hasNextPage:(a==null?void 0:a.pageInfo.hasNextPage)||(i==null?void 0:i.pageInfo.hasNextPage)||!1,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!) {
|
|
404
410
|
closeIssue(input: { issueId: $issueGraphQLId, stateReason: $closeReason }) {
|
|
405
411
|
issue {
|
|
406
412
|
id
|
|
@@ -452,7 +458,7 @@ query getLabelsForRepo($owner: String!, $name: String! $cursor: String, $first:
|
|
|
452
458
|
}
|
|
453
459
|
}
|
|
454
460
|
}
|
|
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
|
|
461
|
+
`,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 Ut="https://gitlab.com/api/v4",vt="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):Ut},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`):vt},f=(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}),Et={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=`
|
|
456
462
|
description
|
|
457
463
|
dueDate
|
|
458
464
|
id
|
|
@@ -461,7 +467,7 @@ startDate
|
|
|
461
467
|
state
|
|
462
468
|
title
|
|
463
469
|
webPath
|
|
464
|
-
|
|
470
|
+
`,$e=`
|
|
465
471
|
id
|
|
466
472
|
path
|
|
467
473
|
fullPath
|
|
@@ -482,7 +488,7 @@ color
|
|
|
482
488
|
description
|
|
483
489
|
id
|
|
484
490
|
title
|
|
485
|
-
|
|
491
|
+
`,qe=`
|
|
486
492
|
author {
|
|
487
493
|
${x}
|
|
488
494
|
}
|
|
@@ -511,7 +517,7 @@ webUrl
|
|
|
511
517
|
milestone {
|
|
512
518
|
${Le}
|
|
513
519
|
}
|
|
514
|
-
`,
|
|
520
|
+
`,Ue=(e,r)=>`
|
|
515
521
|
id
|
|
516
522
|
state
|
|
517
523
|
author {
|
|
@@ -560,13 +566,13 @@ labels {
|
|
|
560
566
|
}
|
|
561
567
|
${e?"project { path fullPath webUrl }":""}
|
|
562
568
|
${r?`milestone { ${Le} }`:""}
|
|
563
|
-
`,
|
|
569
|
+
`,_=e=>`${e.namespace}/${e.name}`,Ot=e=>`${e.namespace}/${e.name}`,ve=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}},Tt={opened:"OPEN",merged:"MERGED",closed:"CLOSED"},N=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:Tt[e.state],commentCount:e.userNotesCount||0,upvoteCount:e.upvotes,author:e.author?N(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(N):null,reviews:(o=e.reviewers)!=null&&o.nodes?e.reviewers.nodes.map(d=>{var c,g;return{reviewer:N(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?Oe(e.milestone,r.webUrl):null,labels:((p=(l=e.labels)==null?void 0:l.nodes)==null?void 0:p.map(Ae))??[]}},Ee=(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?Oe(e.milestone,r.webUrl):null}},Oe=(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 O{async getCurrentUser(r={}){var n;let s=(n=(await f(this.config,{query:`
|
|
564
570
|
query getCurrentUser {
|
|
565
571
|
currentUser {
|
|
566
572
|
${x}
|
|
567
573
|
}
|
|
568
574
|
}
|
|
569
|
-
`},r)).body.data)==null?void 0:n.currentUser;if(!s)throw new Error("Current user not found.");return{data:
|
|
575
|
+
`},r)).body.data)==null?void 0:n.currentUser;if(!s)throw new Error("Current user not found.");return{data:N(s)}}async getUserForCommit(r,t={}){var a,i,u,l;let s=_(r.repo),o=(l=(u=(i=(a=(await f(this.config,{query:`
|
|
570
576
|
query getUserForCommit($fullPath: ID!, $oid: String!) {
|
|
571
577
|
project(fullPath: $fullPath) {
|
|
572
578
|
repository {
|
|
@@ -580,7 +586,7 @@ query getUserForCommit($fullPath: ID!, $oid: String!) {
|
|
|
580
586
|
}
|
|
581
587
|
}
|
|
582
588
|
}
|
|
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
|
|
589
|
+
`,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 f(this.config,{query:`
|
|
584
590
|
query getAccountForEmail($email: String!) {
|
|
585
591
|
users(search: $email) {
|
|
586
592
|
nodes {
|
|
@@ -588,13 +594,13 @@ query getAccountForEmail($email: String!) {
|
|
|
588
594
|
}
|
|
589
595
|
}
|
|
590
596
|
}
|
|
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:
|
|
597
|
+
`,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(n)}}async getAccountForUsername(r,t={}){var o;let n=(o=(await f(this.config,{query:`
|
|
592
598
|
query getAccountForUsername($username: String!) {
|
|
593
599
|
user(username: $username) {
|
|
594
600
|
${x}
|
|
595
601
|
}
|
|
596
602
|
}
|
|
597
|
-
`,variables:{username:r.username}},t)).body.data)==null?void 0:o.user;if(!n)throw new Error("User not found.");return{data:
|
|
603
|
+
`,variables:{username:r.username}},t)).body.data)==null?void 0:o.user;if(!n)throw new Error("User not found.");return{data:N(n)}}async getAccountsForRepo(r,t={}){var u,l,p,d,c,g,I;let{repo:{namespace:s,name:n},cursor:o}=r,a=await f(this.config,{query:`
|
|
598
604
|
query getAccountsForRepo(
|
|
599
605
|
$fullPath: ID!
|
|
600
606
|
$after: String
|
|
@@ -615,22 +621,22 @@ query getAccountsForRepo(
|
|
|
615
621
|
}
|
|
616
622
|
}
|
|
617
623
|
}
|
|
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(
|
|
624
|
+
`,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(R=>R.user).filter(R=>R!==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(N))??[]}}async getRepo(r,t={}){var o;let s=_(r),n=await f(this.config,{query:`
|
|
619
625
|
query getRepo($fullPath: ID!) {
|
|
620
626
|
project(fullPath: $fullPath) {
|
|
621
|
-
${
|
|
627
|
+
${$e}
|
|
622
628
|
}
|
|
623
629
|
}
|
|
624
|
-
`,variables:{fullPath:s}},t);if(!((o=n.body.data)!=null&&o.project))throw new Error(`Repository ${s} not found`);return{data:
|
|
630
|
+
`,variables:{fullPath:s}},t);if(!((o=n.body.data)!=null&&o.project))throw new Error(`Repository ${s} not found`);return{data:ve(n.body.data.project)}}async getRepos(r,t={}){let n=r.map(_).map((u,l)=>`
|
|
625
631
|
getRepo_${l}: project(fullPath: "${u}") {
|
|
626
|
-
${
|
|
632
|
+
${$e}
|
|
627
633
|
}
|
|
628
634
|
`).join(`
|
|
629
|
-
`),o=await
|
|
635
|
+
`),o=await f(this.config,{query:`
|
|
630
636
|
query batchGetRepos {
|
|
631
637
|
${n}
|
|
632
638
|
}
|
|
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(
|
|
639
|
+
`},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(ve(p)):i.push({input:u})}),{data:a,errors:i}}async getReposForCurrentUser(r={},t={}){var o,a,i,u,l,p;let s=await f(this.config,{query:`
|
|
634
640
|
query getReposForCurrentUser($after: String) {
|
|
635
641
|
projects(membership: true first: 100 after: $after) {
|
|
636
642
|
pageInfo {
|
|
@@ -638,11 +644,11 @@ query getReposForCurrentUser($after: String) {
|
|
|
638
644
|
hasNextPage
|
|
639
645
|
}
|
|
640
646
|
nodes {
|
|
641
|
-
${
|
|
647
|
+
${$e}
|
|
642
648
|
}
|
|
643
649
|
}
|
|
644
650
|
}
|
|
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(
|
|
651
|
+
`,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(ve)}}async getRefs(r,t,s={}){var u;let n=_(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=_(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=Et[r.association],n=await f(this.config,{query:`
|
|
646
652
|
query getPullRequestsForUser($username: String! $cursor: String) {
|
|
647
653
|
user(username: $username) {
|
|
648
654
|
${s}(state:opened first:100 after:$cursor) {
|
|
@@ -651,12 +657,12 @@ query getPullRequestsForUser($username: String! $cursor: String) {
|
|
|
651
657
|
hasNextPage
|
|
652
658
|
}
|
|
653
659
|
nodes {
|
|
654
|
-
${
|
|
660
|
+
${Ue(!0,!0)}
|
|
655
661
|
}
|
|
656
662
|
}
|
|
657
663
|
}
|
|
658
664
|
}
|
|
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]
|
|
665
|
+
`,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],[a,i,u]=await Promise.all([s==="null"?null:this.getPullRequestsForUser({username:r.username,association:"authored",cursor:s},t),n==="null"?null:this.getPullRequestsForUser({username:r.username,association:"assigned",cursor:n},t),o==="null"?null: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==null||a.data.forEach(d),i==null||i.data.forEach(d),u==null||u.data.forEach(d),{pageInfo:{hasNextPage:(a==null?void 0:a.pageInfo.hasNextPage)||(i==null?void 0:i.pageInfo.hasNextPage)||(u==null?void 0:u.pageInfo.hasNextPage)||!1,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 R,w,P;let{cursor:s,repo:n}=r||{},o=_(n),{variables:a,variableTypes:i,mergeRequestArguments:u}=this.getVariablesForPullRequests(r),l={fullPath:o,...a},p=await f(this.config,{query:`
|
|
660
666
|
query getPullRequestsForRepo(
|
|
661
667
|
$fullPath: ID!
|
|
662
668
|
$after: String
|
|
@@ -680,12 +686,12 @@ query getPullRequestsForRepo(
|
|
|
680
686
|
hasNextPage
|
|
681
687
|
}
|
|
682
688
|
nodes {
|
|
683
|
-
${
|
|
689
|
+
${Ue(!1,!0)}
|
|
684
690
|
}
|
|
685
691
|
}
|
|
686
692
|
}
|
|
687
693
|
}
|
|
688
|
-
`,variables:{...l,after:s}},t),d=[],c=(
|
|
694
|
+
`,variables:{...l,after:s}},t),d=[],c=(R=p.body.data)==null?void 0:R.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:(P=c==null?void 0:c.mergeRequests)==null?void 0:P.pageInfo,data:d}}async getPullRequestsForRepos(r,t={}){var c,g,I,R,w;let{cursor:s}=r||{},n=r.repoIds.map(P=>P.toString().startsWith(W)?P:`${W}${P}`),{variables:o,variableTypes:a,mergeRequestArguments:i}=this.getVariablesForPullRequests(r),u={projectIds:n,...o},l=await f(this.config,{query:`
|
|
689
695
|
query getPullRequests(
|
|
690
696
|
$projectIds: [ID!]
|
|
691
697
|
$after: String
|
|
@@ -710,20 +716,20 @@ query getPullRequests(
|
|
|
710
716
|
${i.length?i.join(" "):""}
|
|
711
717
|
) {
|
|
712
718
|
nodes {
|
|
713
|
-
${
|
|
719
|
+
${Ue(!1,!1)}
|
|
714
720
|
}
|
|
715
721
|
}
|
|
716
722
|
}
|
|
717
723
|
}
|
|
718
724
|
}
|
|
719
|
-
`,variables:{...u,after:s}},t),p=[];return(((g=(c=l.body.data)==null?void 0:c.projects)==null?void 0:g.nodes)||[]).forEach(
|
|
725
|
+
`,variables:{...u,after:s}},t),p=[];return(((g=(c=l.body.data)==null?void 0:c.projects)==null?void 0:g.nodes)||[]).forEach(P=>{var L;let b=Q(P);(((L=P.mergeRequests)==null?void 0:L.nodes)||[]).forEach(q=>{p.push(De(q,b))})}),{pageInfo:(w=(R=(I=l.body)==null?void 0:I.data)==null?void 0:R.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!) {
|
|
720
726
|
mergeRequestUpdate(input: { projectPath: $fullPath, iid: $pullRequestId, state: CLOSED }) {
|
|
721
727
|
errors,
|
|
722
728
|
mergeRequest {
|
|
723
729
|
id
|
|
724
730
|
}
|
|
725
731
|
}
|
|
726
|
-
}`,u=(l=(await
|
|
732
|
+
}`,u=(l=(await f(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(
|
|
727
733
|
$fullPath: ID!,
|
|
728
734
|
$pullRequestId: String!,
|
|
729
735
|
$expectedSourceSha: String!,
|
|
@@ -740,32 +746,39 @@ query getPullRequests(
|
|
|
740
746
|
id
|
|
741
747
|
}
|
|
742
748
|
}
|
|
743
|
-
}`,p=(d=(await
|
|
749
|
+
}`,p=(d=(await f(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) {
|
|
744
750
|
mergeRequestSetMilestone(input: { projectPath: $fullPath, iid: $pullRequestId, milestoneId: $milestoneGraphQLId }) {
|
|
745
751
|
errors,
|
|
746
752
|
mergeRequest {
|
|
747
753
|
id
|
|
748
754
|
}
|
|
749
755
|
}
|
|
750
|
-
}`,u=await
|
|
756
|
+
}`,u=await f(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!) {
|
|
751
757
|
mergeRequestSetDraft(input: { projectPath: $fullPath, iid: $pullRequestId, draft: $isDraft }) {
|
|
752
758
|
errors,
|
|
753
759
|
mergeRequest {
|
|
754
760
|
id
|
|
755
761
|
}
|
|
756
762
|
}
|
|
757
|
-
}`,l=(p=(await
|
|
763
|
+
}`,l=(p=(await f(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 setPullRequestAssignees(r,t={}){var p,d,c;let{repo:{namespace:s,name:n},pullRequestId:o,assigneeUsernames:a}=r,i=`mutation MergeRequestSetAssignees($fullPath: ID!, $pullRequestId: String!, $assigneeUsernames: [String!]!) {
|
|
764
|
+
mergeRequestSetAssignees(input: { projectPath: $fullPath, iid: $pullRequestId, assigneeUsernames: $assigneeUsernames }) {
|
|
765
|
+
errors,
|
|
766
|
+
mergeRequest {
|
|
767
|
+
id
|
|
768
|
+
}
|
|
769
|
+
}
|
|
770
|
+
}`,l=(p=(await f(this.config,{query:i,variables:{fullPath:`${s}/${n}`,pullRequestId:o,assigneeUsernames:a}},t)).body.data)==null?void 0:p.mergeRequestSetAssignees;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 assignees")}async getIssue(r,t={}){var o,a,i;let s=Ot(r),n=await f(this.config,{query:`
|
|
758
771
|
query GetSingleIssue($projectId: ID!, $issueId: String!) {
|
|
759
772
|
project(fullPath: $projectId) {
|
|
760
773
|
path
|
|
761
774
|
fullPath
|
|
762
775
|
webUrl
|
|
763
776
|
issue(iid: $issueId) {
|
|
764
|
-
${
|
|
777
|
+
${qe}
|
|
765
778
|
}
|
|
766
779
|
}
|
|
767
780
|
}
|
|
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:
|
|
781
|
+
`,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:Ee(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,P,b;let{cursor:s,repo:n}=r||{},o=_(n),{variables:a,variableTypes:i,issueArguments:u}=this.getVariablesForIssues(r),l={fullPath:o,...a},p=`
|
|
769
782
|
query GetIssuesFromProject(
|
|
770
783
|
$fullPath: ID!
|
|
771
784
|
$after: String
|
|
@@ -785,7 +798,7 @@ query GetSingleIssue($projectId: ID!, $issueId: String!) {
|
|
|
785
798
|
${u.length?u.join(" "):""}
|
|
786
799
|
) {
|
|
787
800
|
nodes {
|
|
788
|
-
${
|
|
801
|
+
${qe}
|
|
789
802
|
}
|
|
790
803
|
pageInfo {
|
|
791
804
|
endCursor
|
|
@@ -793,7 +806,7 @@ query GetSingleIssue($projectId: ID!, $issueId: String!) {
|
|
|
793
806
|
}
|
|
794
807
|
}
|
|
795
808
|
}
|
|
796
|
-
}`,d=await
|
|
809
|
+
}`,d=await f(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(((P=g==null?void 0:g.issues)==null?void 0:P.nodes)||[]).forEach($=>{c.push(Ee($,I))}),{pageInfo:(b=g==null?void 0:g.issues)==null?void 0:b.pageInfo,data:c.sort(($,L)=>($.updatedDate||$.createdDate).getTime()-(L.updatedDate||L.createdDate).getTime())}}async getIssuesForRepos(r,t={}){var g,I,R,w,P;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=`
|
|
797
810
|
query GetIssuesFromProject(
|
|
798
811
|
$projectIds: [ID!]
|
|
799
812
|
$after: String
|
|
@@ -818,18 +831,18 @@ query GetSingleIssue($projectId: ID!, $issueId: String!) {
|
|
|
818
831
|
${i.length?i.join(" "):""}
|
|
819
832
|
) {
|
|
820
833
|
nodes {
|
|
821
|
-
${
|
|
834
|
+
${qe}
|
|
822
835
|
}
|
|
823
836
|
}
|
|
824
837
|
}
|
|
825
838
|
}
|
|
826
|
-
}`,p=await
|
|
839
|
+
}`,p=await f(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 q;let $=Q(b);(((q=b.issues)==null?void 0:q.nodes)||[]).forEach(le=>d.push(Ee(le,$)))}),{pageInfo:(P=(w=(R=p.body)==null?void 0:R.data)==null?void 0:w.projects)==null?void 0:P.pageInfo,data:d.sort((b,$)=>(b.updatedDate||b.createdDate).getTime()-($.updatedDate||$.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!) {
|
|
827
840
|
updateIssue(input: { projectPath: $fullPath, iid: $issueId, stateEvent: $status }) {
|
|
828
841
|
issue {
|
|
829
842
|
id
|
|
830
843
|
}
|
|
831
844
|
}
|
|
832
|
-
}`;if(!((d=(p=(l=(await
|
|
845
|
+
}`;if(!((d=(p=(l=(await f(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) {
|
|
833
846
|
updateIssue(input: { projectPath: $fullPath, iid: $issueId, milestoneId: $milestoneGraphQLId }) {
|
|
834
847
|
errors
|
|
835
848
|
issue {
|
|
@@ -839,7 +852,7 @@ query GetSingleIssue($projectId: ID!, $issueId: String!) {
|
|
|
839
852
|
}
|
|
840
853
|
}
|
|
841
854
|
}
|
|
842
|
-
}`,u=await
|
|
855
|
+
}`,u=await f(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 f(this.config,{query:`
|
|
843
856
|
query getLabelsForRepo(
|
|
844
857
|
$fullPath: ID!
|
|
845
858
|
$after: String
|
|
@@ -859,7 +872,7 @@ query getLabelsForRepo(
|
|
|
859
872
|
}
|
|
860
873
|
}
|
|
861
874
|
}
|
|
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
|
|
875
|
+
`,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 R,w;return Oe(I,((w=(R=a.body.data)==null?void 0:R.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 f(this.config,{query:`
|
|
863
876
|
query getLabelsForRepo(
|
|
864
877
|
$fullPath: ID!
|
|
865
878
|
$after: String
|
|
@@ -878,4 +891,4 @@ query getLabelsForRepo(
|
|
|
878
891
|
}
|
|
879
892
|
}
|
|
880
893
|
}
|
|
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};
|
|
894
|
+
`,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 U{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}"`,"statusCategory != Done"];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 T="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 U{async getCurrentUser(r,t={}){let s=await this.config.request({url:`${t.baseUrl||T}/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||T}/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||T}/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||T}/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||T}/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||T}/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 setIssueArchived(r,t={}){let{appKey:s,cardId:n,archived:o}=r;if(!(await this.config.request({method:"PUT",url:`${t.baseUrl||T}/1/cards/${n}?key=${s}&token=${t.token||this.config.token}&closed=${o}`,headers:m(t.token||this.config.token)})).body.id)throw new Error("Could not update issue archived status")}async getLabelsForBoard(r,t={}){let{appKey:s,boardId:n}=r;return{data:(await this.config.request({url:`${t.baseUrl||T}/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};
|
|
@@ -2,7 +2,7 @@ import { PagedResult, Result } from '../../types';
|
|
|
2
2
|
import { CursorPageInput, EnterpriseOptions, GetRepoErrorData, GetRepoInput, GitMergeStrategy, GitProvider, GitPullRequest, GitRepository, NumberedPageInput, Options } from '../gitProvider';
|
|
3
3
|
import { Issue } from '../issueProvider';
|
|
4
4
|
import { Provider } from '../provider';
|
|
5
|
-
import { WorkItemType } from './azureDevOpsTypes';
|
|
5
|
+
import { PullRequestAsyncStatus, WorkItemType } from './azureDevOpsTypes';
|
|
6
6
|
export interface AzureGetRepoInput extends GetRepoInput {
|
|
7
7
|
project: string;
|
|
8
8
|
}
|
|
@@ -146,6 +146,12 @@ export declare class AzureDevOps extends Provider implements GitProvider {
|
|
|
146
146
|
}, options?: EnterpriseOptions): Promise<{
|
|
147
147
|
data: GitPullRequest[];
|
|
148
148
|
}>;
|
|
149
|
+
getAzurePullRequestLastMergeStatus(input: {
|
|
150
|
+
repo: GetRepoInput;
|
|
151
|
+
pullRequestId: string;
|
|
152
|
+
}, options?: EnterpriseOptions): Promise<{
|
|
153
|
+
data: PullRequestAsyncStatus;
|
|
154
|
+
}>;
|
|
149
155
|
private updatePullRequest;
|
|
150
156
|
closePullRequest(input: {
|
|
151
157
|
repo: GetRepoInput;
|
|
@@ -227,4 +227,12 @@ export interface WorkItemType {
|
|
|
227
227
|
export interface UpdatePullRequestResponse {
|
|
228
228
|
status: string;
|
|
229
229
|
}
|
|
230
|
+
export declare enum PullRequestAsyncStatus {
|
|
231
|
+
Conflicts = "conflicts",
|
|
232
|
+
Failure = "failure",
|
|
233
|
+
NotSet = "notSet",
|
|
234
|
+
Queued = "queued",
|
|
235
|
+
RejectedByPolicy = "rejectedByPolicy",
|
|
236
|
+
Succeeded = "succeeded"
|
|
237
|
+
}
|
|
230
238
|
export {};
|
|
@@ -204,6 +204,10 @@ export declare class GitHub extends EnterpriseProvider implements GitProvider {
|
|
|
204
204
|
pullRequestGraphQLId: string;
|
|
205
205
|
isDraft: boolean;
|
|
206
206
|
}, options?: EnterpriseOptions): Promise<void>;
|
|
207
|
+
setPullRequestAssignees(input: {
|
|
208
|
+
pullRequestGraphQLId: string;
|
|
209
|
+
assigneeGraphQLIds: string[];
|
|
210
|
+
}, options?: EnterpriseOptions): Promise<void>;
|
|
207
211
|
/**
|
|
208
212
|
* Returns issues that were created by or are assigned to the user.
|
|
209
213
|
*/
|
|
@@ -186,6 +186,11 @@ export declare class GitLab extends EnterpriseProvider implements GitProvider, I
|
|
|
186
186
|
pullRequestId: string;
|
|
187
187
|
isDraft: boolean;
|
|
188
188
|
}, options?: EnterpriseOptions): Promise<void>;
|
|
189
|
+
setPullRequestAssignees(input: {
|
|
190
|
+
repo: GetRepoInput;
|
|
191
|
+
pullRequestId: string;
|
|
192
|
+
assigneeUsernames: string[];
|
|
193
|
+
}, options?: EnterpriseOptions): Promise<void>;
|
|
189
194
|
getIssue(input: GetIssueInput, options?: EnterpriseOptions): Promise<{
|
|
190
195
|
data: Issue;
|
|
191
196
|
}>;
|
|
@@ -73,6 +73,11 @@ export declare class Trello extends Provider {
|
|
|
73
73
|
cardId: string;
|
|
74
74
|
status: string;
|
|
75
75
|
}, options?: EnterpriseOptions): Promise<void>;
|
|
76
|
+
setIssueArchived(input: {
|
|
77
|
+
appKey: string;
|
|
78
|
+
cardId: string;
|
|
79
|
+
archived: boolean;
|
|
80
|
+
}, options?: EnterpriseOptions): Promise<void>;
|
|
76
81
|
getLabelsForBoard(input: {
|
|
77
82
|
appKey: string;
|
|
78
83
|
boardId: string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gitkraken/provider-apis",
|
|
3
|
-
"version": "0.13.
|
|
3
|
+
"version": "0.13.2",
|
|
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",
|