@gitkraken/provider-apis 0.14.1 → 0.14.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- "use strict";var tt=Object.create;var X=Object.defineProperty;var st=Object.getOwnPropertyDescriptor;var rt=Object.getOwnPropertyNames;var nt=Object.getPrototypeOf,at=Object.prototype.hasOwnProperty;var x=(t,s)=>{for(var e in s)X(t,e,{get:s[e],enumerable:!0})},Te=(t,s,e,r)=>{if(s&&typeof s=="object"||typeof s=="function")for(let n of rt(s))!at.call(t,n)&&n!==e&&X(t,n,{get:()=>s[n],enumerable:!(r=st(s,n))||r.enumerable});return t};var ot=(t,s,e)=>(e=t!=null?tt(nt(t)):{},Te(s||!t||!t.__esModule?X(e,"default",{value:t,enumerable:!0}):e,t)),it=t=>Te(X({},"__esModule",{value:!0}),t);var gs={};x(gs,{AzureDevOps:()=>Q,AzureDevopsUtils:()=>re,Bitbucket:()=>B,BitbucketServer:()=>F,BitbucketServerUtils:()=>ae,BitbucketUtils:()=>ne,GitHub:()=>M,GitHubUtils:()=>oe,GitLab:()=>J,GitLabUtils:()=>ie,Jira:()=>W,JiraServer:()=>H,JiraUtils:()=>ue,Trello:()=>V,TrelloUtils:()=>le,Utils:()=>cs,default:()=>ds});module.exports=it(gs);var Me=require("js-base64");var $=100;var ke=ot(require("node-fetch")),_e=globalThis.fetch||ke.default;var Ne=t=>t.name==="fetch";var ut=async t=>{let s=t.headers.get("content-type")||"",e=null;if(s.startsWith("application/json")){let n=await t.text();e=n.trim().length>0?JSON.parse(n):null}else if(s.startsWith("text/")||s==="")e=await t.text();else throw new Error(`Unsupported content-type: ${s}`);let r={body:e,headers:Object.fromEntries(t.headers.entries()),status:t.status,statusText:t.statusText};if(!t.ok){let n=new Error(t.statusText);throw Object.assign(n,{response:r}),n}return r},pe=t=>Ne(t)?async({url:s,...e})=>{let r=await t(s,e);return ut(r)}:t;var U=class{constructor(s){this.config={...s,request:pe((s==null?void 0:s.request)||_e)}}updateConfig(s){this.config={...this.config,...s,request:s.request?pe(s.request):this.config.request}}},D=class extends U{};var h=(t,s)=>{let e={};return t&&(e.Authorization=`${s?"Basic":"Bearer"} ${t}`),e};var y=(t,s={})=>h(s.token||t.token,s.isPAT||t.isPAT),je=t=>t.url.replace("/_apis/git/repositories/","/_git/").replace(`/${t.repository.project.id}/`,`/${encodeURIComponent(t.repository.project.name)}/`).replace(`/${t.repository.id}/`,`/${encodeURIComponent(t.repository.name)}/`).replace("/pullRequests/","/pullrequest/");var Qe="https://app.vssps.visualstudio.com/_apis",w="https://dev.azure.com",lt={active:"OPEN",completed:"MERGED",abandoned:"CLOSED"},pt={10:"APPROVED",5:"APPROVED",0:"REVIEW_REQUESTED",[-5]:"CHANGES_REQUESTED",[-10]:"CHANGES_REQUESTED"},de=t=>({id:t.id,name:t.displayName,username:t.uniqueName||t.displayName,email:null,avatarUrl:t.imageUrl}),Z=t=>t.startsWith("refs/heads/")?t.replace("refs/heads/",""):t,Be=t=>{var s;return{id:t.pullRequestId.toString(),title:t.title,number:t.codeReviewId,state:lt[t.status],isDraft:t.isDraft,commentCount:null,upvoteCount:null,author:de(t.createdBy),createdDate:new Date(t.creationDate),updatedDate:new Date(t.closedDate||t.creationDate),closedDate:t.closedDate?new Date(t.closedDate):null,repository:{name:t.repository.name,owner:{login:void 0}},headCommit:{buildStatuses:null},baseRef:{name:Z(t.targetRefName),oid:t.lastMergeTargetCommit.commitId},headRef:{name:Z(t.sourceRefName),oid:t.lastMergeSourceCommit.commitId},url:je(t),assignees:t.reviewers.map(de),reviews:t.reviewers.filter(e=>e.vote!==0).map(e=>({reviewer:de(e),state:pt[e.vote]||"REVIEW_REQUESTED"})),additions:null,deletions:null,fileCount:null,commitCount:null,headRepository:null,mergeableState:"UNKNOWN",labels:((s=t.labels)==null?void 0:s.map(e=>({color:null,description:null,id:e.id,name:e.name})))??[]}},Fe=(t,s)=>({id:s.id,name:s.name,namespace:t,project:s.project.name,webUrl:s.webUrl,httpsUrl:s.remoteUrl,sshUrl:s.sshUrl,defaultBranch:s.defaultBranch?{name:Z(s.defaultBranch)}:null,permission:null}),dt=(t,s)=>{var i,u;let e=t.fields,r=e["System.AssignedTo"],n=e["System.State"],o=e["System.WorkItemType"],a;return n&&o&&(a=(i=s[o])==null?void 0:i[n]),{id:t.id.toString(),number:t.id.toString(),title:e["System.Title"],commentCount:e["System.CommentCount"],author:{avatarUrl:e["System.CreatedBy"]._links.avatar.href,email:null,id:e["System.CreatedBy"].id,name:e["System.CreatedBy"].uniqueName,username:e["System.CreatedBy"].displayName},createdDate:new Date(e["System.CreatedDate"]),updatedDate:new Date(e["System.ChangedDate"]),url:t._links.html.href,assignees:r?[{avatarUrl:r._links.avatar.href,email:null,id:r.id,name:r.uniqueName,username:r.displayName}]:[],description:null,state:{name:(a==null?void 0:a.title)||n,color:null},type:e["System.WorkItemType"],repository:null,upvoteCount:0,labels:((u=t.fields["System.Tags"])==null?void 0:u.split(";").map(l=>({color:null,description:null,id:null,name:l.trim()})))??[]}},Q=class extends U{async getCurrentUser(s={}){if(s.isPAT||this.config.isPAT)throw new Error("Azure DevOps does not support PATs for this function.");let e=await this.config.request({url:`${Qe}/profile/profiles/me`,headers:y(this.config,s)});return{data:{id:e.body.id,name:e.body.displayName,username:e.body.displayName,email:e.body.emailAddress,avatarUrl:null}}}async getCurrentUserForInstance(s,e={}){let n=(await this.config.request({url:`${w}/${encodeURIComponent(s.namespace)}/_apis/ConnectionData`,headers:y(this.config,e)})).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(s,e={}){if(!s.repo.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let n=(await this.config.request({url:`${w}/${encodeURIComponent(s.repo.namespace)}/${encodeURIComponent(s.repo.project)}/_apis/git/repositories/${encodeURIComponent(s.repo.name)}/commits/${s.oid}`,headers:y(this.config,e)})).body.author;return{data:{name:n.name,email:n.email,avatarUrl:n.imageUrl}}}async getOrgsForUser(s,e={}){return{data:(await this.config.request({url:`${Qe}/accounts?memberId=${s.userId}&api-version=6.0`,headers:y(this.config,e)})).body.value.map(n=>({id:n.accountId,name:n.accountName}))}}async getAzureProjects(s,e={}){let r=new URL(`${w}/${encodeURIComponent(s.namespace)}/_apis/projects`);r.searchParams.set("$top",$.toString()),s.cursor&&r.searchParams.set("$skip",s.cursor);let n=await this.config.request({url:r.toString(),headers:y(this.config,e)}),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:s.namespace}))}}async getAzureProjectScopeDescriptor(s,e={}){let{namespace:r,projectId:n}=s;return{data:{scope:(await this.config.request({url:`https://vssps.dev.azure.com/${encodeURIComponent(r)}/_apis/graph/descriptors/${n}?api-version=6.0`,headers:y(this.config,e)})).body.value}}}async getAccountsForAzureProject(s,e={}){let{namespace:r,projectScopeDescriptor:n}=s,o=new URL(`https://vssps.dev.azure.com/${encodeURIComponent(r)}/_apis/graph/users`);return n&&o.searchParams.set("scopeDescriptor",n),{data:(await this.config.request({url:o.toString(),headers:y(this.config,e)})).body.value.map(i=>{var u;return{id:Me.Base64.decode(i.descriptor.replace(/.+?\./,"")),name:i.displayName,username:i.displayName,email:i.mailAddress,avatarUrl:(u=i._links.avatar)==null?void 0:u.href}})}}async getRepo(s,e={}){if(!s.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let r=await this.config.request({url:`${w}/${encodeURIComponent(s.namespace)}/${encodeURIComponent(s.project)}/_apis/git/repositories/${encodeURIComponent(s.name)}`,headers:y(this.config,e)});return{data:Fe(s.namespace,r.body)}}async getRepos(s,e={}){let r=[],n=[];return await Promise.all(s.map(async o=>{try{let a=await this.getRepo(o,e);r.push(a.data)}catch(a){n.push({input:o,error:a})}})),{data:r,errors:n}}async getReposForAzureProject(s,e={}){if(!s.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');return{data:(await this.config.request({url:`${w}/${encodeURIComponent(s.namespace)}/${encodeURIComponent(s.project)}/_apis/git/repositories`,headers:y(this.config,e)})).body.value.map(n=>Fe(s.namespace,n))}}async getRefs(s,e,r={}){if(!e.repo.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let n=new URL(`${w}/${encodeURIComponent(e.repo.namespace)}/${encodeURIComponent(e.repo.project)}/_apis/git/repositories/${encodeURIComponent(e.repo.name)}/refs`);n.searchParams.set("filter",s),n.searchParams.set("$top",$.toString()),e.cursor&&n.searchParams.set("continuationToken",e.cursor);let o=await this.config.request({url:n.toString(),headers:y(this.config,r)}),a=o.headers["x-ms-continuationtoken"];return{pageInfo:{hasNextPage:!!a,endCursor:a||null},data:o.body.value.map(i=>({name:Z(i.name),commit:{oid:i.objectId,authoredDate:null,committedDate:null}}))}}async getBranches(s,e={}){return this.getRefs("heads",s,e)}async getTags(s,e={}){return this.getRefs("tags",s,e)}async getPullRequestsForRepoBase(s,e={},r=100){let{page:n,repo:o,assigneeLogins:a,authorLogin:i}=s||{},u=n||1;if(!o.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let l="searchCriteria.status=1";return a&&a.length&&(l+=`&searchCriteria.reviewerId=${a[0]}`),i&&(l+=`&searchCriteria.creatorId=${i}`),await this.config.request({url:`${e.baseUrl||w}/${encodeURIComponent(o.namespace)}/${encodeURIComponent(o.project||"")}/_apis/git/repositories/${encodeURIComponent(o.name)}/pullRequests?${l}&%24top=${r}&%24skip=${(u-1)*r}`,headers:y(this.config,e)})}async getPullRequestsForRepo(s,e={}){let n=s.page||1,o=await this.getPullRequestsForRepoBase(s,e,100);return{pageInfo:{hasNextPage:o.body.value.length===100,nextPage:n+1},data:o.body.value.map(Be)}}async getPullRequestsForRepos(s,e={}){if(!s.repos.every(o=>o.project))throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let{repos:r}=s||{},n=[];return await Promise.all(r.map(async o=>{try{(await this.getPullRequestsForRepoBase({repo:o,...s},e)).body.value.forEach(i=>{n.push(Be(i))})}catch(a){if(a.statusCode!==404&&a.statusCode!==401)throw a}})),{data:n}}async getAzurePullRequestLastMergeStatus(s,e={}){if(!s.repo.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let{repo:{namespace:r,project:n,name:o},pullRequestId:a}=s,i=await this.config.request({url:`${e.baseUrl||w}/${encodeURIComponent(r)}/${encodeURIComponent(n||"")}/_apis/git/repositories/${o}/pullrequests/${a}?includeCommits=true?api-version=6.0`,headers:{...y(this.config,e)}});if(!i.body.mergeStatus)throw new Error("Could not fetch pull request");return{data:i.body.mergeStatus}}async updatePullRequest(s,e,r,n){let{namespace:o,project:a,name:i}=s;return await this.config.request({method:"PATCH",url:`${n.baseUrl||w}/${encodeURIComponent(o)}/${encodeURIComponent(a||"")}/_apis/git/repositories/${i}/pullrequests/${e}?api-version=6.0`,body:r,headers:{...y(this.config,n),"Content-Type":"application/json"}})}async closePullRequest(s,e={}){if(!s.repo.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let{repo:r,pullRequestId:n}=s,o={status:"abandoned"};if(!(await this.updatePullRequest(r,n,JSON.stringify(o),e)).body.status)throw new Error("Could not close pull request")}async mergePullRequest(s,e={}){if(!s.repo.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let{repo:r,pullRequestId:n,expectedSourceSha:o,mergeStrategy:a}=s,i;switch(a){case"MERGE_COMMIT":{i="noFastForward";break}case"REBASE":{i="rebase";break}case"REBASE_THEN_MERGE_COMMIT":{i="rebaseMerge";break}case"SQUASH":{i="squash";break}}let u={completionOptions:{mergeStrategy:i},lastMergeSourceCommit:{commitId:o},status:"completed"};if(!(await this.updatePullRequest(r,n,JSON.stringify(u),e)).body.status)throw new Error("Could not merge pull request")}async addPullRequestLabel(s,e={}){let{repo:{namespace:r,project:n,name:o},pullRequestId:a,labelName:i}=s;if(!n)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let u={name:i};if(!(await this.config.request({method:"POST",url:`${e.baseUrl||w}/${encodeURIComponent(r)}/${encodeURIComponent(n||"")}/_apis/git/repositories/${o}/pullrequests/${a}/labels?api-version=6.0`,body:JSON.stringify(u),headers:{...y(this.config,e),"Content-Type":"application/json"}})).body.id)throw new Error("Could not add pull request label")}async removePullRequestLabel(s,e={}){let{repo:{namespace:r,project:n,name:o},pullRequestId:a,labelNameOrId:i}=s;if(!n)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');await this.config.request({method:"DELETE",url:`${e.baseUrl||w}/${encodeURIComponent(r)}/${encodeURIComponent(n||"")}/_apis/git/repositories/${o}/pullrequests/${a}/labels/${encodeURIComponent(i)}?api-version=6.0`,headers:{...y(this.config,e)}})}async setPullRequestAsDraft(s,e={}){if(!s.repo.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let{repo:r,pullRequestId:n,isDraft:o}=s,a={isDraft:o};if(!(await this.updatePullRequest(r,n,JSON.stringify(a),e)).body.status)throw new Error("Could not set the pull request as draft")}async addPullRequestReviewer(s,e={}){if(!s.repo.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let{repo:{namespace:r,project:n,name:o},pullRequestId:a,reviewerId:i,isRequired:u}=s,l={id:i,isRequired:u};if(!(await this.config.request({method:"PUT",url:`${e.baseUrl||w}/${encodeURIComponent(r)}/${encodeURIComponent(n||"")}/_apis/git/repositories/${o}/pullrequests/${a}/reviewers/${i}?api-version=6.0`,body:JSON.stringify(l),headers:{...y(this.config,e),"Content-Type":"application/json"}})).body.id)throw new Error("Could not add pull request reviewer")}async removePullRequestReviewer(s,e={}){if(!s.repo.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let{repo:{namespace:r,project:n,name:o},pullRequestId:a,reviewerId:i}=s;await this.config.request({method:"DELETE",url:`${e.baseUrl||w}/${encodeURIComponent(r)}/${encodeURIComponent(n||"")}/_apis/git/repositories/${o}/pullrequests/${a}/reviewers/${i}?api-version=6.0`,headers:{...y(this.config,e),Accept:"application/json"}})}async getIssuesForAzureProject(s,e={}){let{page:r,assigneeLogins:n,authorLogin:o,mentionLogin:a,statusByWorkItemIdByStatusId:i}=s||{},u=r||1,l=200,p=["[Microsoft.VSTS.Common.ClosedDate] = ''","[System.TeamProject] = @project","[Microsoft.VSTS.Common.ResolvedDate] = ''"];o&&p.push(`[System.CreatedBy] = '${o.replace("'","''")}'`),n&&n[0]&&p.push(`[System.AssignedTo] = '${n[0].replace("'","''")}'`),a&&p.push("[System.Id] IN (@recentMentions)");let d=`Select [Microsoft.VSTS.Common.ClosedDate], [Microsoft.VSTS.Common.ResolvedDate] From WorkItems Where ${p.join(" AND ")} order by [System.CreatedDate] desc`,c=await this.config.request({url:`${e.baseUrl||w}/${encodeURIComponent(s.namespace)}/${encodeURIComponent(s.project)}/_apis/wit/wiql?api-version=6.0`,body:JSON.stringify({query:d}),method:"POST",headers:{...y(this.config,e),"Content-Type":"application/json"}}),g=c.body.workItems.slice((u-1)*l,l*u).map(R=>R.id);if(g.length==0)return{pageInfo:{hasNextPage:!1,nextPage:null},data:[]};let m=await this.config.request({url:`${e.baseUrl||w}/${encodeURIComponent(s.namespace)}/${encodeURIComponent(s.project)}/_apis/wit/workitemsbatch?api-version=6.0`,body:JSON.stringify({ids:g,$expand:"Links"}),method:"POST",headers:{...y(this.config,e),"Content-Type":"application/json"}});return{pageInfo:{hasNextPage:c.body.workItems.length>l*u,nextPage:u+1},data:m.body.value.map(R=>dt(R,i||{}))}}async updateIssue(s,e,r,n,o={}){return await this.config.request({method:"PATCH",url:`${o.baseUrl||w}/${encodeURIComponent(s)}/${encodeURIComponent(e||"")}/_apis/wit/workitems/${r}?api-version=6.0`,body:JSON.stringify(n),headers:{...y(this.config,o),"Content-Type":"application/json-patch+json"}})}async setIssueStatus(s,e={}){var l;if(!s.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let{namespace:r,project:n,issueId:o,status:a}=s,i=[{op:"add",path:"/fields/System.State",value:a}];if(!((l=(await this.updateIssue(r,n,o,i,e)).body.fields)!=null&&l["System.State"]))throw new Error("Could not set issue status")}async setIssueAssignee(s,e={}){var l;if(!s.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let{namespace:r,project:n,issueId:o,assigneeNameOrEmail:a}=s,i=[{op:"add",path:"/fields/System.AssignedTo",value:a??""}];if(!((l=(await this.updateIssue(r,n,o,i,e)).body.fields)!=null&&l["System.State"]))throw new Error("Could not set issue assignee")}async setIssueLabels(s,e={}){var l;let{namespace:r,project:n,issueId:o,tagNames:a}=s,i=[{op:"replace",path:"/fields/System.Tags",value:a.join(";")}];if(!((l=(await this.updateIssue(r,n,o,i,e)).body.fields)!=null&&l["System.Tags"]))throw new Error("Could not set issue tags")}async getIssueTypesForAzureProject(s,e={}){if(!s.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let{namespace:r,project:n}=s;return{data:(await this.config.request({url:`${e.baseUrl||w}/${encodeURIComponent(r)}/${encodeURIComponent(n||"")}/_apis/wit/workitemtypes?api-version=6.0`,headers:{...y(this.config,e)}})).body.value}}async getLabelsForProject(s,e={}){let{namespace:r,project:n}=s;return{data:(await this.config.request({url:`${e.baseUrl||w}/${encodeURIComponent(r)}/${encodeURIComponent(n||"")}/_apis/wit/tags?api-version=6.0`,headers:{...y(this.config,e)}})).body.value.map(a=>({color:null,description:null,id:a.id,name:a.name}))}}};var S=(t,s={})=>h(s.token||t.token,s.isPAT||t.isPAT);var C="https://api.bitbucket.org/2.0",ct={OPEN:"OPEN",MERGED:"MERGED",DECLINED:"CLOSED"},Je=t=>({id:t.uuid,name:t.display_name||t.nickname,username:t.nickname||t.display_name,email:null,avatarUrl:t.links.avatar.href}),ze=t=>{var s,e;return{id:t.uuid,namespace:t.workspace.slug,name:t.slug,webUrl:t.links.html.href,httpsUrl:((s=t.links.clone.find(r=>r.name==="https"))==null?void 0:s.href)??null,sshUrl:((e=t.links.clone.find(r=>r.name==="ssh"))==null?void 0:e.href)??null,defaultBranch:{name:t.mainbranch.name},permission:null}},he=t=>{let s=t.id;return{id:s.toString(),title:t.title,number:s,state:ct[t.state],isDraft:!1,commentCount:t.comment_count,upvoteCount:null,author:Je(t.author),createdDate:new Date(t.created_on),updatedDate:new Date(t.updated_on),closedDate:null,repository:{name:t.source.repository.name,owner:{login:void 0}},headCommit:{buildStatuses:null},baseRef:{name:t.destination.branch.name,oid:t.destination.commit.hash},headRef:{name:t.source.branch.name,oid:t.source.commit.hash},url:t.links.html.href,assignees:null,reviews:null,additions:null,deletions:null,fileCount:null,commitCount:null,headRepository:null,mergeableState:"UNKNOWN"}},B=class extends U{async refreshToken(s){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 ${s.base64ClientIDColonClientSecret}`},body:`grant_type=refresh_token&refresh_token=${s.refreshToken}`})).body}}async getCurrentUser(s={}){let e=await this.config.request({url:`${C}/user`,headers:S(this.config,s)});return{data:Je(e.body)}}async getUserForCommit(s,e={}){var a;let n=(await this.config.request({url:`${C}/repositories/${s.repo.namespace}/${s.repo.name}/commit/${s.oid}`,headers:S(this.config,e)})).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(s,e={}){let r=await this.config.request({url:`${C}/repositories/${s.namespace}/${s.name}`,headers:S(this.config,e)});return{data:ze(r.body)}}async getRepos(s,e={}){let r=[],n=[];return await Promise.all(s.map(async o=>{try{let a=await this.getRepo(o,e);r.push(a.data)}catch(a){n.push({input:o,error:a})}})),{data:r,errors:n}}async getReposForCurrentUser(s={},e={}){let r=new URL(`${C}/repositories`);r.searchParams.set("role","member"),r.searchParams.set("pagelen",$.toString()),s.cursor&&r.searchParams.set("after",s.cursor);let n=await this.config.request({url:r.toString(),headers:S(this.config,e)}),o=!!n.body.next,a=null;return n.body.next&&(a=new URL(n.body.next).searchParams.get("after")),{pageInfo:{hasNextPage:o,endCursor:a},data:n.body.values.map(ze)}}async getBranches(s,e={}){var a;let r=new URL(`${C}/repositories/${s.repo.namespace}/${s.repo.name}/refs/branches`);r.searchParams.set("page",((a=s.page)==null?void 0:a.toString())||"1"),r.searchParams.set("pagelen",$.toString());let n=await this.config.request({url:r.toString(),headers:S(this.config,e)}),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(s,e={}){let r=new URL(`${C}/repositories/${s.repo.namespace}/${s.repo.name}/refs/tags`);r.searchParams.set("pagelen",$.toString()),s.cursor&&r.searchParams.set("page",s.cursor);let n=await this.config.request({url:r.toString(),headers:S(this.config,e)}),o=!!n.body.next,a=null;return n.body.next&&(a=new URL(n.body.next).searchParams.get("page")),{pageInfo:{hasNextPage:o,endCursor:a},data:n.body.values.map(i=>{let u=new Date(i.target.date);return{name:i.name,commit:{oid:i.target.hash,authoredDate:u,committedDate:u}}})}}async getPullRequestsForUser(s,e={}){var a;let r=new URL(`${C}/pullrequests/${s.userId}`);r.searchParams.set("page",((a=s.page)==null?void 0:a.toString())||"1"),r.searchParams.set("pagelen","50");let n=await this.config.request({url:`${C}/pullrequests/${s.userId}`,headers:S(this.config,e)}),o=!!n.body.next;return{pageInfo:{hasNextPage:o,nextPage:o?n.body.page+1:null},data:n.body.values.map(he)}}async getPullRequestsForRepoBase(s,e={}){var n;let r=new URL(`${C}/repositories/${encodeURI(s.repo.namespace)}/${encodeURI(s.repo.name)}/pullrequests?state=OPEN`);return r.searchParams.set("page",((n=s.page)==null?void 0:n.toString())||"1"),r.searchParams.set("pagelen","50"),await this.config.request({url:r.toString(),headers:S(this.config,e)})}async getPullRequestsForRepo(s,e={}){let r=[],n=await this.getPullRequestsForRepoBase(s,e);n.body.values.forEach(a=>{if(s.authorLogin&&a.author.uuid!==s.authorLogin)return null;r.push(he(a))});let o=!!n.body.next;return{pageInfo:{hasNextPage:o,nextPage:o?n.body.page+1:null},data:r}}async getPullRequestsForRepos(s,e={}){let r=[];return await Promise.all(s.repos.map(async n=>{try{(await this.getPullRequestsForRepoBase({repo:n,...s},e)).body.values.forEach(a=>{if(s.authorLogin&&a.author.uuid!==s.authorLogin)return null;r.push(he(a))})}catch(o){if(o.statusCode!==404&&o.statusCode!==401)throw o}})),{data:r}}async closePullRequest(s,e={}){let{repo:{namespace:r,name:n},pullRequestId:o}=s;if(!(await this.config.request({method:"POST",url:`${C}/repositories/${r}/${n}/pullrequests/${o}/decline`,headers:S(this.config,e)})).body.title)throw new Error("Could not close pull request")}async mergePullRequest(s,e={}){let{repo:{namespace:r,name:n},pullRequestId:o,mergeStrategy:a}=s,i;switch(a){case"MERGE_COMMIT":{i="merge_commit";break}case"FAST_FORWARD":{i="fast_forward";break}case"SQUASH":{i="squash";break}}let u={merge_strategy:i,type:"pullrequest"};if(!(await this.config.request({method:"POST",url:`${C}/repositories/${r}/${n}/pullrequests/${o}/merge`,body:JSON.stringify(u),headers:{...S(this.config,e),"Content-Type":"application/json"}})).body.title)throw new Error("Could not merge pull request")}async setPullRequestReviewers(s,e={}){let{repo:{namespace:r,name:n},pullRequestId:o,reviewerUsernames:a}=s,i={reviewers:a.map(l=>({username:l}))};if(!(await this.config.request({method:"PUT",url:`${C}/repositories/${r}/${n}/pullrequests/${o}`,body:JSON.stringify(i),headers:{...S(this.config,e),"Content-Type":"application/json"}})).body.title)throw new Error("Could not set pull request reviewers")}};var F=class extends D{getBaseUrl(s){let e=s.baseUrl||this.config.baseUrl;if(!e)throw new Error('Bitbucket Server requires "baseUrl"');return e}getRequestHeaders(s){return h(s.token||this.config.token)}async getRepo(s,e={}){var n,o,a;let r=await this.config.request({url:`${this.getBaseUrl(e)}/projects/${s.namespace}/repos/${s.name}`,headers:this.getRequestHeaders(e)});return{data:{id:r.body.id.toString(),namespace:r.body.project.key,name:r.body.slug,webUrl:((n=r.body.links.self[0])==null?void 0:n.href)??null,httpsUrl:((o=r.body.links.clone.find(i=>i.name==="https"))==null?void 0:o.href)??null,sshUrl:((a=r.body.links.clone.find(i=>i.name==="ssh"))==null?void 0:a.href)??null,defaultBranch:null,permission:null}}}async getRepos(s,e={}){let r=[],n=[];return await Promise.all(s.map(async o=>{try{let a=await this.getRepo(o,e);r.push(a.data)}catch(a){n.push({input:o,error:a})}})),{data:r,errors:n}}async closePullRequest(s,e){let{repo:{namespace:r,name:n},pullRequestId:o,version:a}=s;if(!(await this.config.request({method:"POST",url:`${this.getBaseUrl(e)}/projects/${r}/repos/${n}/pull-requests/${o}/decline`,body:JSON.stringify({version:a}),headers:{...this.getRequestHeaders(e),"Content-Type":"application/json"}})).body.title)throw new Error("Could not close pull request")}async mergePullRequest(s,e){let{repo:{namespace:r,name:n},pullRequestId:o,mergeStrategyId:a,version:i}=s;if(!(await this.config.request({method:"POST",url:`${this.getBaseUrl(e)}/projects/${r}/repos/${n}/pull-requests/${o}/merge`,body:JSON.stringify({strategyId:a,version:i}),headers:{...this.getRequestHeaders(e),"Content-Type":"application/json"}})).body.title)throw new Error("Could not merge pull request")}async getMergeStrategies(s){let e=await this.config.request({url:`${this.getBaseUrl(s)}/admin/pull-requests/git`,headers:{...this.getRequestHeaders(s),"Content-Type":"application/json"}});return{data:{defaultStrategy:e.body.mergeConfig.defaultStrategy,strategies:e.body.mergeConfig.strategies}}}async setPullRequestReviewers(s,e={}){let{repo:{namespace:r,name:n},pullRequestId:o,reviewerUsernames:a,version:i}=s,u={reviewers:a.map(p=>({user:{name:p}})),version:i};if(!(await this.config.request({method:"PUT",url:`${this.getBaseUrl(e)}/projects/${r}/repos/${n}/pull-requests/${o}`,body:JSON.stringify(u),headers:{...this.getRequestHeaders(e),"Content-Type":"application/json"}})).body.title)throw new Error("Could not set pull request reviewers")}};var fe="https://api.github.com",gt=`${fe}/graphql`,ee=`
1
+ "use strict";var dt=Object.create;var Y=Object.defineProperty;var ct=Object.getOwnPropertyDescriptor;var gt=Object.getOwnPropertyNames;var mt=Object.getPrototypeOf,ht=Object.prototype.hasOwnProperty;var T=(t,s)=>{for(var e in s)Y(t,e,{get:s[e],enumerable:!0})},ze=(t,s,e,r)=>{if(s&&typeof s=="object"||typeof s=="function")for(let n of gt(s))!ht.call(t,n)&&n!==e&&Y(t,n,{get:()=>s[n],enumerable:!(r=ct(s,n))||r.enumerable});return t};var ft=(t,s,e)=>(e=t!=null?dt(mt(t)):{},ze(s||!t||!t.__esModule?Y(e,"default",{value:t,enumerable:!0}):e,t)),Rt=t=>ze(Y({},"__esModule",{value:!0}),t);var $s={};T($s,{AzureDevOps:()=>j,AzureDevopsUtils:()=>ce,Bitbucket:()=>Q,BitbucketServer:()=>B,BitbucketServerUtils:()=>me,BitbucketUtils:()=>ge,GitHub:()=>F,GitHubUtils:()=>he,GitLab:()=>W,GitLabUtils:()=>fe,Jira:()=>K,JiraServer:()=>V,JiraUtils:()=>Re,Trello:()=>X,TrelloUtils:()=>Ie,Utils:()=>Ss,default:()=>Ds});module.exports=Rt($s);var Ye=require("js-base64");var C=100;var We=ft(require("node-fetch")),He=globalThis.fetch||We.default;var Je=t=>t.name==="fetch";var It=async t=>{let s=t.headers.get("content-type")||"",e=null;if(s.startsWith("application/json")){let n=await t.text();e=n.trim().length>0?JSON.parse(n):null}else if(s.startsWith("text/")||s==="")e=await t.text();else throw new Error(`Unsupported content-type: ${s}`);let r={body:e,headers:Object.fromEntries(t.headers.entries()),status:t.status,statusText:t.statusText};if(!t.ok){let n=new Error(t.statusText);throw Object.assign(n,{response:r}),n}return r},be=t=>Je(t)?async({url:s,...e})=>{let r=await t(s,e);return It(r)}:t;var E=class{constructor(s){this.config={...s,request:be((s==null?void 0:s.request)||He)}}updateConfig(s){this.config={...this.config,...s,request:s.request?be(s.request):this.config.request}}},v=class extends E{};var m=(t,s)=>{let e={};return t&&(e.Authorization=`${s?"Basic":"Bearer"} ${t}`),e};var w=(t,s={})=>m(s.token||t.token,s.isPAT||t.isPAT),Ke=t=>t.url.replace("/_apis/git/repositories/","/_git/").replace(`/${t.repository.project.id}/`,`/${encodeURIComponent(t.repository.project.name)}/`).replace(`/${t.repository.id}/`,`/${encodeURIComponent(t.repository.name)}/`).replace("/pullRequests/","/pullrequest/");var Ve={APPROVED:0,COMMENTED:1,REVIEW_REQUESTED:2,CHANGES_REQUESTED:3},N=t=>!t||t.length===0?null:t.reduce((s,e)=>Ve[e.state]>Ve[s]?e.state:s,"APPROVED");var Xe="https://app.vssps.visualstudio.com/_apis",q="https://dev.azure.com",bt={active:"OPEN",completed:"MERGED",abandoned:"CLOSED"},yt={10:"APPROVED",5:"APPROVED",0:"REVIEW_REQUESTED",[-5]:"CHANGES_REQUESTED",[-10]:"CHANGES_REQUESTED"},ye=t=>({id:t.id,name:t.displayName,username:t.uniqueName||t.displayName,email:null,avatarUrl:t.imageUrl,url:null}),se=t=>t.startsWith("refs/heads/")?t.replace("refs/heads/",""):t,te=t=>{var e;let s=t.reviewers.filter(r=>r.vote!==0).map(r=>({reviewer:ye(r),state:yt[r.vote]||"REVIEW_REQUESTED"}));return{id:t.pullRequestId.toString(),title:t.title,number:t.codeReviewId,state:bt[t.status],isDraft:t.isDraft,commentCount:null,upvoteCount:null,author:ye(t.createdBy),createdDate:new Date(t.creationDate),updatedDate:new Date(t.closedDate||t.creationDate),closedDate:t.closedDate?new Date(t.closedDate):null,mergedDate:t.closedDate&&t.status==="completed"?new Date(t.closedDate):null,repository:{name:t.repository.name,project:t.repository.project.name,owner:{login:void 0},remoteInfo:null},headCommit:{buildStatuses:null},baseRef:{name:se(t.targetRefName),oid:t.lastMergeTargetCommit.commitId},headRef:{name:se(t.sourceRefName),oid:t.lastMergeSourceCommit.commitId},url:Ke(t),assignees:t.reviewers.map(ye),reviews:s,reviewDecision:N(s),additions:null,deletions:null,fileCount:null,commitCount:null,headRepository:null,mergeableState:"UNKNOWN",labels:((e=t.labels)==null?void 0:e.map(r=>({color:null,description:null,id:r.id,name:r.name})))??[]}},Ze=(t,s)=>({id:s.id,name:s.name,namespace:t,project:s.project.name,webUrl:s.webUrl,httpsUrl:s.remoteUrl,sshUrl:s.sshUrl,defaultBranch:s.defaultBranch?{name:se(s.defaultBranch)}:null,permission:null}),Pt=(t,s)=>{var i,u;let e=t.fields,r=e["System.AssignedTo"],n=e["System.State"],a=e["System.WorkItemType"],o;return n&&a&&(o=(i=s[a])==null?void 0:i[n]),{id:t.id.toString(),number:t.id.toString(),title:e["System.Title"],commentCount:e["System.CommentCount"],author:{avatarUrl:e["System.CreatedBy"]._links.avatar.href,email:null,id:e["System.CreatedBy"].id,name:e["System.CreatedBy"].uniqueName,username:e["System.CreatedBy"].displayName,url:null},closedDate:e["Microsoft.VSTS.Common.ClosedDate"]?new Date(e["Microsoft.VSTS.Common.ClosedDate"]):null,createdDate:new Date(e["System.CreatedDate"]),updatedDate:new Date(e["System.ChangedDate"]),url:t._links.html.href,assignees:r?[{avatarUrl:r._links.avatar.href,email:null,id:r.id,name:r.uniqueName,username:r.displayName,url:null}]:[],description:null,state:{name:(o==null?void 0:o.title)||n,color:null},type:e["System.WorkItemType"],repository:null,upvoteCount:0,labels:((u=t.fields["System.Tags"])==null?void 0:u.split(";").map(l=>({color:null,description:null,id:null,name:l.trim()})))??[]}},j=class extends E{async getCurrentUser(s={}){if(s.isPAT||this.config.isPAT)throw new Error("Azure DevOps does not support PATs for this function.");let e=await this.config.request({url:`${Xe}/profile/profiles/me`,headers:w(this.config,s)});return{data:{id:e.body.id,name:e.body.displayName,username:e.body.displayName,email:e.body.emailAddress,avatarUrl:null,url:null}}}async getCurrentUserForInstance(s,e={}){let n=(await this.config.request({url:`${q}/${encodeURIComponent(s.namespace)}/_apis/ConnectionData`,headers:w(this.config,e)})).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(s,e={}){if(!s.repo.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let n=(await this.config.request({url:`${q}/${encodeURIComponent(s.repo.namespace)}/${encodeURIComponent(s.repo.project)}/_apis/git/repositories/${encodeURIComponent(s.repo.name)}/commits/${s.oid}`,headers:w(this.config,e)})).body.author;return{data:{name:n.name,email:n.email,avatarUrl:n.imageUrl}}}async getOrgsForUser(s,e={}){return{data:(await this.config.request({url:`${Xe}/accounts?memberId=${s.userId}&api-version=6.0`,headers:w(this.config,e)})).body.value.map(n=>({id:n.accountId,name:n.accountName}))}}async getAzureProjects(s,e={}){let r=new URL(`${q}/${encodeURIComponent(s.namespace)}/_apis/projects`);r.searchParams.set("$top",C.toString()),s.cursor&&r.searchParams.set("$skip",s.cursor);let n=await this.config.request({url:r.toString(),headers:w(this.config,e)}),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:s.namespace}))}}async getAzureProjectScopeDescriptor(s,e={}){let{namespace:r,projectId:n}=s;return{data:{scope:(await this.config.request({url:`https://vssps.dev.azure.com/${encodeURIComponent(r)}/_apis/graph/descriptors/${n}?api-version=6.0`,headers:w(this.config,e)})).body.value}}}async getAccountsForAzureProject(s,e={}){let{namespace:r,projectScopeDescriptor:n}=s,a=new URL(`https://vssps.dev.azure.com/${encodeURIComponent(r)}/_apis/graph/users`);return n&&a.searchParams.set("scopeDescriptor",n),{data:(await this.config.request({url:a.toString(),headers:w(this.config,e)})).body.value.map(i=>{var u;return{id:Ye.Base64.decode(i.descriptor.replace(/.+?\./,"")),name:i.displayName,username:i.displayName,email:i.mailAddress,avatarUrl:(u=i._links.avatar)==null?void 0:u.href}})}}async getRepo(s,e={}){if(!s.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let r=await this.config.request({url:`${q}/${encodeURIComponent(s.namespace)}/${encodeURIComponent(s.project)}/_apis/git/repositories/${encodeURIComponent(s.name)}`,headers:w(this.config,e)});return{data:Ze(s.namespace,r.body)}}async getRepos(s,e={}){let r=[],n=[];return await Promise.all(s.map(async a=>{try{let o=await this.getRepo(a,e);r.push(o.data)}catch(o){n.push({input:a,error:o})}})),{data:r,errors:n}}async getReposForAzureProject(s,e={}){if(!s.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');return{data:(await this.config.request({url:`${q}/${encodeURIComponent(s.namespace)}/${encodeURIComponent(s.project)}/_apis/git/repositories`,headers:w(this.config,e)})).body.value.map(n=>Ze(s.namespace,n))}}async getRefs(s,e,r={}){if(!e.repo.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let n=new URL(`${q}/${encodeURIComponent(e.repo.namespace)}/${encodeURIComponent(e.repo.project)}/_apis/git/repositories/${encodeURIComponent(e.repo.name)}/refs`);n.searchParams.set("filter",s),n.searchParams.set("$top",C.toString()),e.cursor&&n.searchParams.set("continuationToken",e.cursor);let a=await this.config.request({url:n.toString(),headers:w(this.config,r)}),o=a.headers["x-ms-continuationtoken"];return{pageInfo:{hasNextPage:!!o,endCursor:o||null},data:a.body.value.map(i=>({name:se(i.name),commit:{oid:i.objectId,authoredDate:null,committedDate:null}}))}}async getBranches(s,e={}){return this.getRefs("heads",s,e)}async getTags(s,e={}){return this.getRefs("tags",s,e)}async getPullRequestsForRepoBase(s,e={},r=100){let{page:n,repo:a,assigneeLogins:o,authorLogin:i}=s||{},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:`${e.baseUrl||q}/${encodeURIComponent(a.namespace)}/${encodeURIComponent(a.project||"")}/_apis/git/repositories/${encodeURIComponent(a.name)}/pullRequests?${l}&%24top=${r}&%24skip=${(u-1)*r}`,headers:w(this.config,e)})}async getPullRequestsForRepo(s,e={}){let n=s.page||1,a=await this.getPullRequestsForRepoBase(s,e,100);return{pageInfo:{hasNextPage:a.body.value.length===100,nextPage:n+1},data:a.body.value.map(te)}}async getPullRequestsForRepos(s,e={}){if(!s.repos.every(a=>a.project))throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let{repos:r}=s||{},n=[];return await Promise.all(r.map(async a=>{try{(await this.getPullRequestsForRepoBase({repo:a,...s},e)).body.value.forEach(i=>{n.push(te(i))})}catch(o){if(o.statusCode!==404&&o.statusCode!==401)throw o}})),{data:n}}async getPullRequestsForProjectBase(s,e={},r=100){let{namespace:n,project:a,page:o,assigneeLogins:i,authorLogin:u}=s,l=o||1,p=new URL(`${e.baseUrl||q}/${encodeURIComponent(n)}/${encodeURIComponent(a)}/_apis/git/pullRequests`);return p.searchParams.set("searchCriteria.status","1"),p.searchParams.set("$top",r.toString()),p.searchParams.set("$skip",((l-1)*r).toString()),i&&i.length&&p.searchParams.set("searchCriteria.reviewerId",i[0]),u&&p.searchParams.set("searchCriteria.creatorId",u),await this.config.request({url:p.toString(),headers:w(this.config,e)})}async getPullRequestsForProject(s,e={}){let n=s.page||1,a=await this.getPullRequestsForProjectBase(s,e,100);return{pageInfo:{hasNextPage:a.body.value.length===100,nextPage:n+1},data:a.body.value.map(te)}}async getPullRequestsForProjects(s,e={}){let{projects:r}=s||{},n=[];return await Promise.all(r.map(async a=>{try{(await this.getPullRequestsForProjectBase({...a,...s},e)).body.value.forEach(i=>{n.push(te(i))})}catch(o){if(o.statusCode!==404&&o.statusCode!==401)throw o}})),{data:n}}async getAzurePullRequestLastMergeStatus(s,e={}){if(!s.repo.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let{repo:{namespace:r,project:n,name:a},pullRequestId:o}=s,i=await this.config.request({url:`${e.baseUrl||q}/${encodeURIComponent(r)}/${encodeURIComponent(n||"")}/_apis/git/repositories/${a}/pullrequests/${o}?includeCommits=true?api-version=6.0`,headers:{...w(this.config,e)}});if(!i.body.mergeStatus)throw new Error("Could not fetch pull request");return{data:i.body.mergeStatus}}async updatePullRequest(s,e,r,n){let{namespace:a,project:o,name:i}=s;return await this.config.request({method:"PATCH",url:`${n.baseUrl||q}/${encodeURIComponent(a)}/${encodeURIComponent(o||"")}/_apis/git/repositories/${i}/pullrequests/${e}?api-version=6.0`,body:r,headers:{...w(this.config,n),"Content-Type":"application/json"}})}async closePullRequest(s,e={}){if(!s.repo.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let{repo:r,pullRequestId:n}=s,a={status:"abandoned"};if(!(await this.updatePullRequest(r,n,JSON.stringify(a),e)).body.status)throw new Error("Could not close pull request")}async mergePullRequest(s,e={}){if(!s.repo.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let{repo:r,pullRequestId:n,expectedSourceSha:a,mergeStrategy:o}=s,i;switch(o){case"MERGE_COMMIT":{i="noFastForward";break}case"REBASE":{i="rebase";break}case"REBASE_THEN_MERGE_COMMIT":{i="rebaseMerge";break}case"SQUASH":{i="squash";break}}let u={completionOptions:{mergeStrategy:i},lastMergeSourceCommit:{commitId:a},status:"completed"};if(!(await this.updatePullRequest(r,n,JSON.stringify(u),e)).body.status)throw new Error("Could not merge pull request")}async addPullRequestLabel(s,e={}){let{repo:{namespace:r,project:n,name:a},pullRequestId:o,labelName:i}=s;if(!n)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let u={name:i};if(!(await this.config.request({method:"POST",url:`${e.baseUrl||q}/${encodeURIComponent(r)}/${encodeURIComponent(n||"")}/_apis/git/repositories/${a}/pullrequests/${o}/labels?api-version=6.0`,body:JSON.stringify(u),headers:{...w(this.config,e),"Content-Type":"application/json"}})).body.id)throw new Error("Could not add pull request label")}async removePullRequestLabel(s,e={}){let{repo:{namespace:r,project:n,name:a},pullRequestId:o,labelNameOrId:i}=s;if(!n)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');await this.config.request({method:"DELETE",url:`${e.baseUrl||q}/${encodeURIComponent(r)}/${encodeURIComponent(n||"")}/_apis/git/repositories/${a}/pullrequests/${o}/labels/${encodeURIComponent(i)}?api-version=6.0`,headers:{...w(this.config,e)}})}async setPullRequestAsDraft(s,e={}){if(!s.repo.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let{repo:r,pullRequestId:n,isDraft:a}=s,o={isDraft:a};if(!(await this.updatePullRequest(r,n,JSON.stringify(o),e)).body.status)throw new Error("Could not set the pull request as draft")}async addPullRequestReviewer(s,e={}){if(!s.repo.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let{repo:{namespace:r,project:n,name:a},pullRequestId:o,reviewerId:i,isRequired:u}=s,l={id:i,isRequired:u};if(!(await this.config.request({method:"PUT",url:`${e.baseUrl||q}/${encodeURIComponent(r)}/${encodeURIComponent(n||"")}/_apis/git/repositories/${a}/pullrequests/${o}/reviewers/${i}?api-version=6.0`,body:JSON.stringify(l),headers:{...w(this.config,e),"Content-Type":"application/json"}})).body.id)throw new Error("Could not add pull request reviewer")}async removePullRequestReviewer(s,e={}){if(!s.repo.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let{repo:{namespace:r,project:n,name:a},pullRequestId:o,reviewerId:i}=s;await this.config.request({method:"DELETE",url:`${e.baseUrl||q}/${encodeURIComponent(r)}/${encodeURIComponent(n||"")}/_apis/git/repositories/${a}/pullrequests/${o}/reviewers/${i}?api-version=6.0`,headers:{...w(this.config,e),Accept:"application/json"}})}async getIssuesForAzureProject(s,e={}){let{page:r,assigneeLogins:n,authorLogin:a,mentionLogin:o,statusByWorkItemIdByStatusId:i}=s||{},u=r||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:`${e.baseUrl||q}/${encodeURIComponent(s.namespace)}/${encodeURIComponent(s.project)}/_apis/wit/wiql?api-version=6.0`,body:JSON.stringify({query:d}),method:"POST",headers:{...w(this.config,e),"Content-Type":"application/json"}}),g=c.body.workItems.slice((u-1)*l,l*u).map(h=>h.id);if(g.length==0)return{pageInfo:{hasNextPage:!1,nextPage:null},data:[]};let R=await this.config.request({url:`${e.baseUrl||q}/${encodeURIComponent(s.namespace)}/${encodeURIComponent(s.project)}/_apis/wit/workitemsbatch?api-version=6.0`,body:JSON.stringify({ids:g,$expand:"Links"}),method:"POST",headers:{...w(this.config,e),"Content-Type":"application/json"}});return{pageInfo:{hasNextPage:c.body.workItems.length>l*u,nextPage:u+1},data:R.body.value.map(h=>Pt(h,i||{}))}}async updateIssue(s,e,r,n,a={}){return await this.config.request({method:"PATCH",url:`${a.baseUrl||q}/${encodeURIComponent(s)}/${encodeURIComponent(e||"")}/_apis/wit/workitems/${r}?api-version=6.0`,body:JSON.stringify(n),headers:{...w(this.config,a),"Content-Type":"application/json-patch+json"}})}async setIssueStatus(s,e={}){var l;if(!s.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let{namespace:r,project:n,issueId:a,status:o}=s,i=[{op:"add",path:"/fields/System.State",value:o}];if(!((l=(await this.updateIssue(r,n,a,i,e)).body.fields)!=null&&l["System.State"]))throw new Error("Could not set issue status")}async setIssueAssignee(s,e={}){var l;if(!s.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let{namespace:r,project:n,issueId:a,assigneeNameOrEmail:o}=s,i=[{op:"add",path:"/fields/System.AssignedTo",value:o??""}];if(!((l=(await this.updateIssue(r,n,a,i,e)).body.fields)!=null&&l["System.State"]))throw new Error("Could not set issue assignee")}async setIssueLabels(s,e={}){var l;let{namespace:r,project:n,issueId:a,tagNames:o}=s,i=[{op:"replace",path:"/fields/System.Tags",value:o.join(";")}];if(!((l=(await this.updateIssue(r,n,a,i,e)).body.fields)!=null&&l["System.Tags"]))throw new Error("Could not set issue tags")}async getIssueTypesForAzureProject(s,e={}){if(!s.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let{namespace:r,project:n}=s;return{data:(await this.config.request({url:`${e.baseUrl||q}/${encodeURIComponent(r)}/${encodeURIComponent(n||"")}/_apis/wit/workitemtypes?api-version=6.0`,headers:{...w(this.config,e)}})).body.value}}async getLabelsForProject(s,e={}){let{namespace:r,project:n}=s;return{data:(await this.config.request({url:`${e.baseUrl||q}/${encodeURIComponent(r)}/${encodeURIComponent(n||"")}/_apis/wit/tags?api-version=6.0`,headers:{...w(this.config,e)}})).body.value.map(o=>({color:null,description:null,id:o.id,name:o.name}))}}};var S=(t,s={})=>m(s.token||t.token,s.isPAT||t.isPAT);var $="https://api.bitbucket.org/2.0",wt={OPEN:"OPEN",MERGED:"MERGED",DECLINED:"CLOSED"},tt=t=>({id:t.uuid,name:t.display_name||t.nickname,username:t.nickname||t.display_name,email:null,avatarUrl:t.links.avatar.href,url:t.links.html.href}),et=t=>{var s,e;return{id:t.uuid,namespace:t.workspace.slug,name:t.slug,webUrl:t.links.html.href,httpsUrl:((s=t.links.clone.find(r=>r.name==="https"))==null?void 0:s.href)??null,sshUrl:((e=t.links.clone.find(r=>r.name==="ssh"))==null?void 0:e.href)??null,defaultBranch:{name:t.mainbranch.name},permission:null}},qe=t=>{let s=t.id;return{id:s.toString(),title:t.title,number:s,state:wt[t.state],isDraft:!1,commentCount:t.comment_count,upvoteCount:null,author:tt(t.author),createdDate:new Date(t.created_on),updatedDate:new Date(t.updated_on),closedDate:null,mergedDate:null,repository:{name:t.source.repository.name,owner:{login:void 0},remoteInfo:null},headCommit:{buildStatuses:null},baseRef:{name:t.destination.branch.name,oid:t.destination.commit.hash},headRef:{name:t.source.branch.name,oid:t.source.commit.hash},url:t.links.html.href,assignees:null,reviews:null,reviewDecision:null,additions:null,deletions:null,fileCount:null,commitCount:null,headRepository:null,mergeableState:"UNKNOWN"}},Q=class extends E{async refreshToken(s){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 ${s.base64ClientIDColonClientSecret}`},body:`grant_type=refresh_token&refresh_token=${s.refreshToken}`})).body}}async getCurrentUser(s={}){let e=await this.config.request({url:`${$}/user`,headers:S(this.config,s)});return{data:tt(e.body)}}async getUserForCommit(s,e={}){var o;let n=(await this.config.request({url:`${$}/repositories/${s.repo.namespace}/${s.repo.name}/commit/${s.oid}`,headers:S(this.config,e)})).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(s,e={}){let r=await this.config.request({url:`${$}/repositories/${s.namespace}/${s.name}`,headers:S(this.config,e)});return{data:et(r.body)}}async getRepos(s,e={}){let r=[],n=[];return await Promise.all(s.map(async a=>{try{let o=await this.getRepo(a,e);r.push(o.data)}catch(o){n.push({input:a,error:o})}})),{data:r,errors:n}}async getReposForCurrentUser(s={},e={}){let r=new URL(`${$}/repositories`);r.searchParams.set("role","member"),r.searchParams.set("pagelen",C.toString()),s.cursor&&r.searchParams.set("after",s.cursor);let n=await this.config.request({url:r.toString(),headers:S(this.config,e)}),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(et)}}async getBranches(s,e={}){var o;let r=new URL(`${$}/repositories/${s.repo.namespace}/${s.repo.name}/refs/branches`);r.searchParams.set("page",((o=s.page)==null?void 0:o.toString())||"1"),r.searchParams.set("pagelen",C.toString());let n=await this.config.request({url:r.toString(),headers:S(this.config,e)}),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(s,e={}){let r=new URL(`${$}/repositories/${s.repo.namespace}/${s.repo.name}/refs/tags`);r.searchParams.set("pagelen",C.toString()),s.cursor&&r.searchParams.set("page",s.cursor);let n=await this.config.request({url:r.toString(),headers:S(this.config,e)}),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 getPullRequestsForUser(s,e={}){var o;let r=new URL(`${$}/pullrequests/${s.userId}`);r.searchParams.set("page",((o=s.page)==null?void 0:o.toString())||"1"),r.searchParams.set("pagelen","50");let n=await this.config.request({url:`${$}/pullrequests/${s.userId}`,headers:S(this.config,e)}),a=!!n.body.next;return{pageInfo:{hasNextPage:a,nextPage:a?n.body.page+1:null},data:n.body.values.map(qe)}}async getPullRequestsForRepoBase(s,e={}){var n;let r=new URL(`${$}/repositories/${encodeURI(s.repo.namespace)}/${encodeURI(s.repo.name)}/pullrequests?state=OPEN`);return r.searchParams.set("page",((n=s.page)==null?void 0:n.toString())||"1"),r.searchParams.set("pagelen","50"),await this.config.request({url:r.toString(),headers:S(this.config,e)})}async getPullRequestsForRepo(s,e={}){let r=[],n=await this.getPullRequestsForRepoBase(s,e);n.body.values.forEach(o=>{if(s.authorLogin&&o.author.uuid!==s.authorLogin)return null;r.push(qe(o))});let a=!!n.body.next;return{pageInfo:{hasNextPage:a,nextPage:a?n.body.page+1:null},data:r}}async getPullRequestsForRepos(s,e={}){let r=[];return await Promise.all(s.repos.map(async n=>{try{(await this.getPullRequestsForRepoBase({repo:n,...s},e)).body.values.forEach(o=>{if(s.authorLogin&&o.author.uuid!==s.authorLogin)return null;r.push(qe(o))})}catch(a){if(a.statusCode!==404&&a.statusCode!==401)throw a}})),{data:r}}async closePullRequest(s,e={}){let{repo:{namespace:r,name:n},pullRequestId:a}=s;if(!(await this.config.request({method:"POST",url:`${$}/repositories/${r}/${n}/pullrequests/${a}/decline`,headers:S(this.config,e)})).body.title)throw new Error("Could not close pull request")}async mergePullRequest(s,e={}){let{repo:{namespace:r,name:n},pullRequestId:a,mergeStrategy:o}=s,i;switch(o){case"MERGE_COMMIT":{i="merge_commit";break}case"FAST_FORWARD":{i="fast_forward";break}case"SQUASH":{i="squash";break}}let u={merge_strategy:i,type:"pullrequest"};if(!(await this.config.request({method:"POST",url:`${$}/repositories/${r}/${n}/pullrequests/${a}/merge`,body:JSON.stringify(u),headers:{...S(this.config,e),"Content-Type":"application/json"}})).body.title)throw new Error("Could not merge pull request")}async setPullRequestReviewers(s,e={}){let{repo:{namespace:r,name:n},pullRequestId:a,reviewerUsernames:o}=s,i={reviewers:o.map(l=>({username:l}))};if(!(await this.config.request({method:"PUT",url:`${$}/repositories/${r}/${n}/pullrequests/${a}`,body:JSON.stringify(i),headers:{...S(this.config,e),"Content-Type":"application/json"}})).body.title)throw new Error("Could not set pull request reviewers")}};var B=class extends v{getBaseUrl(s){let e=s.baseUrl||this.config.baseUrl;if(!e)throw new Error('Bitbucket Server requires "baseUrl"');return e}getRequestHeaders(s){return m(s.token||this.config.token)}async getRepo(s,e={}){var n,a,o;let r=await this.config.request({url:`${this.getBaseUrl(e)}/projects/${s.namespace}/repos/${s.name}`,headers:this.getRequestHeaders(e)});return{data:{id:r.body.id.toString(),namespace:r.body.project.key,name:r.body.slug,webUrl:((n=r.body.links.self[0])==null?void 0:n.href)??null,httpsUrl:((a=r.body.links.clone.find(i=>i.name==="https"))==null?void 0:a.href)??null,sshUrl:((o=r.body.links.clone.find(i=>i.name==="ssh"))==null?void 0:o.href)??null,defaultBranch:null,permission:null}}}async getRepos(s,e={}){let r=[],n=[];return await Promise.all(s.map(async a=>{try{let o=await this.getRepo(a,e);r.push(o.data)}catch(o){n.push({input:a,error:o})}})),{data:r,errors:n}}async closePullRequest(s,e){let{repo:{namespace:r,name:n},pullRequestId:a,version:o}=s;if(!(await this.config.request({method:"POST",url:`${this.getBaseUrl(e)}/projects/${r}/repos/${n}/pull-requests/${a}/decline`,body:JSON.stringify({version:o}),headers:{...this.getRequestHeaders(e),"Content-Type":"application/json"}})).body.title)throw new Error("Could not close pull request")}async mergePullRequest(s,e){let{repo:{namespace:r,name:n},pullRequestId:a,mergeStrategyId:o,version:i}=s;if(!(await this.config.request({method:"POST",url:`${this.getBaseUrl(e)}/projects/${r}/repos/${n}/pull-requests/${a}/merge`,body:JSON.stringify({strategyId:o,version:i}),headers:{...this.getRequestHeaders(e),"Content-Type":"application/json"}})).body.title)throw new Error("Could not merge pull request")}async getMergeStrategies(s){let e=await this.config.request({url:`${this.getBaseUrl(s)}/admin/pull-requests/git`,headers:{...this.getRequestHeaders(s),"Content-Type":"application/json"}});return{data:{defaultStrategy:e.body.mergeConfig.defaultStrategy,strategies:e.body.mergeConfig.strategies}}}async setPullRequestReviewers(s,e={}){let{repo:{namespace:r,name:n},pullRequestId:a,reviewerUsernames:o,version:i}=s,u={reviewers:o.map(p=>({user:{name:p}})),version:i};if(!(await this.config.request({method:"PUT",url:`${this.getBaseUrl(e)}/projects/${r}/repos/${n}/pull-requests/${a}`,body:JSON.stringify(u),headers:{...this.getRequestHeaders(e),"Content-Type":"application/json"}})).body.title)throw new Error("Could not set pull request reviewers")}};var Ce="https://api.github.com",qt=`${Ce}/graphql`,ne=`
2
2
  description
3
3
  dueOn
4
4
  id
@@ -6,12 +6,12 @@ number
6
6
  state
7
7
  title
8
8
  url
9
- `,We=/\/api\/v\d+$/,te=`
9
+ `,st=/\/api\/v\d+$/,oe=`
10
10
  color
11
11
  description
12
12
  id
13
13
  name
14
- `,mt=t=>{if(t.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.")},ht=(t,s)=>{let e=s.baseUrl||t.baseUrl;return e?(e=e.replace(/\/$/,""),mt(e),We.test(e)&&(e=e.replace(We,"")),`${e}/api/graphql`):gt},f=(t,s,e)=>{let r=h(e.token||t.token);return r["X-Github-Next-Global-ID"]="1",r["Content-Type"]="application/json",t.request({url:ht(t,e),method:"POST",headers:r,body:JSON.stringify(s)})},ft={user:!0,"user:email":!0,"read:user":!0},T=t=>t.some(s=>ft[s]),E=(t=!1,s=!1)=>`
14
+ `,Ct=t=>{if(t.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.")},Dt=(t,s)=>{let e=s.baseUrl||t.baseUrl;return e?(e=e.replace(/\/$/,""),Ct(e),st.test(e)&&(e=e.replace(st,"")),`${e}/api/graphql`):qt},I=(t,s,e)=>{let r=m(e.token||t.token);return r["X-Github-Next-Global-ID"]="1",r["Content-Type"]="application/json",t.request({url:Dt(t,e),method:"POST",headers:r,body:JSON.stringify(s)})},St={user:!0,"user:email":!0,"read:user":!0},x=t=>t.some(s=>St[s]),U=(t=!1,s=!1)=>`
15
15
  __typename
16
16
  id
17
17
  databaseId
@@ -19,13 +19,15 @@ name
19
19
  login
20
20
  ${s?"email":""}
21
21
  avatarUrl${t?"(size: $avatarSize)":""}
22
- `,He=(t=!1)=>`
22
+ url
23
+ `,rt=(t=!1)=>`
23
24
  __typename
24
25
  id
25
26
  databaseId
26
27
  login
27
28
  avatarUrl${t?"(size: $avatarSize)":""}
28
- `,Rt=(t,s=!1)=>`
29
+ url
30
+ `,$t=(t,s=!1)=>`
29
31
  id
30
32
  databaseId
31
33
  number
@@ -33,10 +35,10 @@ title
33
35
  state
34
36
  author {
35
37
  ... on User {
36
- ${E(!1,s)}
38
+ ${U(!1,s)}
37
39
  }
38
40
  ... on Bot {
39
- ${He(!1)}
41
+ ${rt(!1)}
40
42
  }
41
43
  }
42
44
  commits(last: 1) {
@@ -84,6 +86,8 @@ repository {
84
86
  owner {
85
87
  login
86
88
  }
89
+ url
90
+ sshUrl
87
91
  }
88
92
  headRepository {
89
93
  name
@@ -104,9 +108,10 @@ reactions(content: THUMBS_UP) {
104
108
  }
105
109
  updatedAt
106
110
  closedAt
111
+ mergedAt
107
112
  assignees(first: 100) {
108
113
  nodes {
109
- ${E(!1,s)}
114
+ ${U(!1,s)}
110
115
  }
111
116
  }
112
117
  reviewRequests(first: 100) {
@@ -114,7 +119,7 @@ reviewRequests(first: 100) {
114
119
  asCodeOwner
115
120
  requestedReviewer {
116
121
  ... on User {
117
- ${E(!1,s)}
122
+ ${U(!1,s)}
118
123
  }
119
124
  }
120
125
  }
@@ -123,7 +128,7 @@ latestReviews(first: 100) {
123
128
  nodes {
124
129
  author {
125
130
  ... on User {
126
- ${E(!1,s)}
131
+ ${U(!1,s)}
127
132
  }
128
133
  }
129
134
  state
@@ -134,25 +139,26 @@ deletions
134
139
  changedFiles
135
140
  mergeable
136
141
  milestone {
137
- ${ee}
142
+ ${ne}
138
143
  }
139
144
  labels(first: 100) {
140
145
  nodes {
141
- ${te}
146
+ ${oe}
142
147
  }
143
148
  }
144
- `,It=(t=!1)=>`
149
+ `,Et=(t=!1)=>`
145
150
  id
146
151
  databaseId
147
152
  title
148
153
  author {
149
154
  ... on User {
150
- ${E(!1,t)}
155
+ ${U(!1,t)}
151
156
  }
152
157
  ... on Bot {
153
- ${He(!1)}
158
+ ${rt(!1)}
154
159
  }
155
160
  }
161
+ closedAt
156
162
  createdAt
157
163
  number
158
164
  updatedAt
@@ -171,19 +177,19 @@ comments {
171
177
  }
172
178
  assignees(first: 100) {
173
179
  nodes {
174
- ${E(!1,t)}
180
+ ${U(!1,t)}
175
181
  }
176
182
  }
177
183
  state
178
184
  milestone {
179
- ${ee}
185
+ ${ne}
180
186
  }
181
187
  labels(first: 100) {
182
188
  nodes {
183
- ${te}
189
+ ${oe}
184
190
  }
185
191
  }
186
- `,yt={"-linked":"-linked",archived:"archived",assignee:"assignee",author:"author",base:"base",closed:"closed",commenter:"commenter",comments:"comments",created:"created",draft:"draft",head:"head",label:"label",language:"language",linked:"linked",in:"in",interactions:"interactions",involves:"involves",is:"is",mentions:"mentions",merged:"merged",milestone:"milestone",no:"no",org:"org",project:"project",reactions:"reactions",repo:"repo",review:"review","reviewed-by":"reviewed-by","review-requested":"review-requested",state:"state",status:"status",team:"team","team-review-requested":"team-review-requested",type:"type",updated:"updated",user:"user","user-review-requested":"user-review-requested"},bt=new RegExp('(([^\\s]+:)?\\"(?:[^\\"\\\\]|\\\\.)*\\"?)|([^\\"\\s]+)',"g"),Re=t=>{let s=[];return(t.match(bt)??[]).forEach(r=>{if(r.includes(":")&&r!="is:closed"){let n=r.split(":")[0];yt[n]&&s.push(r)}}),s},Ie=(t,s,e,r,n=!1)=>{let o=t==="issue";return{query:`
192
+ `,Ut={"-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"},vt=new RegExp('(([^\\s]+:)?\\"(?:[^\\"\\\\]|\\\\.)*\\"?)|([^\\"\\s]+)',"g"),De=t=>{let s=[];return(t.match(vt)??[]).forEach(r=>{if(r.includes(":")&&r!="is:closed"){let n=r.split(":")[0];Ut[n]&&s.push(r)}}),s},Se=(t,s,e,r,n=!1)=>{let a=t==="issue";return{query:`
187
193
  query SearchIssuesOrPullRequests($query: String! $after: String) {
188
194
  search(type:ISSUE query:$query first:100 after:$after) {
189
195
  pageInfo {
@@ -191,12 +197,19 @@ query SearchIssuesOrPullRequests($query: String! $after: String) {
191
197
  endCursor
192
198
  }
193
199
  nodes {
194
- ... on ${o?"Issue":"PullRequest"} {
195
- ${o?It(r):Rt(n,r)}
200
+ ... on ${a?"Issue":"PullRequest"} {
201
+ ${a?Et(r):$t(n,r)}
196
202
  }
197
203
  }
198
204
  }
199
- }`,variables:{query:`is:${t} is:open ${s}`,after:e}}},Pt="Field 'isDraft' doesn't exist on type 'PullRequest'",Ve=(t=[])=>t.some(s=>(s==null?void 0:s.message)===Pt);var ye=`
205
+ }`,variables:{query:`is:${t} is:open ${s}`,after:e}}},Lt="Field 'isDraft' doesn't exist on type 'PullRequest'",nt=(t=[])=>t.some(s=>(s==null?void 0:s.message)===Lt),Gt=/@@ -(\d+)(?:,\d+ | )\+(\d+)(?:,\d+ | )@@(?:\\n)?/,Ot=`
206
+ \
207
+ +`,ot=(t,s,e,r)=>{let n=Gt.exec(t);if(!n||!n[0]||!n[1])return[];let a=parseInt(n[1],10),o=parseInt(n[2],10),i=t.replace(Ot,`
208
+ +`).split(`
209
+ `).slice(1),u=a-1,l=o-1,p=i.map(g=>{let R,h;switch(g[0]){case"-":{R="DELETED",u+=1,h=`${g.slice(1)}
210
+ `;break}case"+":{R="ADDED",l+=1,h=`${g.slice(1)}
211
+ `;break}default:R="UNMODIFIED",l+=1,u+=1,h=`${g}
212
+ `}return{line:h,oldLineNumber:R!=="ADDED"?u:null,newLineNumber:R!=="DELETED"?l:null,type:R}}),d=e,c=s;if(d!==null&&c!==null&&r!==null&&d<c){let g=0,R=p.length,h=r==="LEFT"?"oldLineNumber":"newLineNumber";for(let b=0;b<p.length;b++){let P=p[b][h];P===d?g=b:P===c&&(R=b)}p=p.slice(g,R+1)}return p};var $e=`
200
213
  id
201
214
  databaseId
202
215
  owner {
@@ -209,18 +222,18 @@ defaultBranchRef {
209
222
  name
210
223
  }
211
224
  viewerPermission
212
- `,Pe={__typename:"User",id:"U_kgDNJ5k",databaseId:10137,name:"Deleted user",login:"ghost",email:"",avatarUrl:"https://avatars.githubusercontent.com/u/10137?v=4"},wt={APPROVED:"APPROVED",CHANGES_REQUESTED:"CHANGES_REQUESTED",COMMENTED:"COMMENTED",REVIEW_REQUESTED:"REVIEW_REQUESTED"},qt={MERGEABLE:"MERGEABLE",CONFLICTING:"CONFLICTS",UNKNOWN:"UNKNOWN"},$t={OPEN:"OPEN",CLOSED:"CLOSED"},we=t=>({color:t.color,description:t.description,graphQLId:t.id,id:null,name:t.name}),be=t=>({id:t.databaseId.toString(),graphQLId:t.id,namespace:t.owner.login,name:t.name,webUrl:t.url,httpsUrl:t.url.endsWith(".git")?t.url:`${t.url}.git`,sshUrl:t.sshUrl,defaultBranch:t.defaultBranchRef,permission:t.viewerPermission}),St={OPEN:"OPEN",CLOSED:"CLOSED",MERGED:"MERGED"},L=t=>({id:t.databaseId.toString(),graphQLId:t.id,name:t.name??t.login,username:t.login,email:t.email??null,avatarUrl:t.avatarUrl}),Ct=t=>{var n,o,a,i,u,l,p,d,c,g;let s=null;t.author?s=(t.author.__typename==="Bot",t.author):s=Pe;let e=(((n=t.reviewRequests)==null?void 0:n.nodes)||[]).filter(m=>!m.asCodeOwner),r=(o=t.headRepository)==null?void 0:o.url;return r&&!r.endsWith(".git")&&(r=`${r}.git`),{id:t.databaseId.toString(),graphQLId:t.id,title:t.title,number:t.number,state:St[t.state],commentCount:t.comments.totalCount,upvoteCount:t.reactions.totalCount,author:s?L(s):null,createdDate:new Date(t.createdAt),isDraft:t.isDraft,repository:{name:t.repository.name,owner:{login:t.repository.owner.login}},headRepository:t.headRepository?{name:t.headRepository.name,owner:{login:t.headRepository.owner.login},remoteInfo:{cloneUrlHTTPS:r,cloneUrlSSH:t.headRepository.sshUrl}}:null,headCommit:{buildStatuses:((u=(i=(a=t.commits.nodes)==null?void 0:a[0].commit.statusCheckRollup)==null?void 0:i.contexts.nodes)==null?void 0:u.map(m=>"context"in m?{description:m.description,name:m.context,state:m.state,stage:null,url:m.targetUrl}:{description:null,name:m.name,state:m.status,stage:null,url:m.permalink}))??[]},headRef:t.headRef?{name:t.headRef.name,oid:((l=t.headRef.target)==null?void 0:l.oid)??null}:null,baseRef:t.baseRef?{name:t.baseRef.name,oid:((p=t.baseRef.target)==null?void 0:p.oid)??null}:null,url:t.url,updatedDate:new Date(t.updatedAt),closedDate:t.closedAt?new Date(t.closedAt):null,assignees:t.assignees.nodes?t.assignees.nodes.map(L):null,reviews:e.map(m=>({reviewer:L(m.requestedReviewer),state:"REVIEW_REQUESTED"})).concat((((d=t.latestReviews)==null?void 0:d.nodes)||[]).map(m=>{let R=m.author||Pe;return{reviewer:L(R),state:wt[m.state]}})),additions:t.additions,deletions:t.deletions,fileCount:t.changedFiles,commitCount:t.commits.totalCount,mergeableState:qt[t.mergeable],milestone:t.milestone?qe(t.milestone):null,labels:((g=(c=t.labels)==null?void 0:c.nodes)==null?void 0:g.map(we))??[]}},Ut=t=>{var e,r;let s=null;return t.author?s=(t.author.__typename==="Bot",t.author):s=Pe,{id:t.databaseId.toString(),graphQLId:t.id,number:t.number,title:t.title,author:L(s),commentCount:t.comments.totalCount,createdDate:new Date(t.createdAt),description:null,state:{name:$t[t.state],color:null},type:null,repository:{name:t.repository.name,owner:{login:t.repository.owner.login}},url:t.url,updatedDate:new Date(t.updatedAt),assignees:t.assignees.nodes?t.assignees.nodes.map(L):[],upvoteCount:t.reactions.totalCount,milestone:t.milestone?qe(t.milestone):null,labels:((r=(e=t.labels)==null?void 0:e.nodes)==null?void 0:r.map(we))??[]}},qe=t=>({id:t.number.toString(),graphQLId:t.id.toString(),number:t.number,title:t.title,description:t.description,isOpen:t.state=="OPEN",url:t.url,startDate:null,dueDate:t.dueOn?new Date(t.dueOn):null}),M=class extends D{constructor(){super(...arguments);this._scopesCache={}}async getScopes(e){let r=e.token||this.config.token;if(!r)return[];let n=this._scopesCache[r];if(!n){let a=(await f(this.config,{query:"query { rateLimit(dryRun: true) { __typename } }"},e)).headers["x-oauth-scopes"];n=a?a.split(", "):[],this._scopesCache[r]=n}return n}getEnterpriseAvatarUrlIfNeeded(e,r,n){let o=n.baseUrl||this.config.baseUrl;return!o||o.startsWith(fe)?e:r?`https://avatars.githubusercontent.com/u/e?email=${encodeURIComponent(r)}`:""}async getCurrentUser(e={}){var a;let r=await this.getScopes(e),o=(a=(await f(this.config,{query:`
225
+ `,Ue={__typename:"User",id:"U_kgDNJ5k",databaseId:10137,name:"Deleted user",login:"ghost",email:"",avatarUrl:"https://avatars.githubusercontent.com/u/10137?v=4",url:"https://github.com/ghost"},At={APPROVED:"APPROVED",CHANGES_REQUESTED:"CHANGES_REQUESTED",COMMENTED:"COMMENTED",REVIEW_REQUESTED:"REVIEW_REQUESTED"},Tt={MERGEABLE:"MERGEABLE",CONFLICTING:"CONFLICTS",UNKNOWN:"UNKNOWN"},xt={OPEN:"OPEN",CLOSED:"CLOSED"},ve=t=>({color:t.color,description:t.description,graphQLId:t.id,id:null,name:t.name}),Ee=t=>({id:t.databaseId.toString(),graphQLId:t.id,namespace:t.owner.login,name:t.name,webUrl:t.url,httpsUrl:t.url.endsWith(".git")?t.url:`${t.url}.git`,sshUrl:t.sshUrl,defaultBranch:t.defaultBranchRef,permission:t.viewerPermission}),kt={OPEN:"OPEN",CLOSED:"CLOSED",MERGED:"MERGED"},L=t=>({id:t.databaseId.toString(),graphQLId:t.id,name:t.name??t.login,username:t.login,email:t.email??null,avatarUrl:t.avatarUrl,url:t.url}),_t=t=>{var o,i,u,l,p,d,c,g,R,h,b;let s=null;t.author?s=(t.author.__typename==="Bot",t.author):s=Ue;let e=(((o=t.reviewRequests)==null?void 0:o.nodes)||[]).filter(f=>!f.asCodeOwner),r=(i=t.headRepository)==null?void 0:i.url;r&&!r.endsWith(".git")&&(r=`${r}.git`);let n=(u=t.repository)==null?void 0:u.url;n&&!n.endsWith(".git")&&(n=`${n}.git`);let a=e.map(f=>({reviewer:L(f.requestedReviewer),state:"REVIEW_REQUESTED"})).concat((((l=t.latestReviews)==null?void 0:l.nodes)||[]).map(f=>{let P=f.author||Ue;return{reviewer:L(P),state:At[f.state]}}));return{id:t.databaseId.toString(),graphQLId:t.id,title:t.title,number:t.number,state:kt[t.state],commentCount:t.comments.totalCount,upvoteCount:t.reactions.totalCount,author:s?L(s):null,createdDate:new Date(t.createdAt),isDraft:t.isDraft,repository:{name:t.repository.name,owner:{login:t.repository.owner.login},remoteInfo:{cloneUrlHTTPS:n,cloneUrlSSH:t.repository.sshUrl}},headRepository:t.headRepository?{name:t.headRepository.name,owner:{login:t.headRepository.owner.login},remoteInfo:{cloneUrlHTTPS:r,cloneUrlSSH:t.headRepository.sshUrl}}:null,headCommit:{buildStatuses:((c=(d=(p=t.commits.nodes)==null?void 0:p[0].commit.statusCheckRollup)==null?void 0:d.contexts.nodes)==null?void 0:c.map(f=>"context"in f?{description:f.description,name:f.context,state:f.state,stage:null,url:f.targetUrl}:{description:null,name:f.name,state:f.status,stage:null,url:f.permalink}))??[]},headRef:t.headRef?{name:t.headRef.name,oid:((g=t.headRef.target)==null?void 0:g.oid)??null}:null,baseRef:t.baseRef?{name:t.baseRef.name,oid:((R=t.baseRef.target)==null?void 0:R.oid)??null}:null,url:t.url,updatedDate:new Date(t.updatedAt),closedDate:t.closedAt?new Date(t.closedAt):null,mergedDate:t.mergedAt?new Date(t.mergedAt):null,assignees:t.assignees.nodes?t.assignees.nodes.map(L):null,reviews:a,reviewDecision:N(a),additions:t.additions,deletions:t.deletions,fileCount:t.changedFiles,commitCount:t.commits.totalCount,mergeableState:Tt[t.mergeable],milestone:t.milestone?Le(t.milestone):null,labels:((b=(h=t.labels)==null?void 0:h.nodes)==null?void 0:b.map(ve))??[]}},Nt=t=>{let{comments:s,isOutdated:e,isResolved:r,originalLine:n,originalStartLine:a,startDiffSide:o}=t,{author:i,body:u,databaseId:l,id:p,path:d,publishedAt:c,url:g}=s.nodes[0];return{author:i?{avatarUrl:i.avatarUrl,email:null,name:i.login}:null,body:u,createdAt:c?new Date(c):null,diffLines:ot(s.nodes[0].diffHunk,n,a,o),id:l,isOutdated:e,isResolved:r,graphQLId:p,filename:d,replies:s.nodes.slice(1).map(jt),url:g}},jt=t=>({author:t.author?{avatarUrl:t.author.avatarUrl,email:null,name:t.author.login}:null,body:t.body,createdAt:t.publishedAt?new Date(t.publishedAt):null,graphQLId:t.id,id:t.databaseId,url:t.url}),Qt=t=>{var e,r;let s=null;return t.author?s=(t.author.__typename==="Bot",t.author):s=Ue,{id:t.databaseId.toString(),graphQLId:t.id,number:t.number,title:t.title,author:L(s),commentCount:t.comments.totalCount,closedDate:t.closedAt?new Date(t.closedAt):null,createdDate:new Date(t.createdAt),description:null,state:{name:xt[t.state],color:null},type:null,repository:{name:t.repository.name,owner:{login:t.repository.owner.login}},url:t.url,updatedDate:new Date(t.updatedAt),assignees:t.assignees.nodes?t.assignees.nodes.map(L):[],upvoteCount:t.reactions.totalCount,milestone:t.milestone?Le(t.milestone):null,labels:((r=(e=t.labels)==null?void 0:e.nodes)==null?void 0:r.map(ve))??[]}},Le=t=>({id:t.number.toString(),graphQLId:t.id.toString(),number:t.number,title:t.title,description:t.description,isOpen:t.state=="OPEN",url:t.url,startDate:null,dueDate:t.dueOn?new Date(t.dueOn):null}),F=class extends v{constructor(){super(...arguments);this._scopesCache={}}async getScopes(e){let r=e.token||this.config.token;if(!r)return[];let n=this._scopesCache[r];if(!n){let o=(await I(this.config,{query:"query { rateLimit(dryRun: true) { __typename } }"},e)).headers["x-oauth-scopes"];n=o?o.split(", "):[],this._scopesCache[r]=n}return n}getEnterpriseAvatarUrlIfNeeded(e,r,n){let a=n.baseUrl||this.config.baseUrl;return!a||a.startsWith(Ce)?e:r?`https://avatars.githubusercontent.com/u/e?email=${encodeURIComponent(r)}`:""}async getCurrentUser(e={}){var o;let r=await this.getScopes(e),a=(o=(await I(this.config,{query:`
213
226
  query getCurrentUser {
214
227
  viewer {
215
- ${E(!1,T(r))}
228
+ ${U(!1,x(r))}
216
229
  }
217
230
  }
218
- `},e)).body.data)==null?void 0:a.viewer;if(!o)throw new Error("Current user not found.");return{data:L(o)}}async getAccountsForRepo(e,r={}){var l,p,d,c,g,m;let n=await this.getScopes(r),{repo:{namespace:o,name:a},cursor:i}=e,u=await f(this.config,{query:`
231
+ `},e)).body.data)==null?void 0:o.viewer;if(!a)throw new Error("Current user not found.");return{data:L(a)}}async getAccountsForRepo(e,r={}){var l,p,d,c,g,R;let n=await this.getScopes(r),{repo:{namespace:a,name:o},cursor:i}=e,u=await I(this.config,{query:`
219
232
  query getAccountsForRepo($owner: String!, $name: String! $cursor: String, $first: Int!) {
220
233
  repository(owner: $owner, name: $name) {
221
234
  assignableUsers(first: $first, after: $cursor) {
222
235
  nodes {
223
- ${E(!1,T(n))}
236
+ ${U(!1,x(n))}
224
237
  }
225
238
  pageInfo {
226
239
  endCursor
@@ -229,7 +242,7 @@ query getAccountsForRepo($owner: String!, $name: String! $cursor: String, $first
229
242
  }
230
243
  }
231
244
  }
232
- `,variables:{owner:o,name:a,cursor:i,first:$}},r);if(!u.body.data)throw new Error(((l=u.body.errors)==null?void 0:l[0].message)||u.statusText||"Unknown error");return{pageInfo:((d=(p=u.body.data.repository)==null?void 0:p.assignableUsers)==null?void 0:d.pageInfo)??{endCursor:null,hasNextPage:!1},data:((m=(g=(c=u.body.data.repository)==null?void 0:c.assignableUsers)==null?void 0:g.nodes)==null?void 0:m.map(L))??[]}}async getUserForCommit(e,r={}){var i,u;let o=(i=(await f(this.config,{query:`
245
+ `,variables:{owner:a,name:o,cursor:i,first:C}},r);if(!u.body.data)throw new Error(((l=u.body.errors)==null?void 0:l[0].message)||u.statusText||"Unknown error");return{pageInfo:((d=(p=u.body.data.repository)==null?void 0:p.assignableUsers)==null?void 0:d.pageInfo)??{endCursor:null,hasNextPage:!1},data:((R=(g=(c=u.body.data.repository)==null?void 0:c.assignableUsers)==null?void 0:g.nodes)==null?void 0:R.map(L))??[]}}async getUserForCommit(e,r={}){var i,u;let a=(i=(await I(this.config,{query:`
233
246
  query getUserForCommit(
234
247
  $owner: String!
235
248
  $name: String!
@@ -248,23 +261,23 @@ query getUserForCommit(
248
261
  }
249
262
  }
250
263
  }
251
- `,variables:{owner:e.repo.namespace,name:e.repo.name,oid:e.oid,avatarSize:e.avatarSize}},r)).body.data)==null?void 0:i.repository;if(!o)throw new Error("Repository not found.");let a=(u=o.object)==null?void 0:u.author;if(!a)throw new Error("Commit not found.");return{data:{name:a.name,email:a.email,avatarUrl:this.getEnterpriseAvatarUrlIfNeeded(a.avatarUrl,a.email,r)}}}async getAccountForEmail(e,r={}){var i,u,l;let n=await this.getScopes(r),a=(l=(u=(i=(await f(this.config,{query:`
264
+ `,variables:{owner:e.repo.namespace,name:e.repo.name,oid:e.oid,avatarSize:e.avatarSize}},r)).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,r)}}}async getAccountForEmail(e,r={}){var i,u,l;let n=await this.getScopes(r),o=(l=(u=(i=(await I(this.config,{query:`
252
265
  query getAccountForEmail($query: String! $avatarSize: Int) {
253
266
  search(query: $query, type: USER, first: 1) {
254
267
  nodes {
255
268
  ... on User {
256
- ${E(!0,T(n))}
269
+ ${U(!0,x(n))}
257
270
  }
258
271
  }
259
272
  }
260
273
  }
261
- `,variables:{query:`in:email ${e.email}`,avatarSize:e.avatarSize}},r)).body.data)==null?void 0:i.search)==null?void 0:u.nodes)==null?void 0:l[0];if(!a)throw new Error("User not found.");return{data:L({...a,avatarUrl:this.getEnterpriseAvatarUrlIfNeeded(a.avatarUrl,a.email,r)})}}async getAccountForUsername(e,r={}){var i;let n=await this.getScopes(r),a=(i=(await f(this.config,{query:`
274
+ `,variables:{query:`in:email ${e.email}`,avatarSize:e.avatarSize}},r)).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:L({...o,avatarUrl:this.getEnterpriseAvatarUrlIfNeeded(o.avatarUrl,o.email,r)})}}async getAccountForUsername(e,r={}){var i;let n=await this.getScopes(r),o=(i=(await I(this.config,{query:`
262
275
  query getUserForUsername($login: String! $avatarSize: Int) {
263
276
  user(login: $login) {
264
- ${E(!0,T(n))}
277
+ ${U(!0,x(n))}
265
278
  }
266
279
  }
267
- `,variables:{login:e.username,avatarSize:e.avatarSize}},r)).body.data)==null?void 0:i.user;if(!a)throw new Error("User not found.");return{data:L({...a,avatarUrl:this.getEnterpriseAvatarUrlIfNeeded(a.avatarUrl,a.email,r)})}}async getOrgsForCurrentUser(e={},r={}){var a,i;let n=await f(this.config,{query:`
280
+ `,variables:{login:e.username,avatarSize:e.avatarSize}},r)).body.data)==null?void 0:i.user;if(!o)throw new Error("User not found.");return{data:L({...o,avatarUrl:this.getEnterpriseAvatarUrlIfNeeded(o.avatarUrl,o.email,r)})}}async getOrgsForCurrentUser(e={},r={}){var o,i;let n=await I(this.config,{query:`
268
281
  query getOrgsForCurrentUser($cursor: String, $first: Int!) {
269
282
  viewer {
270
283
  organizations(first: $first after: $cursor) {
@@ -283,22 +296,22 @@ query getOrgsForCurrentUser($cursor: String, $first: Int!) {
283
296
  }
284
297
  }
285
298
  }
286
- `,variables:{cursor:e.cursor,first:$}},r);if(!((a=n.body.data)!=null&&a.viewer.organizations))throw new Error(((i=n.body.errors)==null?void 0:i[0].message)||n.statusText||"Unknown error");let o=n.body.data.viewer.organizations.nodes||[];return{pageInfo:n.body.data.viewer.organizations.pageInfo,data:o.map(u=>({id:u.databaseId.toString(),graphQLId:u.id,username:u.login,name:u.name||null,email:u.email||null,avatarUrl:u.avatarUrl}))}}async getRepo(e,r={}){var o;let n=await f(this.config,{query:`
299
+ `,variables:{cursor:e.cursor,first:C}},r);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(e,r={}){var a;let n=await I(this.config,{query:`
287
300
  query getRepo($owner: String!, $name: String!) {
288
301
  repository(owner: $owner, name: $name) {
289
- ${ye}
302
+ ${$e}
290
303
  }
291
304
  }
292
- `,variables:{owner:e.namespace,name:e.name}},r);if(!((o=n.body.data)!=null&&o.repository))throw new Error(`Repository ${e.namespace}/${e.name} not found`);return{data:be(n.body.data.repository)}}async getRepos(e,r={}){let n=e.map(({namespace:u,name:l},p)=>`
305
+ `,variables:{owner:e.namespace,name:e.name}},r);if(!((a=n.body.data)!=null&&a.repository))throw new Error(`Repository ${e.namespace}/${e.name} not found`);return{data:Ee(n.body.data.repository)}}async getRepos(e,r={}){let n=e.map(({namespace:u,name:l},p)=>`
293
306
  getRepo_${p}: repository(owner: "${u}", name: "${l}") {
294
- ${ye}
307
+ ${$e}
295
308
  }
296
309
  `).join(`
297
- `),o=await f(this.config,{query:`
310
+ `),a=await I(this.config,{query:`
298
311
  query batchGetRepos {
299
312
  ${n}
300
313
  }
301
- `},r);if(!o.body.data)throw new Error(o.statusText||"Unknown error");let a=[],i=[];return e.forEach((u,l)=>{let p=o.body.data[`getRepo_${l}`];p?a.push(be(p)):i.push({input:u})}),{data:a,errors:i}}async getReposForUsernames(e,r={}){var a;if(!e.usernames.length)return{pageInfo:{endCursor:null,hasNextPage:!1},data:[]};let n=await f(this.config,{query:`
314
+ `},r);if(!a.body.data)throw new Error(a.statusText||"Unknown error");let o=[],i=[];return e.forEach((u,l)=>{let p=a.body.data[`getRepo_${l}`];p?o.push(Ee(p)):i.push({input:u})}),{data:o,errors:i}}async getReposForUsernames(e,r={}){var o;if(!e.usernames.length)return{pageInfo:{endCursor:null,hasNextPage:!1},data:[]};let n=await I(this.config,{query:`
302
315
  query getReposForUsernames($query: String!, $cursor: String, $first: Int!) {
303
316
  search(query: $query, type: REPOSITORY, first: $first, after: $cursor) {
304
317
  pageInfo {
@@ -307,12 +320,12 @@ query getReposForUsernames($query: String!, $cursor: String, $first: Int!) {
307
320
  }
308
321
  nodes {
309
322
  ... on Repository {
310
- ${ye}
323
+ ${$e}
311
324
  }
312
325
  }
313
326
  }
314
327
  }
315
- `,variables:{query:`fork:true ${e.usernames.map(i=>`user:${i}`).join(" ")}`,cursor:e.cursor,first:$}},r);if(!n.body.data)throw new Error(((a=n.body.errors)==null?void 0:a[0].message)||n.statusText||"Unknown error");let o=n.body.data.search.nodes||[];return{pageInfo:n.body.data.search.pageInfo,data:o.map(be)}}async getReposForOwners(e,r={}){return this.getReposForUsernames({usernames:e.owners.filter(n=>n.username).map(n=>n.username),cursor:e.cursor},r)}async getRefs(e,r,n={}){var u;let a=(u=(await f(this.config,{query:`
328
+ `,variables:{query:`fork:true ${e.usernames.map(i=>`user:${i}`).join(" ")}`,cursor:e.cursor,first:C}},r);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(Ee)}}async getReposForOwners(e,r={}){return this.getReposForUsernames({usernames:e.owners.filter(n=>n.username).map(n=>n.username),cursor:e.cursor},r)}async getRefs(e,r,n={}){var u;let o=(u=(await I(this.config,{query:`
316
329
  query getRefs($owner: String!, $name: String!, $refPrefix: String!, $cursor: String, $first: Int!) {
317
330
  repository(owner: $owner, name: $name) {
318
331
  refs(refPrefix: $refPrefix first: $first after: $cursor) {
@@ -333,7 +346,7 @@ query getRefs($owner: String!, $name: String!, $refPrefix: String!, $cursor: Str
333
346
  }
334
347
  }
335
348
  }
336
- `,variables:{owner:r.repo.namespace,name:r.repo.name,refPrefix:e,cursor:r.cursor,first:$}},n)).body.data)==null?void 0:u.repository;if(!a)throw new Error("Repository not found.");let i=a.refs;return i?{pageInfo:i.pageInfo,data:(i.nodes||[]).map(l=>{var 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(e,r={}){return this.getRefs("refs/heads/",e,r)}async getTags(e,r={}){return this.getRefs("refs/tags/",e,r)}async getBlame(e,r={}){var i;let o=(i=(await f(this.config,{query:`
349
+ `,variables:{owner:r.repo.namespace,name:r.repo.name,refPrefix:e,cursor:r.cursor,first:C}},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(e,r={}){return this.getRefs("refs/heads/",e,r)}async getTags(e,r={}){return this.getRefs("refs/tags/",e,r)}async getBlame(e,r={}){var i;let a=(i=(await I(this.config,{query:`
337
350
  query getBlame($owner: String!, $name: String!, $ref: String!, $path: String!) {
338
351
  repository(owner: $owner, name: $name) {
339
352
  object(expression: $ref) {
@@ -372,13 +385,13 @@ query getBlame($owner: String!, $name: String!, $ref: String!, $path: String!) {
372
385
  }
373
386
  }
374
387
  }
375
- `,variables:{owner:e.repo.namespace,name:e.repo.name,ref:e.ref,path:e.path}},r)).body.data)==null?void 0:i.repository;if(!o)throw new Error("Repository not found.");let a=o.object;if(!a||!("blame"in a))throw new Error("Ref not found.");if(a.blame.ranges.length===0)throw new Error("File not found.");return{data:{ranges:a.blame.ranges.map(u=>{var l;return{startingLine:u.startingLine,endingLine:u.endingLine,commit:{oid:u.commit.oid,parentOids:((l=u.commit.parents.nodes)==null?void 0:l.map(p=>p.oid))||[],authoredDate:new Date(u.commit.authoredDate),author:u.commit.author?{name:u.commit.author.name,email:u.commit.author.email,avatarUrl:u.commit.author.avatarUrl}:null,committedDate:new Date(u.commit.committedDate),committer:u.commit.committer?{name:u.commit.committer.name,email:u.commit.committer.email,avatarUrl:u.commit.committer.avatarUrl}:null,message:u.commit.message,fileCount:u.commit.changedFilesIfAvailable,additions:u.commit.additions,deletions:u.commit.deletions}}})}}}async searchPullRequests(e,r={}){var l,p;let n=await this.getScopes(r),o=T(n),a=d=>{let c=d&&typeof e.isDraft=="boolean"?`${e.query} draft:${e.isDraft}`:e.query;return Ie("pr",c,e.cursor,o,d)},i=await f(this.config,a(!0),r);i.body.errors&&Ve(i.body.errors)&&(this.config.baseUrl||r.baseUrl)&&(i=await f(this.config,a(!1),r));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(Ct))||[]}}async searchIssues(e,r={}){var u,l;let n=await this.getScopes(r),o=T(n),a=await f(this.config,Ie("issue",e.query,e.cursor,o),r),{data:i}=a.body;if(!i)throw new Error(((u=a.body.errors)==null?void 0:u[0].message)||a.statusText||"Unknown error");return{pageInfo:{hasNextPage:i.search.pageInfo.hasNextPage,endCursor:i.search.pageInfo.endCursor},data:((l=i.search.nodes)==null?void 0:l.map(Ut))||[]}}async getPullRequestsAssociatedWithUser(e,r={}){return this.searchPullRequests({query:`involves:${e.username}`,cursor:e.cursor},r)}async getPullRequestsForRepos(e,r={}){let{assigneeLogins:n,updatedBefore:o,authorLogin:a,repos:i,reviewRequestedLogin:u,startQuery:l,mentionLogin:p}=e,d=Re(l||"");return i.forEach(c=>{d.push(`repo:${c.namespace}/${c.name}`)}),n&&n.forEach(c=>{d.push(`assignee:${c}`)}),o&&d.push(`updated:<${o}`),a&&d.push(`author:${a}`),u&&d.push(`review-requested:${u}`),p&&d.push(`mentions:${p}`),this.searchPullRequests({query:`sort:updated ${d.join(" ")}`,isDraft:e.isDraft,cursor:e.cursor},r)}async closePullRequest(e,r={}){var i,u,l;let{pullRequestGraphQLId:n}=e,o=`mutation ClosePullRequest($pullRequestGraphQLId: ID!) {
388
+ `,variables:{owner:e.repo.namespace,name:e.repo.name,ref:e.ref,path:e.path}},r)).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(e,r={}){var l,p;let n=await this.getScopes(r),a=x(n),o=d=>{let c=d&&typeof e.isDraft=="boolean"?`${e.query} draft:${e.isDraft}`:e.query;return Se("pr",c,e.cursor,a,d)},i=await I(this.config,o(!0),r);i.body.errors&&nt(i.body.errors)&&(this.config.baseUrl||r.baseUrl)&&(i=await I(this.config,o(!1),r));let{data:u}=i.body;if(!u)throw new Error(((l=i.body.errors)==null?void 0:l[0].message)||i.statusText||"Unknown error");return{pageInfo:{hasNextPage:u.search.pageInfo.hasNextPage,endCursor:u.search.pageInfo.endCursor},data:((p=u.search.nodes)==null?void 0:p.map(_t))||[]}}async searchIssues(e,r={}){var u,l;let n=await this.getScopes(r),a=x(n),o=await I(this.config,Se("issue",e.query,e.cursor,a),r),{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(Qt))||[]}}async getPullRequestsAssociatedWithUser(e,r={}){return this.searchPullRequests({query:`involves:${e.username}`,cursor:e.cursor},r)}async getPullRequestsForRepos(e,r={}){let{assigneeLogins:n,updatedBefore:a,authorLogin:o,repos:i,reviewRequestedLogin:u,startQuery:l,mentionLogin:p}=e,d=De(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:e.isDraft,cursor:e.cursor},r)}async closePullRequest(e,r={}){var i,u,l;let{pullRequestGraphQLId:n}=e,a=`mutation ClosePullRequest($pullRequestGraphQLId: ID!) {
376
389
  closePullRequest(input: { pullRequestId: $pullRequestGraphQLId }) {
377
390
  pullRequest {
378
391
  id
379
392
  }
380
393
  }
381
- }`;if(!((l=(u=(i=(await f(this.config,{query:`${o}`,variables:{pullRequestGraphQLId:n}},r)).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(e,r={}){var p,d,c;let{pullRequestGraphQLId:n,expectedSourceSha:o,mergeStrategy:a}=e,i;switch(a){case"MERGE_COMMIT":{i="MERGE";break}case"REBASE":{i="REBASE";break}case"SQUASH":{i="SQUASH";break}}let u=`mutation MergePullRequest(
394
+ }`;if(!((l=(u=(i=(await I(this.config,{query:`${a}`,variables:{pullRequestGraphQLId:n}},r)).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(e,r={}){var p,d,c;let{pullRequestGraphQLId:n,expectedSourceSha:a,mergeStrategy:o}=e,i;switch(o){case"MERGE_COMMIT":{i="MERGE";break}case"REBASE":{i="REBASE";break}case"SQUASH":{i="SQUASH";break}}let u=`mutation MergePullRequest(
382
395
  $pullRequestGraphQLId: ID!,
383
396
  $expectedSourceSha: GitObjectID!,
384
397
  $mergeStrategy: PullRequestMergeMethod,
@@ -392,84 +405,136 @@ query getBlame($owner: String!, $name: String!, $ref: String!, $path: String!) {
392
405
  id
393
406
  }
394
407
  }
395
- }`;if(!((c=(d=(p=(await f(this.config,{query:`${u}`,variables:{pullRequestGraphQLId:n,expectedSourceSha:o,mergeStrategy:i}},r)).body.data)==null?void 0:p.mergePullRequest)==null?void 0:d.pullRequest)!=null&&c.id))throw new Error("Could not merge pull request")}async setPullRequestMilestone(e,r={}){var u,l,p;let{pullRequestGraphQLId:n,milestoneGraphQLId:o}=e,a=`mutation SetPullRequestMilestone($pullRequestGraphQLId: ID!, $milestoneGraphQLId: ID) {
408
+ }`;if(!((c=(d=(p=(await I(this.config,{query:`${u}`,variables:{pullRequestGraphQLId:n,expectedSourceSha:a,mergeStrategy:i}},r)).body.data)==null?void 0:p.mergePullRequest)==null?void 0:d.pullRequest)!=null&&c.id))throw new Error("Could not merge pull request")}async setPullRequestMilestone(e,r={}){var u,l,p;let{pullRequestGraphQLId:n,milestoneGraphQLId:a}=e,o=`mutation SetPullRequestMilestone($pullRequestGraphQLId: ID!, $milestoneGraphQLId: ID) {
396
409
  updatePullRequest(input: { pullRequestId: $pullRequestGraphQLId, milestoneId: $milestoneGraphQLId }) {
397
410
  pullRequest {
398
411
  id
399
412
  }
400
413
  }
401
- }`;if(!((p=(l=(u=(await f(this.config,{query:`${a}`,variables:{pullRequestGraphQLId:n,milestoneGraphQLId:o}},r)).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(e,r){var a,i,u;let n=`mutation MarkReadyToReview($pullRequestGraphQLId: ID!) {
414
+ }`;if(!((p=(l=(u=(await I(this.config,{query:`${o}`,variables:{pullRequestGraphQLId:n,milestoneGraphQLId:a}},r)).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(e,r){var o,i,u;let n=`mutation MarkReadyToReview($pullRequestGraphQLId: ID!) {
402
415
  markPullRequestReadyForReview(input: { pullRequestId: $pullRequestGraphQLId }) {
403
416
  pullRequest {
404
417
  id
405
418
  }
406
419
  }
407
- }`;if(!((u=(i=(a=(await f(this.config,{query:n,variables:{pullRequestGraphQLId:e}},r)).body.data)==null?void 0:a.markPullRequestReadyForReview)==null?void 0:i.pullRequest)!=null&&u.id))throw new Error("Could not mark pull request ready to review")}async convertPullRequestToDraft(e,r){var a,i,u;let n=`mutation ConvertToDraft($pullRequestGraphQLId: ID!) {
420
+ }`;if(!((u=(i=(o=(await I(this.config,{query:n,variables:{pullRequestGraphQLId:e}},r)).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(e,r){var o,i,u;let n=`mutation ConvertToDraft($pullRequestGraphQLId: ID!) {
408
421
  convertPullRequestToDraft(input: { pullRequestId: $pullRequestGraphQLId }) {
409
422
  pullRequest {
410
423
  id
411
424
  }
412
425
  }
413
- }`;if(!((u=(i=(a=(await f(this.config,{query:n,variables:{pullRequestGraphQLId:e}},r)).body.data)==null?void 0:a.convertPullRequestToDraft)==null?void 0:i.pullRequest)!=null&&u.id))throw new Error("Could not convert pull request to draft")}async setPullRequestAsDraft(e,r={}){let{pullRequestGraphQLId:n,isDraft:o}=e;if(o){await this.convertPullRequestToDraft(n,r);return}await this.markPullRequestReadyForReview(n,r)}async setPullRequestReviewers(e,r={}){var u,l,p;let{pullRequestGraphQLId:n,reviewerGraphQLIds:o}=e,a=`mutation SetPullRequestReviewers($pullRequestGraphQLId: ID!, $reviewerGraphQLIds: [ID!]!) {
426
+ }`;if(!((u=(i=(o=(await I(this.config,{query:n,variables:{pullRequestGraphQLId:e}},r)).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(e,r={}){let{pullRequestGraphQLId:n,isDraft:a}=e;if(a){await this.convertPullRequestToDraft(n,r);return}await this.markPullRequestReadyForReview(n,r)}async setPullRequestReviewers(e,r={}){var u,l,p;let{pullRequestGraphQLId:n,reviewerGraphQLIds:a}=e,o=`mutation SetPullRequestReviewers($pullRequestGraphQLId: ID!, $reviewerGraphQLIds: [ID!]!) {
414
427
  requestReviews(input: { pullRequestId: $pullRequestGraphQLId, userIds: $reviewerGraphQLIds }) {
415
428
  pullRequest {
416
429
  id
417
430
  }
418
431
  }
419
- }`;if(!((p=(l=(u=(await f(this.config,{query:a,variables:{pullRequestGraphQLId:n,reviewerGraphQLIds:o}},r)).body.data)==null?void 0:u.requestReviews)==null?void 0:l.pullRequest)!=null&&p.id))throw new Error("Could not set pull request reviewers")}async setPullRequestAssignees(e,r={}){var u,l,p;let{pullRequestGraphQLId:n,assigneeGraphQLIds:o}=e,a=`mutation SetPullRequestAssignees($pullRequestGraphQLId: ID!, $assigneeGraphQLIds: [ID!]!) {
432
+ }`;if(!((p=(l=(u=(await I(this.config,{query:o,variables:{pullRequestGraphQLId:n,reviewerGraphQLIds:a}},r)).body.data)==null?void 0:u.requestReviews)==null?void 0:l.pullRequest)!=null&&p.id))throw new Error("Could not set pull request reviewers")}async setPullRequestAssignees(e,r={}){var u,l,p;let{pullRequestGraphQLId:n,assigneeGraphQLIds:a}=e,o=`mutation SetPullRequestAssignees($pullRequestGraphQLId: ID!, $assigneeGraphQLIds: [ID!]!) {
420
433
  updatePullRequest(input: { pullRequestId: $pullRequestGraphQLId, assigneeIds: $assigneeGraphQLIds }) {
421
434
  pullRequest {
422
435
  id
423
436
  }
424
437
  }
425
- }`;if(!((p=(l=(u=(await f(this.config,{query:a,variables:{pullRequestGraphQLId:n,assigneeGraphQLIds:o}},r)).body.data)==null?void 0:u.updatePullRequest)==null?void 0:l.pullRequest)!=null&&p.id))throw new Error("Could not set pull request assignees")}async getIssuesAssociatedWithUser(e,r={}){var d;let[n,o]=((d=e.cursor)==null?void 0:d.split(";"))||[void 0,void 0],[a,i]=await Promise.all([n==="null"?null:this.searchIssues({query:`author:${e.username}`,cursor:n},r),o==="null"?null:this.searchIssues({query:`assignee:${e.username}`,cursor:o},r)]),u={},l=[],p=c=>{u[c.id]||(u[c.id]=!0,l.push(c))};return a==null||a.data.forEach(p),i==null||i.data.forEach(p),{pageInfo:{hasNextPage:(a==null?void 0:a.pageInfo.hasNextPage)||(i==null?void 0:i.pageInfo.hasNextPage)||!1,endCursor:`${(a==null?void 0:a.pageInfo.hasNextPage)&&(a==null?void 0:a.pageInfo.endCursor)||"null"};${(i==null?void 0:i.pageInfo.hasNextPage)&&(i==null?void 0:i.pageInfo.endCursor)||"null"}`},data:l}}async setPullRequestLabels(e,r={}){var u,l,p;let{pullRequestGraphQLId:n,labelGraphQLIds:o}=e,a=`mutation SetPullRequestLabels($pullRequestGraphQLId: ID!, $labelGraphQLIds: [ID!]) {
438
+ }`;if(!((p=(l=(u=(await I(this.config,{query:o,variables:{pullRequestGraphQLId:n,assigneeGraphQLIds:a}},r)).body.data)==null?void 0:u.updatePullRequest)==null?void 0:l.pullRequest)!=null&&p.id))throw new Error("Could not set pull request assignees")}async getReviewsForPullRequest(e,r={}){var d,c;let{repo:{namespace:n,name:a},pullRequestId:o}=e,i=`query getPullRequests(
439
+ $namespace: String!
440
+ $name: String!
441
+ $pullRequestId: Int!
442
+ ) {
443
+ repository(
444
+ owner: $namespace,
445
+ name: $name
446
+ ) {
447
+ pullRequest(number: $pullRequestId) {
448
+ reviewThreads(first: 100) {
449
+ nodes {
450
+ isOutdated
451
+ isResolved
452
+ originalLine
453
+ originalStartLine
454
+ startDiffSide
455
+ comments(first: 100) {
456
+ nodes {
457
+ author {
458
+ avatarUrl
459
+ login
460
+ }
461
+ body
462
+ databaseId
463
+ diffHunk
464
+ id
465
+ path
466
+ publishedAt
467
+ pullRequestReview {
468
+ id
469
+ }
470
+ url
471
+ }
472
+ }
473
+ }
474
+ }
475
+ reviews(first: 100) {
476
+ nodes {
477
+ author {
478
+ avatarUrl
479
+ login
480
+ }
481
+ body
482
+ databaseId
483
+ id
484
+ publishedAt
485
+ url
486
+ }
487
+ }
488
+ }
489
+ }
490
+ }`,u=await I(this.config,{query:i,variables:{namespace:n,name:a,pullRequestId:o}},r),l=((d=u.body.data)==null?void 0:d.repository.pullRequest.reviewThreads.nodes.reduce((g,R)=>{let h=R.comments.nodes[0].pullRequestReview;return h&&(g[h.id]||(g[h.id]=[]),g[h.id].push(Nt(R))),g},{}))??{};return{data:((c=u.body.data)==null?void 0:c.repository.pullRequest.reviews.nodes.filter(g=>l[g.id]).map(g=>({author:g.author?{avatarUrl:g.author.avatarUrl,email:null,name:g.author.login}:null,body:g.body,createdAt:g.publishedAt?new Date(g.publishedAt):null,id:g.databaseId,graphQLId:g.id,reviewComments:l[g.id],url:g.url})))??[]}}async getIssuesAssociatedWithUser(e,r={}){var d;let[n,a]=((d=e.cursor)==null?void 0:d.split(";"))||[void 0,void 0],[o,i]=await Promise.all([n==="null"?null:this.searchIssues({query:`author:${e.username}`,cursor:n},r),a==="null"?null:this.searchIssues({query:`assignee:${e.username}`,cursor:a},r)]),u={},l=[],p=c=>{u[c.id]||(u[c.id]=!0,l.push(c))};return o==null||o.data.forEach(p),i==null||i.data.forEach(p),{pageInfo:{hasNextPage:(o==null?void 0:o.pageInfo.hasNextPage)||(i==null?void 0:i.pageInfo.hasNextPage)||!1,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 setPullRequestLabels(e,r={}){var u,l,p;let{pullRequestGraphQLId:n,labelGraphQLIds:a}=e,o=`mutation SetPullRequestLabels($pullRequestGraphQLId: ID!, $labelGraphQLIds: [ID!]) {
426
491
  updatePullRequest(input: { pullRequestId: $pullRequestGraphQLId, labelIds: $labelGraphQLIds }) {
427
492
  pullRequest {
428
493
  id
429
494
  }
430
495
  }
431
- }`;if(!((p=(l=(u=(await f(this.config,{query:a,variables:{pullRequestGraphQLId:n,labelGraphQLIds:o}},r)).body.data)==null?void 0:u.updatePullRequest)==null?void 0:l.pullRequest)!=null&&p.id))throw new Error("Could not set pull request labels")}async getIssuesForRepos(e,r={}){let n=Re(e.startQuery||""),{cursor:o,assigneeLogins:a,updatedBefore:i,authorLogin:u,mentionLogin:l}=e;return e.repos.forEach(p=>{n.push(`repo:${p.namespace}/${p.name}`)}),a&&a.forEach(p=>{n.push(`assignee:${p}`)}),i&&n.push(`updated:<${i}`),u&&n.push(`author:${u}`),l&&n.push(`mentions:${l}`),this.searchIssues({query:`sort:updated ${n.join(" ")}`,cursor:o},r)}async closeIssueWithReason(e,r,n){var i,u,l;let o=`mutation CloseIssueWithReason($issueGraphQLId: ID!, $closeReason: IssueClosedStateReason!) {
496
+ }`;if(!((p=(l=(u=(await I(this.config,{query:o,variables:{pullRequestGraphQLId:n,labelGraphQLIds:a}},r)).body.data)==null?void 0:u.updatePullRequest)==null?void 0:l.pullRequest)!=null&&p.id))throw new Error("Could not set pull request labels")}async getIssuesForRepos(e,r={}){let n=De(e.startQuery||""),{cursor:a,assigneeLogins:o,updatedBefore:i,authorLogin:u,mentionLogin:l}=e;return e.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},r)}async closeIssueWithReason(e,r,n){var i,u,l;let a=`mutation CloseIssueWithReason($issueGraphQLId: ID!, $closeReason: IssueClosedStateReason!) {
432
497
  closeIssue(input: { issueId: $issueGraphQLId, stateReason: $closeReason }) {
433
498
  issue {
434
499
  id
435
500
  }
436
501
  }
437
- }`;if(!((l=(u=(i=(await f(this.config,{query:o,variables:{issueGraphQLId:e,closeReason:r}},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(e,r){var a,i,u;let n=`mutation SetIssueState($issueGraphQLId: ID!) {
502
+ }`;if(!((l=(u=(i=(await I(this.config,{query:a,variables:{issueGraphQLId:e,closeReason:r}},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(e,r){var o,i,u;let n=`mutation SetIssueState($issueGraphQLId: ID!) {
438
503
  updateIssue(input: { id: $issueGraphQLId, state: CLOSED }) {
439
504
  issue {
440
505
  id
441
506
  }
442
507
  }
443
- }`;if(!((u=(i=(a=(await f(this.config,{query:n,variables:{issueGraphQLId:e}},r)).body.data)==null?void 0:a.updateIssue)==null?void 0:i.issue)!=null&&u.id))throw new Error("Could not close issue")}async reopenIssue(e,r){var a,i,u;let n=`mutation ReOpenIssue($issueGraphQLId: ID!) {
508
+ }`;if(!((u=(i=(o=(await I(this.config,{query:n,variables:{issueGraphQLId:e}},r)).body.data)==null?void 0:o.updateIssue)==null?void 0:i.issue)!=null&&u.id))throw new Error("Could not close issue")}async reopenIssue(e,r){var o,i,u;let n=`mutation ReOpenIssue($issueGraphQLId: ID!) {
444
509
  reopenIssue(input: { issueId: $issueGraphQLId }) {
445
510
  issue {
446
511
  id
447
512
  }
448
513
  }
449
- }`;if(!((u=(i=(a=(await f(this.config,{query:n,variables:{issueGraphQLId:e}},r)).body.data)==null?void 0:a.reopenIssue)==null?void 0:i.issue)!=null&&u.id))throw new Error("Could not reopen issue")}async setIssueStatus(e,r={}){let{issueGraphQLId:n,status:o,closeReason:a}=e;if(a&&o=="OPEN")throw new Error("Did not expect closeReason to be set when trying to reopen issue");o=="OPEN"?await this.reopenIssue(n,r):o=="CLOSED"&&!a?await this.closeIssueWithoutReason(n,r):a&&await this.closeIssueWithReason(n,a,r)}async setIssueLabels(e,r={}){var u,l,p;let{issueGraphQLId:n,labelGraphQLIds:o}=e,a=`mutation SetIssueLabels($issueGraphQLId: ID!, $labelGraphQLIds: [ID!]) {
514
+ }`;if(!((u=(i=(o=(await I(this.config,{query:n,variables:{issueGraphQLId:e}},r)).body.data)==null?void 0:o.reopenIssue)==null?void 0:i.issue)!=null&&u.id))throw new Error("Could not reopen issue")}async setIssueStatus(e,r={}){let{issueGraphQLId:n,status:a,closeReason:o}=e;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,r):a=="CLOSED"&&!o?await this.closeIssueWithoutReason(n,r):o&&await this.closeIssueWithReason(n,o,r)}async setIssueLabels(e,r={}){var u,l,p;let{issueGraphQLId:n,labelGraphQLIds:a}=e,o=`mutation SetIssueLabels($issueGraphQLId: ID!, $labelGraphQLIds: [ID!]) {
450
515
  updateIssue(input: { id: $issueGraphQLId, labelIds: $labelGraphQLIds }) {
451
516
  issue {
452
517
  id
453
518
  }
454
519
  }
455
- }`;if(!((p=(l=(u=(await f(this.config,{query:a,variables:{issueGraphQLId:n,labelGraphQLIds:o}},r)).body.data)==null?void 0:u.updateIssue)==null?void 0:l.issue)!=null&&p.id))throw new Error("Could not set issue labels")}async setIssueMilestone(e,r={}){var u,l,p;let{issueGraphQLId:n,milestoneGraphQLId:o}=e,a=`mutation SetIssueMilestone($issueGraphQLId: ID!, $milestoneGraphQLId: ID) {
520
+ }`;if(!((p=(l=(u=(await I(this.config,{query:o,variables:{issueGraphQLId:n,labelGraphQLIds:a}},r)).body.data)==null?void 0:u.updateIssue)==null?void 0:l.issue)!=null&&p.id))throw new Error("Could not set issue labels")}async setIssueMilestone(e,r={}){var u,l,p;let{issueGraphQLId:n,milestoneGraphQLId:a}=e,o=`mutation SetIssueMilestone($issueGraphQLId: ID!, $milestoneGraphQLId: ID) {
456
521
  updateIssue(input: { id: $issueGraphQLId, milestoneId: $milestoneGraphQLId }) {
457
522
  issue {
458
523
  id
459
524
  }
460
525
  }
461
- }`;if(!((p=(l=(u=(await f(this.config,{query:`${a}`,variables:{issueGraphQLId:n,milestoneGraphQLId:o}},r)).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 setIssueAssignees(e,r={}){var u,l,p;let{issueGraphQLId:n,assigneeGraphQLIds:o}=e,a=`mutation SetIssueAssignees($issueGraphQLId: ID!, $assigneeGraphQLIds: [ID!]!) {
526
+ }`;if(!((p=(l=(u=(await I(this.config,{query:`${o}`,variables:{issueGraphQLId:n,milestoneGraphQLId:a}},r)).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 setIssueAssignees(e,r={}){var u,l,p;let{issueGraphQLId:n,assigneeGraphQLIds:a}=e,o=`mutation SetIssueAssignees($issueGraphQLId: ID!, $assigneeGraphQLIds: [ID!]!) {
462
527
  updateIssue(input: { id: $issueGraphQLId, assigneeIds: $assigneeGraphQLIds }) {
463
528
  issue {
464
529
  id
465
530
  }
466
531
  }
467
- }`;if(!((p=(l=(u=(await f(this.config,{query:a,variables:{issueGraphQLId:n,assigneeGraphQLIds:o}},r)).body.data)==null?void 0:u.updateIssue)==null?void 0:l.issue)!=null&&p.id))throw new Error("Could not set issue assignees")}async getMilestonesForRepo(e,r={}){var u,l,p,d;let{repo:{namespace:n,name:o},cursor:a}=e,i=await f(this.config,{query:`
532
+ }`;if(!((p=(l=(u=(await I(this.config,{query:o,variables:{issueGraphQLId:n,assigneeGraphQLIds:a}},r)).body.data)==null?void 0:u.updateIssue)==null?void 0:l.issue)!=null&&p.id))throw new Error("Could not set issue assignees")}async getMilestonesForRepo(e,r={}){var u,l,p,d;let{repo:{namespace:n,name:a},cursor:o}=e,i=await I(this.config,{query:`
468
533
  query getLabelsForRepo($owner: String!, $name: String! $cursor: String, $first: Int!) {
469
534
  repository(owner: $owner, name: $name) {
470
535
  milestones(first: $first, after: $cursor) {
471
536
  nodes {
472
- ${ee}
537
+ ${ne}
473
538
  }
474
539
  pageInfo {
475
540
  endCursor
@@ -478,12 +543,12 @@ query getLabelsForRepo($owner: String!, $name: String! $cursor: String, $first:
478
543
  }
479
544
  }
480
545
  }
481
- `,variables:{owner:n,name:o,cursor:a,first:$}},r);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(qe))??[]}}async getLabelsForRepo(e,r={}){var u,l,p,d;let{repo:{namespace:n,name:o},cursor:a}=e,i=await f(this.config,{query:`
546
+ `,variables:{owner:n,name:a,cursor:o,first:C}},r);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(Le))??[]}}async getLabelsForRepo(e,r={}){var u,l,p,d;let{repo:{namespace:n,name:a},cursor:o}=e,i=await I(this.config,{query:`
482
547
  query getLabelsForRepo($owner: String!, $name: String! $cursor: String, $first: Int!) {
483
548
  repository(owner: $owner, name: $name) {
484
549
  labels(first: $first, after: $cursor) {
485
550
  nodes {
486
- ${te}
551
+ ${oe}
487
552
  }
488
553
  pageInfo {
489
554
  endCursor
@@ -492,7 +557,7 @@ query getLabelsForRepo($owner: String!, $name: String! $cursor: String, $first:
492
557
  }
493
558
  }
494
559
  }
495
- `,variables:{owner:n,name:o,cursor:a,first:$}},r);if(!i.body.data)throw new Error(((u=i.body.errors)==null?void 0:u[0].message)||i.statusText||"Unknown error");return{pageInfo:((l=i.body.data.repository.labels)==null?void 0:l.pageInfo)??{endCursor:null,hasNextPage:!1},data:((d=(p=i.body.data.repository.labels)==null?void 0:p.nodes)==null?void 0:d.map(we))??[]}}};var Et="https://gitlab.com/api/v4",vt="https://gitlab.com/api/graphql",Ke=/\/api\/v\d+$/,Xe=t=>{if(t.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.")},$e=(t,s)=>{let e=s.baseUrl||t.baseUrl;return e?(e=e.replace(/\/$/,""),Xe(e),e):Et},Dt=(t,s)=>{let e=s.baseUrl||t.baseUrl;return e?(e=e.replace(/\/$/,""),Xe(e),Ke.test(e)&&(e=e.replace(Ke,"")),`${e}/api/graphql`):vt},I=(t,s,e)=>{let r=h(e.token||t.token);return t.request({url:Dt(t,e),method:"POST",headers:{...r,"Content-Type":"application/json"},body:JSON.stringify(s)})};var Ze=t=>t.split("/").slice(0,-1).join("/"),j=t=>({namespace:Ze(t.fullPath),name:t.path,webUrl:t.webUrl}),Lt={assigned:"assignedMergeRequests",authored:"authoredMergeRequests",reviewRequested:"reviewRequestedMergeRequests"},Gt={CAN_BE_MERGED:"MERGEABLE",CANNOT_BE_MERGED:"CONFLICTS",CANNOT_BE_MERGED_RECHECK:"UNKNOWN",UNCHECKED:"UNKNOWN",CHECKING:"UNKNOWN"},Le="gid://gitlab/User/",z="gid://gitlab/Project/",Ot="gid://gitlab/MergeRequest/",At="gid://gitlab/Issue/",xt="gid://gitlab/ProjectLabel/",Ye="gid://gitlab/Milestone/",Tt="gid://gitlab/Ci::Build/",Ge=`
560
+ `,variables:{owner:n,name:a,cursor:o,first:C}},r);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(ve))??[]}}};var Bt="https://gitlab.com/api/v4",Ft="https://gitlab.com/api/graphql",at=/\/api\/v\d+$/,it=t=>{if(t.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.")},Ge=(t,s)=>{let e=s.baseUrl||t.baseUrl;return e?(e=e.replace(/\/$/,""),it(e),e):Bt},Mt=(t,s)=>{let e=s.baseUrl||t.baseUrl;return e?(e=e.replace(/\/$/,""),it(e),at.test(e)&&(e=e.replace(at,"")),`${e}/api/graphql`):Ft},y=(t,s,e)=>{let r=m(e.token||t.token);return t.request({url:Mt(t,e),method:"POST",headers:{...r,"Content-Type":"application/json"},body:JSON.stringify(s)})};var Ne=t=>t.split("/").slice(0,-1).join("/"),M=t=>({namespace:Ne(t.fullPath),name:t.path,webUrl:t.webUrl}),ut=t=>({httpsUrl:t.httpUrlToRepo,namespace:Ne(t.fullPath),name:t.path,sshUrl:t.sshUrlToRepo,webUrl:t.webUrl}),zt={assigned:"assignedMergeRequests",authored:"authoredMergeRequests",reviewRequested:"reviewRequestedMergeRequests"},Wt={CAN_BE_MERGED:"MERGEABLE",CANNOT_BE_MERGED:"CONFLICTS",CANNOT_BE_MERGED_RECHECK:"UNKNOWN",UNCHECKED:"UNKNOWN",CHECKING:"UNKNOWN"},Ht="gid://gitlab/User/",z="gid://gitlab/Project/",Jt="gid://gitlab/MergeRequest/",Kt="gid://gitlab/Issue/",Vt="gid://gitlab/ProjectLabel/",lt="gid://gitlab/Milestone/",Xt="gid://gitlab/Ci::Build/",je=`
496
561
  description
497
562
  dueDate
498
563
  id
@@ -501,7 +566,7 @@ startDate
501
566
  state
502
567
  title
503
568
  webPath
504
- `,Se=`
569
+ `,Oe=`
505
570
  id
506
571
  path
507
572
  fullPath
@@ -511,26 +576,28 @@ sshUrlToRepo
511
576
  repository {
512
577
  rootRef
513
578
  }
514
- `,O=`
579
+ `,G=`
515
580
  id
516
581
  name
517
582
  username
518
583
  publicEmail
519
584
  avatarUrl
520
- `,Oe=`
585
+ webUrl
586
+ `,Qe=`
521
587
  color
522
588
  description
523
589
  id
524
590
  title
525
- `,Ce=`
591
+ `,Ae=`
526
592
  author {
527
- ${O}
593
+ ${G}
528
594
  }
529
595
  assignees {
530
596
  nodes {
531
- ${O}
597
+ ${G}
532
598
  }
533
599
  }
600
+ closedAt
534
601
  createdAt
535
602
  description
536
603
  dueDate
@@ -538,7 +605,7 @@ id
538
605
  iid
539
606
  labels {
540
607
  nodes {
541
- ${Oe}
608
+ ${Qe}
542
609
  }
543
610
  }
544
611
  state
@@ -549,9 +616,9 @@ upvotes
549
616
  userNotesCount
550
617
  webUrl
551
618
  milestone {
552
- ${Ge}
619
+ ${je}
553
620
  }
554
- `,kt=`
621
+ `,Zt=`
555
622
  stages {
556
623
  nodes {
557
624
  jobs {
@@ -564,11 +631,12 @@ stages {
564
631
  name
565
632
  }
566
633
  }
567
- `,Ue=(t,s,e)=>`
634
+ `,Te=(t,s,e)=>`
568
635
  id
569
636
  state
637
+ approved
570
638
  author {
571
- ${O}
639
+ ${G}
572
640
  }
573
641
  diffRefs {
574
642
  baseSha
@@ -593,12 +661,12 @@ targetBranch
593
661
  sourceBranch
594
662
  assignees {
595
663
  nodes {
596
- ${O}
664
+ ${G}
597
665
  }
598
666
  }
599
667
  reviewers {
600
668
  nodes {
601
- ${O}
669
+ ${G}
602
670
  mergeRequestInteraction {
603
671
  approved
604
672
  reviewState
@@ -608,19 +676,19 @@ reviewers {
608
676
  mergeStatusEnum
609
677
  labels {
610
678
  nodes {
611
- ${Oe}
679
+ ${Qe}
612
680
  }
613
681
  }
614
- ${t?"project { path fullPath webUrl }":""}
615
- ${s?`milestone { ${Ge} }`:""}
616
- ${e?`headPipeline { ${kt} }`:""}
617
- `,k=t=>`${t.namespace}/${t.name}`,_t=t=>`${t.namespace}/${t.name}`,Ee=t=>{var s;return{id:t.id.replace(z,""),graphQLId:t.id,namespace:Ze(t.fullPath),name:t.path,webUrl:t.webUrl,httpsUrl:t.httpUrlToRepo,sshUrl:t.sshUrlToRepo,defaultBranch:(s=t.repository)!=null&&s.rootRef?{name:t.repository.rootRef}:null,permission:null}},Nt={opened:"OPEN",merged:"MERGED",closed:"CLOSED"},_=t=>({id:t.id.replace(Le,""),graphQLId:t.id,name:t.name,username:t.username,email:t.publicEmail,avatarUrl:t.avatarUrl}),Ae=t=>({color:t.color,description:t.description,id:t.id.replace(xt,""),graphQLId:t.id,name:t.title}),ve=(t,s)=>{var e,r,n,o,a,i,u,l,p,d,c,g;return{id:t.id.replace(Ot,""),graphQLId:t.id,title:t.title,number:parseInt(t.iid,10),state:Nt[t.state],commentCount:t.userNotesCount||0,upvoteCount:t.upvotes,author:t.author?_(t.author):null,createdDate:new Date(t.createdAt),isDraft:t.draft,repository:{name:s.name,owner:{login:s.namespace}},headRepository:null,headCommit:{buildStatuses:((n=(r=(e=t.headPipeline)==null?void 0:e.stages)==null?void 0:r.nodes)==null?void 0:n.flatMap(m=>{var R,b;return((b=(R=m.jobs)==null?void 0:R.nodes)==null?void 0:b.map(P=>({description:null,name:P.name??null,state:P.status??null,stage:m.name??null,url:`${s.webUrl}/-/jobs/${P.id.replace(Tt,"")}`})))??[]}))??[]},baseRef:{name:t.targetBranch,oid:((o=t.diffRefs)==null?void 0:o.baseSha)??null},headRef:{name:t.sourceBranch,oid:((a=t.diffRefs)==null?void 0:a.headSha)??null},url:t.webUrl,updatedDate:new Date(t.updatedAt),closedDate:t.mergedAt?new Date(t.mergedAt):null,assignees:(i=t.assignees)!=null&&i.nodes?t.assignees.nodes.map(_):null,reviews:(u=t.reviewers)!=null&&u.nodes?t.reviewers.nodes.map(m=>{var R,b;return{reviewer:_(m),state:(R=m.mergeRequestInteraction)!=null&&R.approved?"APPROVED":((b=m.mergeRequestInteraction)==null?void 0:b.reviewState)==="REVIEWED"?"CHANGES_REQUESTED":"CHANGES_REQUESTED"}}):null,additions:((l=t.diffStatsSummary)==null?void 0:l.additions)||0,deletions:((p=t.diffStatsSummary)==null?void 0:p.deletions)||0,fileCount:((d=t.diffStatsSummary)==null?void 0:d.fileCount)||0,commitCount:t.commitCount||0,mergeableState:Gt[t.mergeStatusEnum],milestone:t.milestone?xe(t.milestone,s.webUrl):null,labels:((g=(c=t.labels)==null?void 0:c.nodes)==null?void 0:g.map(Ae))??[]}},De=(t,s)=>{var e,r;return{author:{avatarUrl:t.author.avatarUrl,email:null,graphQLId:t.author.id,id:t.author.id.replace(Le,""),name:t.author.name,username:t.author.username},assignees:t.assignees.nodes.map(n=>({avatarUrl:n.avatarUrl,email:null,graphQLId:n.id,id:n.id.replace(Le,""),name:n.name,username:n.username})),commentCount:t.userNotesCount,createdDate:new Date(t.createdAt),description:t.description,graphQLId:t.id,id:t.id.replace(At,""),labels:((r=(e=t.labels)==null?void 0:e.nodes)==null?void 0:r.map(Ae))??[],number:t.iid,repository:{name:s.name,owner:{login:s.namespace}},updatedDate:new Date(t.updatedAt),upvoteCount:t.upvotes,state:{name:t.state,color:null},type:t.type,title:t.title,url:t.webUrl,milestone:t.milestone?xe(t.milestone,s.webUrl):null}},xe=(t,s)=>({id:t.id.replace(Ye,""),graphQLId:t.id,number:parseInt(t.iid,10),title:t.title,description:t.description,isOpen:t.state==="active",url:`${s}/-/${t.webPath.replace(/.+?\/-\//,"")}`,startDate:t.startDate?new Date(t.startDate):null,dueDate:t.dueDate?new Date(t.dueDate):null}),J=class extends D{async getCurrentUser(s={}){var n;let r=(n=(await I(this.config,{query:`
682
+ ${t?"project { httpUrlToRepo path fullPath sshUrlToRepo webUrl } sourceProject { httpUrlToRepo path fullPath sshUrlToRepo webUrl }":""}
683
+ ${s?`milestone { ${je} }`:""}
684
+ ${e?`headPipeline { ${Zt} }`:""}
685
+ `,k=t=>`${t.namespace}/${t.name}`,Yt=t=>`${t.namespace}/${t.name}`,xe=t=>{var s;return{id:t.id.replace(z,""),graphQLId:t.id,namespace:Ne(t.fullPath),name:t.path,webUrl:t.webUrl,httpsUrl:t.httpUrlToRepo,sshUrl:t.sshUrlToRepo,defaultBranch:(s=t.repository)!=null&&s.rootRef?{name:t.repository.rootRef}:null,permission:null}},es={opened:"OPEN",merged:"MERGED",closed:"CLOSED"},O=t=>({id:t.id.replace(Ht,""),graphQLId:t.id,name:t.name,username:t.username,email:t.publicEmail??null,avatarUrl:t.avatarUrl,url:t.webUrl}),Be=t=>({color:t.color,description:t.description,id:t.id.replace(Vt,""),graphQLId:t.id,name:t.title}),ke=(t,s,e)=>{var n,a,o,i,u,l,p,d,c,g,R,h;let r=(n=t.reviewers)!=null&&n.nodes?t.reviewers.nodes.map(b=>{var f,P;return{reviewer:O(b),state:(f=b.mergeRequestInteraction)!=null&&f.approved?"APPROVED":((P=b.mergeRequestInteraction)==null?void 0:P.reviewState)==="REVIEWED"?"CHANGES_REQUESTED":"CHANGES_REQUESTED"}}):null;return{id:t.id.replace(Jt,""),graphQLId:t.id,title:t.title,number:parseInt(t.iid,10),state:es[t.state],commentCount:t.userNotesCount||0,upvoteCount:t.upvotes,author:t.author?O(t.author):null,createdDate:new Date(t.createdAt),isDraft:t.draft,repository:{name:s.name,owner:{login:s.namespace},remoteInfo:s.httpsUrl&&s.sshUrl?{cloneUrlHTTPS:s.httpsUrl,cloneUrlSSH:s.sshUrl}:null},headRepository:e?{name:e.name,owner:{login:e.namespace},remoteInfo:{cloneUrlHTTPS:e.httpsUrl,cloneUrlSSH:e.sshUrl}}:null,headCommit:{buildStatuses:((i=(o=(a=t.headPipeline)==null?void 0:a.stages)==null?void 0:o.nodes)==null?void 0:i.flatMap(b=>{var f,P;return((P=(f=b.jobs)==null?void 0:f.nodes)==null?void 0:P.map(D=>({description:null,name:D.name??null,state:D.status??null,stage:b.name??null,url:`${s.webUrl}/-/jobs/${D.id.replace(Xt,"")}`})))??[]}))??[]},baseRef:{name:t.targetBranch,oid:((u=t.diffRefs)==null?void 0:u.baseSha)??null},headRef:{name:t.sourceBranch,oid:((l=t.diffRefs)==null?void 0:l.headSha)??null},url:t.webUrl,updatedDate:new Date(t.updatedAt),closedDate:t.mergedAt?new Date(t.mergedAt):null,mergedDate:t.mergedAt?new Date(t.mergedAt):null,assignees:(p=t.assignees)!=null&&p.nodes?t.assignees.nodes.map(O):null,reviews:r,reviewDecision:t.approved?"APPROVED":N(r),additions:((d=t.diffStatsSummary)==null?void 0:d.additions)||0,deletions:((c=t.diffStatsSummary)==null?void 0:c.deletions)||0,fileCount:((g=t.diffStatsSummary)==null?void 0:g.fileCount)||0,commitCount:t.commitCount||0,mergeableState:Wt[t.mergeStatusEnum],milestone:t.milestone?Fe(t.milestone,s.webUrl):null,labels:((h=(R=t.labels)==null?void 0:R.nodes)==null?void 0:h.map(Be))??[]}},_e=(t,s)=>{var e,r;return{author:O(t.author),assignees:t.assignees.nodes.map(O),commentCount:t.userNotesCount,closedDate:t.closedAt?new Date(t.closedAt):null,createdDate:new Date(t.createdAt),description:t.description,graphQLId:t.id,id:t.id.replace(Kt,""),labels:((r=(e=t.labels)==null?void 0:e.nodes)==null?void 0:r.map(Be))??[],number:t.iid,repository:{name:s.name,owner:{login:s.namespace}},updatedDate:new Date(t.updatedAt),upvoteCount:t.upvotes,state:{name:t.state,color:null},type:t.type,title:t.title,url:t.webUrl,milestone:t.milestone?Fe(t.milestone,s.webUrl):null}},Fe=(t,s)=>({id:t.id.replace(lt,""),graphQLId:t.id,number:parseInt(t.iid,10),title:t.title,description:t.description,isOpen:t.state==="active",url:`${s}/-/${t.webPath.replace(/.+?\/-\//,"")}`,startDate:t.startDate?new Date(t.startDate):null,dueDate:t.dueDate?new Date(t.dueDate):null}),W=class extends v{async getCurrentUser(s={}){var n;let r=(n=(await y(this.config,{query:`
618
686
  query getCurrentUser {
619
687
  currentUser {
620
- ${O}
688
+ ${G}
621
689
  }
622
690
  }
623
- `},s)).body.data)==null?void 0:n.currentUser;if(!r)throw new Error("Current user not found.");return{data:_(r)}}async getUserForCommit(s,e={}){var a,i,u,l;let r=k(s.repo),o=(l=(u=(i=(a=(await I(this.config,{query:`
691
+ `},s)).body.data)==null?void 0:n.currentUser;if(!r)throw new Error("Current user not found.");return{data:O(r)}}async getUserForCommit(s,e={}){var o,i,u,l;let r=k(s.repo),a=(l=(u=(i=(o=(await y(this.config,{query:`
624
692
  query getUserForCommit($fullPath: ID!, $oid: String!) {
625
693
  project(fullPath: $fullPath) {
626
694
  repository {
@@ -634,21 +702,21 @@ query getUserForCommit($fullPath: ID!, $oid: String!) {
634
702
  }
635
703
  }
636
704
  }
637
- `,variables:{fullPath:r,oid:s.oid}},e)).body.data)==null?void 0:a.project)==null?void 0:i.repository)==null?void 0:u.tree)==null?void 0:l.lastCommit;if(!o)throw new Error("Commit not found.");return{data:{name:o.authorName,email:o.authorEmail,avatarUrl:o.authorGravatar}}}async getAccountForEmail(s,e={}){var o,a,i;let n=(i=(a=(o=(await I(this.config,{query:`
705
+ `,variables:{fullPath:r,oid:s.oid}},e)).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(s,e={}){var a,o,i;let n=(i=(o=(a=(await y(this.config,{query:`
638
706
  query getAccountForEmail($email: String!) {
639
707
  users(search: $email) {
640
708
  nodes {
641
- ${O}
709
+ ${G}
642
710
  }
643
711
  }
644
712
  }
645
- `,variables:{email:s.email}},e)).body.data)==null?void 0:o.users)==null?void 0:a.nodes)==null?void 0:i[0];if(!n)throw new Error("User not found.");return{data:_(n)}}async getAccountForUsername(s,e={}){var o;let n=(o=(await I(this.config,{query:`
713
+ `,variables:{email:s.email}},e)).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:O(n)}}async getAccountForUsername(s,e={}){var a;let n=(a=(await y(this.config,{query:`
646
714
  query getAccountForUsername($username: String!) {
647
715
  user(username: $username) {
648
- ${O}
716
+ ${G}
649
717
  }
650
718
  }
651
- `,variables:{username:s.username}},e)).body.data)==null?void 0:o.user;if(!n)throw new Error("User not found.");return{data:_(n)}}async getAccountsForRepo(s,e={}){var u,l,p,d,c,g,m;let{repo:{namespace:r,name:n},cursor:o}=s,a=await I(this.config,{query:`
719
+ `,variables:{username:s.username}},e)).body.data)==null?void 0:a.user;if(!n)throw new Error("User not found.");return{data:O(n)}}async getAccountsForRepo(s,e={}){var u,l,p,d,c,g,R;let{repo:{namespace:r,name:n},cursor:a}=s,o=await y(this.config,{query:`
652
720
  query getAccountsForRepo(
653
721
  $fullPath: ID!
654
722
  $after: String
@@ -659,7 +727,7 @@ query getAccountsForRepo(
659
727
  projectMembers(after: $after) {
660
728
  nodes {
661
729
  user {
662
- ${O}
730
+ ${G}
663
731
  }
664
732
  }
665
733
  pageInfo {
@@ -669,22 +737,22 @@ query getAccountsForRepo(
669
737
  }
670
738
  }
671
739
  }
672
- `,variables:{fullPath:`${r}/${n}`,after:o}},e),i=(d=(p=(l=(u=a.body.data)==null?void 0:u.project)==null?void 0:l.projectMembers)==null?void 0:p.nodes)==null?void 0:d.map(R=>R.user).filter(R=>R!==null);return{pageInfo:((m=(g=(c=a.body.data)==null?void 0:c.project)==null?void 0:g.projectMembers)==null?void 0:m.pageInfo)??{endCursor:null,hasNextPage:!1},data:(i==null?void 0:i.map(_))??[]}}async getRepo(s,e={}){var o;let r=k(s),n=await I(this.config,{query:`
740
+ `,variables:{fullPath:`${r}/${n}`,after:a}},e),i=(d=(p=(l=(u=o.body.data)==null?void 0:u.project)==null?void 0:l.projectMembers)==null?void 0:p.nodes)==null?void 0:d.map(h=>h.user).filter(h=>h!==null);return{pageInfo:((R=(g=(c=o.body.data)==null?void 0:c.project)==null?void 0:g.projectMembers)==null?void 0:R.pageInfo)??{endCursor:null,hasNextPage:!1},data:(i==null?void 0:i.map(O))??[]}}async getRepo(s,e={}){var a;let r=k(s),n=await y(this.config,{query:`
673
741
  query getRepo($fullPath: ID!) {
674
742
  project(fullPath: $fullPath) {
675
- ${Se}
743
+ ${Oe}
676
744
  }
677
745
  }
678
- `,variables:{fullPath:r}},e);if(!((o=n.body.data)!=null&&o.project))throw new Error(`Repository ${r} not found`);return{data:Ee(n.body.data.project)}}async getRepos(s,e={}){let n=s.map(k).map((u,l)=>`
746
+ `,variables:{fullPath:r}},e);if(!((a=n.body.data)!=null&&a.project))throw new Error(`Repository ${r} not found`);return{data:xe(n.body.data.project)}}async getRepos(s,e={}){let n=s.map(k).map((u,l)=>`
679
747
  getRepo_${l}: project(fullPath: "${u}") {
680
- ${Se}
748
+ ${Oe}
681
749
  }
682
750
  `).join(`
683
- `),o=await I(this.config,{query:`
751
+ `),a=await y(this.config,{query:`
684
752
  query batchGetRepos {
685
753
  ${n}
686
754
  }
687
- `},e);if(!o.body.data)throw new Error(o.statusText||"Unknown error");let a=[],i=[];return s.forEach((u,l)=>{let p=o.body.data[`getRepo_${l}`];p?a.push(Ee(p)):i.push({input:u})}),{data:a,errors:i}}async getReposForCurrentUser(s={},e={}){var o,a,i,u,l,p;let r=await I(this.config,{query:`
755
+ `},e);if(!a.body.data)throw new Error(a.statusText||"Unknown error");let o=[],i=[];return s.forEach((u,l)=>{let p=a.body.data[`getRepo_${l}`];p?o.push(xe(p)):i.push({input:u})}),{data:o,errors:i}}async getReposForCurrentUser(s={},e={}){var a,o,i,u,l,p;let r=await y(this.config,{query:`
688
756
  query getReposForCurrentUser($after: String) {
689
757
  projects(membership: true first: 100 after: $after) {
690
758
  pageInfo {
@@ -692,11 +760,11 @@ query getReposForCurrentUser($after: String) {
692
760
  hasNextPage
693
761
  }
694
762
  nodes {
695
- ${Se}
763
+ ${Oe}
696
764
  }
697
765
  }
698
766
  }
699
- `,variables:{after:s.cursor}},e);if(!((o=r.body.data)!=null&&o.projects))throw new Error(((a=r.body.errors)==null?void 0:a[0].message)||r.statusText||"Unknown error");let n=((u=(i=r.body.data)==null?void 0:i.projects)==null?void 0:u.nodes)||[];return{pageInfo:(p=(l=r.body.data)==null?void 0:l.projects)==null?void 0:p.pageInfo,data:n.map(Ee)}}async getRefs(s,e,r={}){var u;let n=k(e.repo),o=new URL(`${$e(this.config,r)}/projects/${encodeURIComponent(n)}/repository/${s}`);o.searchParams.set("page",((u=e.page)==null?void 0:u.toString())||"1"),o.searchParams.set("per_page",$.toString());let a=await this.config.request({url:o.toString(),headers:h(r.token||this.config.token)}),i=a.headers["x-next-page"];return{pageInfo:{hasNextPage:!!i,nextPage:i?parseInt(i,10):null},data:a.body.map(l=>({name:l.name,commit:{oid:l.commit.id,authoredDate:new Date(l.commit.authored_date),committedDate:new Date(l.commit.committed_date)}}))}}async getBranches(s,e={}){return this.getRefs("branches",s,e)}async getTags(s,e={}){return this.getRefs("tags",s,e)}async getBlame(s,e={}){let r=k(s.repo),n=new URL(`${$e(this.config,e)}/projects/${encodeURIComponent(r)}/repository/files/${encodeURIComponent(s.path)}/blame`);n.searchParams.set("ref",s.ref);let o=await this.config.request({url:n.toString(),headers:h(e.token||this.config.token)}),a=0;return{data:{ranges:o.body.map(i=>{let u=a+1;return a+=i.lines.length,{startingLine:u,endingLine:a,commit:{oid:i.commit.id,parentOids:i.commit.parent_ids,authoredDate:new Date(i.commit.authored_date),author:{name:i.commit.author_name,email:i.commit.author_email,avatarUrl:null},committedDate:new Date(i.commit.committed_date),committer:{name:i.commit.committer_name,email:i.commit.committer_email,avatarUrl:null},message:i.commit.message,fileCount:null,additions:null,deletions:null}}})}}}async getPullRequestsForUser(s,e={}){var a,i;let r=Lt[s.association],n=await I(this.config,{query:`
767
+ `,variables:{after:s.cursor}},e);if(!((a=r.body.data)!=null&&a.projects))throw new Error(((o=r.body.errors)==null?void 0:o[0].message)||r.statusText||"Unknown error");let n=((u=(i=r.body.data)==null?void 0:i.projects)==null?void 0:u.nodes)||[];return{pageInfo:(p=(l=r.body.data)==null?void 0:l.projects)==null?void 0:p.pageInfo,data:n.map(xe)}}async getRefs(s,e,r={}){var u;let n=k(e.repo),a=new URL(`${Ge(this.config,r)}/projects/${encodeURIComponent(n)}/repository/${s}`);a.searchParams.set("page",((u=e.page)==null?void 0:u.toString())||"1"),a.searchParams.set("per_page",C.toString());let o=await this.config.request({url:a.toString(),headers:m(r.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(s,e={}){return this.getRefs("branches",s,e)}async getTags(s,e={}){return this.getRefs("tags",s,e)}async getBlame(s,e={}){let r=k(s.repo),n=new URL(`${Ge(this.config,e)}/projects/${encodeURIComponent(r)}/repository/files/${encodeURIComponent(s.path)}/blame`);n.searchParams.set("ref",s.ref);let a=await this.config.request({url:n.toString(),headers:m(e.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}}})}}}async getPullRequestsForUser(s,e={}){var o,i;let r=zt[s.association],n=await y(this.config,{query:`
700
768
  query getPullRequestsForUser($username: String! $cursor: String) {
701
769
  user(username: $username) {
702
770
  ${r}(state:opened first:100 after:$cursor) {
@@ -705,12 +773,12 @@ query getPullRequestsForUser($username: String! $cursor: String) {
705
773
  hasNextPage
706
774
  }
707
775
  nodes {
708
- ${Ue(!0,!0,!0)}
776
+ ${Te(!0,!0,!0)}
709
777
  }
710
778
  }
711
779
  }
712
780
  }
713
- `,variables:{username:s.username,cursor:s.cursor}},e);if(!n.body.data)throw new Error(((a=n.body.errors)==null?void 0:a[0].message)||n.statusText||"Unknown error");if(!n.body.data.user)throw new Error("User not found");let o=n.body.data.user[r];if(!o)throw new Error("Unexpected response");return{pageInfo:o.pageInfo,data:((i=o.nodes)==null?void 0:i.map(u=>ve(u,j(u.project))))||[]}}async getPullRequestsAssociatedWithUser(s,e={}){var c;let[r,n,o]=((c=s.cursor)==null?void 0:c.split(";"))||[void 0,void 0,void 0],[a,i,u]=await Promise.all([r==="null"?null:this.getPullRequestsForUser({username:s.username,association:"authored",cursor:r},e),n==="null"?null:this.getPullRequestsForUser({username:s.username,association:"assigned",cursor:n},e),o==="null"?null:this.getPullRequestsForUser({username:s.username,association:"reviewRequested",cursor:o},e)]),l={},p=[],d=g=>{l[g.id]||(l[g.id]=!0,p.push(g))};return a==null||a.data.forEach(d),i==null||i.data.forEach(d),u==null||u.data.forEach(d),{pageInfo:{hasNextPage:(a==null?void 0:a.pageInfo.hasNextPage)||(i==null?void 0:i.pageInfo.hasNextPage)||(u==null?void 0:u.pageInfo.hasNextPage)||!1,endCursor:`${(a==null?void 0:a.pageInfo.hasNextPage)&&(a==null?void 0:a.pageInfo.endCursor)||"null"};${(i==null?void 0:i.pageInfo.hasNextPage)&&(i==null?void 0:i.pageInfo.endCursor)||"null"};${(u==null?void 0:u.pageInfo.hasNextPage)&&(u==null?void 0:u.pageInfo.endCursor)||"null"}`},data:p}}getVariablesForPullRequests(s){let{updatedBefore:e,isDraft:r,authorLogin:n,assigneeLogins:o,reviewRequestedLogin:a}=s||{},i={},u=[],l=[],p=(d,c,g)=>{u.push(`$${d}: ${g}`),l.push(`${d}: $${d}`),i[d]=c};return e&&p("updatedBefore",e,"Time"),n&&p("authorUsername",n,"String"),o&&p("assigneeUsername",o[0],"String"),r!=null&&p("draft",r,"Boolean"),a&&p("reviewerUsername",a,"String"),{variables:i,variableTypes:u,mergeRequestArguments:l}}async getPullRequestsForRepo(s,e={}){var R,b,P;let{cursor:r,repo:n}=s||{},o=k(n),{variables:a,variableTypes:i,mergeRequestArguments:u}=this.getVariablesForPullRequests(s),l={fullPath:o,...a},p=await I(this.config,{query:`
781
+ `,variables:{username:s.username,cursor:s.cursor}},e);if(!n.body.data)throw new Error(((o=n.body.errors)==null?void 0:o[0].message)||n.statusText||"Unknown error");if(!n.body.data.user)throw new Error("User not found");let a=n.body.data.user[r];if(!a)throw new Error("Unexpected response");return{pageInfo:a.pageInfo,data:((i=a.nodes)==null?void 0:i.map(u=>ke(u,ut(u.project),ut(u.sourceProject))))||[]}}async getPullRequestsAssociatedWithUser(s,e={}){var c;let[r,n,a]=((c=s.cursor)==null?void 0:c.split(";"))||[void 0,void 0,void 0],[o,i,u]=await Promise.all([r==="null"?null:this.getPullRequestsForUser({username:s.username,association:"authored",cursor:r},e),n==="null"?null:this.getPullRequestsForUser({username:s.username,association:"assigned",cursor:n},e),a==="null"?null:this.getPullRequestsForUser({username:s.username,association:"reviewRequested",cursor:a},e)]),l={},p=[],d=g=>{l[g.id]||(l[g.id]=!0,p.push(g))};return o==null||o.data.forEach(d),i==null||i.data.forEach(d),u==null||u.data.forEach(d),{pageInfo:{hasNextPage:(o==null?void 0:o.pageInfo.hasNextPage)||(i==null?void 0:i.pageInfo.hasNextPage)||(u==null?void 0:u.pageInfo.hasNextPage)||!1,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"};${(u==null?void 0:u.pageInfo.hasNextPage)&&(u==null?void 0:u.pageInfo.endCursor)||"null"}`},data:p}}getVariablesForPullRequests(s){let{updatedBefore:e,isDraft:r,authorLogin:n,assigneeLogins:a,reviewRequestedLogin:o}=s||{},i={},u=[],l=[],p=(d,c,g)=>{u.push(`$${d}: ${g}`),l.push(`${d}: $${d}`),i[d]=c};return e&&p("updatedBefore",e,"Time"),n&&p("authorUsername",n,"String"),a&&p("assigneeUsername",a[0],"String"),r!=null&&p("draft",r,"Boolean"),o&&p("reviewerUsername",o,"String"),{variables:i,variableTypes:u,mergeRequestArguments:l}}async getPullRequestsForRepo(s,e={}){var h,b,f;let{cursor:r,repo:n}=s||{},a=k(n),{variables:o,variableTypes:i,mergeRequestArguments:u}=this.getVariablesForPullRequests(s),l={fullPath:a,...o},p=await y(this.config,{query:`
714
782
  query getPullRequestsForRepo(
715
783
  $fullPath: ID!
716
784
  $after: String
@@ -734,16 +802,16 @@ query getPullRequestsForRepo(
734
802
  hasNextPage
735
803
  }
736
804
  nodes {
737
- ${Ue(!1,!0,!0)}
805
+ ${Te(!1,!0,!0)}
738
806
  }
739
807
  }
740
808
  }
741
809
  }
742
- `,variables:{...l,after:r}},e),d=[],c=(R=p.body.data)==null?void 0:R.project,g=j(c||{fullPath:"",path:"",webUrl:""});return(((b=c==null?void 0:c.mergeRequests)==null?void 0:b.nodes)||[]).forEach(q=>{d.push(ve(q,g))}),{pageInfo:(P=c==null?void 0:c.mergeRequests)==null?void 0:P.pageInfo,data:d}}async getPullRequestsForRepos(s,e={}){var c,g,m,R,b;let{cursor:r}=s||{},n=s.repoIds.map(P=>P.toString().startsWith(z)?P:`${z}${P}`),{variables:o,variableTypes:a,mergeRequestArguments:i}=this.getVariablesForPullRequests(s),u={projectIds:n,...o},l=await I(this.config,{query:`
810
+ `,variables:{...l,after:r}},e),d=[],c=(h=p.body.data)==null?void 0:h.project,g=M(c||{fullPath:"",path:"",webUrl:""});return(((b=c==null?void 0:c.mergeRequests)==null?void 0:b.nodes)||[]).forEach(P=>{d.push(ke(P,g,null))}),{pageInfo:(f=c==null?void 0:c.mergeRequests)==null?void 0:f.pageInfo,data:d}}async getPullRequestsForRepos(s,e={}){var c,g,R,h,b;let{cursor:r}=s||{},n=s.repoIds.map(f=>f.toString().startsWith(z)?f:`${z}${f}`),{variables:a,variableTypes:o,mergeRequestArguments:i}=this.getVariablesForPullRequests(s),u={projectIds:n,...a},l=await y(this.config,{query:`
743
811
  query getPullRequests(
744
812
  $projectIds: [ID!]
745
813
  $after: String
746
- ${a.length?a.join(" "):""}
814
+ ${o.length?o.join(" "):""}
747
815
  ) {
748
816
  projects(
749
817
  ids: $projectIds
@@ -764,20 +832,20 @@ query getPullRequests(
764
832
  ${i.length?i.join(" "):""}
765
833
  ) {
766
834
  nodes {
767
- ${Ue(!1,!1,!1)}
835
+ ${Te(!1,!1,!1)}
768
836
  }
769
837
  }
770
838
  }
771
839
  }
772
840
  }
773
- `,variables:{...u,after:r}},e),p=[];return(((g=(c=l.body.data)==null?void 0:c.projects)==null?void 0:g.nodes)||[]).forEach(P=>{var N;let q=j(P);(((N=P.mergeRequests)==null?void 0:N.nodes)||[]).forEach(K=>{p.push(ve(K,q))})}),{pageInfo:(b=(R=(m=l.body)==null?void 0:m.data)==null?void 0:R.projects)==null?void 0:b.pageInfo,data:p}}async closePullRequest(s,e={}){var l,p,d;let{repo:{namespace:r,name:n},pullRequestId:o}=s,a=`mutation ClosePullRequest($fullPath: ID!, $pullRequestId: String!) {
841
+ `,variables:{...u,after:r}},e),p=[];return(((g=(c=l.body.data)==null?void 0:c.projects)==null?void 0:g.nodes)||[]).forEach(f=>{var _;let P=M(f);(((_=f.mergeRequests)==null?void 0:_.nodes)||[]).forEach(Z=>{p.push(ke(Z,P,null))})}),{pageInfo:(b=(h=(R=l.body)==null?void 0:R.data)==null?void 0:h.projects)==null?void 0:b.pageInfo,data:p}}async closePullRequest(s,e={}){var l,p,d;let{repo:{namespace:r,name:n},pullRequestId:a}=s,o=`mutation ClosePullRequest($fullPath: ID!, $pullRequestId: String!) {
774
842
  mergeRequestUpdate(input: { projectPath: $fullPath, iid: $pullRequestId, state: CLOSED }) {
775
843
  errors,
776
844
  mergeRequest {
777
845
  id
778
846
  }
779
847
  }
780
- }`,u=(l=(await I(this.config,{query:a,variables:{fullPath:`${r}/${n}`,pullRequestId:o}},e)).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(s,e={}){var d,c,g;let{repo:{namespace:r,name:n},pullRequestId:o,expectedSourceSha:a,mergeStrategy:i}=s,u=`mutation MergePullRequest(
848
+ }`,u=(l=(await y(this.config,{query:o,variables:{fullPath:`${r}/${n}`,pullRequestId:a}},e)).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(s,e={}){var d,c,g;let{repo:{namespace:r,name:n},pullRequestId:a,expectedSourceSha:o,mergeStrategy:i}=s,u=`mutation MergePullRequest(
781
849
  $fullPath: ID!,
782
850
  $pullRequestId: String!,
783
851
  $expectedSourceSha: String!,
@@ -794,52 +862,52 @@ query getPullRequests(
794
862
  id
795
863
  }
796
864
  }
797
- }`,p=(d=(await I(this.config,{query:u,variables:{fullPath:`${r}/${n}`,pullRequestId:o,expectedSourceSha:a,squash:i==="SQUASH"}},e)).body.data)==null?void 0:d.mergeRequestAccept;if(!((c=p==null?void 0:p.mergeRequest)!=null&&c.id)||((g=p==null?void 0:p.errors)==null?void 0:g.length)!==0)throw new Error("Could not merge pull request")}async setPullRequestMilestone(s,e={}){var p,d,c;let{repo:{namespace:r,name:n},pullRequestId:o,milestoneGraphQLId:a}=s,i=`mutation SetPullRequestMilestone($fullPath: ID!, $pullRequestId: String!, $milestoneGraphQLId: MilestoneID) {
865
+ }`,p=(d=(await y(this.config,{query:u,variables:{fullPath:`${r}/${n}`,pullRequestId:a,expectedSourceSha:o,squash:i==="SQUASH"}},e)).body.data)==null?void 0:d.mergeRequestAccept;if(!((c=p==null?void 0:p.mergeRequest)!=null&&c.id)||((g=p==null?void 0:p.errors)==null?void 0:g.length)!==0)throw new Error("Could not merge pull request")}async setPullRequestMilestone(s,e={}){var p,d,c;let{repo:{namespace:r,name:n},pullRequestId:a,milestoneGraphQLId:o}=s,i=`mutation SetPullRequestMilestone($fullPath: ID!, $pullRequestId: String!, $milestoneGraphQLId: MilestoneID) {
798
866
  mergeRequestSetMilestone(input: { projectPath: $fullPath, iid: $pullRequestId, milestoneId: $milestoneGraphQLId }) {
799
867
  errors,
800
868
  mergeRequest {
801
869
  id
802
870
  }
803
871
  }
804
- }`,u=await I(this.config,{query:i,variables:{fullPath:`${r}/${n}`,pullRequestId:o,milestoneGraphQLId:a}},e),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(s,e={}){var p,d,c;let{repo:{namespace:r,name:n},pullRequestId:o,isDraft:a}=s,i=`mutation MergeRequestSetDraft($fullPath: ID!, $pullRequestId: String!, $isDraft: Boolean!) {
872
+ }`,u=await y(this.config,{query:i,variables:{fullPath:`${r}/${n}`,pullRequestId:a,milestoneGraphQLId:o}},e),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(s,e={}){var p,d,c;let{repo:{namespace:r,name:n},pullRequestId:a,isDraft:o}=s,i=`mutation MergeRequestSetDraft($fullPath: ID!, $pullRequestId: String!, $isDraft: Boolean!) {
805
873
  mergeRequestSetDraft(input: { projectPath: $fullPath, iid: $pullRequestId, draft: $isDraft }) {
806
874
  errors,
807
875
  mergeRequest {
808
876
  id
809
877
  }
810
878
  }
811
- }`,l=(p=(await I(this.config,{query:i,variables:{fullPath:`${r}/${n}`,pullRequestId:o,isDraft:a}},e)).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 setPullRequestReviewers(s,e={}){var p,d,c;let{repo:{namespace:r,name:n},pullRequestId:o,reviewerUsernames:a}=s,i=`mutation MergeRequestSetReviewers($fullPath: ID!, $pullRequestId: String!, $reviewerUsernames: [String!]!) {
879
+ }`,l=(p=(await y(this.config,{query:i,variables:{fullPath:`${r}/${n}`,pullRequestId:a,isDraft:o}},e)).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 setPullRequestReviewers(s,e={}){var p,d,c;let{repo:{namespace:r,name:n},pullRequestId:a,reviewerUsernames:o}=s,i=`mutation MergeRequestSetReviewers($fullPath: ID!, $pullRequestId: String!, $reviewerUsernames: [String!]!) {
812
880
  mergeRequestSetReviewers(input: { projectPath: $fullPath, iid: $pullRequestId, reviewerUsernames: $reviewerUsernames }) {
813
881
  errors,
814
882
  mergeRequest {
815
883
  id
816
884
  }
817
885
  }
818
- }`,l=(p=(await I(this.config,{query:i,variables:{fullPath:`${r}/${n}`,pullRequestId:o,reviewerUsernames:a}},e)).body.data)==null?void 0:p.mergeRequestSetReviewers;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 reviewers")}async setPullRequestAssignees(s,e={}){var p,d,c;let{repo:{namespace:r,name:n},pullRequestId:o,assigneeUsernames:a}=s,i=`mutation MergeRequestSetAssignees($fullPath: ID!, $pullRequestId: String!, $assigneeUsernames: [String!]!) {
886
+ }`,l=(p=(await y(this.config,{query:i,variables:{fullPath:`${r}/${n}`,pullRequestId:a,reviewerUsernames:o}},e)).body.data)==null?void 0:p.mergeRequestSetReviewers;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 reviewers")}async setPullRequestAssignees(s,e={}){var p,d,c;let{repo:{namespace:r,name:n},pullRequestId:a,assigneeUsernames:o}=s,i=`mutation MergeRequestSetAssignees($fullPath: ID!, $pullRequestId: String!, $assigneeUsernames: [String!]!) {
819
887
  mergeRequestSetAssignees(input: { projectPath: $fullPath, iid: $pullRequestId, assigneeUsernames: $assigneeUsernames }) {
820
888
  errors,
821
889
  mergeRequest {
822
890
  id
823
891
  }
824
892
  }
825
- }`,l=(p=(await I(this.config,{query:i,variables:{fullPath:`${r}/${n}`,pullRequestId:o,assigneeUsernames:a}},e)).body.data)==null?void 0:p.mergeRequestSetAssignees;if(!((d=l==null?void 0:l.mergeRequest)!=null&&d.id)||((c=l==null?void 0:l.errors)==null?void 0:c.length)!==0)throw new Error("Could not set pull request assignees")}async setPullRequestLabels(s,e={}){var l,p,d;let{repo:{namespace:r,name:n},pullRequestId:o,labelGraphQLIds:a}=s,i=`mutation SetPullRequestLabels($fullPath: ID!, $pullRequestId: String!, $labelGraphQLIds: [LabelID!]!) {
893
+ }`,l=(p=(await y(this.config,{query:i,variables:{fullPath:`${r}/${n}`,pullRequestId:a,assigneeUsernames:o}},e)).body.data)==null?void 0:p.mergeRequestSetAssignees;if(!((d=l==null?void 0:l.mergeRequest)!=null&&d.id)||((c=l==null?void 0:l.errors)==null?void 0:c.length)!==0)throw new Error("Could not set pull request assignees")}async setPullRequestLabels(s,e={}){var l,p,d;let{repo:{namespace:r,name:n},pullRequestId:a,labelGraphQLIds:o}=s,i=`mutation SetPullRequestLabels($fullPath: ID!, $pullRequestId: String!, $labelGraphQLIds: [LabelID!]!) {
826
894
  mergeRequestSetLabels(input: { projectPath: $fullPath, iid: $pullRequestId, labelIds: $labelGraphQLIds }) {
827
895
  mergeRequest {
828
896
  id
829
897
  }
830
898
  }
831
- }`;if(!((d=(p=(l=(await I(this.config,{query:i,variables:{fullPath:`${r}/${n}`,pullRequestId:o,labelGraphQLIds:a}},e)).body.data)==null?void 0:l.mergeRequestSetLabels)==null?void 0:p.mergeRequest)!=null&&d.id))throw new Error("Could not set pull request labels")}async getIssue(s,e={}){var o,a,i;let r=_t(s),n=await I(this.config,{query:`
899
+ }`;if(!((d=(p=(l=(await y(this.config,{query:i,variables:{fullPath:`${r}/${n}`,pullRequestId:a,labelGraphQLIds:o}},e)).body.data)==null?void 0:l.mergeRequestSetLabels)==null?void 0:p.mergeRequest)!=null&&d.id))throw new Error("Could not set pull request labels")}async getIssue(s,e={}){var a,o,i;let r=Yt(s),n=await y(this.config,{query:`
832
900
  query GetSingleIssue($projectId: ID!, $issueId: String!) {
833
901
  project(fullPath: $projectId) {
834
902
  path
835
903
  fullPath
836
904
  webUrl
837
905
  issue(iid: $issueId) {
838
- ${Ce}
906
+ ${Ae}
839
907
  }
840
908
  }
841
909
  }
842
- `,variables:{issueId:s.id,projectId:r}},e);if(!((o=n.body.data)!=null&&o.project))throw new Error(`Repository ${r} not found`);if(!((i=(a=n.body.data)==null?void 0:a.project)!=null&&i.issue))throw new Error(`Issue ${s.id} not found`);return{data:De(n.body.data.project.issue,j(n.body.data.project))}}getVariablesForIssues(s){let{updatedBefore:e,authorLogin:r,assigneeLogins:n}=s||{},o={},a=[],i=[],u=(l,p,d)=>{a.push(`$${l}: ${d}`),i.push(`${l}: $${l}`),o[l]=p};return e&&u("updatedBefore",e,"Time"),r&&u("authorUsername",r,"String"),n&&u("assigneeUsername",n[0],"String"),{variables:o,variableTypes:a,issueArguments:i}}async getIssuesForRepo(s,e={}){var b,P,q;let{cursor:r,repo:n}=s||{},o=k(n),{variables:a,variableTypes:i,issueArguments:u}=this.getVariablesForIssues(s),l={fullPath:o,...a},p=`
910
+ `,variables:{issueId:s.id,projectId:r}},e);if(!((a=n.body.data)!=null&&a.project))throw new Error(`Repository ${r} not found`);if(!((i=(o=n.body.data)==null?void 0:o.project)!=null&&i.issue))throw new Error(`Issue ${s.id} not found`);return{data:_e(n.body.data.project.issue,M(n.body.data.project))}}getVariablesForIssues(s){let{updatedBefore:e,authorLogin:r,assigneeLogins:n}=s||{},a={},o=[],i=[],u=(l,p,d)=>{o.push(`$${l}: ${d}`),i.push(`${l}: $${l}`),a[l]=p};return e&&u("updatedBefore",e,"Time"),r&&u("authorUsername",r,"String"),n&&u("assigneeUsername",n[0],"String"),{variables:a,variableTypes:o,issueArguments:i}}async getIssuesForRepo(s,e={}){var b,f,P;let{cursor:r,repo:n}=s||{},a=k(n),{variables:o,variableTypes:i,issueArguments:u}=this.getVariablesForIssues(s),l={fullPath:a,...o},p=`
843
911
  query GetIssuesFromProject(
844
912
  $fullPath: ID!
845
913
  $after: String
@@ -859,7 +927,7 @@ query GetSingleIssue($projectId: ID!, $issueId: String!) {
859
927
  ${u.length?u.join(" "):""}
860
928
  ) {
861
929
  nodes {
862
- ${Ce}
930
+ ${Ae}
863
931
  }
864
932
  pageInfo {
865
933
  endCursor
@@ -867,11 +935,11 @@ query GetSingleIssue($projectId: ID!, $issueId: String!) {
867
935
  }
868
936
  }
869
937
  }
870
- }`,d=await I(this.config,{query:p,variables:{...l,after:r}},e),c=[],g=(b=d.body.data)==null?void 0:b.project,m=j(g||{fullPath:"",path:"",webUrl:""});return(((P=g==null?void 0:g.issues)==null?void 0:P.nodes)||[]).forEach(v=>{c.push(De(v,m))}),{pageInfo:(q=g==null?void 0:g.issues)==null?void 0:q.pageInfo,data:c.sort((v,N)=>(v.updatedDate||v.createdDate).getTime()-(N.updatedDate||N.createdDate).getTime())}}async getIssuesForRepos(s,e={}){var g,m,R,b,P;let{cursor:r}=s||{},n=s.repoIds.map(q=>q.toString().startsWith(z)?q:`${z}${q}`),{variables:o,variableTypes:a,mergeRequestArguments:i}=this.getVariablesForPullRequests(s),u={projectIds:n,...o},l=`
938
+ }`,d=await y(this.config,{query:p,variables:{...l,after:r}},e),c=[],g=(b=d.body.data)==null?void 0:b.project,R=M(g||{fullPath:"",path:"",webUrl:""});return(((f=g==null?void 0:g.issues)==null?void 0:f.nodes)||[]).forEach(D=>{c.push(_e(D,R))}),{pageInfo:(P=g==null?void 0:g.issues)==null?void 0:P.pageInfo,data:c.sort((D,_)=>(D.updatedDate||D.createdDate).getTime()-(_.updatedDate||_.createdDate).getTime())}}async getIssuesForRepos(s,e={}){var g,R,h,b,f;let{cursor:r}=s||{},n=s.repoIds.map(P=>P.toString().startsWith(z)?P:`${z}${P}`),{variables:a,variableTypes:o,mergeRequestArguments:i}=this.getVariablesForPullRequests(s),u={projectIds:n,...a},l=`
871
939
  query GetIssuesFromProject(
872
940
  $projectIds: [ID!]
873
941
  $after: String
874
- ${a.length?a.join(" "):""}
942
+ ${o.length?o.join(" "):""}
875
943
  ) {
876
944
  projects(
877
945
  ids: $projectIds
@@ -892,24 +960,24 @@ query GetSingleIssue($projectId: ID!, $issueId: String!) {
892
960
  ${i.length?i.join(" "):""}
893
961
  ) {
894
962
  nodes {
895
- ${Ce}
963
+ ${Ae}
896
964
  }
897
965
  }
898
966
  }
899
967
  }
900
- }`,p=await I(this.config,{query:l,variables:{...u,after:r}},e),d=[];return(((m=(g=p.body.data)==null?void 0:g.projects)==null?void 0:m.nodes)||[]).forEach(q=>{var K;let v=j(q);(((K=q.issues)==null?void 0:K.nodes)||[]).forEach(et=>d.push(De(et,v)))}),{pageInfo:(P=(b=(R=p.body)==null?void 0:R.data)==null?void 0:b.projects)==null?void 0:P.pageInfo,data:d.sort((q,v)=>(q.updatedDate||q.createdDate).getTime()-(v.updatedDate||v.createdDate).getTime())}}async setIssueStatus(s,e={}){var l,p,d;let{repo:{namespace:r,name:n},issueId:o,status:a}=s,i=`mutation SetIssueState($fullPath: ID!, $issueId: String!, $status: IssueStateEvent!) {
968
+ }`,p=await y(this.config,{query:l,variables:{...u,after:r}},e),d=[];return(((R=(g=p.body.data)==null?void 0:g.projects)==null?void 0:R.nodes)||[]).forEach(P=>{var Z;let D=M(P);(((Z=P.issues)==null?void 0:Z.nodes)||[]).forEach(pt=>d.push(_e(pt,D)))}),{pageInfo:(f=(b=(h=p.body)==null?void 0:h.data)==null?void 0:b.projects)==null?void 0:f.pageInfo,data:d.sort((P,D)=>(P.updatedDate||P.createdDate).getTime()-(D.updatedDate||D.createdDate).getTime())}}async setIssueStatus(s,e={}){var l,p,d;let{repo:{namespace:r,name:n},issueId:a,status:o}=s,i=`mutation SetIssueState($fullPath: ID!, $issueId: String!, $status: IssueStateEvent!) {
901
969
  updateIssue(input: { projectPath: $fullPath, iid: $issueId, stateEvent: $status }) {
902
970
  issue {
903
971
  id
904
972
  }
905
973
  }
906
- }`;if(!((d=(p=(l=(await I(this.config,{query:i,variables:{fullPath:`${r}/${n}`,issueId:o,status:a}},e)).body.data)==null?void 0:l.updateIssue)==null?void 0:p.issue)!=null&&d.id))throw new Error("Could not set issue status")}async setIssueLabels(s,e={}){var l,p,d;let{repo:{namespace:r,name:n},issueId:o,labelGraphQLIds:a}=s,i=`mutation SetIssueLabels($fullPath: ID!, $issueId: String!, $labelGraphQLIds: [ID!]) {
974
+ }`;if(!((d=(p=(l=(await y(this.config,{query:i,variables:{fullPath:`${r}/${n}`,issueId:a,status:o}},e)).body.data)==null?void 0:l.updateIssue)==null?void 0:p.issue)!=null&&d.id))throw new Error("Could not set issue status")}async setIssueLabels(s,e={}){var l,p,d;let{repo:{namespace:r,name:n},issueId:a,labelGraphQLIds:o}=s,i=`mutation SetIssueLabels($fullPath: ID!, $issueId: String!, $labelGraphQLIds: [ID!]) {
907
975
  updateIssue(input: { projectPath: $fullPath, iid: $issueId, labelIds: $labelGraphQLIds }) {
908
976
  issue {
909
977
  id
910
978
  }
911
979
  }
912
- }`;if(!((d=(p=(l=(await I(this.config,{query:i,variables:{fullPath:`${r}/${n}`,issueId:o,labelGraphQLIds:a}},e)).body.data)==null?void 0:l.updateIssue)==null?void 0:p.issue)!=null&&d.id))throw new Error("Could not set issue labels")}async setIssueMilestone(s,e={}){var p,d,c,g;let{repo:{namespace:r,name:n},issueId:o}=s,a=((p=s.milestoneGraphQLId)==null?void 0:p.replace(Ye,""))??"",i=`mutation SetIssueMilestone($fullPath: ID!, $issueId: String!, $milestoneGraphQLId: ID) {
980
+ }`;if(!((d=(p=(l=(await y(this.config,{query:i,variables:{fullPath:`${r}/${n}`,issueId:a,labelGraphQLIds:o}},e)).body.data)==null?void 0:l.updateIssue)==null?void 0:p.issue)!=null&&d.id))throw new Error("Could not set issue labels")}async setIssueMilestone(s,e={}){var p,d,c,g;let{repo:{namespace:r,name:n},issueId:a}=s,o=((p=s.milestoneGraphQLId)==null?void 0:p.replace(lt,""))??"",i=`mutation SetIssueMilestone($fullPath: ID!, $issueId: String!, $milestoneGraphQLId: ID) {
913
981
  updateIssue(input: { projectPath: $fullPath, iid: $issueId, milestoneId: $milestoneGraphQLId }) {
914
982
  errors
915
983
  issue {
@@ -919,14 +987,14 @@ query GetSingleIssue($projectId: ID!, $issueId: String!) {
919
987
  }
920
988
  }
921
989
  }
922
- }`,u=await I(this.config,{query:i,variables:{fullPath:`${r}/${n}`,issueId:o,milestoneGraphQLId:a}},e),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 setIssueAssignees(s,e={}){var p,d,c;let{repo:{namespace:r,name:n},issueId:o,assigneeUsernames:a}=s,i=`mutation SetIssueAssignees($fullPath: ID!, $issueId: String!, $assigneeUsernames: [String!]!) {
990
+ }`,u=await y(this.config,{query:i,variables:{fullPath:`${r}/${n}`,issueId:a,milestoneGraphQLId:o}},e),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 setIssueAssignees(s,e={}){var p,d,c;let{repo:{namespace:r,name:n},issueId:a,assigneeUsernames:o}=s,i=`mutation SetIssueAssignees($fullPath: ID!, $issueId: String!, $assigneeUsernames: [String!]!) {
923
991
  issueSetAssignees(input: { projectPath: $fullPath, iid: $issueId, assigneeUsernames: $assigneeUsernames }) {
924
992
  errors,
925
993
  issue {
926
994
  id
927
995
  }
928
996
  }
929
- }`,l=(p=(await I(this.config,{query:i,variables:{fullPath:`${r}/${n}`,issueId:o,assigneeUsernames:a}},e)).body.data)==null?void 0:p.issueSetAssignees;if(!((d=l==null?void 0:l.issue)!=null&&d.id)||((c=l==null?void 0:l.errors)==null?void 0:c.length)!==0)throw new Error("Could not set issue assignees")}async getMilestonesForRepo(s,e={}){var i,u,l,p,d,c,g;let{repo:{namespace:r,name:n},cursor:o}=s,a=await I(this.config,{query:`
997
+ }`,l=(p=(await y(this.config,{query:i,variables:{fullPath:`${r}/${n}`,issueId:a,assigneeUsernames:o}},e)).body.data)==null?void 0:p.issueSetAssignees;if(!((d=l==null?void 0:l.issue)!=null&&d.id)||((c=l==null?void 0:l.errors)==null?void 0:c.length)!==0)throw new Error("Could not set issue assignees")}async getMilestonesForRepo(s,e={}){var i,u,l,p,d,c,g;let{repo:{namespace:r,name:n},cursor:a}=s,o=await y(this.config,{query:`
930
998
  query getLabelsForRepo(
931
999
  $fullPath: ID!
932
1000
  $after: String
@@ -937,7 +1005,7 @@ query getLabelsForRepo(
937
1005
  webUrl
938
1006
  milestones(after: $after) {
939
1007
  nodes {
940
- ${Ge}
1008
+ ${je}
941
1009
  }
942
1010
  pageInfo {
943
1011
  endCursor
@@ -946,7 +1014,7 @@ query getLabelsForRepo(
946
1014
  }
947
1015
  }
948
1016
  }
949
- `,variables:{fullPath:`${r}/${n}`,after:o}},e);return{pageInfo:((l=(u=(i=a.body.data)==null?void 0:i.project)==null?void 0:u.milestones)==null?void 0:l.pageInfo)??{endCursor:null,hasNextPage:!1},data:((g=(c=(d=(p=a.body.data)==null?void 0:p.project)==null?void 0:d.milestones)==null?void 0:c.nodes)==null?void 0:g.map(m=>{var R,b;return xe(m,((b=(R=a.body.data)==null?void 0:R.project)==null?void 0:b.webUrl)||"")}))??[]}}async getLabelsForRepo(s,e={}){var i,u,l,p,d,c,g;let{repo:{namespace:r,name:n},cursor:o}=s,a=await I(this.config,{query:`
1017
+ `,variables:{fullPath:`${r}/${n}`,after:a}},e);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(R=>{var h,b;return Fe(R,((b=(h=o.body.data)==null?void 0:h.project)==null?void 0:b.webUrl)||"")}))??[]}}async getLabelsForRepo(s,e={}){var i,u,l,p,d,c,g;let{repo:{namespace:r,name:n},cursor:a}=s,o=await y(this.config,{query:`
950
1018
  query getLabelsForRepo(
951
1019
  $fullPath: ID!
952
1020
  $after: String
@@ -956,7 +1024,7 @@ query getLabelsForRepo(
956
1024
  ) {
957
1025
  labels(after: $after) {
958
1026
  nodes {
959
- ${Oe}
1027
+ ${Qe}
960
1028
  }
961
1029
  pageInfo {
962
1030
  endCursor
@@ -965,4 +1033,4 @@ query getLabelsForRepo(
965
1033
  }
966
1034
  }
967
1035
  }
968
- `,variables:{fullPath:`${r}/${n}`,after:o}},e);return{pageInfo:((l=(u=(i=a.body.data)==null?void 0:i.project)==null?void 0:u.labels)==null?void 0:l.pageInfo)??{endCursor:null,hasNextPage:!1},data:((g=(c=(d=(p=a.body.data)==null?void 0:p.project)==null?void 0:d.labels)==null?void 0:c.nodes)==null?void 0:g.map(Ae))??[]}}};var G="https://api.atlassian.com/ex/jira",se=100,jt=(t,s)=>{var r,n,o,a;let e=t.fields.assignee;return{id:t.id,commentCount:t.fields.comment.comments.length,number:t.key,title:t.fields.summary,url:s?`${s}/browse/${t.key}`:null,createdDate:new Date(t.fields.created),author:{id:t.fields.creator.accountId,name:t.fields.creator.displayName,email:t.fields.creator.emailAddress,avatarUrl:t.fields.creator.avatarUrls["32x32"],username:t.fields.creator.displayName},updatedDate:new Date(t.fields.updated),assignees:e?[{id:e.accountId,name:e.displayName,email:e.emailAddress,avatarUrl:e.avatarUrls["32x32"],username:e.displayName}]:[],description:null,repository:null,state:Mt(t.fields.status),statusTransitions:((r=t.transitions)==null?void 0:r.map(Qt))??[],components:((n=t.fields.components)==null?void 0:n.map(Bt))??[],type:t.fields.issuetype.name,upvoteCount:((o=t.fields.votes)==null?void 0:o.votes)||0,labels:((a=t.fields.labels)==null?void 0:a.map(i=>({color:null,description:null,id:null,name:i})))??[]}},Qt=t=>({name:t.name,id:t.id}),Bt=t=>({description:t.description??null,id:t.id,name:t.name}),Ft=t=>({id:t.accountId,name:t.displayName,email:t.emailAddress,avatarUrl:t.avatarUrls["48x48"],username:t.displayName}),Mt=t=>{let s;switch(t.statusCategory.name){case"To Do":s="TO_DO";break;case"In Progress":s="IN_PROGRESS";break;default:s="DONE";break}return{name:t.name,color:t.statusCategory.colorName,category:s}},W=class extends U{constructor(){super(...arguments);this._resourceUrlCache={}}async getResourceUrl(e,r={}){var a;let n=r.token||this.config.token;if(!n)return null;let o=this._resourceUrlCache[n];return o?o[e.resourceId]??null:(await this.getJiraResourcesForCurrentUser(r),((a=this._resourceUrlCache[n])==null?void 0:a[e.resourceId])??null)}async getCurrentUserForResource(e,r={}){let n=await this.config.request({url:`${r.baseUrl||G}/${e.resourceId}/rest/api/2/myself`,headers:h(r.token||this.config.token)});return{data:{name:n.body.displayName,email:n.body.emailAddress,avatarUrl:n.body.avatarUrls["48x48"],id:n.body.accountId,username:n.body.displayName}}}async getJiraResourcesForCurrentUser(e={}){let r=await this.config.request({url:`${e.baseUrl||"https://api.atlassian.com/"}/oauth/token/accessible-resources`,headers:h(e.token||this.config.token)}),n=e.token||this.config.token,o=n?this._resourceUrlCache[n]||{}:void 0,a=r.body.map(i=>(o&&(o[i.id]=i.url),{avatarUrl:i.avatarUrl,id:i.id,name:i.name,url:i.url}));return n&&(this._resourceUrlCache[n]=o),{data:a}}async getJiraProjectsForResource(e,r={}){let n=new URL(`${r.baseUrl||G}/${e.resourceId}/rest/api/2/project/search`);n.searchParams.set("maxResults",se.toString()),e.cursor&&n.searchParams.set("startAt",e.cursor);let o=await this.config.request({url:n.toString(),headers:h(r.token||this.config.token)});return{pageInfo:{hasNextPage:o.body.values.length!==0,endCursor:(o.body.startAt+o.body.values.length).toString()},data:o.body.values.map(a=>({id:a.id,key:a.key,name:a.name,resourceId:e.resourceId}))}}async getJiraProjectsForResources(e,r={}){let n=[];return await Promise.all(e.resourceIds.map(async o=>{let a=await this.getJiraProjectsForResource({resourceId:o},r);n.push(...a.data)})),{data:n}}async getAccountsForJiraProject(e,r={}){let{resourceId:n,projectKey:o,cursor:a}=e,i=new URL(`${r.baseUrl||G}/${n}/rest/api/2/user/assignable/search`);i.searchParams.set("maxResults",se.toString()),a&&i.searchParams.set("startAt",a),i.searchParams.set("project",o);let u=await this.config.request({url:i.toString(),headers:h(r.token||this.config.token)});return{pageInfo:{hasNextPage:u.body.length!==0,endCursor:((a?parseInt(a):0)+u.body.length).toString()},data:u.body.filter(l=>l.accountType!=="app"&&l.active).map(Ft)}}async getComponentsForJiraProject(e,r={}){let{resourceId:n,projectIdOrKey:o}=e,a=new URL(`${r.baseUrl||G}/${n}/rest/api/2/project/${o}/components`);return{data:(await this.config.request({url:a.toString(),headers:h(r.token||this.config.token)})).body}}async getIssuesForProject(e,r={}){let{assigneeLogins:n,authorLogin:o,mentionLogin:a,project:i}=e||{},u=[`project = "${i}"`,"statusCategory != Done"];o&&u.push(`creator in ("${o}")`),n&&n.length!==0&&u.push(`assignee in ("${n.join('", "')}")`),a&&u.push(`comment ~ "${a}"`);let l=await this.config.request({url:`${r.baseUrl||G}/${e.resourceId}/rest/api/2/search?jql=${u.join(" AND ")}&startAt=0&maxResults=${se}&fields=${["assignee","comment","summary","created","creator","updated","votes","issuetype","status","labels","components"].join(",")}&expand=transitions`,headers:h(r.token||this.config.token)}),p=await this.getResourceUrl({resourceId:e.resourceId},r);return{data:l.body.issues.map(d=>jt(d,p))}}async setIssueStatus(e,r={}){let{resourceId:n,issueId:o,status:a}=e,i={transition:{id:a}};await this.config.request({method:"POST",url:`${r.baseUrl||G}/${n}/rest/api/2/issue/${o}/transitions`,body:JSON.stringify(i),headers:{...h(r.token||this.config.token),"Content-Type":"application/json"}})}async setIssueAssignee(e,r={}){let{resourceId:n,issueId:o,assigneeId:a}=e,i={accountId:a};await this.config.request({method:"PUT",url:`${r.baseUrl||G}/${n}/rest/api/2/issue/${o}/assignee`,body:JSON.stringify(i),headers:{...h(r.token||this.config.token),"Content-Type":"application/json"}})}async setIssueComponents(e,r={}){let{resourceId:n,issueId:o,componentIds:a}=e,i={fields:{components:a.map(u=>({id:u}))}};await this.config.request({method:"PUT",url:`${r.baseUrl||G}/${n}/rest/api/2/issue/${o}`,body:JSON.stringify(i),headers:{...h(r.token||this.config.token),"Content-Type":"application/json"}})}async setIssueLabels(e,r={}){let{resourceId:n,issueId:o,labelNames:a}=e,i={fields:{labels:a}};if(!(await this.config.request({method:"PUT",url:`${r.baseUrl||G}/${n}/rest/api/2/issue/${o}?returnIssue=true`,body:JSON.stringify(i),headers:{...h(r.token||this.config.token),"Content-Type":"application/json"}})).body.id)throw new Error("Could not set issue labels")}async getLabelsForResource(e,r={}){let{resourceId:n,cursor:o}=e,a=new URL(`${r.baseUrl||G}/${n}/rest/api/2/label`);a.searchParams.set("maxResults",se.toString()),o&&a.searchParams.set("startAt",o);let i=await this.config.request({url:a.toString(),headers:h(r.token||this.config.token)});return{pageInfo:{hasNextPage:!i.body.isLast,endCursor:(i.body.startAt+i.body.values.length).toString()},data:i.body.values.map(u=>({color:null,description:null,id:null,name:u}))}}};var zt=100,Jt=t=>{var r,n,o,a,i,u,l,p,d;let s=t.fields.assignee,e=new URL(t.self);return{id:t.id,commentCount:((o=(n=(r=t.fields)==null?void 0:r.comment)==null?void 0:n.comments)==null?void 0:o.length)||0,number:t.key,title:t.fields.summary,url:`${e.origin}/browse/${t.key}`,createdDate:new Date(t.fields.created),author:{id:t.fields.creator.key,name:t.fields.creator.displayName,email:t.fields.creator.emailAddress,avatarUrl:t.fields.creator.avatarUrls["32x32"],username:t.fields.creator.displayName},updatedDate:new Date(t.fields.updated),assignees:s?[{id:s.key,name:s.displayName,email:s.emailAddress,avatarUrl:s.avatarUrls["32x32"],username:s.displayName}]:[],description:null,repository:null,state:{name:(a=t.fields.status)==null?void 0:a.name,color:(u=(i=t.fields.status)==null?void 0:i.statusCategory)==null?void 0:u.colorName},statusTransitions:((l=t.transitions)==null?void 0:l.map(Wt))??[],type:t.fields.issuetype.name,upvoteCount:((p=t.fields.votes)==null?void 0:p.votes)||0,labels:((d=t.fields.labels)==null?void 0:d.map(c=>({color:null,description:null,id:null,name:c})))??[]}},Wt=t=>({name:t.name,id:t.id}),H=class extends D{async getCurrentUser(s){let e=await this.config.request({url:`${(s==null?void 0:s.baseUrl)||this.config.baseUrl}/rest/api/2/myself`,headers:h((s==null?void 0:s.token)||this.config.token)});return{data:{name:e.body.displayName,email:e.body.emailAddress,avatarUrl:e.body.avatarUrls["48x48"],id:e.body.key,username:e.body.displayName}}}async getJiraProjects(s){return{data:(await this.config.request({url:`${(s==null?void 0:s.baseUrl)||this.config.baseUrl}/rest/api/2/project`,headers:h((s==null?void 0:s.token)||this.config.token)})).body.map(r=>({id:r.id,name:r.name}))}}async getIssuesForProject(s,e){let{assigneeLogins:r,authorLogin:n,mentionLogin:o,project:a}=s||{},i=[`project = "${a}"`];return n&&i.push(`creator in ("${n}")`),r&&r.length!==0&&i.push(`assignee in ("${r.join('", "')}")`),o&&i.push(`comment ~ "${o}"`),{data:(await this.config.request({url:`${(e==null?void 0:e.baseUrl)||this.config.baseUrl}/rest/api/2/search?jql=${i.join(" AND ")}&startAt=0&maxResults=${zt}&fields=${["assignee","comment","summary","created","creator","updated","votes","issuetype","status","labels"].join(",")}&expand=transitions`,headers:h((e==null?void 0:e.token)||this.config.token)})).body.issues.map(Jt)}}async setIssueStatus(s,e){let{issueId:r,status:n}=s,o={transition:{id:n}};try{await this.config.request({method:"POST",url:`${(e==null?void 0:e.baseUrl)||this.config.baseUrl}/rest/api/2/issue/${r}/transitions`,body:JSON.stringify(o),headers:{...h((e==null?void 0:e.token)||this.config.token),"Content-Type":"application/json"}})}catch(a){if(a.message=="Unexpected end of JSON input")return;throw new Error("Could not set issue status")}}async getLabels(s){return{data:(await this.config.request({url:`${(s==null?void 0:s.baseUrl)||this.config.baseUrl}/rest/api/2/jql/autocompletedata/suggestions?fieldName=labels`,headers:h(s.token||this.config.token)})).body.results.map(({displayName:r})=>({color:null,description:null,id:null,name:r}))}}};var A="https://api.trello.com",Ht=1e3,Vt=(t,s)=>{let e=new Date(1e3*parseInt(t.id.substring(0,8),16));return{id:t.id,commentCount:t.badges.comments,number:t.idShort.toString(),title:t.name,url:t.url,createdDate:new Date(e.toISOString()),author:null,updatedDate:new Date(t.dateLastActivity),assignees:t.idMembers.map(r=>({id:r,username:null,name:null,email:null,avatarUrl:null})),description:null,state:s[t.idList??""]?{name:s[t.idList].name,color:null}:null,type:null,repository:null,upvoteCount:t.badges.votes,labels:t.labels.map(r=>({color:r.color,description:null,id:r.id,name:r.name}))}},V=class extends U{async getCurrentUser(s,e={}){let r=await this.config.request({url:`${e.baseUrl||A}/1/members/me?key=${s.appKey}&token=${e.token||this.config.token}`,headers:h(e.token||this.config.token)});return{data:{name:r.body.fullName,email:r.body.email,avatarUrl:r.body.avatarHash?`https://trello-members.s3.amazonaws.com/${r.body.id}/${r.body.avatarHash}/50.png`:null,id:r.body.id,username:r.body.username}}}async getBoardsForCurrentUser(s,e={}){return{data:(await this.config.request({url:`${e.baseUrl||A}/1/members/me/boards?fields=name&key=${s.appKey}&token=${e.token||this.config.token}&filter=open`,headers:h(e.token||this.config.token)})).body.map(n=>({id:n.id,name:n.name}))}}async getListsForTrelloBoard(s,e={}){let{appKey:r,boardId:n}=s;return{data:(await this.config.request({url:`${e.baseUrl||A}/1/boards/${n}/lists?key=${r}&token=${e.token||this.config.token}`,headers:h(e.token||this.config.token)})).body}}async getAccountsForTrelloBoard(s,e={}){let{appKey:r,boardId:n}=s;return{data:(await this.config.request({url:`${e.baseUrl||A}/1/boards/${n}/members?key=${r}&token=${e.token||this.config.token}`,headers:h(e.token||this.config.token)})).body.map(a=>({id:a.id,name:a.fullName,username:a.username,email:null,avatarUrl:null}))}}async getIssuesForBoard(s,e={}){let r=["-is:archived","sort:edited"],{appKey:n,boardId:o,filterText:a,assigneeLogins:i,trelloBoardListsById:u}=s||{};i&&r.push("@me");let l=`${a?`${a}`:""}${r.join(" ")} board:${o}`;return{data:(await this.config.request({url:`${e.baseUrl||A}/1/search?key=${n}&query=${l}&cards_limit=${Ht}&token=${e.token||this.config.token}`,headers:h(e.token||this.config.token)})).body.cards.map(d=>Vt(d,u||{}))}}async updateIssue(s,e,r,n){return await this.config.request({method:"PUT",url:`${n.baseUrl||A}/1/cards/${e}?key=${s}&token=${n.token||this.config.token}&${r}`,headers:h(n.token||this.config.token)})}async setIssueStatus(s,e={}){let{appKey:r,cardId:n,status:o}=s,a=`idList=${o}`;if(!(await this.updateIssue(r,n,a,e)).body.id)throw new Error("Could not set issue status")}async setIssueAssignees(s,e={}){let{appKey:r,cardId:n,assigneeIds:o}=s,a=`idMembers=${encodeURIComponent(o.join(","))}`;if(!(await this.updateIssue(r,n,a,e)).body.id)throw new Error("Could not set issue status")}async setIssueLabels(s,e={}){let{appKey:r,cardId:n,labelIds:o}=s;if(!(await this.config.request({method:"PUT",url:`${e.baseUrl||A}/1/cards/${n}?key=${r}&token=${e.token||this.config.token}&idLabels=${encodeURIComponent(o.join(","))}`,headers:h(e.token||this.config.token)})).body.id)throw new Error("Could not set issue status")}async setIssueArchived(s,e={}){let{appKey:r,cardId:n,archived:o}=s;if(!(await this.config.request({method:"PUT",url:`${e.baseUrl||A}/1/cards/${n}?key=${r}&token=${e.token||this.config.token}&closed=${o}`,headers:h(e.token||this.config.token)})).body.id)throw new Error("Could not update issue archived status")}async getLabelsForBoard(s,e={}){let{appKey:r,boardId:n}=s;return{data:(await this.config.request({url:`${e.baseUrl||A}/1/boards/${n}/labels?key=${r}&token=${e.token||this.config.token}`,headers:h(e.token||this.config.token)})).body.map(a=>({color:a.color,description:null,id:a.id,name:a.name}))}}};var re={};x(re,{getIssueUniqueId:()=>Kt,getPullRequestUniqueId:()=>Xt});var Kt=(t,s,e,r="")=>{let n=[];return n.push(r),n.push(t),n.push(s),n.push(e),JSON.stringify(n)},Xt=(t,s,e,r,n="")=>{let o=[];return o.push(n),o.push(t),o.push(s),o.push(e),o.push(r),JSON.stringify(o)};var ne={};x(ne,{getIssueUniqueId:()=>Zt,getPullRequestUniqueId:()=>Yt});var Zt=(t,s)=>JSON.stringify(["",t,s]),Yt=(t,s)=>JSON.stringify(["",t,s]);var ae={};x(ae,{getIssueUniqueId:()=>es,getPullRequestUniqueId:()=>ts});var es=(t,s,e)=>JSON.stringify([e,t,s]),ts=(t,s,e)=>JSON.stringify([e,t,s]);var oe={};x(oe,{getIssueUniqueId:()=>ss,getPullRequestRank:()=>ns,getPullRequestUniqueId:()=>rs});var ss=(t,s="")=>{let e=[];return e.push(s),e.push(t),JSON.stringify(e)},rs=(t,s="")=>{let e=[];return e.push(s),e.push(t),JSON.stringify(e)},ns=(t,s,e)=>{var a,i,u;let r=0,n,o;return(a=t.reviews)==null||a.forEach(l=>{l.reviewer.id===s&&(n=l.state),l.state==="CHANGES_REQUESTED"?o="CHANGES_REQUESTED":l.state==="APPROVED"&&o!=="CHANGES_REQUESTED"&&(o="APPROVED")}),o||(o="REVIEW_REQUESTED"),((i=t.author)==null?void 0:i.id)===s?r+=1e3:(u=t.assignees)!=null&&u.find(l=>l.id===s)?r+=900:n==="REVIEW_REQUESTED"?r+=800:e&&(r+=700),o==="APPROVED"?t.mergeableState==="MERGEABLE"?r+=100:t.mergeableState==="CONFLICTS"?r+=90:r+=80:o=="CHANGES_REQUESTED"&&(r+=70),r};var ie={};x(ie,{getIssueUniqueId:()=>as,getPullRequestUniqueId:()=>os});var as=(t,s="")=>{let e=[];return e.push(s),e.push(t),JSON.stringify(e)},os=(t,s="")=>{let e=[];return e.push(s),e.push(t),JSON.stringify(e)};var ue={};x(ue,{getIssueUniqueId:()=>is,getJiraServerIssueUniqueId:()=>us});var is=(t,s,e)=>{let r=[];return r.push(""),r.push(t),r.push(s),r.push(e),JSON.stringify(r)},us=(t,s,e)=>{let r=[];return r.push(e),r.push(""),r.push(t),r.push(s),JSON.stringify(r)};var le={};x(le,{getIssueUniqueId:()=>ls});var ls=(t,s,e,r="")=>{let n=[];return n.push(r),n.push(t),n.push(s),n.push(e),JSON.stringify(n)};var ps=t=>{let s={request:t==null?void 0:t.request};return{azureDevOps:new Q({...s,...t==null?void 0:t.azureDevOps}),bitbucket:new B({...s,...t==null?void 0:t.bitbucket}),bitbucketServer:new F({...s,...t==null?void 0:t.bitbucketServer}),github:new M({...s,...t==null?void 0:t.github}),gitlab:new J({...s,...t==null?void 0:t.gitlab}),jira:new W({...s,...t==null?void 0:t.jira}),jiraServer:new H({...s,...t==null?void 0:t.jiraServer}),trello:new V({...s,...t==null?void 0:t.trello})}},ds=ps;var cs={azureDevOps:re,bitbucket:ne,bitbucketServer:ae,github:oe,gitlab:ie,jira:ue,trello:le};
1036
+ `,variables:{fullPath:`${r}/${n}`,after:a}},e);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(Be))??[]}}};var ts="https://api.atlassian.com/ex/jira",ss=100,rs=(t,s,e)=>{var n,a,o,i;let r=t.fields.assignee;return{id:t.id,commentCount:t.fields.comment.comments.length,number:t.key,title:t.fields.summary,url:s?`${s}/browse/${t.key}`:null,closedDate:null,createdDate:new Date(t.fields.created),author:ae(t.fields.creator,s,e),updatedDate:new Date(t.fields.updated),assignees:r?[ae(r,s,e)]:[],description:null,repository:null,state:is(t.fields.status),statusTransitions:((n=t.transitions)==null?void 0:n.map(ns))??[],components:((a=t.fields.components)==null?void 0:a.map(os))??[],type:t.fields.issuetype.name,upvoteCount:((o=t.fields.votes)==null?void 0:o.votes)||0,labels:((i=t.fields.labels)==null?void 0:i.map(u=>({color:null,description:null,id:null,name:u})))??[]}},ns=t=>({name:t.name,id:t.id}),os=t=>({description:t.description??null,id:t.id,name:t.name}),as=(t,s,e)=>e&&t.name?`${s}/secure/ViewProfile.jspa?name=${encodeURIComponent(t.name)}`:`${s}/jira/people/${t.accountId}`,ae=(t,s,e)=>({id:(e?t.key:t.accountId)??"",name:t.displayName,email:t.emailAddress,avatarUrl:t.avatarUrls["48x48"],username:t.displayName,url:as(t,s,e)}),is=t=>{let s;switch(t.statusCategory.name){case"To Do":s="TO_DO";break;case"In Progress":s="IN_PROGRESS";break;default:s="DONE";break}return{name:t.name,color:t.statusCategory.colorName,category:s}},H=(t,s,e)=>e?`${s.baseUrl||ts}/${e}`:`${(s==null?void 0:s.baseUrl)||t.baseUrl}`,ie=async(t,s,e,r={})=>{let{assigneeLogins:n,authorLogin:a,mentionLogin:o,project:i,resourceId:u}=s||{},l=[`project = "${i}"`,"statusCategory != Done"];return a&&l.push(`creator in ("${a}")`),n&&n.length!==0&&l.push(`assignee in ("${n.join('", "')}")`),o&&l.push(`comment ~ "${o}"`),{data:(await t.request({url:`${H(t,r,u)}/rest/api/2/search?jql=${l.join(" AND ")}&startAt=0&maxResults=${ss}&fields=${["assignee","comment","summary","created","creator","updated","votes","issuetype","status","labels","components"].join(",")}&expand=transitions`,headers:m(r.token||t.token)})).body.issues.map(d=>rs(d,e,!u))}},ue=async(t,s,e={})=>{let{resourceId:r,issueId:n,labelNames:a}=s,o={fields:{labels:a}};await t.request({method:"PUT",url:`${H(t,e,r)}/rest/api/2/issue/${n}`,body:JSON.stringify(o),headers:{...m(e.token||t.token),"Content-Type":"application/json"}})},le=async(t,s,e={})=>{let{resourceId:r,issueId:n,componentIds:a}=s,o={fields:{components:a.map(i=>({id:i}))}};await t.request({method:"PUT",url:`${H(t,e,r)}/rest/api/2/issue/${n}`,body:JSON.stringify(o),headers:{...m(e.token||t.token),"Content-Type":"application/json"}})},pe=async(t,s,e={})=>{let{resourceId:r,issueId:n,status:a}=s,o={transition:{id:a}};await t.request({method:"POST",url:`${H(t,e,r)}/rest/api/2/issue/${n}/transitions`,body:JSON.stringify(o),headers:{...m(e.token||t.token),"Content-Type":"application/json"}})},de=async(t,s,e={})=>{let{resourceId:r,projectIdOrKey:n}=s,a=new URL(`${H(t,e,r)}/rest/api/2/project/${n}/components`);return{data:(await t.request({url:a.toString(),headers:m(e.token||t.token)})).body}};var J="https://api.atlassian.com/ex/jira",Me=100,K=class extends E{constructor(){super(...arguments);this._resourceUrlCache={}}async getResourceUrl(e,r={}){var o;let n=r.token||this.config.token;if(!n)return null;let a=this._resourceUrlCache[n];return a?a[e.resourceId]??null:(await this.getJiraResourcesForCurrentUser(r),((o=this._resourceUrlCache[n])==null?void 0:o[e.resourceId])??null)}async getCurrentUserForResource(e,r={}){let n=await this.getResourceUrl({resourceId:e.resourceId},r),a=await this.config.request({url:`${r.baseUrl||J}/${e.resourceId}/rest/api/2/myself`,headers:m(r.token||this.config.token)});return{data:{name:a.body.displayName,email:a.body.emailAddress,avatarUrl:a.body.avatarUrls["48x48"],id:a.body.accountId,username:a.body.displayName,url:n?`${n}/jira/people/${a.body.accountId}`:null}}}async getJiraResourcesForCurrentUser(e={}){let r=await this.config.request({url:`${e.baseUrl||"https://api.atlassian.com/"}/oauth/token/accessible-resources`,headers:m(e.token||this.config.token)}),n=e.token||this.config.token,a=n?this._resourceUrlCache[n]||{}:void 0,o=r.body.map(i=>(a&&(a[i.id]=i.url),{avatarUrl:i.avatarUrl,id:i.id,name:i.name,url:i.url}));return n&&(this._resourceUrlCache[n]=a),{data:o}}async getJiraProjectsForResource(e,r={}){let n=new URL(`${r.baseUrl||J}/${e.resourceId}/rest/api/2/project/search`);n.searchParams.set("maxResults",Me.toString()),e.cursor&&n.searchParams.set("startAt",e.cursor);let a=await this.config.request({url:n.toString(),headers:m(r.token||this.config.token)});return{pageInfo:{hasNextPage:a.body.values.length!==0,endCursor:(a.body.startAt+a.body.values.length).toString()},data:a.body.values.map(o=>({id:o.id,key:o.key,name:o.name,resourceId:e.resourceId}))}}async getJiraProjectsForResources(e,r={}){let n=[];return await Promise.all(e.resourceIds.map(async a=>{let o=await this.getJiraProjectsForResource({resourceId:a},r);n.push(...o.data)})),{data:n}}async getAccountsForJiraProject(e,r={}){let{resourceId:n,projectKey:a,cursor:o}=e,i=await this.getResourceUrl({resourceId:n},r),u=new URL(`${r.baseUrl||J}/${n}/rest/api/2/user/assignable/search`);u.searchParams.set("maxResults",Me.toString()),o&&u.searchParams.set("startAt",o),u.searchParams.set("project",a);let l=await this.config.request({url:u.toString(),headers:m(r.token||this.config.token)});return{pageInfo:{hasNextPage:l.body.length!==0,endCursor:((o?parseInt(o):0)+l.body.length).toString()},data:l.body.filter(p=>p.accountType!=="app"&&p.active).map(p=>ae(p,i,!1))}}async getComponentsForJiraProject(e,r={}){return await de(this.config,e,r)}async getIssuesForProject(e,r={}){let n=await this.getResourceUrl({resourceId:e.resourceId},r);return await ie(this.config,e,n,r)}async setIssueStatus(e,r={}){await pe(this.config,e,r)}async setIssueAssignee(e,r={}){let{resourceId:n,issueId:a,assigneeId:o}=e,i={accountId:o};await this.config.request({method:"PUT",url:`${r.baseUrl||J}/${n}/rest/api/2/issue/${a}/assignee`,body:JSON.stringify(i),headers:{...m(r.token||this.config.token),"Content-Type":"application/json"}})}async setIssueComponents(e,r={}){await le(this.config,e,r)}async setIssueLabels(e,r={}){await ue(this.config,e,r)}async getLabelsForResource(e,r={}){let{resourceId:n,cursor:a}=e,o=new URL(`${r.baseUrl||J}/${n}/rest/api/2/label`);o.searchParams.set("maxResults",Me.toString()),a&&o.searchParams.set("startAt",a);let i=await this.config.request({url:o.toString(),headers:m(r.token||this.config.token)});return{pageInfo:{hasNextPage:!i.body.isLast,endCursor:(i.body.startAt+i.body.values.length).toString()},data:i.body.values.map(u=>({color:null,description:null,id:null,name:u}))}}};var V=class extends v{async getCurrentUser(s={}){let e=await this.config.request({url:`${(s==null?void 0:s.baseUrl)||this.config.baseUrl}/rest/api/2/myself`,headers:m((s==null?void 0:s.token)||this.config.token)});return{data:{name:e.body.displayName,email:e.body.emailAddress,avatarUrl:e.body.avatarUrls["48x48"],id:e.body.key,username:e.body.displayName,url:null}}}async getJiraProjects(s={}){return{data:(await this.config.request({url:`${(s==null?void 0:s.baseUrl)||this.config.baseUrl}/rest/api/2/project`,headers:m((s==null?void 0:s.token)||this.config.token)})).body.map(r=>({id:r.id,name:r.name}))}}async getIssuesForProject(s,e={}){if(!e.baseUrl)throw new Error('Jira Server requires a "baseUrl" for this function.');return await ie(this.config,s,e.baseUrl,e)}async setIssueStatus(s,e={}){await pe(this.config,s,e)}async setIssueLabels(s,e={}){await ue(this.config,s,e)}async setIssueComponents(s,e={}){await le(this.config,s,e)}async getLabels(s={}){return{data:(await this.config.request({url:`${(s==null?void 0:s.baseUrl)||this.config.baseUrl}/rest/api/2/jql/autocompletedata/suggestions?fieldName=labels`,headers:m(s.token||this.config.token)})).body.results.map(({displayName:r})=>({color:null,description:null,id:null,name:r}))}}async getComponentsForJiraProject(s,e={}){return await de(this.config,s,e)}};var A="https://api.trello.com",us=1e3,ls=(t,s)=>{let e=new Date(1e3*parseInt(t.id.substring(0,8),16));return{id:t.id,commentCount:t.badges.comments,number:t.idShort.toString(),title:t.name,url:t.url,closedDate:null,createdDate:new Date(e.toISOString()),author:null,updatedDate:new Date(t.dateLastActivity),assignees:t.idMembers.map(r=>({id:r,username:null,name:null,email:null,avatarUrl:null,url:null})),description:null,state:s[t.idList??""]?{name:s[t.idList].name,color:null}:null,type:null,repository:null,upvoteCount:t.badges.votes,labels:t.labels.map(r=>({color:r.color,description:null,id:r.id,name:r.name}))}},X=class extends E{async getCurrentUser(s,e={}){let r=await this.config.request({url:`${e.baseUrl||A}/1/members/me?key=${s.appKey}&token=${e.token||this.config.token}`,headers:m(e.token||this.config.token)});return{data:{name:r.body.fullName,email:r.body.email,avatarUrl:r.body.avatarHash?`https://trello-members.s3.amazonaws.com/${r.body.id}/${r.body.avatarHash}/50.png`:null,id:r.body.id,username:r.body.username,url:r.body.url}}}async getBoardsForCurrentUser(s,e={}){return{data:(await this.config.request({url:`${e.baseUrl||A}/1/members/me/boards?fields=name&key=${s.appKey}&token=${e.token||this.config.token}&filter=open`,headers:m(e.token||this.config.token)})).body.map(n=>({id:n.id,name:n.name}))}}async getListsForTrelloBoard(s,e={}){let{appKey:r,boardId:n}=s;return{data:(await this.config.request({url:`${e.baseUrl||A}/1/boards/${n}/lists?key=${r}&token=${e.token||this.config.token}`,headers:m(e.token||this.config.token)})).body}}async getAccountsForTrelloBoard(s,e={}){let{appKey:r,boardId:n}=s;return{data:(await this.config.request({url:`${e.baseUrl||A}/1/boards/${n}/members?key=${r}&token=${e.token||this.config.token}`,headers:m(e.token||this.config.token)})).body.map(o=>({id:o.id,name:o.fullName,username:o.username,email:null,avatarUrl:null,url:null}))}}async getIssuesForBoard(s,e={}){let r=["-is:archived","sort:edited"],{appKey:n,boardId:a,filterText:o,assigneeLogins:i,trelloBoardListsById:u}=s||{};i&&r.push("@me");let l=`${o?`${o}`:""}${r.join(" ")} board:${a}`;return{data:(await this.config.request({url:`${e.baseUrl||A}/1/search?key=${n}&query=${l}&cards_limit=${us}&token=${e.token||this.config.token}`,headers:m(e.token||this.config.token)})).body.cards.map(d=>ls(d,u||{}))}}async updateIssue(s,e,r,n){return await this.config.request({method:"PUT",url:`${n.baseUrl||A}/1/cards/${e}?key=${s}&token=${n.token||this.config.token}&${r}`,headers:m(n.token||this.config.token)})}async setIssueStatus(s,e={}){let{appKey:r,cardId:n,status:a}=s,o=`idList=${a}`;if(!(await this.updateIssue(r,n,o,e)).body.id)throw new Error("Could not set issue status")}async setIssueAssignees(s,e={}){let{appKey:r,cardId:n,assigneeIds:a}=s,o=`idMembers=${encodeURIComponent(a.join(","))}`;if(!(await this.updateIssue(r,n,o,e)).body.id)throw new Error("Could not set issue status")}async setIssueLabels(s,e={}){let{appKey:r,cardId:n,labelIds:a}=s;if(!(await this.config.request({method:"PUT",url:`${e.baseUrl||A}/1/cards/${n}?key=${r}&token=${e.token||this.config.token}&idLabels=${encodeURIComponent(a.join(","))}`,headers:m(e.token||this.config.token)})).body.id)throw new Error("Could not set issue status")}async setIssueArchived(s,e={}){let{appKey:r,cardId:n,archived:a}=s;if(!(await this.config.request({method:"PUT",url:`${e.baseUrl||A}/1/cards/${n}?key=${r}&token=${e.token||this.config.token}&closed=${a}`,headers:m(e.token||this.config.token)})).body.id)throw new Error("Could not update issue archived status")}async getLabelsForBoard(s,e={}){let{appKey:r,boardId:n}=s;return{data:(await this.config.request({url:`${e.baseUrl||A}/1/boards/${n}/labels?key=${r}&token=${e.token||this.config.token}`,headers:m(e.token||this.config.token)})).body.map(o=>({color:o.color,description:null,id:o.id,name:o.name}))}}};var ce={};T(ce,{getIssueUniqueId:()=>ps,getPullRequestUniqueId:()=>ds});var ps=(t,s,e,r="")=>{let n=[];return n.push(r),n.push(t),n.push(s),n.push(e),JSON.stringify(n)},ds=(t,s,e,r,n="")=>{let a=[];return a.push(n),a.push(t),a.push(s),a.push(e),a.push(r),JSON.stringify(a)};var ge={};T(ge,{getIssueUniqueId:()=>cs,getPullRequestUniqueId:()=>gs});var cs=(t,s)=>JSON.stringify(["",t,s]),gs=(t,s)=>JSON.stringify(["",t,s]);var me={};T(me,{getIssueUniqueId:()=>ms,getPullRequestUniqueId:()=>hs});var ms=(t,s,e)=>JSON.stringify([e,t,s]),hs=(t,s,e)=>JSON.stringify([e,t,s]);var he={};T(he,{getIssueUniqueId:()=>fs,getPullRequestRank:()=>Is,getPullRequestUniqueId:()=>Rs});var fs=(t,s="")=>{let e=[];return e.push(s),e.push(t),JSON.stringify(e)},Rs=(t,s="")=>{let e=[];return e.push(s),e.push(t),JSON.stringify(e)},Is=(t,s,e)=>{var o,i,u;let r=0,n,a;return(o=t.reviews)==null||o.forEach(l=>{l.reviewer.id===s&&(n=l.state),l.state==="CHANGES_REQUESTED"?a="CHANGES_REQUESTED":l.state==="APPROVED"&&a!=="CHANGES_REQUESTED"&&(a="APPROVED")}),a||(a="REVIEW_REQUESTED"),((i=t.author)==null?void 0:i.id)===s?r+=1e3:(u=t.assignees)!=null&&u.find(l=>l.id===s)?r+=900:n==="REVIEW_REQUESTED"?r+=800:e&&(r+=700),a==="APPROVED"?t.mergeableState==="MERGEABLE"?r+=100:t.mergeableState==="CONFLICTS"?r+=90:r+=80:a=="CHANGES_REQUESTED"&&(r+=70),r};var fe={};T(fe,{getIssueUniqueId:()=>bs,getPullRequestUniqueId:()=>ys});var bs=(t,s="")=>{let e=[];return e.push(s),e.push(t),JSON.stringify(e)},ys=(t,s="")=>{let e=[];return e.push(s),e.push(t),JSON.stringify(e)};var Re={};T(Re,{getIssueUniqueId:()=>Ps,getJiraServerIssueUniqueId:()=>ws});var Ps=(t,s,e)=>{let r=[];return r.push(""),r.push(t),r.push(s),r.push(e),JSON.stringify(r)},ws=(t,s,e)=>{let r=[];return r.push(e),r.push(""),r.push(t),r.push(s),JSON.stringify(r)};var Ie={};T(Ie,{getIssueUniqueId:()=>qs});var qs=(t,s,e,r="")=>{let n=[];return n.push(r),n.push(t),n.push(s),n.push(e),JSON.stringify(n)};var Cs=t=>{let s={request:t==null?void 0:t.request};return{azureDevOps:new j({...s,...t==null?void 0:t.azureDevOps}),bitbucket:new Q({...s,...t==null?void 0:t.bitbucket}),bitbucketServer:new B({...s,...t==null?void 0:t.bitbucketServer}),github:new F({...s,...t==null?void 0:t.github}),gitlab:new W({...s,...t==null?void 0:t.gitlab}),jira:new K({...s,...t==null?void 0:t.jira}),jiraServer:new V({...s,...t==null?void 0:t.jiraServer}),trello:new X({...s,...t==null?void 0:t.trello})}},Ds=Cs;var Ss={azureDevOps:ce,bitbucket:ge,bitbucketServer:me,github:he,gitlab:fe,jira:Re,trello:Ie};