@gitkraken/provider-apis 0.10.0 → 0.11.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +28 -0
- package/dist/index.js +278 -118
- package/dist/providers/azureDevops/azureDevOps.d.ts +32 -0
- package/dist/providers/azureDevops/azureDevOpsTypes.d.ts +36 -0
- package/dist/providers/bitbucketServer/bitbucketServer.d.ts +3 -11
- package/dist/providers/gitProvider.d.ts +20 -0
- package/dist/providers/github/github.d.ts +55 -2
- package/dist/providers/github/githubHelpers.d.ts +5 -2
- package/dist/providers/github/githubTypes.d.ts +28 -0
- package/dist/providers/gitlab/gitlab.d.ts +44 -1
- package/dist/providers/issueProvider.d.ts +16 -2
- package/dist/providers/jira/jira.d.ts +16 -0
- package/dist/providers/trello/trello.d.ts +39 -0
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,18 +1,31 @@
|
|
|
1
|
-
"use strict";var Ne=Object.create;var W=Object.defineProperty;var Qe=Object.getOwnPropertyDescriptor;var Fe=Object.getOwnPropertyNames;var ze=Object.getPrototypeOf,Me=Object.prototype.hasOwnProperty;var x=(e,t)=>{for(var r in t)W(e,r,{get:t[r],enumerable:!0})},Pe=(e,t,r,s)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of Fe(t))!Me.call(e,n)&&n!==r&&W(e,n,{get:()=>t[n],enumerable:!(s=Qe(t,n))||s.enumerable});return e};var He=(e,t,r)=>(r=e!=null?Ne(ze(e)):{},Pe(t||!e||!e.__esModule?W(r,"default",{value:e,enumerable:!0}):r,e)),We=e=>Pe(W({},"__esModule",{value:!0}),e);var Bt={};x(Bt,{AzureDevOps:()=>j,AzureDevopsUtils:()=>X,Bitbucket:()=>B,BitbucketServer:()=>N,BitbucketServerUtils:()=>Z,BitbucketUtils:()=>K,GitHub:()=>Q,GitHubUtils:()=>Y,GitLab:()=>z,GitLabUtils:()=>ee,Jira:()=>M,JiraUtils:()=>te,Trello:()=>H,TrelloUtils:()=>re,Utils:()=>jt,default:()=>kt});module.exports=We(Bt);var v=100;var we=He(require("node-fetch")),Ce=globalThis.fetch||we.default;var ve=e=>e.name==="fetch";var Je=async e=>{let t=e.headers.get("content-type")||"",r=null;if(t.startsWith("application/json"))r=await e.json();else if(t.startsWith("text/"))r=await e.text();else throw new Error(`Unsupported content-type: ${t}`);let s={body:r,headers:Object.fromEntries(e.headers.entries()),status:e.status,statusText:e.statusText};if(!e.ok){let n=new Error(e.statusText);throw Object.assign(n,{response:s}),n}return s},se=e=>ve(e)?async({url:t,...r})=>{let s=await e(t,r);return Je(s)}:e;var E=class{constructor(t){this.config={...t,request:se((t==null?void 0:t.request)||Ce)}}updateConfig(t){this.config={...this.config,...t,request:t.request?se(t.request):this.config.request}}},A=class extends E{};var f=(e,t)=>{let r={};return e&&(r.Authorization=`${t?"Basic":"Bearer"} ${e}`),r};var w=(e,t={})=>f(t.token||e.token,t.isPAT||e.isPAT),Ue=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 Ee="https://app.vssps.visualstudio.com/_apis",U="https://dev.azure.com",Ve={active:"OPEN",completed:"MERGED",abandoned:"CLOSED"},Xe={10:"APPROVED",5:"APPROVED",0:"REVIEW_REQUESTED",[-5]:"CHANGES_REQUESTED",[-10]:"CHANGES_REQUESTED"},ne=e=>({id:e.id,name:e.displayName,username:e.uniqueName||e.displayName,email:null,avatarUrl:e.imageUrl}),J=e=>e.startsWith("refs/heads/")?e.replace("refs/heads/",""):e,Se=e=>({id:e.pullRequestId.toString(),title:e.title,number:e.codeReviewId,state:Ve[e.status],isDraft:e.isDraft,commentCount:null,upvoteCount:null,author:ne(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:J(e.targetRefName)},headRef:{name:J(e.sourceRefName)},url:Ue(e),assignees:e.reviewers.map(ne),reviews:e.reviewers.filter(t=>t.vote!==0).map(t=>({reviewer:ne(t),state:Xe[t.vote]||"REVIEW_REQUESTED"})),additions:null,deletions:null,fileCount:null,commitCount:null,headRepository:null,mergeableState:"UNKNOWN"}),$e=(e,t)=>({id:t.id,name:t.name,namespace:e,project:t.project.name,webUrl:t.webUrl,httpsUrl:t.remoteUrl,sshUrl:t.sshUrl,defaultBranch:t.defaultBranch?{name:J(t.defaultBranch)}:null,permission:null}),Ke=e=>{let t=e.fields,r=t["System.AssignedTo"];return{id:e.id.toString(),number:e.id.toString(),title:t["System.Title"],commentCount:t["System.CommentCount"],author:{avatarUrl:t["System.CreatedBy"]._links.avatar.href,email:null,id:t["System.CreatedBy"].id,name:t["System.CreatedBy"].uniqueName,username:t["System.CreatedBy"].displayName},createdDate:new Date(t["System.CreatedDate"]),updatedDate:new Date(t["System.ChangedDate"]),url:e._links.html.href,assignees:r?[{avatarUrl:r._links.avatar.href,email:null,id:r.id,name:r.uniqueName,username:r.displayName}]:[],description:null,state:null,type:t["System.WorkItemType"],repository:null,upvoteCount:0}},j=class extends E{async getCurrentUser(t={}){if(t.isPAT||this.config.isPAT)throw new Error("Azure DevOps does not support PATs for this function.");let r=await this.config.request({url:`${Ee}/profile/profiles/me`,headers:w(this.config,t)});return{data:{id:r.body.id,name:r.body.displayName,username:r.body.displayName,email:r.body.emailAddress,avatarUrl:null}}}async getCurrentUserForInstance(t,r={}){let n=(await this.config.request({url:`${U}/${encodeURIComponent(t.namespace)}/_apis/ConnectionData`,headers:w(this.config,r)})).body.authorizedUser;if(n.providerDisplayName==="Anonymous")throw new Error("Current user not found.");return{data:{id:n.id,name:n.providerDisplayName,username:n.providerDisplayName,email:n.properties.Account.$value,avatarUrl:null}}}async getUserForCommit(t,r={}){if(!t.repo.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let n=(await this.config.request({url:`${U}/${encodeURIComponent(t.repo.namespace)}/${encodeURIComponent(t.repo.project)}/_apis/git/repositories/${encodeURIComponent(t.repo.name)}/commits/${t.oid}`,headers:w(this.config,r)})).body.author;return{data:{name:n.name,email:n.email,avatarUrl:n.imageUrl}}}async getOrgsForUser(t,r={}){return{data:(await this.config.request({url:`${Ee}/accounts?memberId=${t.userId}&api-version=6.0`,headers:w(this.config,r)})).body.value.map(n=>({id:n.accountId,name:n.accountName}))}}async getAzureProjects(t,r={}){let s=new URL(`${U}/${encodeURIComponent(t.namespace)}/_apis/projects`);s.searchParams.set("$top",v.toString()),t.cursor&&s.searchParams.set("$skip",t.cursor);let n=await this.config.request({url:s.toString(),headers:w(this.config,r)}),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:t.namespace}))}}async getRepo(t,r={}){if(!t.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let s=await this.config.request({url:`${U}/${encodeURIComponent(t.namespace)}/${encodeURIComponent(t.project)}/_apis/git/repositories/${encodeURIComponent(t.name)}`,headers:w(this.config,r)});return{data:$e(t.namespace,s.body)}}async getRepos(t,r={}){let s=[],n=[];return await Promise.all(t.map(async o=>{try{let a=await this.getRepo(o,r);s.push(a.data)}catch(a){n.push({input:o,error:a})}})),{data:s,errors:n}}async getReposForAzureProject(t,r={}){if(!t.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');return{data:(await this.config.request({url:`${U}/${encodeURIComponent(t.namespace)}/${encodeURIComponent(t.project)}/_apis/git/repositories`,headers:w(this.config,r)})).body.value.map(n=>$e(t.namespace,n))}}async getRefs(t,r,s={}){if(!r.repo.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let n=new URL(`${U}/${encodeURIComponent(r.repo.namespace)}/${encodeURIComponent(r.repo.project)}/_apis/git/repositories/${encodeURIComponent(r.repo.name)}/refs`);n.searchParams.set("filter",t),n.searchParams.set("$top",v.toString()),r.cursor&&n.searchParams.set("continuationToken",r.cursor);let o=await this.config.request({url:n.toString(),headers:w(this.config,s)}),a=o.headers["x-ms-continuationtoken"];return{pageInfo:{hasNextPage:!!a,endCursor:a||null},data:o.body.value.map(i=>({name:J(i.name),commit:{oid:i.objectId,authoredDate:null,committedDate:null}}))}}async getBranches(t,r={}){return this.getRefs("heads",t,r)}async getTags(t,r={}){return this.getRefs("tags",t,r)}async getPullRequestsForRepoBase(t,r={},s=100){let{page:n,repo:o,assigneeLogins:a,authorLogin:i}=t||{},u=n||1;if(!o.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let p="searchCriteria.status=1";return a&&a.length&&(p+=`&searchCriteria.reviewerId=${a[0]}`),i&&(p+=`&searchCriteria.creatorId=${i}`),await this.config.request({url:`${r.baseUrl||U}/${encodeURIComponent(o.namespace)}/${encodeURIComponent(o.project||"")}/_apis/git/repositories/${encodeURIComponent(o.name)}/pullRequests?${p}&%24top=${s}&%24skip=${(u-1)*s}`,headers:w(this.config,r)})}async getPullRequestsForRepo(t,r={}){let n=t.page||1,o=await this.getPullRequestsForRepoBase(t,r,100);return{pageInfo:{hasNextPage:o.body.value.length===100,nextPage:n+1},data:o.body.value.map(Se)}}async getPullRequestsForRepos(t,r={}){if(!t.repos.every(o=>o.project))throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let{repos:s}=t||{},n=[];return await Promise.all(s.map(async o=>{try{(await this.getPullRequestsForRepoBase({repo:o,...t},r)).body.value.forEach(i=>{n.push(Se(i))})}catch(a){if(a.statusCode!==404&&a.statusCode!==401)throw a}})),{data:n}}async closePullRequest(t,r={}){if(!t.repo.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let{repo:{namespace:s,name:n,project:o},pullRequestId:a}=t,i={status:"abandoned"};if(!(await this.config.request({method:"PATCH",url:`${r.baseUrl||U}/${encodeURIComponent(s)}/${encodeURIComponent(o||"")}/_apis/git/repositories/${n}/pullrequests/${a}?api-version=6.0`,body:JSON.stringify(i),headers:{...w(this.config,r),"Content-Type":"application/json"}})).body.status)throw new Error("Could not close pull request")}async mergePullRequest(t,r={}){if(!t.repo.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let{repo:{namespace:s,name:n,project:o},pullRequestId:a,expectedSourceSha:i}=t,u={lastMergeSourceCommit:{commitId:i},status:"completed"};if(!(await this.config.request({method:"PATCH",url:`${r.baseUrl||U}/${encodeURIComponent(s)}/${encodeURIComponent(o||"")}/_apis/git/repositories/${n}/pullrequests/${a}?api-version=6.0`,body:JSON.stringify(u),headers:{...w(this.config,r),"Content-Type":"application/json"}})).body.status)throw new Error("Could not merge pull request")}async getIssuesForAzureProject(t,r={}){let{page:s,assigneeLogins:n,authorLogin:o,mentionLogin:a}=t||{},i=s||1,u=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 l=`Select [Microsoft.VSTS.Common.ClosedDate], [Microsoft.VSTS.Common.ResolvedDate] From WorkItems Where ${p.join(" AND ")} order by [System.CreatedDate] desc`,d=await this.config.request({url:`${r.baseUrl||U}/${encodeURIComponent(t.namespace)}/${encodeURIComponent(t.project)}/_apis/wit/wiql?api-version=6.0`,body:JSON.stringify({query:l}),method:"POST",headers:{...w(this.config,r),"Content-Type":"application/json"}}),c=d.body.workItems.slice((i-1)*u,u*i).map(I=>I.id);if(c.length==0)return{pageInfo:{hasNextPage:!1,nextPage:null},data:[]};let g=await this.config.request({url:`${r.baseUrl||U}/${encodeURIComponent(t.namespace)}/${encodeURIComponent(t.project)}/_apis/wit/workitemsbatch?api-version=6.0`,body:JSON.stringify({ids:c,$expand:"Links"}),method:"POST",headers:{...w(this.config,r),"Content-Type":"application/json"}});return{pageInfo:{hasNextPage:d.body.workItems.length>u*i,nextPage:i+1},data:g.body.value.map(Ke)}}async setIssueStatus(t,r={}){var p;if(!t.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let{namespace:s,project:n,issueId:o,status:a}=t,i=[{op:"add",path:"/fields/System.State",value:a}];if(!((p=(await this.config.request({method:"PATCH",url:`${r.baseUrl||U}/${encodeURIComponent(s)}/${encodeURIComponent(n||"")}/_apis/wit/workitems/${o}?api-version=6.0`,body:JSON.stringify(i),headers:{...w(this.config,r),"Content-Type":"application/json-patch+json"}})).body.fields)!=null&&p["System.State"]))throw new Error("Could not set issue status")}};var S=(e,t={})=>f(t.token||e.token,t.isPAT||e.isPAT);var G="https://api.bitbucket.org/2.0",Ze={OPEN:"OPEN",MERGED:"MERGED",DECLINED:"CLOSED"},Ge=e=>({id:e.uuid,name:e.display_name||e.nickname,username:e.nickname||e.display_name,email:null,avatarUrl:e.links.avatar.href}),De=e=>{var t,r;return{id:e.uuid,namespace:e.workspace.slug,name:e.slug,webUrl:e.links.html.href,httpsUrl:((t=e.links.clone.find(s=>s.name==="https"))==null?void 0:t.href)??null,sshUrl:((r=e.links.clone.find(s=>s.name==="ssh"))==null?void 0:r.href)??null,defaultBranch:{name:e.mainbranch.name},permission:null}},qe=e=>{let t=e.id;return{id:t.toString(),title:e.title,number:t,state:Ze[e.state],isDraft:!1,commentCount:e.comment_count,upvoteCount:null,author:Ge(e.author),createdDate:new Date(e.created_on),updatedDate:new Date(e.updated_on),closedDate:null,repository:{name:e.source.repository.name,owner:{login:void 0}},headCommit:{buildStatus:null},baseRef:{name:e.destination.branch.name},headRef:{name:e.source.branch.name},url:e.links.html.href,assignees:null,reviews:null,additions:null,deletions:null,fileCount:null,commitCount:null,headRepository:null,mergeableState:"UNKNOWN"}},B=class extends E{async refreshToken(t){return{data:(await this.config.request({url:"https://bitbucket.org/site/oauth2/access_token",method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded",Authorization:`Basic ${t.base64ClientIDColonClientSecret}`},body:`grant_type=refresh_token&refresh_token=${t.refreshToken}`})).body}}async getCurrentUser(t={}){let r=await this.config.request({url:`${G}/user`,headers:S(this.config,t)});return{data:Ge(r.body)}}async getUserForCommit(t,r={}){var a;let n=(await this.config.request({url:`${G}/repositories/${t.repo.namespace}/${t.repo.name}/commit/${t.oid}`,headers:S(this.config,r)})).body.author,o=n.raw.match(/([^<]+)<(.+)>/);return{data:{name:o?o[1].trim():null,email:o?o[2]:null,avatarUrl:((a=n.user)==null?void 0:a.links.avatar.href)||null}}}async getRepo(t,r={}){let s=await this.config.request({url:`${G}/repositories/${t.namespace}/${t.name}`,headers:S(this.config,r)});return{data:De(s.body)}}async getRepos(t,r={}){let s=[],n=[];return await Promise.all(t.map(async o=>{try{let a=await this.getRepo(o,r);s.push(a.data)}catch(a){n.push({input:o,error:a})}})),{data:s,errors:n}}async getReposForCurrentUser(t={},r={}){let s=new URL(`${G}/repositories`);s.searchParams.set("role","member"),s.searchParams.set("pagelen",v.toString()),t.cursor&&s.searchParams.set("after",t.cursor);let n=await this.config.request({url:s.toString(),headers:S(this.config,r)}),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(De)}}async getBranches(t,r={}){var a;let s=new URL(`${G}/repositories/${t.repo.namespace}/${t.repo.name}/refs/branches`);s.searchParams.set("page",((a=t.page)==null?void 0:a.toString())||"1"),s.searchParams.set("pagelen",v.toString());let n=await this.config.request({url:s.toString(),headers:S(this.config,r)}),o=!!n.body.next;return{pageInfo:{hasNextPage:o,nextPage:o?n.body.page+1:null},data:n.body.values.map(i=>{let u=new Date(i.target.date);return{name:i.name,commit:{oid:i.target.hash,authoredDate:u,committedDate:u}}})}}async getTags(t,r={}){let s=new URL(`${G}/repositories/${t.repo.namespace}/${t.repo.name}/refs/tags`);s.searchParams.set("pagelen",v.toString()),t.cursor&&s.searchParams.set("page",t.cursor);let n=await this.config.request({url:s.toString(),headers:S(this.config,r)}),o=!!n.body.next,a=null;return n.body.next&&(a=new URL(n.body.next).searchParams.get("page")),{pageInfo:{hasNextPage:o,endCursor:a},data:n.body.values.map(i=>{let u=new Date(i.target.date);return{name:i.name,commit:{oid:i.target.hash,authoredDate:u,committedDate:u}}})}}async getPullRequestsForRepoBase(t,r={}){var n;let s=new URL(`${G}/repositories/${encodeURI(t.repo.namespace)}/${encodeURI(t.repo.name)}/pullrequests?state=OPEN`);return s.searchParams.set("page",((n=t.page)==null?void 0:n.toString())||"1"),s.searchParams.set("pagelen","50"),await this.config.request({url:s.toString(),headers:S(this.config,r)})}async getPullRequestsForRepo(t,r={}){let s=[],n=await this.getPullRequestsForRepoBase(t,r);n.body.values.forEach(a=>{if(t.authorLogin&&a.author.uuid!==t.authorLogin)return null;s.push(qe(a))});let o=!!n.body.next;return{pageInfo:{hasNextPage:o,nextPage:o?n.body.page+1:null},data:s}}async getPullRequestsForRepos(t,r={}){let s=[];return await Promise.all(t.repos.map(async n=>{try{(await this.getPullRequestsForRepoBase({repo:n,...t},r)).body.values.forEach(a=>{if(t.authorLogin&&a.author.uuid!==t.authorLogin)return null;s.push(qe(a))})}catch(o){if(o.statusCode!==404&&o.statusCode!==401)throw o}})),{data:s}}async closePullRequest(t,r={}){let{repo:{namespace:s,name:n},pullRequestId:o}=t;if(!(await this.config.request({method:"POST",url:`${G}/repositories/${s}/${n}/pullrequests/${o}/decline`,headers:S(this.config,r)})).body.title)throw new Error("Could not close pull request")}async mergePullRequest(t,r={}){let{repo:{namespace:s,name:n},pullRequestId:o}=t;if(!(await this.config.request({method:"POST",url:`${G}/repositories/${s}/${n}/pullrequests/${o}/merge`,headers:S(this.config,r)})).body.title)throw new Error("Could not merge pull request")}};var N=class extends A{getBaseUrl(t){let r=t.baseUrl||this.config.baseUrl;if(!r)throw new Error('Bitbucket Server requires "baseUrl"');return r}getRequestHeaders(t){return f(t.token||this.config.token)}async getRepo(t,r={}){var n,o,a;let s=await this.config.request({url:`${this.getBaseUrl(r)}/projects/${t.namespace}/repos/${t.name}`,headers:this.getRequestHeaders(r)});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(t,r={}){return{data:(await Promise.all(t.map(n=>this.getRepo(n,r)))).map(n=>n.data)}}};var ie="https://api.github.com",Ye=`${ie}/graphql`,Le=/\/api\/v\d+$/,et=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.")},tt=(e,t)=>{let r=t.baseUrl||e.baseUrl;return r?(r=r.replace(/\/$/,""),et(r),Le.test(r)&&(r=r.replace(Le,"")),`${r}/api/graphql`):Ye},R=(e,t,r)=>{let s=f(r.token||e.token);return s["X-Github-Next-Global-ID"]="1",s["Content-Type"]="application/json",e.request({url:tt(e,r),method:"POST",headers:s,body:JSON.stringify(t)})},rt={user:!0,"user:email":!0,"read:user":!0},_=e=>e.some(t=>rt[t]),$=(e=!1,t=!1)=>`
|
|
1
|
+
"use strict";var Xe=Object.create;var J=Object.defineProperty;var Ke=Object.getOwnPropertyDescriptor;var Ze=Object.getOwnPropertyNames;var Ye=Object.getPrototypeOf,et=Object.prototype.hasOwnProperty;var G=(e,r)=>{for(var t in r)J(e,t,{get:r[t],enumerable:!0})},qe=(e,r,t,s)=>{if(r&&typeof r=="object"||typeof r=="function")for(let n of Ze(r))!et.call(e,n)&&n!==t&&J(e,n,{get:()=>r[n],enumerable:!(s=Ke(r,n))||s.enumerable});return e};var tt=(e,r,t)=>(t=e!=null?Xe(Ye(e)):{},qe(r||!e||!e.__esModule?J(t,"default",{value:e,enumerable:!0}):t,e)),rt=e=>qe(J({},"__esModule",{value:!0}),e);var Yt={};G(Yt,{AzureDevOps:()=>_,AzureDevopsUtils:()=>ee,Bitbucket:()=>Q,BitbucketServer:()=>N,BitbucketServerUtils:()=>re,BitbucketUtils:()=>te,GitHub:()=>j,GitHubUtils:()=>se,GitLab:()=>F,GitLabUtils:()=>ne,Jira:()=>M,JiraUtils:()=>oe,Trello:()=>W,TrelloUtils:()=>ae,Utils:()=>Zt,default:()=>Kt});module.exports=rt(Yt);var E=100;var Le=tt(require("node-fetch")),Ge=globalThis.fetch||Le.default;var xe=e=>e.name==="fetch";var st=async e=>{let r=e.headers.get("content-type")||"",t=null;if(r.startsWith("application/json"))t=await e.json();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},ie=e=>xe(e)?async({url:r,...t})=>{let s=await e(r,t);return st(s)}:e;var D=class{constructor(r){this.config={...r,request:ie((r==null?void 0:r.request)||Ge)}}updateConfig(r){this.config={...this.config,...r,request:r.request?ie(r.request):this.config.request}}},x=class extends D{};var h=(e,r)=>{let t={};return e&&(t.Authorization=`${r?"Basic":"Bearer"} ${e}`),t};var C=(e,r={})=>h(r.token||e.token,r.isPAT||e.isPAT),Te=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 Oe="https://app.vssps.visualstudio.com/_apis",v="https://dev.azure.com",nt={active:"OPEN",completed:"MERGED",abandoned:"CLOSED"},ot={10:"APPROVED",5:"APPROVED",0:"REVIEW_REQUESTED",[-5]:"CHANGES_REQUESTED",[-10]:"CHANGES_REQUESTED"},ue=e=>({id:e.id,name:e.displayName,username:e.uniqueName||e.displayName,email:null,avatarUrl:e.imageUrl}),V=e=>e.startsWith("refs/heads/")?e.replace("refs/heads/",""):e,Ae=e=>{var r;return{id:e.pullRequestId.toString(),title:e.title,number:e.codeReviewId,state:nt[e.status],isDraft:e.isDraft,commentCount:null,upvoteCount:null,author:ue(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:V(e.targetRefName)},headRef:{name:V(e.sourceRefName)},url:Te(e),assignees:e.reviewers.map(ue),reviews:e.reviewers.filter(t=>t.vote!==0).map(t=>({reviewer:ue(t),state:ot[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})))??[]}},ke=(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:V(r.defaultBranch)}:null,permission:null}),at=(e,r)=>{var i,u;let t=e.fields,s=t["System.AssignedTo"],n=t["System.State"],a=t["System.WorkItemType"],o;return n&&a&&(o=(i=r[a])==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:(o==null?void 0:o.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()})))??[]}},_=class extends D{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:`${Oe}/profile/profiles/me`,headers:C(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:`${v}/${encodeURIComponent(r.namespace)}/_apis/ConnectionData`,headers:C(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:`${v}/${encodeURIComponent(r.repo.namespace)}/${encodeURIComponent(r.repo.project)}/_apis/git/repositories/${encodeURIComponent(r.repo.name)}/commits/${r.oid}`,headers:C(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:`${Oe}/accounts?memberId=${r.userId}&api-version=6.0`,headers:C(this.config,t)})).body.value.map(n=>({id:n.accountId,name:n.accountName}))}}async getAzureProjects(r,t={}){let s=new URL(`${v}/${encodeURIComponent(r.namespace)}/_apis/projects`);s.searchParams.set("$top",E.toString()),r.cursor&&s.searchParams.set("$skip",r.cursor);let n=await this.config.request({url:s.toString(),headers:C(this.config,t)}),a=n.headers["x-ms-continuationtoken"];return{pageInfo:{hasNextPage:!!a,endCursor:a||null},data:n.body.value.map(o=>({id:o.id,name:o.name,namespace:r.namespace}))}}async getRepo(r,t={}){if(!r.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let s=await this.config.request({url:`${v}/${encodeURIComponent(r.namespace)}/${encodeURIComponent(r.project)}/_apis/git/repositories/${encodeURIComponent(r.name)}`,headers:C(this.config,t)});return{data:ke(r.namespace,s.body)}}async getRepos(r,t={}){let s=[],n=[];return await Promise.all(r.map(async a=>{try{let o=await this.getRepo(a,t);s.push(o.data)}catch(o){n.push({input:a,error:o})}})),{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:`${v}/${encodeURIComponent(r.namespace)}/${encodeURIComponent(r.project)}/_apis/git/repositories`,headers:C(this.config,t)})).body.value.map(n=>ke(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(`${v}/${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",E.toString()),t.cursor&&n.searchParams.set("continuationToken",t.cursor);let a=await this.config.request({url:n.toString(),headers:C(this.config,s)}),o=a.headers["x-ms-continuationtoken"];return{pageInfo:{hasNextPage:!!o,endCursor:o||null},data:a.body.value.map(i=>({name:V(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:a,assigneeLogins:o,authorLogin:i}=r||{},u=n||1;if(!a.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let l="searchCriteria.status=1";return o&&o.length&&(l+=`&searchCriteria.reviewerId=${o[0]}`),i&&(l+=`&searchCriteria.creatorId=${i}`),await this.config.request({url:`${t.baseUrl||v}/${encodeURIComponent(a.namespace)}/${encodeURIComponent(a.project||"")}/_apis/git/repositories/${encodeURIComponent(a.name)}/pullRequests?${l}&%24top=${s}&%24skip=${(u-1)*s}`,headers:C(this.config,t)})}async getPullRequestsForRepo(r,t={}){let n=r.page||1,a=await this.getPullRequestsForRepoBase(r,t,100);return{pageInfo:{hasNextPage:a.body.value.length===100,nextPage:n+1},data:a.body.value.map(Ae)}}async getPullRequestsForRepos(r,t={}){if(!r.repos.every(a=>a.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 a=>{try{(await this.getPullRequestsForRepoBase({repo:a,...r},t)).body.value.forEach(i=>{n.push(Ae(i))})}catch(o){if(o.statusCode!==404&&o.statusCode!==401)throw o}})),{data:n}}async updatePullRequest(r,t,s,n){let{namespace:a,project:o,name:i}=r;return await this.config.request({method:"PATCH",url:`${n.baseUrl||v}/${encodeURIComponent(a)}/${encodeURIComponent(o||"")}/_apis/git/repositories/${i}/pullrequests/${t}?api-version=6.0`,body:s,headers:{...C(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,a={status:"abandoned"};if(!(await this.updatePullRequest(s,n,JSON.stringify(a),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:a}=r,o={lastMergeSourceCommit:{commitId:a},status:"completed"};if(!(await this.updatePullRequest(s,n,JSON.stringify(o),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:a}=r,o={isDraft:a};if(!(await this.updatePullRequest(s,n,JSON.stringify(o),t)).body.status)throw new Error("Could not set the pull request as draft")}async getIssuesForAzureProject(r,t={}){let{page:s,assigneeLogins:n,authorLogin:a,mentionLogin:o,statusByWorkItemIdByStatusId:i}=r||{},u=s||1,l=200,p=["[Microsoft.VSTS.Common.ClosedDate] = ''","[System.TeamProject] = @project","[Microsoft.VSTS.Common.ResolvedDate] = ''"];a&&p.push(`[System.CreatedBy] = '${a.replace("'","''")}'`),n&&n[0]&&p.push(`[System.AssignedTo] = '${n[0].replace("'","''")}'`),o&&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||v}/${encodeURIComponent(r.namespace)}/${encodeURIComponent(r.project)}/_apis/wit/wiql?api-version=6.0`,body:JSON.stringify({query:d}),method:"POST",headers:{...C(this.config,t),"Content-Type":"application/json"}}),g=c.body.workItems.slice((u-1)*l,l*u).map(y=>y.id);if(g.length==0)return{pageInfo:{hasNextPage:!1,nextPage:null},data:[]};let b=await this.config.request({url:`${t.baseUrl||v}/${encodeURIComponent(r.namespace)}/${encodeURIComponent(r.project)}/_apis/wit/workitemsbatch?api-version=6.0`,body:JSON.stringify({ids:g,$expand:"Links"}),method:"POST",headers:{...C(this.config,t),"Content-Type":"application/json"}});return{pageInfo:{hasNextPage:c.body.workItems.length>l*u,nextPage:u+1},data:b.body.value.map(y=>at(y,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:a,status:o}=r,i=[{op:"add",path:"/fields/System.State",value:o}];if(!((l=(await this.config.request({method:"PATCH",url:`${t.baseUrl||v}/${encodeURIComponent(s)}/${encodeURIComponent(n||"")}/_apis/wit/workitems/${a}?api-version=6.0`,body:JSON.stringify(i),headers:{...C(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||v}/${encodeURIComponent(s)}/${encodeURIComponent(n||"")}/_apis/wit/workitemtypes?api-version=6.0`,headers:{...C(this.config,t)}})).body.value}}async getLabelsForProject(r,t={}){let{namespace:s,project:n}=r;return{data:(await this.config.request({url:`${t.baseUrl||v}/${encodeURIComponent(s)}/${encodeURIComponent(n||"")}/_apis/wit/tags?api-version=6.0`,headers:{...C(this.config,t)}})).body.value.map(o=>({color:null,description:null,id:o.id,name:o.name}))}}};var S=(e,r={})=>h(r.token||e.token,r.isPAT||e.isPAT);var $="https://api.bitbucket.org/2.0",it={OPEN:"OPEN",MERGED:"MERGED",DECLINED:"CLOSED"},Ne=e=>({id:e.uuid,name:e.display_name||e.nickname,username:e.nickname||e.display_name,email:null,avatarUrl:e.links.avatar.href}),_e=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}},Qe=e=>{let r=e.id;return{id:r.toString(),title:e.title,number:r,state:it[e.state],isDraft:!1,commentCount:e.comment_count,upvoteCount:null,author:Ne(e.author),createdDate:new Date(e.created_on),updatedDate:new Date(e.updated_on),closedDate:null,repository:{name:e.source.repository.name,owner:{login:void 0}},headCommit:{buildStatus:null},baseRef:{name:e.destination.branch.name},headRef:{name:e.source.branch.name},url:e.links.html.href,assignees:null,reviews:null,additions:null,deletions:null,fileCount:null,commitCount:null,headRepository:null,mergeableState:"UNKNOWN"}},Q=class extends D{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:`${$}/user`,headers:S(this.config,r)});return{data:Ne(t.body)}}async getUserForCommit(r,t={}){var o;let n=(await this.config.request({url:`${$}/repositories/${r.repo.namespace}/${r.repo.name}/commit/${r.oid}`,headers:S(this.config,t)})).body.author,a=n.raw.match(/([^<]+)<(.+)>/);return{data:{name:a?a[1].trim():null,email:a?a[2]:null,avatarUrl:((o=n.user)==null?void 0:o.links.avatar.href)||null}}}async getRepo(r,t={}){let s=await this.config.request({url:`${$}/repositories/${r.namespace}/${r.name}`,headers:S(this.config,t)});return{data:_e(s.body)}}async getRepos(r,t={}){let s=[],n=[];return await Promise.all(r.map(async a=>{try{let o=await this.getRepo(a,t);s.push(o.data)}catch(o){n.push({input:a,error:o})}})),{data:s,errors:n}}async getReposForCurrentUser(r={},t={}){let s=new URL(`${$}/repositories`);s.searchParams.set("role","member"),s.searchParams.set("pagelen",E.toString()),r.cursor&&s.searchParams.set("after",r.cursor);let n=await this.config.request({url:s.toString(),headers:S(this.config,t)}),a=!!n.body.next,o=null;return n.body.next&&(o=new URL(n.body.next).searchParams.get("after")),{pageInfo:{hasNextPage:a,endCursor:o},data:n.body.values.map(_e)}}async getBranches(r,t={}){var o;let s=new URL(`${$}/repositories/${r.repo.namespace}/${r.repo.name}/refs/branches`);s.searchParams.set("page",((o=r.page)==null?void 0:o.toString())||"1"),s.searchParams.set("pagelen",E.toString());let n=await this.config.request({url:s.toString(),headers:S(this.config,t)}),a=!!n.body.next;return{pageInfo:{hasNextPage:a,nextPage:a?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(`${$}/repositories/${r.repo.namespace}/${r.repo.name}/refs/tags`);s.searchParams.set("pagelen",E.toString()),r.cursor&&s.searchParams.set("page",r.cursor);let n=await this.config.request({url:s.toString(),headers:S(this.config,t)}),a=!!n.body.next,o=null;return n.body.next&&(o=new URL(n.body.next).searchParams.get("page")),{pageInfo:{hasNextPage:a,endCursor:o},data:n.body.values.map(i=>{let u=new Date(i.target.date);return{name:i.name,commit:{oid:i.target.hash,authoredDate:u,committedDate:u}}})}}async getPullRequestsForRepoBase(r,t={}){var n;let s=new URL(`${$}/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:S(this.config,t)})}async getPullRequestsForRepo(r,t={}){let s=[],n=await this.getPullRequestsForRepoBase(r,t);n.body.values.forEach(o=>{if(r.authorLogin&&o.author.uuid!==r.authorLogin)return null;s.push(Qe(o))});let a=!!n.body.next;return{pageInfo:{hasNextPage:a,nextPage:a?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(o=>{if(r.authorLogin&&o.author.uuid!==r.authorLogin)return null;s.push(Qe(o))})}catch(a){if(a.statusCode!==404&&a.statusCode!==401)throw a}})),{data:s}}async closePullRequest(r,t={}){let{repo:{namespace:s,name:n},pullRequestId:a}=r;if(!(await this.config.request({method:"POST",url:`${$}/repositories/${s}/${n}/pullrequests/${a}/decline`,headers:S(this.config,t)})).body.title)throw new Error("Could not close pull request")}async mergePullRequest(r,t={}){let{repo:{namespace:s,name:n},pullRequestId:a}=r;if(!(await this.config.request({method:"POST",url:`${$}/repositories/${s}/${n}/pullrequests/${a}/merge`,headers:S(this.config,t)})).body.title)throw new Error("Could not merge pull request")}};var N=class extends x{getBaseUrl(r){let t=r.baseUrl||this.config.baseUrl;if(!t)throw new Error('Bitbucket Server requires "baseUrl"');return t}getRequestHeaders(r){return h(r.token||this.config.token)}async getRepo(r,t={}){var n,a,o;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:((a=s.body.links.clone.find(i=>i.name==="https"))==null?void 0:a.href)??null,sshUrl:((o=s.body.links.clone.find(i=>i.name==="ssh"))==null?void 0:o.href)??null,defaultBranch:null,permission:null}}}async getRepos(r,t={}){let s=[],n=[];return await Promise.all(r.map(async a=>{try{let o=await this.getRepo(a,t);s.push(o.data)}catch(o){n.push({input:a,error:o})}})),{data:s,errors:n}}};var de="https://api.github.com",ut=`${de}/graphql`,K=`
|
|
2
|
+
description
|
|
3
|
+
dueOn
|
|
4
|
+
id
|
|
5
|
+
number
|
|
6
|
+
state
|
|
7
|
+
title
|
|
8
|
+
url
|
|
9
|
+
`,je=/\/api\/v\d+$/,Z=`
|
|
10
|
+
color
|
|
11
|
+
description
|
|
12
|
+
id
|
|
13
|
+
name
|
|
14
|
+
`,lt=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.")},pt=(e,r)=>{let t=r.baseUrl||e.baseUrl;return t?(t=t.replace(/\/$/,""),lt(t),je.test(t)&&(t=t.replace(je,"")),`${t}/api/graphql`):ut},m=(e,r,t)=>{let s=h(t.token||e.token);return s["X-Github-Next-Global-ID"]="1",s["Content-Type"]="application/json",e.request({url:pt(e,t),method:"POST",headers:s,body:JSON.stringify(r)})},dt={user:!0,"user:email":!0,"read:user":!0},A=e=>e.some(r=>dt[r]),U=(e=!1,r=!1)=>`
|
|
2
15
|
__typename
|
|
3
16
|
id
|
|
4
17
|
databaseId
|
|
5
18
|
name
|
|
6
19
|
login
|
|
7
|
-
${
|
|
20
|
+
${r?"email":""}
|
|
8
21
|
avatarUrl${e?"(size: $avatarSize)":""}
|
|
9
|
-
`,
|
|
22
|
+
`,Be=(e=!1)=>`
|
|
10
23
|
__typename
|
|
11
24
|
id
|
|
12
25
|
databaseId
|
|
13
26
|
login
|
|
14
27
|
avatarUrl${e?"(size: $avatarSize)":""}
|
|
15
|
-
`,
|
|
28
|
+
`,ct=(e,r=!1)=>`
|
|
16
29
|
id
|
|
17
30
|
databaseId
|
|
18
31
|
number
|
|
@@ -20,10 +33,10 @@ title
|
|
|
20
33
|
state
|
|
21
34
|
author {
|
|
22
35
|
... on User {
|
|
23
|
-
${
|
|
36
|
+
${U(!1,r)}
|
|
24
37
|
}
|
|
25
38
|
... on Bot {
|
|
26
|
-
${
|
|
39
|
+
${Be(!1)}
|
|
27
40
|
}
|
|
28
41
|
}
|
|
29
42
|
commits(last: 1) {
|
|
@@ -83,7 +96,7 @@ updatedAt
|
|
|
83
96
|
closedAt
|
|
84
97
|
assignees(first: 100) {
|
|
85
98
|
nodes {
|
|
86
|
-
${
|
|
99
|
+
${U(!1,r)}
|
|
87
100
|
}
|
|
88
101
|
}
|
|
89
102
|
reviewRequests(first: 100) {
|
|
@@ -91,7 +104,7 @@ reviewRequests(first: 100) {
|
|
|
91
104
|
asCodeOwner
|
|
92
105
|
requestedReviewer {
|
|
93
106
|
... on User {
|
|
94
|
-
${
|
|
107
|
+
${U(!1,r)}
|
|
95
108
|
}
|
|
96
109
|
}
|
|
97
110
|
}
|
|
@@ -100,7 +113,7 @@ latestReviews(first: 100) {
|
|
|
100
113
|
nodes {
|
|
101
114
|
author {
|
|
102
115
|
... on User {
|
|
103
|
-
${
|
|
116
|
+
${U(!1,r)}
|
|
104
117
|
}
|
|
105
118
|
}
|
|
106
119
|
state
|
|
@@ -110,20 +123,70 @@ additions
|
|
|
110
123
|
deletions
|
|
111
124
|
changedFiles
|
|
112
125
|
mergeable
|
|
113
|
-
|
|
114
|
-
|
|
126
|
+
milestone {
|
|
127
|
+
${K}
|
|
128
|
+
}
|
|
129
|
+
labels(first: 100) {
|
|
130
|
+
nodes {
|
|
131
|
+
${Z}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
`,gt=(e=!1)=>`
|
|
135
|
+
id
|
|
136
|
+
databaseId
|
|
137
|
+
title
|
|
138
|
+
author {
|
|
139
|
+
... on User {
|
|
140
|
+
${U(!1,e)}
|
|
141
|
+
}
|
|
142
|
+
... on Bot {
|
|
143
|
+
${Be(!1)}
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
createdAt
|
|
147
|
+
number
|
|
148
|
+
updatedAt
|
|
149
|
+
url
|
|
150
|
+
reactions(content: THUMBS_UP) {
|
|
151
|
+
totalCount
|
|
152
|
+
}
|
|
153
|
+
repository {
|
|
154
|
+
name
|
|
155
|
+
owner {
|
|
156
|
+
login
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
comments {
|
|
160
|
+
totalCount
|
|
161
|
+
}
|
|
162
|
+
assignees(first: 100) {
|
|
163
|
+
nodes {
|
|
164
|
+
${U(!1,e)}
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
state
|
|
168
|
+
milestone {
|
|
169
|
+
${K}
|
|
170
|
+
}
|
|
171
|
+
labels(first: 100) {
|
|
172
|
+
nodes {
|
|
173
|
+
${Z}
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
`,mt={"-linked":"-linked",archived:"archived",assignee:"assignee",author:"author",base:"base",closed:"closed",commenter:"commenter",comments:"comments",created:"created",draft:"draft",head:"head",label:"label",language:"language",linked:"linked",in:"in",interactions:"interactions",involves:"involves",is:"is",mentions:"mentions",merged:"merged",milestone:"milestone",no:"no",org:"org",project:"project",reactions:"reactions",repo:"repo",review:"review","reviewed-by":"reviewed-by","review-requested":"review-requested",state:"state",status:"status",team:"team","team-review-requested":"team-review-requested",type:"type",updated:"updated",user:"user","user-review-requested":"user-review-requested"},ht=new RegExp('(([^\\s]+:)?\\"(?:[^\\"\\\\]|\\\\.)*\\"?)|([^\\"\\s]+)',"g"),ce=e=>{let r=[];return(e.match(ht)??[]).forEach(s=>{if(s.includes(":")&&s!="is:closed"){let n=s.split(":")[0];mt[n]&&r.push(s)}}),r},ge=(e,r,t,s,n=!1)=>{let a=e==="issue";return{query:`
|
|
177
|
+
query SearchIssuesOrPullRequests($query: String! $after: String) {
|
|
115
178
|
search(type:ISSUE query:$query first:100 after:$after) {
|
|
116
179
|
pageInfo {
|
|
117
180
|
hasNextPage
|
|
118
181
|
endCursor
|
|
119
182
|
}
|
|
120
183
|
nodes {
|
|
121
|
-
... on PullRequest {
|
|
122
|
-
${
|
|
184
|
+
... on ${a?"Issue":"PullRequest"} {
|
|
185
|
+
${a?gt(s):ct(n,s)}
|
|
123
186
|
}
|
|
124
187
|
}
|
|
125
188
|
}
|
|
126
|
-
}`,variables:{query:`is
|
|
189
|
+
}`,variables:{query:`is:${e} is:open ${r}`,after:t}}},ft="Field 'isDraft' doesn't exist on type 'PullRequest'",Fe=(e=[])=>e.some(r=>(r==null?void 0:r.message)===ft);var me=`
|
|
127
190
|
id
|
|
128
191
|
databaseId
|
|
129
192
|
owner {
|
|
@@ -136,13 +199,13 @@ defaultBranchRef {
|
|
|
136
199
|
name
|
|
137
200
|
}
|
|
138
201
|
viewerPermission
|
|
139
|
-
`,
|
|
202
|
+
`,fe={__typename:"User",id:"U_kgDNJ5k",databaseId:10137,name:"Deleted user",login:"ghost",email:"",avatarUrl:"https://avatars.githubusercontent.com/u/10137?v=4"},Rt={APPROVED:"APPROVED",CHANGES_REQUESTED:"CHANGES_REQUESTED",COMMENTED:"COMMENTED",REVIEW_REQUESTED:"REVIEW_REQUESTED"},It={MERGEABLE:"MERGEABLE",CONFLICTING:"CONFLICTS",UNKNOWN:"UNKNOWN"},bt={OPEN:"OPEN",CLOSED:"CLOSED"},Re=e=>({color:e.color,description:e.description,graphQLId:e.id,id:null,name:e.name}),he=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}),yt={OPEN:"OPEN",CLOSED:"CLOSED",MERGED:"MERGED"},q=e=>({id:e.databaseId.toString(),graphQLId:e.id,name:e.name??e.login,username:e.login,email:e.email??null,avatarUrl:e.avatarUrl}),Pt=e=>{var l,p,d,c,g,b,y,P,I,f;let r=null;e.author?r=(e.author.__typename==="Bot",e.author):r=fe;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,a=t==null?void 0:t.oid,o=n===a?(g=(c=t==null?void 0:t.status)==null?void 0:c.contexts)==null?void 0:g[0]:null,i=(((b=e.reviewRequests)==null?void 0:b.nodes)||[]).filter(w=>!w.asCodeOwner),u=(y=e.headRepository)==null?void 0:y.url;return u&&!u.endsWith(".git")&&(u=`${u}.git`),{id:e.databaseId.toString(),graphQLId:e.id,title:e.title,number:e.number,state:yt[e.state],commentCount:e.comments.totalCount,upvoteCount:e.reactions.totalCount,author:r?q(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:o||null},headRef:e.headRef?{name:e.headRef.name}:null,baseRef:e.baseRef?{name:e.baseRef.name}:null,url:e.url,updatedDate:new Date(e.updatedAt),closedDate:e.closedAt?new Date(e.closedAt):null,assignees:e.assignees.nodes?e.assignees.nodes.map(q):null,reviews:i.map(w=>({reviewer:q(w.requestedReviewer),state:"REVIEW_REQUESTED"})).concat((((P=e.latestReviews)==null?void 0:P.nodes)||[]).map(w=>{let L=w.author||fe;return{reviewer:q(L),state:Rt[w.state]}})),additions:e.additions,deletions:e.deletions,fileCount:e.changedFiles,commitCount:e.commits.totalCount,mergeableState:It[e.mergeable],milestone:e.milestone?Ie(e.milestone):null,labels:((f=(I=e.labels)==null?void 0:I.nodes)==null?void 0:f.map(Re))??[]}},wt=e=>{var t,s;let r=null;return e.author?r=(e.author.__typename==="Bot",e.author):r=fe,{id:e.databaseId.toString(),graphQLId:e.id,number:e.number,title:e.title,author:q(r),commentCount:e.comments.totalCount,createdDate:new Date(e.createdAt),description:null,state:{name:bt[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(q):[],upvoteCount:e.reactions.totalCount,milestone:e.milestone?Ie(e.milestone):null,labels:((s=(t=e.labels)==null?void 0:t.nodes)==null?void 0:s.map(Re))??[]}},Ie=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}),j=class extends x{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 o=(await m(this.config,{query:"query { rateLimit(dryRun: true) { __typename } }"},t)).headers["x-oauth-scopes"];n=o?o.split(", "):[],this._scopesCache[s]=n}return n}getEnterpriseAvatarUrlIfNeeded(t,s,n){let a=n.baseUrl||this.config.baseUrl;return!a||a.startsWith(de)?t:s?`https://avatars.githubusercontent.com/u/e?email=${encodeURIComponent(s)}`:""}async getCurrentUser(t={}){var o;let s=await this.getScopes(t),a=(o=(await m(this.config,{query:`
|
|
140
203
|
query getCurrentUser {
|
|
141
204
|
viewer {
|
|
142
|
-
${
|
|
205
|
+
${U(!1,A(s))}
|
|
143
206
|
}
|
|
144
207
|
}
|
|
145
|
-
`},
|
|
208
|
+
`},t)).body.data)==null?void 0:o.viewer;if(!a)throw new Error("Current user not found.");return{data:q(a)}}async getUserForCommit(t,s={}){var i,u;let a=(i=(await m(this.config,{query:`
|
|
146
209
|
query getUserForCommit(
|
|
147
210
|
$owner: String!
|
|
148
211
|
$name: String!
|
|
@@ -161,23 +224,23 @@ query getUserForCommit(
|
|
|
161
224
|
}
|
|
162
225
|
}
|
|
163
226
|
}
|
|
164
|
-
`,variables:{owner:
|
|
227
|
+
`,variables:{owner:t.repo.namespace,name:t.repo.name,oid:t.oid,avatarSize:t.avatarSize}},s)).body.data)==null?void 0:i.repository;if(!a)throw new Error("Repository not found.");let o=(u=a.object)==null?void 0:u.author;if(!o)throw new Error("Commit not found.");return{data:{name:o.name,email:o.email,avatarUrl:this.getEnterpriseAvatarUrlIfNeeded(o.avatarUrl,o.email,s)}}}async getAccountForEmail(t,s={}){var i,u,l;let n=await this.getScopes(s),o=(l=(u=(i=(await m(this.config,{query:`
|
|
165
228
|
query getAccountForEmail($query: String! $avatarSize: Int) {
|
|
166
229
|
search(query: $query, type: USER, first: 1) {
|
|
167
230
|
nodes {
|
|
168
231
|
... on User {
|
|
169
|
-
${
|
|
232
|
+
${U(!0,A(n))}
|
|
170
233
|
}
|
|
171
234
|
}
|
|
172
235
|
}
|
|
173
236
|
}
|
|
174
|
-
`,variables:{query:`in:email ${
|
|
237
|
+
`,variables:{query:`in:email ${t.email}`,avatarSize:t.avatarSize}},s)).body.data)==null?void 0:i.search)==null?void 0:u.nodes)==null?void 0:l[0];if(!o)throw new Error("User not found.");return{data:q({...o,avatarUrl:this.getEnterpriseAvatarUrlIfNeeded(o.avatarUrl,o.email,s)})}}async getAccountForUsername(t,s={}){var i;let n=await this.getScopes(s),o=(i=(await m(this.config,{query:`
|
|
175
238
|
query getUserForUsername($login: String! $avatarSize: Int) {
|
|
176
239
|
user(login: $login) {
|
|
177
|
-
${
|
|
240
|
+
${U(!0,A(n))}
|
|
178
241
|
}
|
|
179
242
|
}
|
|
180
|
-
`,variables:{login:
|
|
243
|
+
`,variables:{login:t.username,avatarSize:t.avatarSize}},s)).body.data)==null?void 0:i.user;if(!o)throw new Error("User not found.");return{data:q({...o,avatarUrl:this.getEnterpriseAvatarUrlIfNeeded(o.avatarUrl,o.email,s)})}}async getOrgsForCurrentUser(t={},s={}){var o,i;let n=await m(this.config,{query:`
|
|
181
244
|
query getOrgsForCurrentUser($cursor: String, $first: Int!) {
|
|
182
245
|
viewer {
|
|
183
246
|
organizations(first: $first after: $cursor) {
|
|
@@ -196,22 +259,22 @@ query getOrgsForCurrentUser($cursor: String, $first: Int!) {
|
|
|
196
259
|
}
|
|
197
260
|
}
|
|
198
261
|
}
|
|
199
|
-
`,variables:{cursor:
|
|
262
|
+
`,variables:{cursor:t.cursor,first:E}},s);if(!((o=n.body.data)!=null&&o.viewer.organizations))throw new Error(((i=n.body.errors)==null?void 0:i[0].message)||n.statusText||"Unknown error");let a=n.body.data.viewer.organizations.nodes||[];return{pageInfo:n.body.data.viewer.organizations.pageInfo,data:a.map(u=>({id:u.databaseId.toString(),graphQLId:u.id,username:u.login,name:u.name||null,email:u.email||null,avatarUrl:u.avatarUrl}))}}async getRepo(t,s={}){var a;let n=await m(this.config,{query:`
|
|
200
263
|
query getRepo($owner: String!, $name: String!) {
|
|
201
264
|
repository(owner: $owner, name: $name) {
|
|
202
|
-
${
|
|
265
|
+
${me}
|
|
203
266
|
}
|
|
204
267
|
}
|
|
205
|
-
`,variables:{owner:
|
|
206
|
-
getRepo_${
|
|
207
|
-
${
|
|
268
|
+
`,variables:{owner:t.namespace,name:t.name}},s);if(!((a=n.body.data)!=null&&a.repository))throw new Error(`Repository ${t.namespace}/${t.name} not found`);return{data:he(n.body.data.repository)}}async getRepos(t,s={}){let n=t.map(({namespace:u,name:l},p)=>`
|
|
269
|
+
getRepo_${p}: repository(owner: "${u}", name: "${l}") {
|
|
270
|
+
${me}
|
|
208
271
|
}
|
|
209
272
|
`).join(`
|
|
210
|
-
`),
|
|
273
|
+
`),a=await m(this.config,{query:`
|
|
211
274
|
query batchGetRepos {
|
|
212
275
|
${n}
|
|
213
276
|
}
|
|
214
|
-
`},s);if(!
|
|
277
|
+
`},s);if(!a.body.data)throw new Error(a.statusText||"Unknown error");let o=[],i=[];return t.forEach((u,l)=>{let p=a.body.data[`getRepo_${l}`];p?o.push(he(p)):i.push({input:u})}),{data:o,errors:i}}async getReposForUsernames(t,s={}){var o;if(!t.usernames.length)return{pageInfo:{endCursor:null,hasNextPage:!1},data:[]};let n=await m(this.config,{query:`
|
|
215
278
|
query getReposForUsernames($query: String!, $cursor: String, $first: Int!) {
|
|
216
279
|
search(query: $query, type: REPOSITORY, first: $first, after: $cursor) {
|
|
217
280
|
pageInfo {
|
|
@@ -220,12 +283,12 @@ query getReposForUsernames($query: String!, $cursor: String, $first: Int!) {
|
|
|
220
283
|
}
|
|
221
284
|
nodes {
|
|
222
285
|
... on Repository {
|
|
223
|
-
${
|
|
286
|
+
${me}
|
|
224
287
|
}
|
|
225
288
|
}
|
|
226
289
|
}
|
|
227
290
|
}
|
|
228
|
-
`,variables:{query:`fork:true ${
|
|
291
|
+
`,variables:{query:`fork:true ${t.usernames.map(i=>`user:${i}`).join(" ")}`,cursor:t.cursor,first:E}},s);if(!n.body.data)throw new Error(((o=n.body.errors)==null?void 0:o[0].message)||n.statusText||"Unknown error");let a=n.body.data.search.nodes||[];return{pageInfo:n.body.data.search.pageInfo,data:a.map(he)}}async getReposForOwners(t,s={}){return this.getReposForUsernames({usernames:t.owners.filter(n=>n.username).map(n=>n.username),cursor:t.cursor},s)}async getRefs(t,s,n={}){var u;let o=(u=(await m(this.config,{query:`
|
|
229
292
|
query getRefs($owner: String!, $name: String!, $refPrefix: String!, $cursor: String, $first: Int!) {
|
|
230
293
|
repository(owner: $owner, name: $name) {
|
|
231
294
|
refs(refPrefix: $refPrefix first: $first after: $cursor) {
|
|
@@ -246,7 +309,7 @@ query getRefs($owner: String!, $name: String!, $refPrefix: String!, $cursor: Str
|
|
|
246
309
|
}
|
|
247
310
|
}
|
|
248
311
|
}
|
|
249
|
-
`,variables:{owner:s.repo.namespace,name:s.repo.name,refPrefix:
|
|
312
|
+
`,variables:{owner:s.repo.namespace,name:s.repo.name,refPrefix:t,cursor:s.cursor,first:E}},n)).body.data)==null?void 0:u.repository;if(!o)throw new Error("Repository not found.");let i=o.refs;return i?{pageInfo:i.pageInfo,data:(i.nodes||[]).map(l=>{var d;let p=(d=l.target)!=null&&d.oid?l.target:null;return{name:l.name,commit:p?{oid:p.oid,authoredDate:new Date(p.authoredDate),committedDate:new Date(p.committedDate)}:null}})}:{pageInfo:{endCursor:null,hasNextPage:!1},data:[]}}async getBranches(t,s={}){return this.getRefs("refs/heads/",t,s)}async getTags(t,s={}){return this.getRefs("refs/tags/",t,s)}async getBlame(t,s={}){var i;let a=(i=(await m(this.config,{query:`
|
|
250
313
|
query getBlame($owner: String!, $name: String!, $ref: String!, $path: String!) {
|
|
251
314
|
repository(owner: $owner, name: $name) {
|
|
252
315
|
object(expression: $ref) {
|
|
@@ -285,90 +348,98 @@ query getBlame($owner: String!, $name: String!, $ref: String!, $path: String!) {
|
|
|
285
348
|
}
|
|
286
349
|
}
|
|
287
350
|
}
|
|
288
|
-
`,variables:{owner:
|
|
351
|
+
`,variables:{owner:t.repo.namespace,name:t.repo.name,ref:t.ref,path:t.path}},s)).body.data)==null?void 0:i.repository;if(!a)throw new Error("Repository not found.");let o=a.object;if(!o||!("blame"in o))throw new Error("Ref not found.");if(o.blame.ranges.length===0)throw new Error("File not found.");return{data:{ranges:o.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),a=A(n),o=d=>{let c=d&&typeof t.isDraft=="boolean"?`${t.query} draft:${t.isDraft}`:t.query;return ge("pr",c,t.cursor,a,d)},i=await m(this.config,o(!0),s);i.body.errors&&Fe(i.body.errors)&&(this.config.baseUrl||s.baseUrl)&&(i=await m(this.config,o(!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(Pt))||[]}}async searchIssues(t,s={}){var u,l;let n=await this.getScopes(s),a=A(n),o=await m(this.config,ge("issue",t.query,t.cursor,a),s),{data:i}=o.body;if(!i)throw new Error(((u=o.body.errors)==null?void 0:u[0].message)||o.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(wt))||[]}}async getPullRequestsAssociatedWithUser(t,s={}){var g;let[n,a,o]=((g=t.cursor)==null?void 0:g.split(";"))||[void 0,void 0,void 0];if(t.cursor&&n==="null"&&a==="null"&&o==="null")return{pageInfo:{hasNextPage:!1,endCursor:"null;null;null"},data:[]};let[i,u,l]=await Promise.all([this.searchPullRequests({query:`author:${t.username}`,cursor:n},s),this.searchPullRequests({query:`assignee:${t.username}`,cursor:a},s),this.searchPullRequests({query:`review-requested:${t.username}`,cursor:o},s)]),p={},d=[],c=b=>{p[b.id]||(p[b.id]=!0,d.push(b))};return i.data.forEach(c),u.data.forEach(c),l.data.forEach(c),{pageInfo:{hasNextPage:i.pageInfo.hasNextPage||u.pageInfo.hasNextPage||l.pageInfo.hasNextPage,endCursor:`${(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"};${(l==null?void 0:l.pageInfo.hasNextPage)&&(l==null?void 0:l.pageInfo.endCursor)||"null"}`},data:d}}async getPullRequestsForRepos(t,s={}){let{assigneeLogins:n,updatedBefore:a,authorLogin:o,repos:i,reviewRequestedLogin:u,startQuery:l,mentionLogin:p}=t,d=ce(l||"");return i.forEach(c=>{d.push(`repo:${c.namespace}/${c.name}`)}),n&&n.forEach(c=>{d.push(`assignee:${c}`)}),a&&d.push(`updated:<${a}`),o&&d.push(`author:${o}`),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,a=`mutation ClosePullRequest($pullRequestGraphQLId: ID!) {
|
|
289
352
|
closePullRequest(input: { pullRequestId: $pullRequestGraphQLId }) {
|
|
290
353
|
pullRequest {
|
|
291
354
|
id
|
|
292
355
|
}
|
|
293
356
|
}
|
|
294
|
-
}`;if(!((
|
|
357
|
+
}`;if(!((l=(u=(i=(await m(this.config,{query:`${a}`,variables:{pullRequestGraphQLId:n}},s)).body.data)==null?void 0:i.closePullRequest)==null?void 0:u.pullRequest)!=null&&l.id))throw new Error("Could not close pull request")}async mergePullRequest(t,s={}){var u,l,p;let{pullRequestGraphQLId:n,expectedSourceSha:a}=t,o=`mutation MergePullRequest($pullRequestGraphQLId: ID!, $expectedSourceSha: GitObjectID!) {
|
|
295
358
|
mergePullRequest(input: { pullRequestId: $pullRequestGraphQLId, expectedHeadOid: $expectedSourceSha }) {
|
|
296
359
|
pullRequest {
|
|
297
360
|
id
|
|
298
361
|
}
|
|
299
362
|
}
|
|
300
|
-
}`;if(!((
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
) {
|
|
305
|
-
search(
|
|
306
|
-
type: ISSUE
|
|
307
|
-
first: 100
|
|
308
|
-
after: $after
|
|
309
|
-
query: $search
|
|
310
|
-
) {
|
|
311
|
-
nodes {
|
|
312
|
-
... on Issue {
|
|
313
|
-
id
|
|
314
|
-
databaseId
|
|
315
|
-
title
|
|
316
|
-
author {
|
|
317
|
-
... on User {
|
|
318
|
-
${$(!1,o)}
|
|
319
|
-
}
|
|
320
|
-
... on Bot {
|
|
321
|
-
${ue(!1)}
|
|
322
|
-
}
|
|
323
|
-
}
|
|
324
|
-
createdAt
|
|
325
|
-
number
|
|
326
|
-
updatedAt
|
|
327
|
-
url
|
|
328
|
-
reactions(content: THUMBS_UP) {
|
|
329
|
-
totalCount
|
|
330
|
-
}
|
|
331
|
-
repository {
|
|
332
|
-
name
|
|
333
|
-
owner {
|
|
334
|
-
login
|
|
335
|
-
}
|
|
336
|
-
}
|
|
337
|
-
comments {
|
|
338
|
-
totalCount
|
|
339
|
-
}
|
|
340
|
-
assignees(first: 100) {
|
|
341
|
-
nodes {
|
|
342
|
-
${$(!1,o)}
|
|
343
|
-
}
|
|
344
|
-
}
|
|
345
|
-
}
|
|
363
|
+
}`;if(!((p=(l=(u=(await m(this.config,{query:`${o}`,variables:{pullRequestGraphQLId:n,expectedSourceSha:a}},s)).body.data)==null?void 0:u.mergePullRequest)==null?void 0:l.pullRequest)!=null&&p.id))throw new Error("Could not merge pull request")}async setPullRequestMilestone(t,s={}){var u,l,p;let{pullRequestGraphQLId:n,milestoneGraphQLId:a}=t,o=`mutation SetPullRequestMilestone($pullRequestGraphQLId: ID!, $milestoneGraphQLId: ID) {
|
|
364
|
+
updatePullRequest(input: { pullRequestId: $pullRequestGraphQLId, milestoneId: $milestoneGraphQLId }) {
|
|
365
|
+
pullRequest {
|
|
366
|
+
id
|
|
346
367
|
}
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
368
|
+
}
|
|
369
|
+
}`;if(!((p=(l=(u=(await m(this.config,{query:`${o}`,variables:{pullRequestGraphQLId:n,milestoneGraphQLId:a}},s)).body.data)==null?void 0:u.updatePullRequest)==null?void 0:l.pullRequest)!=null&&p.id))throw new Error("Could not set milestone of pull request")}async markPullRequestReadyForReview(t,s){var o,i,u;let n=`mutation MarkReadyToReview($pullRequestGraphQLId: ID!) {
|
|
370
|
+
markPullRequestReadyForReview(input: { pullRequestId: $pullRequestGraphQLId }) {
|
|
371
|
+
pullRequest {
|
|
372
|
+
id
|
|
350
373
|
}
|
|
351
374
|
}
|
|
352
|
-
}
|
|
353
|
-
|
|
375
|
+
}`;if(!((u=(i=(o=(await m(this.config,{query:n,variables:{pullRequestGraphQLId:t}},s)).body.data)==null?void 0:o.markPullRequestReadyForReview)==null?void 0:i.pullRequest)!=null&&u.id))throw new Error("Could not mark pull request ready to review")}async convertPullRequestToDraft(t,s){var o,i,u;let n=`mutation ConvertToDraft($pullRequestGraphQLId: ID!) {
|
|
376
|
+
convertPullRequestToDraft(input: { pullRequestId: $pullRequestGraphQLId }) {
|
|
377
|
+
pullRequest {
|
|
378
|
+
id
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
}`;if(!((u=(i=(o=(await m(this.config,{query:n,variables:{pullRequestGraphQLId:t}},s)).body.data)==null?void 0:o.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:a}=t;if(a){await this.convertPullRequestToDraft(n,s);return}await this.markPullRequestReadyForReview(n,s)}async getIssuesAssociatedWithUser(t,s={}){var d;let[n,a]=((d=t.cursor)==null?void 0:d.split(";"))||[void 0,void 0];if(t.cursor&&n==="null"&&a==="null")return{pageInfo:{hasNextPage:!1,endCursor:"null;null"},data:[]};let[o,i]=await Promise.all([this.searchIssues({query:`author:${t.username}`,cursor:n},s),this.searchIssues({query:`assignee:${t.username}`,cursor:a},s)]),u={},l=[],p=c=>{u[c.id]||(u[c.id]=!0,l.push(c))};return o.data.forEach(p),i.data.forEach(p),{pageInfo:{hasNextPage:o.pageInfo.hasNextPage||i.pageInfo.hasNextPage,endCursor:`${(o==null?void 0:o.pageInfo.hasNextPage)&&(o==null?void 0:o.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=ce(t.startQuery||""),{cursor:a,assigneeLogins:o,updatedBefore:i,authorLogin:u,mentionLogin:l}=t;return t.repos.forEach(p=>{n.push(`repo:${p.namespace}/${p.name}`)}),o&&o.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:a},s)}async closeIssueWithReason(t,s,n){var i,u,l;let a=`mutation CloseIssueWithReason($issueGraphQLId: ID!, $closeReason: IssueClosedStateReason!) {
|
|
354
382
|
closeIssue(input: { issueId: $issueGraphQLId, stateReason: $closeReason }) {
|
|
355
383
|
issue {
|
|
356
384
|
id
|
|
357
385
|
}
|
|
358
386
|
}
|
|
359
|
-
}`;if(!((
|
|
387
|
+
}`;if(!((l=(u=(i=(await m(this.config,{query:a,variables:{issueGraphQLId:t,closeReason:s}},n)).body.data)==null?void 0:i.closeIssue)==null?void 0:u.issue)!=null&&l.id))throw new Error("Could not close issue with reason")}async closeIssueWithoutReason(t,s){var o,i,u;let n=`mutation SetIssueState($issueGraphQLId: ID!) {
|
|
360
388
|
updateIssue(input: { id: $issueGraphQLId, state: CLOSED }) {
|
|
361
389
|
issue {
|
|
362
390
|
id
|
|
363
391
|
}
|
|
364
392
|
}
|
|
365
|
-
}`;if(!((u=(i=(
|
|
393
|
+
}`;if(!((u=(i=(o=(await m(this.config,{query:n,variables:{issueGraphQLId:t}},s)).body.data)==null?void 0:o.updateIssue)==null?void 0:i.issue)!=null&&u.id))throw new Error("Could not close issue")}async reopenIssue(t,s){var o,i,u;let n=`mutation ReOpenIssue($issueGraphQLId: ID!) {
|
|
366
394
|
reopenIssue(input: { issueId: $issueGraphQLId }) {
|
|
367
395
|
issue {
|
|
368
396
|
id
|
|
369
397
|
}
|
|
370
398
|
}
|
|
371
|
-
}`;if(!((u=(i=(
|
|
399
|
+
}`;if(!((u=(i=(o=(await m(this.config,{query:n,variables:{issueGraphQLId:t}},s)).body.data)==null?void 0:o.reopenIssue)==null?void 0:i.issue)!=null&&u.id))throw new Error("Could not reopen issue")}async setIssueStatus(t,s={}){let{issueGraphQLId:n,status:a,closeReason:o}=t;if(o&&a=="OPEN")throw new Error("Did not expect closeReason to be set when trying to reopen issue");a=="OPEN"?await this.reopenIssue(n,s):a=="CLOSED"&&!o?await this.closeIssueWithoutReason(n,s):o&&await this.closeIssueWithReason(n,o,s)}async setIssueMilestone(t,s={}){var u,l,p;let{issueGraphQLId:n,milestoneGraphQLId:a}=t,o=`mutation SetIssueMilestone($issueGraphQLId: ID!, $milestoneGraphQLId: ID) {
|
|
400
|
+
updateIssue(input: { id: $issueGraphQLId, milestoneId: $milestoneGraphQLId }) {
|
|
401
|
+
issue {
|
|
402
|
+
id
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
}`;if(!((p=(l=(u=(await m(this.config,{query:`${o}`,variables:{issueGraphQLId:n,milestoneGraphQLId:a}},s)).body.data)==null?void 0:u.updateIssue)==null?void 0:l.issue)!=null&&p.id))throw new Error("Could not set milestone of issue")}async getMilestonesForRepo(t,s={}){var u,l,p,d;let{repo:{namespace:n,name:a},cursor:o}=t,i=await m(this.config,{query:`
|
|
406
|
+
query getLabelsForRepo($owner: String!, $name: String! $cursor: String, $first: Int!) {
|
|
407
|
+
repository(owner: $owner, name: $name) {
|
|
408
|
+
milestones(first: $first, after: $cursor) {
|
|
409
|
+
nodes {
|
|
410
|
+
${K}
|
|
411
|
+
}
|
|
412
|
+
pageInfo {
|
|
413
|
+
endCursor
|
|
414
|
+
hasNextPage
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
`,variables:{owner:n,name:a,cursor:o,first:E}},s);if(!i.body.data)throw new Error(((u=i.body.errors)==null?void 0:u[0].message)||i.statusText||"Unknown error");return{pageInfo:((l=i.body.data.repository.milestones)==null?void 0:l.pageInfo)??{endCursor:null,hasNextPage:!1},data:((d=(p=i.body.data.repository.milestones)==null?void 0:p.nodes)==null?void 0:d.map(Ie))??[]}}async getLabelsForRepo(t,s={}){var u,l,p,d;let{repo:{namespace:n,name:a},cursor:o}=t,i=await m(this.config,{query:`
|
|
420
|
+
query getLabelsForRepo($owner: String!, $name: String! $cursor: String, $first: Int!) {
|
|
421
|
+
repository(owner: $owner, name: $name) {
|
|
422
|
+
labels(first: $first, after: $cursor) {
|
|
423
|
+
nodes {
|
|
424
|
+
${Z}
|
|
425
|
+
}
|
|
426
|
+
pageInfo {
|
|
427
|
+
endCursor
|
|
428
|
+
hasNextPage
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
`,variables:{owner:n,name:a,cursor:o,first:E}},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(Re))??[]}}};var Ct="https://gitlab.com/api/v4",Et="https://gitlab.com/api/graphql",Me=/\/api\/v\d+$/,ze=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.")},be=(e,r)=>{let t=r.baseUrl||e.baseUrl;return t?(t=t.replace(/\/$/,""),ze(t),t):Ct},vt=(e,r)=>{let t=r.baseUrl||e.baseUrl;return t?(t=t.replace(/\/$/,""),ze(t),Me.test(t)&&(t=t.replace(Me,"")),`${t}/api/graphql`):Et},R=(e,r,t)=>{let s=h(t.token||e.token);return e.request({url:vt(e,t),method:"POST",headers:{...s,"Content-Type":"application/json"},body:JSON.stringify(r)})};var Dt={CAN_BE_MERGED:"MERGEABLE",CANNOT_BE_MERGED:"CONFLICTS",CANNOT_BE_MERGED_RECHECK:"UNKNOWN",UNCHECKED:"UNKNOWN",CHECKING:"UNKNOWN"},Ee="gid://gitlab/User/",B="gid://gitlab/Project/",St="gid://gitlab/MergeRequest/",Ut="gid://gitlab/Issue/",$t="gid://gitlab/ProjectLabel/",Je="gid://gitlab/Milestone/",ve=`
|
|
434
|
+
description
|
|
435
|
+
dueDate
|
|
436
|
+
id
|
|
437
|
+
iid
|
|
438
|
+
startDate
|
|
439
|
+
state
|
|
440
|
+
title
|
|
441
|
+
webPath
|
|
442
|
+
`,ye=`
|
|
372
443
|
id
|
|
373
444
|
path
|
|
374
445
|
fullPath
|
|
@@ -384,7 +455,12 @@ name
|
|
|
384
455
|
username
|
|
385
456
|
publicEmail
|
|
386
457
|
avatarUrl
|
|
387
|
-
`,
|
|
458
|
+
`,De=`
|
|
459
|
+
color
|
|
460
|
+
description
|
|
461
|
+
id
|
|
462
|
+
title
|
|
463
|
+
`,Pe=`
|
|
388
464
|
author {
|
|
389
465
|
${T}
|
|
390
466
|
}
|
|
@@ -398,6 +474,11 @@ description
|
|
|
398
474
|
dueDate
|
|
399
475
|
id
|
|
400
476
|
iid
|
|
477
|
+
labels {
|
|
478
|
+
nodes {
|
|
479
|
+
${De}
|
|
480
|
+
}
|
|
481
|
+
}
|
|
401
482
|
state
|
|
402
483
|
title
|
|
403
484
|
type
|
|
@@ -405,7 +486,10 @@ updatedAt
|
|
|
405
486
|
upvotes
|
|
406
487
|
userNotesCount
|
|
407
488
|
webUrl
|
|
408
|
-
|
|
489
|
+
milestone {
|
|
490
|
+
${ve}
|
|
491
|
+
}
|
|
492
|
+
`,We=`
|
|
409
493
|
id
|
|
410
494
|
state
|
|
411
495
|
author {
|
|
@@ -442,13 +526,18 @@ reviewers {
|
|
|
442
526
|
}
|
|
443
527
|
}
|
|
444
528
|
}
|
|
445
|
-
mergeStatusEnum
|
|
529
|
+
mergeStatusEnum
|
|
530
|
+
labels {
|
|
531
|
+
nodes {
|
|
532
|
+
${De}
|
|
533
|
+
}
|
|
534
|
+
}`,O=e=>`${e.namespace}/${e.name}`,qt=e=>`${e.namespace}/${e.name}`,we=e=>{var r;return{id:e.id.replace(B,""),graphQLId:e.id,namespace:e.fullPath.split("/").slice(0,-1).join("/"),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}},Lt={opened:"OPEN",merged:"MERGED",closed:"CLOSED"},k=e=>({id:e.id.replace(Ee,""),graphQLId:e.id,name:e.name,username:e.username,email:e.publicEmail,avatarUrl:e.avatarUrl}),Se=e=>({color:e.color,description:e.description,id:e.id.replace($t,""),graphQLId:e.id,name:e.title}),He=(e,r)=>{var t,s,n,a,o,i,u;return{id:e.id.replace(St,""),graphQLId:e.id,title:e.title,number:parseInt(e.iid,10),state:Lt[e.state],commentCount:e.userNotesCount||0,upvoteCount:e.upvotes,author:e.author?k(e.author):null,createdDate:new Date(e.createdAt),isDraft:e.draft,repository:{name:r.name,owner:{login:r.owner}},headRepository:null,headCommit:{buildStatus:null},baseRef:{name:e.targetBranch},headRef:{name:e.sourceBranch},url:e.webUrl,updatedDate:new Date(e.updatedAt),closedDate:e.mergedAt?new Date(e.mergedAt):null,assignees:(t=e.assignees)!=null&&t.nodes?e.assignees.nodes.map(k):null,reviews:(s=e.reviewers)!=null&&s.nodes?e.reviewers.nodes.map(l=>{var p,d;return{reviewer:k(l),state:(p=l.mergeRequestInteraction)!=null&&p.approved?"APPROVED":((d=l.mergeRequestInteraction)==null?void 0:d.reviewState)==="REVIEWED"?"CHANGES_REQUESTED":"CHANGES_REQUESTED"}}):null,additions:((n=e.diffStatsSummary)==null?void 0:n.additions)||0,deletions:((a=e.diffStatsSummary)==null?void 0:a.deletions)||0,fileCount:((o=e.diffStatsSummary)==null?void 0:o.fileCount)||0,commitCount:e.commitCount||0,mergeableState:Dt[e.mergeStatusEnum],milestone:e.milestone?Ue(e.milestone,r.webUrl):null,labels:((u=(i=e.labels)==null?void 0:i.nodes)==null?void 0:u.map(Se))??[]}},Ce=(e,r)=>{var t,s;return{author:{avatarUrl:e.author.avatarUrl,email:null,graphQLId:e.author.id,id:e.author.id.replace(Ee,""),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(Ee,""),name:n.name,username:n.username})),commentCount:e.userNotesCount,createdDate:new Date(e.createdAt),description:e.description,graphQLId:e.id,id:e.id.replace(Ut,""),labels:((s=(t=e.labels)==null?void 0:t.nodes)==null?void 0:s.map(Se))??[],number:e.iid,repository:{name:r.name,owner:{login:r.owner}},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?Ue(e.milestone,r.webUrl):null}},Ue=(e,r)=>({id:e.id.replace(Je,""),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}),F=class extends x{async getCurrentUser(r={}){var n;let s=(n=(await R(this.config,{query:`
|
|
446
535
|
query getCurrentUser {
|
|
447
536
|
currentUser {
|
|
448
537
|
${T}
|
|
449
538
|
}
|
|
450
539
|
}
|
|
451
|
-
`},
|
|
540
|
+
`},r)).body.data)==null?void 0:n.currentUser;if(!s)throw new Error("Current user not found.");return{data:k(s)}}async getUserForCommit(r,t={}){var o,i,u,l;let s=O(r.repo),a=(l=(u=(i=(o=(await R(this.config,{query:`
|
|
452
541
|
query getUserForCommit($fullPath: ID!, $oid: String!) {
|
|
453
542
|
project(fullPath: $fullPath) {
|
|
454
543
|
repository {
|
|
@@ -462,7 +551,7 @@ query getUserForCommit($fullPath: ID!, $oid: String!) {
|
|
|
462
551
|
}
|
|
463
552
|
}
|
|
464
553
|
}
|
|
465
|
-
`,variables:{fullPath:s,oid:
|
|
554
|
+
`,variables:{fullPath:s,oid:r.oid}},t)).body.data)==null?void 0:o.project)==null?void 0:i.repository)==null?void 0:u.tree)==null?void 0:l.lastCommit;if(!a)throw new Error("Commit not found.");return{data:{name:a.authorName,email:a.authorEmail,avatarUrl:a.authorGravatar}}}async getAccountForEmail(r,t={}){var a,o,i;let n=(i=(o=(a=(await R(this.config,{query:`
|
|
466
555
|
query getAccountForEmail($email: String!) {
|
|
467
556
|
users(search: $email) {
|
|
468
557
|
nodes {
|
|
@@ -470,28 +559,28 @@ query getAccountForEmail($email: String!) {
|
|
|
470
559
|
}
|
|
471
560
|
}
|
|
472
561
|
}
|
|
473
|
-
`,variables:{email:
|
|
562
|
+
`,variables:{email:r.email}},t)).body.data)==null?void 0:a.users)==null?void 0:o.nodes)==null?void 0:i[0];if(!n)throw new Error("User not found.");return{data:k(n)}}async getAccountForUsername(r,t={}){var a;let n=(a=(await R(this.config,{query:`
|
|
474
563
|
query getAccountForUsername($username: String!) {
|
|
475
564
|
user(username: $username) {
|
|
476
565
|
${T}
|
|
477
566
|
}
|
|
478
567
|
}
|
|
479
|
-
`,variables:{username:
|
|
568
|
+
`,variables:{username:r.username}},t)).body.data)==null?void 0:a.user;if(!n)throw new Error("User not found.");return{data:k(n)}}async getRepo(r,t={}){var a;let s=O(r),n=await R(this.config,{query:`
|
|
480
569
|
query getRepo($fullPath: ID!) {
|
|
481
570
|
project(fullPath: $fullPath) {
|
|
482
|
-
${
|
|
571
|
+
${ye}
|
|
483
572
|
}
|
|
484
573
|
}
|
|
485
|
-
`,variables:{fullPath:s}},
|
|
486
|
-
getRepo_${
|
|
487
|
-
${
|
|
574
|
+
`,variables:{fullPath:s}},t);if(!((a=n.body.data)!=null&&a.project))throw new Error(`Repository ${s} not found`);return{data:we(n.body.data.project)}}async getRepos(r,t={}){let n=r.map(O).map((u,l)=>`
|
|
575
|
+
getRepo_${l}: project(fullPath: "${u}") {
|
|
576
|
+
${ye}
|
|
488
577
|
}
|
|
489
578
|
`).join(`
|
|
490
|
-
`),
|
|
579
|
+
`),a=await R(this.config,{query:`
|
|
491
580
|
query batchGetRepos {
|
|
492
581
|
${n}
|
|
493
582
|
}
|
|
494
|
-
`},
|
|
583
|
+
`},t);if(!a.body.data)throw new Error(a.statusText||"Unknown error");let o=[],i=[];return r.forEach((u,l)=>{let p=a.body.data[`getRepo_${l}`];p?o.push(we(p)):i.push({input:u})}),{data:o,errors:i}}async getReposForCurrentUser(r={},t={}){var a,o,i,u,l,p;let s=await R(this.config,{query:`
|
|
495
584
|
query getReposForCurrentUser($after: String) {
|
|
496
585
|
projects(membership: true first: 100 after: $after) {
|
|
497
586
|
pageInfo {
|
|
@@ -499,11 +588,11 @@ query getReposForCurrentUser($after: String) {
|
|
|
499
588
|
hasNextPage
|
|
500
589
|
}
|
|
501
590
|
nodes {
|
|
502
|
-
${
|
|
591
|
+
${ye}
|
|
503
592
|
}
|
|
504
593
|
}
|
|
505
594
|
}
|
|
506
|
-
`,variables:{after:
|
|
595
|
+
`,variables:{after:r.cursor}},t);if(!((a=s.body.data)!=null&&a.projects))throw new Error(((o=s.body.errors)==null?void 0:o[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(we)}}async getRefs(r,t,s={}){var u;let n=O(t.repo),a=new URL(`${be(this.config,s)}/projects/${encodeURIComponent(n)}/repository/${r}`);a.searchParams.set("page",((u=t.page)==null?void 0:u.toString())||"1"),a.searchParams.set("per_page",E.toString());let o=await this.config.request({url:a.toString(),headers:h(s.token||this.config.token)}),i=o.headers["x-next-page"];return{pageInfo:{hasNextPage:!!i,nextPage:i?parseInt(i,10):null},data:o.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=O(r.repo),n=new URL(`${be(this.config,t)}/projects/${encodeURIComponent(s)}/repository/files/${encodeURIComponent(r.path)}/blame`);n.searchParams.set("ref",r.ref);let a=await this.config.request({url:n.toString(),headers:h(t.token||this.config.token)}),o=0;return{data:{ranges:a.body.map(i=>{let u=o+1;return o+=i.lines.length,{startingLine:u,endingLine:o,commit:{oid:i.commit.id,parentOids:i.commit.parent_ids,authoredDate:new Date(i.commit.authored_date),author:{name:i.commit.author_name,email:i.commit.author_email,avatarUrl:null},committedDate:new Date(i.commit.committed_date),committer:{name:i.commit.committer_name,email:i.commit.committer_email,avatarUrl:null},message:i.commit.message,fileCount:null,additions:null,deletions:null}}})}}}getVariablesForPullRequests(r){let{updatedBefore:t,isDraft:s,authorLogin:n,assigneeLogins:a,reviewRequestedLogin:o}=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"),a&&p("assigneeUsername",a[0],"String"),s!=null&&p("draft",s,"Boolean"),o&&p("reviewerUsername",o,"String"),{variables:i,variableTypes:u,mergeRequestArguments:l}}async getPullRequestsForRepo(r,t={}){var y,P,I;let{cursor:s,repo:n}=r||{},a=O(n),{variables:o,variableTypes:i,mergeRequestArguments:u}=this.getVariablesForPullRequests(r),l={fullPath:a,...o},p=await R(this.config,{query:`
|
|
507
596
|
query getPullRequestsForRepo(
|
|
508
597
|
$fullPath: ID!
|
|
509
598
|
$after: String
|
|
@@ -514,6 +603,7 @@ query getPullRequestsForRepo(
|
|
|
514
603
|
) {
|
|
515
604
|
name
|
|
516
605
|
fullPath
|
|
606
|
+
webUrl
|
|
517
607
|
mergeRequests(
|
|
518
608
|
first: 100
|
|
519
609
|
state: opened
|
|
@@ -526,16 +616,19 @@ query getPullRequestsForRepo(
|
|
|
526
616
|
hasNextPage
|
|
527
617
|
}
|
|
528
618
|
nodes {
|
|
529
|
-
${
|
|
619
|
+
${We}
|
|
620
|
+
milestone {
|
|
621
|
+
${ve}
|
|
622
|
+
}
|
|
530
623
|
}
|
|
531
624
|
}
|
|
532
625
|
}
|
|
533
626
|
}
|
|
534
|
-
`,variables:{...
|
|
627
|
+
`,variables:{...l,after:s}},t),d=[],c=(y=p.body.data)==null?void 0:y.project,g={name:(c==null?void 0:c.name)||"",owner:((c==null?void 0:c.fullPath)||"").split("/").slice(0,-1).join("/"),webUrl:(c==null?void 0:c.webUrl)||""};return(((P=c==null?void 0:c.mergeRequests)==null?void 0:P.nodes)||[]).forEach(f=>{d.push(He(f,g))}),{pageInfo:(I=c==null?void 0:c.mergeRequests)==null?void 0:I.pageInfo,data:d}}async getPullRequestsForRepos(r,t={}){var c,g,b,y,P;let{cursor:s}=r||{},n=r.repoIds.map(I=>I.toString().startsWith(B)?I:`${B}${I}`),{variables:a,variableTypes:o,mergeRequestArguments:i}=this.getVariablesForPullRequests(r),u={projectIds:n,...a},l=await R(this.config,{query:`
|
|
535
628
|
query getPullRequests(
|
|
536
629
|
$projectIds: [ID!]
|
|
537
630
|
$after: String
|
|
538
|
-
${
|
|
631
|
+
${o.length?o.join(" "):""}
|
|
539
632
|
) {
|
|
540
633
|
projects(
|
|
541
634
|
ids: $projectIds
|
|
@@ -548,6 +641,7 @@ query getPullRequests(
|
|
|
548
641
|
nodes {
|
|
549
642
|
name
|
|
550
643
|
fullPath
|
|
644
|
+
webUrl
|
|
551
645
|
mergeRequests(
|
|
552
646
|
first: 100
|
|
553
647
|
state: opened
|
|
@@ -555,37 +649,52 @@ query getPullRequests(
|
|
|
555
649
|
${i.length?i.join(" "):""}
|
|
556
650
|
) {
|
|
557
651
|
nodes {
|
|
558
|
-
${
|
|
652
|
+
${We}
|
|
559
653
|
}
|
|
560
654
|
}
|
|
561
655
|
}
|
|
562
656
|
}
|
|
563
657
|
}
|
|
564
|
-
`,variables:{...u,after:s}},
|
|
658
|
+
`,variables:{...u,after:s}},t),p=[];return(((g=(c=l.body.data)==null?void 0:c.projects)==null?void 0:g.nodes)||[]).forEach(I=>{var L;let f={name:I.name,owner:I.fullPath.split("/").slice(0,-1).join("/"),webUrl:I.webUrl};(((L=I.mergeRequests)==null?void 0:L.nodes)||[]).forEach(H=>{p.push(He(H,f))})}),{pageInfo:(P=(y=(b=l.body)==null?void 0:b.data)==null?void 0:y.projects)==null?void 0:P.pageInfo,data:p}}async closePullRequest(r,t={}){var l,p,d;let{repo:{namespace:s,name:n},pullRequestId:a}=r,o=`mutation ClosePullRequest($fullPath: ID!, $pullRequestId: String!) {
|
|
565
659
|
mergeRequestUpdate(input: { projectPath: $fullPath, iid: $pullRequestId, state: CLOSED }) {
|
|
566
660
|
errors,
|
|
567
661
|
mergeRequest {
|
|
568
662
|
id
|
|
569
663
|
}
|
|
570
664
|
}
|
|
571
|
-
}`,u=(
|
|
665
|
+
}`,u=(l=(await R(this.config,{query:o,variables:{fullPath:`${s}/${n}`,pullRequestId:a}},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 p,d,c;let{repo:{namespace:s,name:n},pullRequestId:a,expectedSourceSha:o}=r,i=`mutation MergePullRequest($fullPath: ID!, $pullRequestId: String!, $expectedSourceSha: String!) {
|
|
572
666
|
mergeRequestAccept(input: { projectPath: $fullPath, iid: $pullRequestId, sha: $expectedSourceSha }) {
|
|
573
667
|
errors,
|
|
574
668
|
mergeRequest {
|
|
575
669
|
id
|
|
576
670
|
}
|
|
577
671
|
}
|
|
578
|
-
}`,
|
|
672
|
+
}`,l=(p=(await R(this.config,{query:i,variables:{fullPath:`${s}/${n}`,pullRequestId:a,expectedSourceSha:o}},t)).body.data)==null?void 0:p.mergeRequestAccept;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 merge pull request")}async setPullRequestMilestone(r,t={}){var p,d,c;let{repo:{namespace:s,name:n},pullRequestId:a,milestoneGraphQLId:o}=r,i=`mutation SetPullRequestMilestone($fullPath: ID!, $pullRequestId: String!, $milestoneGraphQLId: MilestoneID) {
|
|
673
|
+
mergeRequestSetMilestone(input: { projectPath: $fullPath, iid: $pullRequestId, milestoneId: $milestoneGraphQLId }) {
|
|
674
|
+
errors,
|
|
675
|
+
mergeRequest {
|
|
676
|
+
id
|
|
677
|
+
}
|
|
678
|
+
}
|
|
679
|
+
}`,u=await R(this.config,{query:i,variables:{fullPath:`${s}/${n}`,pullRequestId:a,milestoneGraphQLId:o}},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:a,isDraft:o}=r,i=`mutation MergeRequestSetDraft($fullPath: ID!, $pullRequestId: String!, $isDraft: Boolean!) {
|
|
680
|
+
mergeRequestSetDraft(input: { projectPath: $fullPath, iid: $pullRequestId, draft: $isDraft }) {
|
|
681
|
+
errors,
|
|
682
|
+
mergeRequest {
|
|
683
|
+
id
|
|
684
|
+
}
|
|
685
|
+
}
|
|
686
|
+
}`,l=(p=(await R(this.config,{query:i,variables:{fullPath:`${s}/${n}`,pullRequestId:a,isDraft:o}},t)).body.data)==null?void 0:p.mergeRequestSetDraft;if(!((d=l==null?void 0:l.mergeRequest)!=null&&d.id)||((c=l==null?void 0:l.errors)==null?void 0:c.length)!==0)throw new Error("Could not set pull request as draft")}async getIssue(r,t={}){var a,o,i,u,l,p,d,c;let s=qt(r),n=await R(this.config,{query:`
|
|
579
687
|
query GetSingleIssue($projectId: ID!, $issueId: String!) {
|
|
580
688
|
project(fullPath: $projectId) {
|
|
581
689
|
name
|
|
582
690
|
fullPath
|
|
691
|
+
webUrl
|
|
583
692
|
issue(iid: $issueId) {
|
|
584
|
-
${
|
|
693
|
+
${Pe}
|
|
585
694
|
}
|
|
586
695
|
}
|
|
587
696
|
}
|
|
588
|
-
`,variables:{issueId:
|
|
697
|
+
`,variables:{issueId:r.id,projectId:s}},t);if(!((a=n.body.data)!=null&&a.project))throw new Error(`Repository ${s} not found`);if(!((i=(o=n.body.data)==null?void 0:o.project)!=null&&i.issue))throw new Error(`Issue ${r.id} not found`);return{data:Ce((l=(u=n.body.data)==null?void 0:u.project)==null?void 0:l.issue,{name:(p=n.body.data)==null?void 0:p.project.name,owner:(d=n.body.data)==null?void 0:d.project.fullPath.split("/").slice(0,-1).join("/"),webUrl:(c=n.body.data)==null?void 0:c.project.webUrl})}}getVariablesForIssues(r){let{updatedBefore:t,authorLogin:s,assigneeLogins:n}=r||{},a={},o=[],i=[],u=(l,p,d)=>{o.push(`$${l}: ${d}`),i.push(`${l}: $${l}`),a[l]=p};return t&&u("updatedBefore",t,"Time"),s&&u("authorUsername",s,"String"),n&&u("assigneeUsername",n[0],"String"),{variables:a,variableTypes:o,issueArguments:i}}async getIssuesForRepo(r,t={}){var P,I,f;let{cursor:s,repo:n}=r||{},a=O(n),{variables:o,variableTypes:i,issueArguments:u}=this.getVariablesForIssues(r),l={fullPath:a,...o},p=`
|
|
589
698
|
query GetIssuesFromProject(
|
|
590
699
|
$fullPath: ID!
|
|
591
700
|
$after: String
|
|
@@ -596,6 +705,7 @@ query GetSingleIssue($projectId: ID!, $issueId: String!) {
|
|
|
596
705
|
) {
|
|
597
706
|
name
|
|
598
707
|
fullPath
|
|
708
|
+
webUrl
|
|
599
709
|
issues(
|
|
600
710
|
first: 100
|
|
601
711
|
state: opened
|
|
@@ -604,7 +714,7 @@ query GetSingleIssue($projectId: ID!, $issueId: String!) {
|
|
|
604
714
|
${u.length?u.join(" "):""}
|
|
605
715
|
) {
|
|
606
716
|
nodes {
|
|
607
|
-
${
|
|
717
|
+
${Pe}
|
|
608
718
|
}
|
|
609
719
|
pageInfo {
|
|
610
720
|
endCursor
|
|
@@ -612,11 +722,11 @@ query GetSingleIssue($projectId: ID!, $issueId: String!) {
|
|
|
612
722
|
}
|
|
613
723
|
}
|
|
614
724
|
}
|
|
615
|
-
}`,d=await
|
|
725
|
+
}`,d=await R(this.config,{query:p,variables:{...l,after:s}},t),c=[],g=(P=d.body.data)==null?void 0:P.project,b={name:(g==null?void 0:g.name)||"",owner:((g==null?void 0:g.fullPath)||"").split("/").slice(0,-1).join("/"),webUrl:(g==null?void 0:g.webUrl)||""};return(((I=g==null?void 0:g.issues)==null?void 0:I.nodes)||[]).forEach(w=>{c.push(Ce(w,b))}),{pageInfo:(f=g==null?void 0:g.issues)==null?void 0:f.pageInfo,data:c.sort((w,L)=>(w.updatedDate||w.createdDate).getTime()-(L.updatedDate||L.createdDate).getTime())}}async getIssuesForRepos(r,t={}){var g,b,y,P,I;let{cursor:s}=r||{},n=r.repoIds.map(f=>f.toString().startsWith(B)?f:`${B}${f}`),{variables:a,variableTypes:o,mergeRequestArguments:i}=this.getVariablesForPullRequests(r),u={projectIds:n,...a},l=`
|
|
616
726
|
query GetIssuesFromProject(
|
|
617
727
|
$projectIds: [ID!]
|
|
618
728
|
$after: String
|
|
619
|
-
${
|
|
729
|
+
${o.length?o.join(" "):""}
|
|
620
730
|
) {
|
|
621
731
|
projects(
|
|
622
732
|
ids: $projectIds
|
|
@@ -629,6 +739,7 @@ query GetSingleIssue($projectId: ID!, $issueId: String!) {
|
|
|
629
739
|
nodes {
|
|
630
740
|
name
|
|
631
741
|
fullPath
|
|
742
|
+
webUrl
|
|
632
743
|
issues(
|
|
633
744
|
first: 100
|
|
634
745
|
state: opened
|
|
@@ -636,15 +747,64 @@ query GetSingleIssue($projectId: ID!, $issueId: String!) {
|
|
|
636
747
|
${i.length?i.join(" "):""}
|
|
637
748
|
) {
|
|
638
749
|
nodes {
|
|
639
|
-
${
|
|
750
|
+
${Pe}
|
|
640
751
|
}
|
|
641
752
|
}
|
|
642
753
|
}
|
|
643
754
|
}
|
|
644
|
-
}`,
|
|
755
|
+
}`,p=await R(this.config,{query:l,variables:{...u,after:s}},t),d=[];return(((b=(g=p.body.data)==null?void 0:g.projects)==null?void 0:b.nodes)||[]).forEach(f=>{var H;let w={name:f.name,owner:f.fullPath.split("/").slice(0,-1).join("/"),webUrl:f.webUrl};(((H=f.issues)==null?void 0:H.nodes)||[]).forEach(Ve=>d.push(Ce(Ve,w)))}),{pageInfo:(I=(P=(y=p.body)==null?void 0:y.data)==null?void 0:P.projects)==null?void 0:I.pageInfo,data:d.sort((f,w)=>(f.updatedDate||f.createdDate).getTime()-(w.updatedDate||w.createdDate).getTime())}}async setIssueStatus(r,t={}){var l,p,d;let{repo:{namespace:s,name:n},issueId:a,status:o}=r,i=`mutation SetIssueState($fullPath: ID!, $issueId: String!, $status: IssueStateEvent!) {
|
|
645
756
|
updateIssue(input: { projectPath: $fullPath, iid: $issueId, stateEvent: $status }) {
|
|
646
757
|
issue {
|
|
647
758
|
id
|
|
648
759
|
}
|
|
649
760
|
}
|
|
650
|
-
}`;if(!((d=(
|
|
761
|
+
}`;if(!((d=(p=(l=(await R(this.config,{query:i,variables:{fullPath:`${s}/${n}`,issueId:a,status:o}},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:a}=r,o=((p=r.milestoneGraphQLId)==null?void 0:p.replace(Je,""))??"",i=`mutation SetIssueMilestone($fullPath: ID!, $issueId: String!, $milestoneGraphQLId: ID) {
|
|
762
|
+
updateIssue(input: { projectPath: $fullPath, iid: $issueId, milestoneId: $milestoneGraphQLId }) {
|
|
763
|
+
errors
|
|
764
|
+
issue {
|
|
765
|
+
id
|
|
766
|
+
milestone {
|
|
767
|
+
id
|
|
768
|
+
}
|
|
769
|
+
}
|
|
770
|
+
}
|
|
771
|
+
}`,u=await R(this.config,{query:i,variables:{fullPath:`${s}/${n}`,issueId:a,milestoneGraphQLId:o}},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:a}=r,o=await R(this.config,{query:`
|
|
772
|
+
query getLabelsForRepo(
|
|
773
|
+
$fullPath: ID!
|
|
774
|
+
$after: String
|
|
775
|
+
) {
|
|
776
|
+
project(
|
|
777
|
+
fullPath: $fullPath
|
|
778
|
+
) {
|
|
779
|
+
webUrl
|
|
780
|
+
milestones(after: $after) {
|
|
781
|
+
nodes {
|
|
782
|
+
${ve}
|
|
783
|
+
}
|
|
784
|
+
pageInfo {
|
|
785
|
+
endCursor
|
|
786
|
+
hasNextPage
|
|
787
|
+
}
|
|
788
|
+
}
|
|
789
|
+
}
|
|
790
|
+
}
|
|
791
|
+
`,variables:{fullPath:`${s}/${n}`,after:a}},t);return{pageInfo:((l=(u=(i=o.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=o.body.data)==null?void 0:p.project)==null?void 0:d.milestones)==null?void 0:c.nodes)==null?void 0:g.map(b=>{var y,P;return Ue(b,((P=(y=o.body.data)==null?void 0:y.project)==null?void 0:P.webUrl)||"")}))??[]}}async getLabelsForRepo(r,t={}){var i,u,l,p,d,c,g;let{repo:{namespace:s,name:n},cursor:a}=r,o=await R(this.config,{query:`
|
|
792
|
+
query getLabelsForRepo(
|
|
793
|
+
$fullPath: ID!
|
|
794
|
+
$after: String
|
|
795
|
+
) {
|
|
796
|
+
project(
|
|
797
|
+
fullPath: $fullPath
|
|
798
|
+
) {
|
|
799
|
+
labels(after: $after) {
|
|
800
|
+
nodes {
|
|
801
|
+
${De}
|
|
802
|
+
}
|
|
803
|
+
pageInfo {
|
|
804
|
+
endCursor
|
|
805
|
+
hasNextPage
|
|
806
|
+
}
|
|
807
|
+
}
|
|
808
|
+
}
|
|
809
|
+
}
|
|
810
|
+
`,variables:{fullPath:`${s}/${n}`,after:a}},t);return{pageInfo:((l=(u=(i=o.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=o.body.data)==null?void 0:p.project)==null?void 0:d.labels)==null?void 0:c.nodes)==null?void 0:g.map(Se))??[]}}};var Y="https://api.atlassian.com/ex/jira",$e=100,Gt=e=>{var t,s,n,a,o,i;let r=e.fields.assignee;return{id:e.id,commentCount:e.fields.comment.comments.length,number:e.key,title:e.fields.summary,url:e.self,createdDate:new Date(e.fields.created),author:{id:e.fields.creator.accountId,name:e.fields.creator.displayName,email:e.fields.creator.emailAddress,avatarUrl:e.fields.creator.avatarUrls["32x32"],username:e.fields.creator.displayName},updatedDate:new Date(e.fields.updated),assignees:r?[{id:r.accountId,name:r.displayName,email:r.emailAddress,avatarUrl:r.avatarUrls["32x32"],username:r.displayName}]:[],description:null,repository:null,state:{name:(t=e.fields.status)==null?void 0:t.name,color:(n=(s=e.fields.status)==null?void 0:s.statusCategory)==null?void 0:n.colorName},statusTransitions:((a=e.transitions)==null?void 0:a.map(xt))??[],type:e.fields.issuetype.name,upvoteCount:((o=e.fields.votes)==null?void 0:o.votes)||0,labels:((i=e.fields.labels)==null?void 0:i.map(u=>({color:null,description:null,id:null,name:u})))??[]}},xt=e=>({name:e.name,id:e.id}),M=class extends D{async getJiraResourcesForCurrentUser(r={}){return{data:(await this.config.request({url:`${r.baseUrl||"https://api.atlassian.com/"}/oauth/token/accessible-resources`,headers:h(r.token||this.config.token)})).body.map(s=>({avatarUrl:s.avatarUrl,id:s.id,name:s.name}))}}async getJiraProjectsForResource(r,t={}){let s=new URL(`${t.baseUrl||Y}/${r.resourceId}/rest/api/2/project/search`);s.searchParams.set("maxResults",$e.toString()),r.cursor&&s.searchParams.set("startAt",r.cursor);let n=await this.config.request({url:s.toString(),headers:h(t.token||this.config.token)});return{pageInfo:{hasNextPage:n.body.values.length!==0,endCursor:(n.body.startAt+n.body.values.length).toString()},data:n.body.values.map(a=>({id:a.id,name:a.name,resourceId:r.resourceId}))}}async getJiraProjectsForResources(r,t={}){let s=[];return await Promise.all(r.resourceIds.map(async n=>{let a=await this.getJiraProjectsForResource({resourceId:n},t);s.push(...a.data)})),{data:s}}async getIssuesForProject(r,t={}){let{assigneeLogins:s,authorLogin:n,mentionLogin:a,project:o}=r||{},i=[`project = "${o}"`];return n&&i.push(`creator in (${n})`),s&&i.push(`assignee in (${s.join(", ")})`),a&&i.push(`comment ~ ${a}`),{data:(await this.config.request({url:`${t.baseUrl||Y}/${r.resourceId}/rest/api/2/search?jql=${i.join(" AND ")}&startAt=0&maxResults=${$e}&fields=${["assignee","comment","summary","created","creator","updated","votes","issuetype","status","labels"].join(",")}&expand=transitions`,headers:h(t.token||this.config.token)})).body.issues.map(Gt)}}async setIssueStatus(r,t={}){let{resourceId:s,issueId:n,status:a}=r,o={transition:{id:a}};try{await this.config.request({method:"POST",url:`${t.baseUrl||Y}/${s}/rest/api/2/issue/${n}/transitions`,body:JSON.stringify(o),headers:{...h(t.token||this.config.token),"Content-Type":"application/json"}})}catch(i){if(i.message=="Unexpected end of JSON input")return;throw new Error("Could not set issue status")}}async getLabelsForResource(r,t={}){let{resourceId:s,cursor:n}=r,a=new URL(`${t.baseUrl||Y}/${s}/rest/api/2/label`);a.searchParams.set("maxResults",$e.toString()),n&&a.searchParams.set("startAt",n);let o=await this.config.request({url:a.toString(),headers:h(t.token||this.config.token)});return{pageInfo:{hasNextPage:!o.body.isLast,endCursor:(o.body.startAt+o.body.values.length).toString()},data:o.body.values.map(i=>({color:null,description:null,id:null,name:i}))}}};var z="https://api.trello.com",Tt=1e3,Ot=(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}))}},W=class extends D{async getBoardsForCurrentUser(r,t={}){return{data:(await this.config.request({url:`${t.baseUrl||z}/1/members/me/boards?fields=name&key=${r.appKey}&token=${t.token||this.config.token}&filter=open`,headers:h(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||z}/1/boards/${n}/lists?key=${s}&token=${t.token||this.config.token}`,headers:h(t.token||this.config.token)})).body}}async getIssuesForBoard(r,t={}){let s=["-is:archived","sort:edited"],{appKey:n,boardId:a,filterText:o,assigneeLogins:i,trelloBoardListsById:u}=r||{};i&&s.push("@me");let l=`${o?`${o}`:""}${s.join(" ")} board:${a}`;return{data:(await this.config.request({url:`${t.baseUrl||z}/1/search?key=${n}&query=${l}&cards_limit=${Tt}&token=${t.token||this.config.token}`,headers:h(t.token||this.config.token)})).body.cards.map(d=>Ot(d,u||{}))}}async setIssueStatus(r,t={}){let{appKey:s,cardId:n,status:a}=r;if(!(await this.config.request({method:"PUT",url:`${t.baseUrl||z}/1/cards/${n}?key=${s}&token=${t.token||this.config.token}&idList=${a}`,headers:h(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||z}/1/boards/${n}/labels?key=${s}&token=${t.token||this.config.token}`,headers:h(t.token||this.config.token)})).body.map(o=>({color:o.color,description:null,id:o.id,name:o.name}))}}};var ee={};G(ee,{getIssueUniqueId:()=>At,getPullRequestUniqueId:()=>kt});var At=(e,r,t,s="")=>{let n=[];return n.push(s),n.push(e),n.push(r),n.push(t),JSON.stringify(n)},kt=(e,r,t,s,n="")=>{let a=[];return a.push(n),a.push(e),a.push(r),a.push(t),a.push(s),JSON.stringify(a)};var te={};G(te,{getIssueUniqueId:()=>_t,getPullRequestUniqueId:()=>Qt});var _t=(e,r)=>JSON.stringify(["",e,r]),Qt=(e,r)=>JSON.stringify(["",e,r]);var re={};G(re,{getIssueUniqueId:()=>Nt,getPullRequestUniqueId:()=>jt});var Nt=(e,r,t)=>JSON.stringify([t,e,r]),jt=(e,r,t)=>JSON.stringify([t,e,r]);var se={};G(se,{getIssueUniqueId:()=>Bt,getPullRequestRank:()=>Mt,getPullRequestUniqueId:()=>Ft});var Bt=(e,r="")=>{let t=[];return t.push(r),t.push(e),JSON.stringify(t)},Ft=(e,r="")=>{let t=[];return t.push(r),t.push(e),JSON.stringify(t)},Mt=(e,r,t)=>{var o,i,u;let s=0,n,a;return(o=e.reviews)==null||o.forEach(l=>{l.reviewer.id===r&&(n=l.state),l.state==="CHANGES_REQUESTED"?a="CHANGES_REQUESTED":l.state==="APPROVED"&&a!=="CHANGES_REQUESTED"&&(a="APPROVED")}),a||(a="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),a==="APPROVED"?e.mergeableState==="MERGEABLE"?s+=100:e.mergeableState==="CONFLICTS"?s+=90:s+=80:a=="CHANGES_REQUESTED"&&(s+=70),s};var ne={};G(ne,{getIssueUniqueId:()=>zt,getPullRequestUniqueId:()=>Wt});var zt=(e,r="")=>{let t=[];return t.push(r),t.push(e),JSON.stringify(t)},Wt=(e,r="")=>{let t=[];return t.push(r),t.push(e),JSON.stringify(t)};var oe={};G(oe,{getIssueUniqueId:()=>Ht,getJiraServerIssueUniqueId:()=>Jt});var Ht=(e,r,t)=>{let s=[];return s.push(""),s.push(e),s.push(r),s.push(t),JSON.stringify(s)},Jt=(e,r,t)=>{let s=[];return s.push(t),s.push(""),s.push(e),s.push(r),JSON.stringify(s)};var ae={};G(ae,{getIssueUniqueId:()=>Vt});var Vt=(e,r,t,s="")=>{let n=[];return n.push(s),n.push(e),n.push(r),n.push(t),JSON.stringify(n)};var Xt=e=>{let r={request:e==null?void 0:e.request};return{azureDevOps:new _({...r,...e==null?void 0:e.azureDevOps}),bitbucket:new Q({...r,...e==null?void 0:e.bitbucket}),bitbucketServer:new N({...r,...e==null?void 0:e.bitbucketServer}),github:new j({...r,...e==null?void 0:e.github}),gitlab:new F({...r,...e==null?void 0:e.gitlab}),jira:new M({...r,...e==null?void 0:e.jira}),trello:new W({...r,...e==null?void 0:e.trello})}},Kt=Xt;var Zt={azureDevOps:ee,bitbucket:te,bitbucketServer:re,github:se,gitlab:ne,jira:oe,trello:ae};
|