@gitkraken/provider-apis 0.44.0 → 0.45.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,5 @@
1
- "use strict";var Ve=Object.defineProperty;var Tr=Object.getOwnPropertyDescriptor;var Or=Object.getOwnPropertyNames;var xr=Object.prototype.hasOwnProperty;var kr=(r,n)=>{for(var e in n)Ve(r,e,{get:n[e],enumerable:!0})},Nr=(r,n,e,t)=>{if(n&&typeof n=="object"||typeof n=="function")for(let s of Or(n))!xr.call(r,s)&&s!==e&&Ve(r,s,{get:()=>n[s],enumerable:!(t=Tr(n,s))||t.enumerable});return r};var _r=r=>Nr(Ve({},"__esModule",{value:!0}),r);var gn={};kr(gn,{AzureDevOps:()=>se,Bitbucket:()=>ne,BitbucketServer:()=>oe,EntityIdentifierProviderType:()=>Dr,EntityType:()=>Cr,EntityVersion:()=>Er,GitBuildStatusStage:()=>At,GitBuildStatusState:()=>Re,GitDiffLineType:()=>Ke,GitHub:()=>ie,GitHubIssueCloseReason:()=>Lr,GitIssueState:()=>ve,GitLab:()=>ue,GitMergeStrategy:()=>te,GitPullRequestMergeableState:()=>Z,GitPullRequestReviewState:()=>H,GitPullRequestState:()=>X,GraphQLErrors:()=>h,Jira:()=>le,JiraServer:()=>pe,PullRequestAsyncStatus:()=>qr,Trello:()=>de,default:()=>cn,isFetch:()=>Ie});module.exports=_r(gn);var _t=require("diff");var At=(s=>(s.Build="build",s.Production="production",s.Staging="staging",s.Test="test",s))(At||{}),Re=(d=>(d.ActionRequired="ACTION_REQUIRED",d.Cancelled="CANCELLED",d.Error="ERROR",d.Failed="FAILED",d.Pending="PENDING",d.Running="RUNNING",d.Skipped="SKIPPED",d.Success="SUCCESS",d.Warning="WARNING",d.OptionalActionRequired="OPTIONAL_ACTION_REQUIRED",d))(Re||{}),te=(o=>(o.MergeCommit="MERGE_COMMIT",o.Rebase="REBASE",o.RebaseThenMergeCommit="REBASE_THEN_MERGE_COMMIT",o.FastForward="FAST_FORWARD",o.Squash="SQUASH",o))(te||{}),X=(t=>(t.Open="OPEN",t.Closed="CLOSED",t.Merged="MERGED",t))(X||{}),H=(s=>(s.Approved="APPROVED",s.ChangesRequested="CHANGES_REQUESTED",s.Commented="COMMENTED",s.ReviewRequested="REVIEW_REQUESTED",s))(H||{}),Z=(u=>(u.Behind="BEHIND",u.Blocked="BLOCKED",u.Conflicts="CONFLICTS",u.FailingChecks="FAILING_CHECKS",u.Mergeable="MERGEABLE",u.Unknown="UNKNOWN",u.UnknownAndBlocked="UNKNOWN_AND_BLOCKED",u.Unstable="UNSTABLE",u))(Z||{}),Ke=(t=>(t.ADDED="ADDED",t.DELETED="DELETED",t.UNMODIFIED="UNMODIFIED",t))(Ke||{});var Gt={APPROVED:0,COMMENTED:1,REVIEW_REQUESTED:2,CHANGES_REQUESTED:3},N=r=>!r||r.length===0?null:r.reduce((n,e)=>Gt[e.state]>Gt[n]?e.state:n,"APPROVED");var E=100;var Tt=globalThis.fetch;var Fr=async r=>{let n=r.headers.get("content-type")||"",e=null;if(n.startsWith("application/json")){let o=await r.text();e=o.trim().length>0?JSON.parse(o):null}else if(n.startsWith("text/")||n==="")e=await r.text();else if(n.startsWith("application/vnd.github.raw+json")||n.startsWith("application/octet-stream"))e=await r.arrayBuffer();else throw new Error(`Unsupported content-type: ${n}`);let t={};r.headers.forEach((o,i)=>{t[i]=o});let s={body:e,headers:t,status:r.status,statusText:r.statusText};if(!r.ok){let o=new Error(r.statusText);throw Object.assign(o,{response:s}),o}return s},Xe=r=>async({url:n,...e})=>{let t=await r(n,e);return Fr(t)};var Ie=(r,n=!1)=>r.name==="fetch"||n;var T=class{constructor(n){let e=n?.request||Tt;this.config={...n,request:Ie(e,n?.forceIsFetch)?Xe(e):e}}updateConfig(n){this.config={...this.config,...n,request:n.request&&Ie(n.request,n?.forceIsFetch??this.config.forceIsFetch)?Xe(n.request):this.config.request}}},A=class extends T{};var I=(r,n)=>{let e={};return r&&(e.Authorization=`${n?"Basic":"Bearer"} ${r}`),e},Ot=r=>r?r.reduce((n,e)=>(n[e]=!0,n),{}):void 0,W=(r,n,e)=>!r||n.some(t=>r[t])?e:"",xt=async r=>{let n=[],e=!0,t;for(;e;){let s=await r(t);n=n.concat(s.data),e=!!s?.pageInfo?.hasNextPage,t=s?.pageInfo?.endCursor||s?.pageInfo?.nextPage}return n};async function Ze(r){return(await Promise.allSettled(r)).map(e=>Qr(e)).filter(e=>e!=null)}function Qr(r,n=void 0){return r?.status==="fulfilled"?r.value:n}var jr="https://app.vssps.visualstudio.com/_apis",Br="https://vssps.dev.azure.com/",Mr="https://dev.azure.com",y=(r,n={})=>I(n.token||r.token,n.isPAT||r.isPAT),kt=r=>r.url.replace("/_apis/git/repositories/","/_git/").replace(`/${r.repository.project.id}/`,`/${encodeURIComponent(r.repository.project.name)}/`).replace(`/${r.repository.id}/`,`/${encodeURIComponent(r.repository.name)}/`).replace("/pullRequests/","/pullrequest/"),Ye=(r,n)=>{let e=n.baseUrl||r.baseUrl||jr;return e=e.replace(/\/$/,""),e},v=(r,n)=>{let e=n.baseUrl||r.baseUrl||Mr;return e=e.replace(/\/$/,""),e},et=(r,n)=>{let e=n.baseUrl||r.baseUrl||Br;return e=e.replace(/\/$/,""),e};var zr={active:"OPEN",completed:"MERGED",abandoned:"CLOSED"},Hr=new Set([2,3,4,5]),Wr={10:"APPROVED",5:"APPROVED",0:"REVIEW_REQUESTED",[-5]:"CHANGES_REQUESTED",[-10]:"CHANGES_REQUESTED"},re=r=>({id:r.id,name:r.displayName??null,username:(r.uniqueName||r.displayName)??null,email:null,avatarUrl:r.imageUrl??null,url:null}),be=r=>r.startsWith("refs/heads/")?r.replace("refs/heads/",""):r,Jr=r=>{switch(r){case"conflicts":return"CONFLICTS";case"failure":return"FAILING_CHECKS";case"rejectedByPolicy":return"BLOCKED";case"succeeded":return"MERGEABLE";case"notSet":case"queued":default:return"UNKNOWN"}},ce=(r,n)=>{let e=[],t=[];return n.reviewers.forEach(s=>{let o={reviewer:re(s),state:Wr[s.vote??0]||"REVIEW_REQUESTED"};s.isRequired&&e.push(o),t.push(o)}),{id:n.pullRequestId.toString(),title:n.title,description:n.description??null,number:n.codeReviewId,state:zr[n.status],isDraft:n.isDraft,commentCount:null,upvoteCount:null,author:re(n.createdBy),createdDate:new Date(n.creationDate),updatedDate:new Date(n.closedDate||n.creationDate),closedDate:n.closedDate?new Date(n.closedDate):null,mergedDate:n.closedDate&&n.status==="completed"?new Date(n.closedDate):null,repository:{id:n.repository.id,name:n.repository.name,project:n.repository.project.name,owner:{login:r},remoteInfo:null},headCommit:{buildStatuses:null},baseRef:{name:be(n.targetRefName),oid:n.lastMergeTargetCommit.commitId},headRef:{name:be(n.sourceRefName),oid:n.lastMergeSourceCommit.commitId},url:kt(n),assignees:n.reviewers.map(re),reviews:t,reviewDecision:N(e),additions:null,deletions:null,fileCount:null,commitCount:null,headRepository:n.forkSource?{id:n.forkSource.repository.id,name:n.forkSource.repository.name,project:void 0,owner:{login:r},remoteInfo:null}:{id:n.repository.id,name:n.repository.name,project:n.repository.project.name,owner:{login:r},remoteInfo:null},mergeableState:Jr(n.mergeStatus),labels:n.labels?.map(s=>({color:null,description:null,id:s.id,name:s.name}))??[],permissions:null}},Nt=(r,n)=>({id:n.id,name:n.name,namespace:r,project:n.project.name,projectId:n.project.id,webUrl:n.webUrl,httpsUrl:n.remoteUrl,sshUrl:n.sshUrl,defaultBranch:n.defaultBranch?{name:be(n.defaultBranch)}:null,permissions:null}),Vr=(r,n,e,t)=>{let s=e.fields,o=s["System.AssignedTo"],i=s["System.State"],a=s["System.WorkItemType"],u;return i&&a&&(u=t[a]?.[i]),{id:e.id.toString(),number:e.id.toString(),title:s["System.Title"],commentCount:s["System.CommentCount"],author:{avatarUrl:s["System.CreatedBy"]._links?.avatar?.href??null,email:null,id:s["System.CreatedBy"].id,name:s["System.CreatedBy"].uniqueName??null,username:s["System.CreatedBy"].displayName??null,url:null},closedDate:s["Microsoft.VSTS.Common.ClosedDate"]?new Date(s["Microsoft.VSTS.Common.ClosedDate"]):null,createdDate:new Date(s["System.CreatedDate"]),updatedDate:new Date(s["System.ChangedDate"]),url:e._links.html.href,assignees:o?[{avatarUrl:o._links?.avatar?.href??null,email:null,id:o.id,name:o.uniqueName??null,username:o.displayName??null,url:null}]:[],description:s["System.Description"]??null,state:{name:u?.title||i,color:null},type:s["System.WorkItemType"],repository:null,project:{namespace:r,name:n,resourceId:null,key:null,id:null},upvoteCount:0,labels:e.fields["System.Tags"]?.split(";").map(p=>({color:null,description:null,id:null,name:p.trim()}))??[]}},se=class extends A{constructor(){super(...arguments);this.cachedUserIds=new Map;this.inflightUserIds=new Map}getCurrentUserId(e,t){let s=JSON.stringify([e,t.token??null,t.isPAT??this.config.isPAT??!1,t.baseUrl??null]),o=this.cachedUserIds.get(s);if(o)return Promise.resolve(o);let i=this.inflightUserIds.get(s);if(i)return i;let a=this.fetchCurrentUserId(e,t,s);return this.inflightUserIds.set(s,a),a}async fetchCurrentUserId(e,t,s){try{let o=await this.getCurrentUserForInstance({namespace:e},t);return this.cachedUserIds.set(s,o.data.id),o.data.id}finally{this.inflightUserIds.delete(s)}}getRepoApiUrl(e,t,s,o){return`${v(this.config,o)}/${encodeURIComponent(e)}/${encodeURIComponent(t)}/_apis/git/repositories/${encodeURIComponent(s)}`}async getCurrentUser(e={},t={}){if(t.isPAT||this.config.isPAT)throw new Error("Azure DevOps does not support PATs for this function.");let s=`${Ye(this.config,t)}/profile/profiles/me`,o=await this.config.request({url:s,headers:y(this.config,t)});return{data:{id:o.body.id,name:o.body.displayName,username:o.body.displayName,email:o.body.emailAddress,avatarUrl:null,url:null}}}async getCurrentUserForInstance(e,t={}){let o=(await this.config.request({url:`${v(this.config,t)}/${encodeURIComponent(e.namespace)}/_apis/ConnectionData`,headers:y(this.config,t)})).body.authorizedUser;if(o.providerDisplayName==="Anonymous")throw new Error("Current user not found.");return{data:{id:o.id,name:o.providerDisplayName,username:o.providerDisplayName,email:o.properties.Account.$value,avatarUrl:null,url:null}}}async getUserForCommit(e,t={}){if(!e.repo.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let o=(await this.config.request({url:`${v(this.config,t)}/${encodeURIComponent(e.repo.namespace)}/${encodeURIComponent(e.repo.project)}/_apis/git/repositories/${encodeURIComponent(e.repo.name)}/commits/${e.oid}`,headers:y(this.config,t)})).body.author;return{data:{name:o.name,email:o.email,avatarUrl:o.imageUrl}}}async getOrgsForUser(e,t={}){let s=`${Ye(this.config,t)}/accounts?memberId=${e.userId}&api-version=6.0`;return{data:(await this.config.request({url:s,headers:y(this.config,t)})).body.value.map(i=>({id:i.accountId,name:i.accountName}))}}async getCollectionsForUser(e,t={}){let s=`${v(this.config,t)}/_apis/projectCollections`;return{data:(await this.config.request({url:s,headers:y(this.config,t)})).body.value.map(i=>({id:i.id,name:i.name}))}}async getAzureProjects(e,t={}){let s=new URL(`${v(this.config,t)}/${encodeURIComponent(e.namespace)}/_apis/projects`);s.searchParams.set("$top",E.toString()),e.cursor&&s.searchParams.set("$skip",e.cursor);let o=await this.config.request({url:s.toString(),headers:y(this.config,t)}),i=o.headers["x-ms-continuationtoken"];return{pageInfo:{hasNextPage:!!i,endCursor:i||null},data:o.body.value.map(a=>({id:a.id,name:a.name,namespace:e.namespace}))}}async getAzureProjectScopeDescriptor(e,t={}){let{namespace:s,projectId:o}=e;return{data:{scope:(await this.config.request({url:`${et(this.config,t)}/${encodeURIComponent(s)}/_apis/graph/descriptors/${o}?api-version=6.0`,headers:y(this.config,t)})).body.value}}}async getAzureGraphAccountsForAzureProject(e,t={}){let{namespace:s,projectScopeDescriptor:o,cursor:i}=e,a=new URL(`${et(this.config,t)}/${encodeURIComponent(s)}/_apis/graph/users`);o&&a.searchParams.set("scopeDescriptor",o),i&&a.searchParams.set("continuationToken",i);let u=await this.config.request({url:a.toString(),headers:y(this.config,t)}),p=u.headers["x-ms-continuationtoken"];return{pageInfo:{endCursor:p||null,hasNextPage:!!p},data:u.body.value.map(d=>({avatarUrl:d._links?.avatar?.href??null,descriptor:d.descriptor??null,email:d.mailAddress??null,name:d.displayName??null,storageKeyURL:d._links?.storageKey?.href??null,username:d.displayName??null}))}}async getAccountFromAzureGraphAccount(e,t={}){let{azureGraphAccount:s}=e;if(!s.storageKeyURL)throw new Error("Expected 'storageKeyURL' to not be null for 'azureGraphAccount'");let o=await this.config.request({url:s.storageKeyURL,headers:y(this.config,t)});return{data:{avatarUrl:s.avatarUrl,email:s.email,id:o.body.value,name:s.name,username:s.username,url:null}}}async getAccountsFromAzureGraphAccounts(e,t={}){let s=[];for(let o of e.azureGraphAccounts){let i=await this.getAccountFromAzureGraphAccount({azureGraphAccount:o},t);s.push(i.data)}return{data:s}}async getRepo(e,t={}){if(!e.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let s=await this.config.request({url:`${v(this.config,t)}/${encodeURIComponent(e.namespace)}/${encodeURIComponent(e.project)}/_apis/git/repositories/${encodeURIComponent(e.name)}`,headers:y(this.config,t)});return{data:Nt(e.namespace,s.body)}}async getRepos(e,t={}){let s=[],o=[];return await Promise.all(e.map(async i=>{try{let a=await this.getRepo(i,t);s.push(a.data)}catch(a){o.push({input:i,error:a})}})),{data:s,errors:o}}async getReposForAzureProject(e,t={}){if(!e.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');return{data:(await this.config.request({url:`${v(this.config,t)}/${encodeURIComponent(e.namespace)}/${encodeURIComponent(e.project)}/_apis/git/repositories`,headers:y(this.config,t)})).body.value.map(o=>Nt(e.namespace,o))}}async getRefs(e,t,s={}){if(!t.repo.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let o=new URL(`${v(this.config,s)}/${encodeURIComponent(t.repo.namespace)}/${encodeURIComponent(t.repo.project)}/_apis/git/repositories/${encodeURIComponent(t.repo.name)}/refs`);o.searchParams.set("filter",e),o.searchParams.set("$top",E.toString()),t.cursor&&o.searchParams.set("continuationToken",t.cursor);let i=await this.config.request({url:o.toString(),headers:y(this.config,s)}),a=i.headers["x-ms-continuationtoken"];return{pageInfo:{hasNextPage:!!a,endCursor:a||null},data:i.body.value.map(u=>({name:be(u.name),commit:{oid:u.objectId,authoredDate:null,committedDate:null}}))}}async getBranches(e,t={}){return this.getRefs("heads",e,t)}async getTags(e,t={}){return this.getRefs("tags",e,t)}async getPullRequestsForRepoBase(e,t={},s=100){let{page:o,repo:i,assigneeLogins:a,authorLogin:u}=e||{},p=o||1;if(!i.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let d="searchCriteria.status=1";return a&&a.length&&(d+=`&searchCriteria.reviewerId=${a[0]}`),u&&(d+=`&searchCriteria.creatorId=${u}`),await this.config.request({url:`${v(this.config,t)}/${encodeURIComponent(i.namespace)}/${encodeURIComponent(i.project||"")}/_apis/git/repositories/${encodeURIComponent(i.name)}/pullRequests?${d}&%24top=${s}&%24skip=${(p-1)*s}`,headers:y(this.config,t)})}async getPullRequestsForRepo(e,t={}){let o=e.page||1,i=await this.getPullRequestsForRepoBase(e,t,100);return{pageInfo:{hasNextPage:i.body.value.length===100,nextPage:o+1},data:i.body.value.map(a=>ce(e.repo.namespace,a))}}async getPullRequestsForRepos(e,t={}){if(!e.repos.every(i=>i.project))throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let{repos:s}=e||{},o=[];return await Promise.all(s.map(async i=>{try{(await this.getPullRequestsForRepoBase({repo:i,...e},t)).body.value.forEach(u=>{o.push(ce(i.namespace,u))})}catch(a){if(a.statusCode!==404&&a.statusCode!==401)throw a}})),{data:o}}async getPullRequestsForProjectBase(e,t={},s=100){let{namespace:o,project:i,page:a,assigneeLogins:u,authorLogin:p,repo:d}=e;if(d?.project&&d.project!==i)throw new Error("Could not fetch pull requests, project mismatch");let c=a||1,l=new URL(`${v(this.config,t)}/${encodeURIComponent(o)}/${encodeURIComponent(i)}/_apis/git/pullRequests`);return l.searchParams.set("searchCriteria.status","1"),l.searchParams.set("$top",s.toString()),l.searchParams.set("$skip",((c-1)*s).toString()),d?.id&&d?.project===i&&l.searchParams.set("searchCriteria.repositoryId",d.id),u&&u.length&&l.searchParams.set("searchCriteria.reviewerId",u[0]),p&&l.searchParams.set("searchCriteria.creatorId",p),await this.config.request({url:l.toString(),headers:y(this.config,t)})}async getPullRequestsForProject(e,t={}){let o=e.page||1,i=await this.getPullRequestsForProjectBase(e,t,100);return{pageInfo:{hasNextPage:i?.body.value.length===100,nextPage:o+1},data:i?.body.value.map(a=>ce(e.namespace,a))||[]}}async getPullRequestsForProjects(e,t={}){let{projects:s}=e||{},o=[];return await Promise.all(s.map(async i=>{try{(!e.repo||e.repo.project&&e.repo.project===i.project)&&(await this.getPullRequestsForProjectBase({...i,...e},t))?.body.value.forEach(u=>{o.push(ce(i.namespace,u))})}catch(a){if(a.statusCode!==404&&a.statusCode!==401)throw a}})),{data:o}}async getAzurePullRequestLastMergeStatus(e,t={}){if(!e.repo.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let{repo:{namespace:s,project:o,name:i},pullRequestId:a}=e,u=await this.config.request({url:`${v(this.config,t)}/${encodeURIComponent(s)}/${encodeURIComponent(o||"")}/_apis/git/repositories/${i}/pullrequests/${a}?includeCommits=true?api-version=6.0`,headers:{...y(this.config,t)}});if(!u.body.mergeStatus)throw new Error("Could not fetch pull request");return{data:u.body.mergeStatus}}async updatePullRequest(e,t,s){return await this.config.request({method:"PATCH",url:`${v(this.config,s)}/${encodeURIComponent(e.repository.owner.login)}/${encodeURIComponent(e.repository.project)}/_apis/git/repositories/${e.repository.name}/pullrequests/${e.id}?api-version=6.0`,body:t,headers:{...y(this.config,s),"Content-Type":"application/json"}})}async closePullRequest(e,t={}){let{pullRequest:s}=e,o={status:"abandoned"};if(!(await this.updatePullRequest(s,JSON.stringify(o),t)).body.status)throw new Error("Could not close pull request")}async mergePullRequest(e,t={}){let{pullRequest:s,mergeStrategy:o}=e,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 a={completionOptions:{mergeStrategy:i},lastMergeSourceCommit:{commitId:s.headRef?.oid},status:"completed"};if(!(await this.updatePullRequest(s,JSON.stringify(a),t)).body.status)throw new Error("Could not merge pull request")}async addPullRequestLabel(e,t={}){let{pullRequest:s,label:o}=e;if(!s.repository.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let i={name:o.name};if(!(await this.config.request({method:"POST",url:`${v(this.config,t)}/${encodeURIComponent(s.repository.owner.login)}/${encodeURIComponent(s.repository.project)}/_apis/git/repositories/${s.repository.name}/pullrequests/${s.id}/labels?api-version=6.0`,body:JSON.stringify(i),headers:{...y(this.config,t),"Content-Type":"application/json"}})).body.id)throw new Error("Could not add pull request label")}async removePullRequestLabel(e,t={}){let{pullRequest:s,label:o}=e;if(!s.repository.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');await this.config.request({method:"DELETE",url:`${v(this.config,t)}/${encodeURIComponent(s.repository.owner.login)}/${encodeURIComponent(s.repository.project)}/_apis/git/repositories/${s.repository.name}/pullrequests/${s.id}/labels/${encodeURIComponent(o.name)}?api-version=6.0`,headers:{...y(this.config,t)}})}async setPullRequestLabels(e,t={}){let{pullRequest:s,labels:o}=e;if(!s.repository.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let i=s.labels;if(!i)throw new Error('Azure DevOps requires "labels" for this function.');for(let a of o)i.find(u=>u.id===a.id)||await this.addPullRequestLabel({pullRequest:s,label:a},t);for(let a of i)o.find(u=>a.id===u.id)||await this.removePullRequestLabel({pullRequest:s,label:a},t)}async setPullRequestAsDraft(e,t={}){let{pullRequest:s,isDraft:o}=e,i={isDraft:o};if(!(await this.updatePullRequest(s,JSON.stringify(i),t)).body.status)throw new Error("Could not set the pull request as draft")}async addPullRequestReviewer(e,t={}){let{pullRequest:s,reviewer:o,isRequired:i}=e,a={id:o.id,isRequired:i};if(!(await this.config.request({method:"PUT",url:`${v(this.config,t)}/${encodeURIComponent(s.repository.owner.login)}/${encodeURIComponent(s.repository.project)}/_apis/git/repositories/${s.repository.name}/pullrequests/${s.id}/reviewers/${o.id}?api-version=6.0`,body:JSON.stringify(a),headers:{...y(this.config,t),"Content-Type":"application/json"}})).body.id)throw new Error("Could not add pull request reviewer")}async removePullRequestReviewer(e,t={}){let{pullRequest:s,reviewer:o}=e;await this.config.request({method:"DELETE",url:`${v(this.config,t)}/${encodeURIComponent(s.repository.owner.login)}/${encodeURIComponent(s.repository.project)}/_apis/git/repositories/${s.repository.name}/pullrequests/${s.id}/reviewers/${o.id}?api-version=6.0`,headers:{...y(this.config,t),Accept:"application/json"}})}async setPullRequestReviewers(e,t={}){let{pullRequest:s,reviewers:o}=e;for(let i of o)s.assignees.find(a=>a.id===i.id)||await this.addPullRequestReviewer({pullRequest:s,reviewer:i,isRequired:!0},t);for(let i of s.assignees)o.find(a=>i.id===a.id)||await this.removePullRequestReviewer({pullRequest:s,reviewer:i},t)}async getIssuesForAzureProject(e,t={}){let{page:s,assigneeLogins:o,authorLogin:i,mentionLogin:a,labelNames:u,statusByWorkItemIdByStatusId:p}=e||{},d=s||1,c=200,l=["[Microsoft.VSTS.Common.ClosedDate] = ''","[System.TeamProject] = @project","[Microsoft.VSTS.Common.ResolvedDate] = ''"];i&&l.push(`[System.CreatedBy] = '${i.replace("'","''")}'`),o&&o[0]&&l.push(`[System.AssignedTo] = '${o[0].replace("'","''")}'`),a&&l.push("[System.Id] IN (@recentMentions)"),u&&u.forEach(P=>l.push(`[System.Tags] Contains '${P}'`));let g=`Select [Microsoft.VSTS.Common.ClosedDate], [Microsoft.VSTS.Common.ResolvedDate] From WorkItems Where ${l.join(" AND ")} order by [System.CreatedDate] desc`,m=await this.config.request({url:`${v(this.config,t)}/${encodeURIComponent(e.namespace)}/${encodeURIComponent(e.project)}/_apis/wit/wiql?api-version=6.0`,body:JSON.stringify({query:g}),method:"POST",headers:{...y(this.config,t),"Content-Type":"application/json"}}),b=m.body.workItems.slice((d-1)*c,c*d).map(P=>P.id);if(b.length==0)return{pageInfo:{hasNextPage:!1,nextPage:null},data:[]};let R=await this.config.request({url:`${v(this.config,t)}/${encodeURIComponent(e.namespace)}/${encodeURIComponent(e.project)}/_apis/wit/workitemsbatch?api-version=6.0`,body:JSON.stringify({ids:b,$expand:"Links"}),method:"POST",headers:{...y(this.config,t),"Content-Type":"application/json"}});return{pageInfo:{hasNextPage:m.body.workItems.length>c*d,nextPage:d+1},data:R.body.value.map(P=>Vr(e.namespace,e.project,P,p||{}))}}async getPermissionsForRepos(e,t={}){let{namespace:s,repos:o}=e,i={4:["canPush","canCreateWebhook"],1024:["isAdmin"],2048:["isAdmin"],4096:["isAdmin"],8192:["isAdmin"]},a=c=>{let l="2e9eb7ed-3c0a-47d4-87c1-0ffdd275fd87",g=`repoV2/${c.projectId}/${c.id}`;return Object.keys(i).map(m=>({securityNamespaceId:l,token:g,permissions:m}))},u={alwaysAllowAdministrators:!1,evaluations:o.flatMap(a)};return{data:(await this.config.request({method:"POST",url:`${v(this.config,t)}/${encodeURIComponent(s)}/_apis/security/permissionevaluationbatch?api-version=7.0`,body:JSON.stringify(u),headers:{...y(this.config,t),"Content-Type":"application/json"}})).body.evaluations.reduce((c,l)=>{let[,g,m]=l.token.split("/"),b=`${g}/${m}`,R=i[l.permissions];for(let P of R)c[b]===void 0&&(c[b]={canCreateWebhook:!0,canPush:!0,isAdmin:!0}),l.value===!1&&(c[b][P]=!1);return c},{})}}async decorateReposWithPermissions(e,t={}){let{namespace:s,repos:o}=e,i=await this.getPermissionsForRepos({namespace:s,repos:o},t);return{data:o.map(a=>({...a,permissions:i.data[`${a.projectId}/${a.id}`]}))}}async updateIssue(e,t,s={}){return await this.config.request({method:"PATCH",url:`${v(this.config,s)}/${encodeURIComponent(e.project.namespace)}/${encodeURIComponent(e.project.name)}/_apis/wit/workitems/${e.id}?api-version=6.0`,body:JSON.stringify(t),headers:{...y(this.config,s),"Content-Type":"application/json-patch+json"}})}async setIssueStatus(e,t={}){let{issue:s,status:o}=e,i=[{op:"add",path:"/fields/System.State",value:o.name}];if(!(await this.updateIssue(s,i,t)).body.fields?.["System.State"])throw new Error("Could not set issue status")}async setIssueAssignee(e,t={}){let{issue:s,assignee:o}=e,i=[{op:"add",path:"/fields/System.AssignedTo",value:o?.name??""}];if(!(await this.updateIssue(s,i,t)).body.fields?.["System.State"])throw new Error("Could not set issue assignee")}async setIssueLabels(e,t={}){let{issue:s,labels:o}=e,a=[{op:"replace",path:"/fields/System.Tags",value:o.map(p=>p.name).join(";")}];if(!(await this.updateIssue(s,a,t)).body.fields?.["System.Tags"])throw new Error("Could not set issue tags")}async getIssueTypesForAzureProject(e,t={}){if(!e.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let{namespace:s,project:o}=e;return{data:(await this.config.request({url:`${v(this.config,t)}/${encodeURIComponent(s)}/${encodeURIComponent(o||"")}/_apis/wit/workitemtypes?api-version=6.0`,headers:{...y(this.config,t)}})).body.value}}async getLabelsForProject(e,t={}){let{namespace:s,project:o}=e;return{data:(await this.config.request({url:`${v(this.config,t)}/${encodeURIComponent(s)}/${encodeURIComponent(o||"")}/_apis/wit/tags?api-version=6.0`,headers:{...y(this.config,t)}})).body.value.map(a=>({color:null,description:null,id:a.id,name:a.name,url:a.url}))}}async getPullRequestForRepo(e,t={}){let{repo:s,number:o}=e;if(!s.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let i=await this.config.request({url:`${this.getRepoApiUrl(s.namespace,s.project,s.name,t)}/pullrequests/${o}?api-version=7.1`,headers:y(this.config,t)});return{data:ce(s.namespace,i.body)}}async getMergeBase(e,t={}){if(!e.repo.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let s=await this.config.request({url:`${this.getRepoApiUrl(e.repo.namespace,e.repo.project,e.repo.name,t)}/commits/${encodeURIComponent(e.base)}/mergebases?otherCommitId=${encodeURIComponent(e.head)}&api-version=7.1`,headers:y(this.config,t)});if(!s.body.value?.length)throw new Error("No merge base found between the specified commits.");return{data:s.body.value[0].commitId}}async getFileContents(e,t={}){if(!e.repo.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let s=await this.config.request({url:`${this.getRepoApiUrl(e.repo.namespace,e.repo.project,e.repo.name,t)}/items?path=${encodeURIComponent(e.path)}&versionDescriptor[version]=${encodeURIComponent(e.ref)}&versionDescriptor[versionType]=commit&api-version=7.1`,headers:{...y(this.config,t),Accept:"application/octet-stream"}});return{data:new Blob([s.body])}}async getPullRequestDiff(e,t={}){if(!e.repo.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let s=this.getRepoApiUrl(e.repo.namespace,e.repo.project,e.repo.name,t),o=y(this.config,t),i={...o,Accept:"application/octet-stream"},[a,u]=await Promise.all([this.config.request({url:`${s}/pullrequests/${e.pullRequestId}?api-version=7.1`,headers:o}),this.config.request({url:`${s}/pullrequests/${e.pullRequestId}/iterations?api-version=7.1`,headers:o})]),p=a.body.lastMergeTargetCommit.commitId,d=a.body.lastMergeSourceCommit.commitId,c=u.body.value;if(c.length===0)return"";let l=c[c.length-1],m=(await this.config.request({url:`${s}/pullrequests/${e.pullRequestId}/iterations/${l.id}/changes?api-version=7.1`,headers:o})).body.changeEntries;if(m.length===0)return"";let b=5,R=[],P=new TextDecoder,U=q=>q instanceof ArrayBuffer?P.decode(q):typeof q=="string"?q:"",K=async(q,C)=>{try{let Je=await this.config.request({url:`${s}/items?path=${encodeURIComponent(q)}&versionDescriptor[version]=${encodeURIComponent(C)}&versionDescriptor[versionType]=commit&includeContent=true&api-version=7.1`,headers:i});return U(Je.body)}catch{return""}},x=1,S=8,k=16;for(let q=0;q<m.length;q+=b){let C=m.slice(q,q+b),Je=await Promise.all(C.map(async ee=>{let Lt=ee.item.path,$r=(ee.changeType&x)!==0,Ur=(ee.changeType&S)!==0,$t=(ee.changeType&k)!==0&&ee.item.originalPath?ee.item.originalPath:Lt,Ut=Lt,[Ar,Gr]=await Promise.all([$r?Promise.resolve(""):K($t,p),Ur?Promise.resolve(""):K(Ut,d)]);return(0,_t.createTwoFilesPatch)(`a${$t}`,`b${Ut}`,Ar,Gr)}));R.push(...Je)}return R.join(`
2
- `)}getPullRequestWriteHeaders(e){return{...y(this.config,e),"Content-Type":"application/json"}}setReviewerVote(e,t,s,o,i){return this.config.request({method:"PUT",url:`${e}/pullRequests/${t}/reviewers/${encodeURIComponent(s)}?api-version=7.1`,headers:this.getPullRequestWriteHeaders(i),body:JSON.stringify({vote:o})})}postPullRequestThread(e,t,s,o){return this.config.request({method:"POST",url:`${e}/pullRequests/${t}/threads?api-version=7.1`,headers:this.getPullRequestWriteHeaders(o),body:JSON.stringify({comments:[{parentCommentId:0,content:s,commentType:1}],status:1})})}async approvePullRequest(e,t={}){if(!e.pullRequest.repository.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let s=e.pullRequest.repository.owner.login,o=this.getRepoApiUrl(s,e.pullRequest.repository.project,e.pullRequest.repository.name,t),i=await this.getCurrentUserId(s,t);await Promise.all([this.setReviewerVote(o,e.pullRequest.id,i,10,t),e.comment?this.postPullRequestThread(o,e.pullRequest.id,e.comment,t):null])}async requestPullRequestChanges(e,t={}){if(!e.pullRequest.repository.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let s=e.pullRequest.repository.owner.login,o=this.getRepoApiUrl(s,e.pullRequest.repository.project,e.pullRequest.repository.name,t),i=await this.getCurrentUserId(s,t);await this.postPullRequestThread(o,e.pullRequest.id,e.comment,t),await this.setReviewerVote(o,e.pullRequest.id,i,-5,t)}async commentOnPullRequest(e,t={}){if(!e.pullRequest.repository.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let s=this.getRepoApiUrl(e.pullRequest.repository.owner.login,e.pullRequest.repository.project,e.pullRequest.repository.name,t);await this.postPullRequestThread(s,e.pullRequest.id,e.comment,t)}async getReviewsForPullRequest(e,t={}){if(!e.repo.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let s=this.getRepoApiUrl(e.repo.namespace,e.repo.project,e.repo.name,t),o=y(this.config,t),[i,a]=await Promise.all([this.config.request({url:`${s}/pullRequests/${e.pullRequestId}/reviewers?api-version=7.1`,headers:o}),this.config.request({url:`${s}/pullRequests/${e.pullRequestId}/threads?api-version=7.1`,headers:o})]),u=new Map;for(let c of a.body.value){if(c.isDeleted)continue;let l=c.comments.filter(C=>!C.isDeleted&&C.commentType!=="system"),g=l.find(C=>C.parentCommentId===0)??l[0];if(!g)continue;let m=g.author?.id;if(!m)continue;let b=l.filter(C=>C.id!==g.id),R=c.threadContext,P=R?.rightFileStart?{side:"RIGHT",start:R.rightFileStart,end:R.rightFileEnd}:R?.leftFileStart?{side:"LEFT",start:R.leftFileStart,end:R.leftFileEnd}:null,U=P?.end?.line??P?.start.line??null,K=P?.start&&P.end&&P.start.line!==P.end.line?P.start.line:null,x=R?.filePath??"",S=x.startsWith("/")?x.slice(1):x,k={id:c.id.toString(),author:g.author?re(g.author):null,body:g.content??"",createdAt:g.publishedDate?new Date(g.publishedDate):null,url:"",diffLines:[],filename:S,replies:b.map(C=>({id:C.id.toString(),author:C.author?re(C.author):null,body:C.content??"",createdAt:C.publishedDate?new Date(C.publishedDate):null,url:""})),isOutdated:!1,isResolved:Hr.has(c.status),line:U,startLine:K,side:P?.side??null,threadId:c.id.toString()},q=u.get(m);q?q.push(k):u.set(m,[k])}let p=[],d=new Set;for(let c of i.body.value){if(c.hasDeclined)continue;let l=c.vote??0,g=u.get(c.id);l===0&&!g?.length||(p.push({id:c.id,author:re(c),body:"",createdAt:null,url:"",reviewComments:g??[]}),d.add(c.id))}for(let[c,l]of u){if(d.has(c)||!l.length)continue;let g=l[0].author;g&&p.push({id:c,author:g,body:"",createdAt:null,url:"",reviewComments:l})}return{data:p}}};var D=(r,n={})=>I(n.token||r.token,n.isPAT||r.isPAT);var L="https://api.bitbucket.org/2.0",Kr={OPEN:"OPEN",MERGED:"MERGED",DECLINED:"CLOSED"},ye={owner:4,admin:3,contributor:2,member:1},Pe=r=>({id:r.uuid,name:r.display_name||r.nickname,username:r.nickname||r.display_name,email:null,avatarUrl:r.links.avatar.href,url:r.links.html.href}),Ft=r=>{let n=r.links.clone,e=n?.find(s=>s.name==="ssh"),t=n?.find(s=>s.name==="https");return e&&t?{cloneUrlHTTPS:t.href,cloneUrlSSH:e.href}:null},tt=r=>({id:r.uuid,namespace:r.workspace.slug,name:r.slug,webUrl:r.links.html.href,httpsUrl:r.links.clone.find(n=>n.name==="https")?.href??null,sshUrl:r.links.clone.find(n=>n.name==="ssh")?.href??null,defaultBranch:{name:r.mainbranch.name},permissions:null}),rt=r=>{let n=r.id,e=r.participants?.map(t=>{let s="REVIEW_REQUESTED";return t.approved?s="APPROVED":t.state==="changes_requested"?s="CHANGES_REQUESTED":t.participated_on!==null&&(s="COMMENTED"),{reviewer:Pe(t.user),state:s}})??[];return{id:n.toString(),title:r.title,description:r.description,number:n,state:Kr[r.state],isDraft:!1,commentCount:r.comment_count,upvoteCount:null,author:Pe(r.author),createdDate:new Date(r.created_on),updatedDate:new Date(r.updated_on),closedDate:null,mergedDate:null,repository:{id:r.destination.repository.uuid,name:r.destination.repository.name,owner:{login:r.destination.repository.full_name.split("/")[0]},remoteInfo:Ft(r.destination.repository)},headCommit:{buildStatuses:null},baseRef:{name:r.destination.branch.name,oid:r.destination.commit.hash},headRef:{name:r.source.branch.name,oid:r.source.commit.hash},url:r.links.html.href,assignees:null,reviews:e,reviewDecision:N(e),additions:null,deletions:null,fileCount:null,commitCount:null,headRepository:{id:r.source.repository.uuid,name:r.source.repository.name,owner:{login:r.source.repository.full_name.split("/")[0]},remoteInfo:Ft(r.source.repository)},mergeableState:"MERGEABLE",permissions:null}},Xr=r=>{switch(r){case"owner":case"admin":return{canCreateWebhook:!0,canPush:!0,isAdmin:!0};case"write":return{canCreateWebhook:!1,canPush:!0,isAdmin:!1};case"read":case"none":return{canCreateWebhook:!1,canPush:!1,isAdmin:!1}}},Zr=r=>{switch(r){case"owner":case"admin":return{canCreateWebhook:!0,canPush:!0,isAdmin:!0};case"contributor":return{canCreateWebhook:!1,canPush:!0,isAdmin:!1};default:return{canCreateWebhook:!1,canPush:!1,isAdmin:!1}}},ne=class extends T{async refreshToken(n){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 ${n.base64ClientIDColonClientSecret}`},body:`grant_type=refresh_token&refresh_token=${n.refreshToken}`})).body}}async getCurrentUser(n={},e={}){let t=await this.config.request({url:`${L}/user`,headers:D(this.config,e)});return{data:Pe(t.body)}}async getUserForCommit(n,e={}){let s=(await this.config.request({url:`${L}/repositories/${n.repo.namespace}/${n.repo.name}/commit/${n.oid}`,headers:D(this.config,e)})).body.author,o=s.raw.match(/([^<]+)<(.+)>/);return{data:{name:o?o[1].trim():null,email:o?o[2]:null,avatarUrl:s.user?.links.avatar.href||null}}}async getRepo(n,e={}){let t=await this.config.request({url:`${L}/repositories/${n.namespace}/${n.name}`,headers:D(this.config,e)});return{data:tt(t.body)}}async getRepos(n,e={}){let t=[],s=[];return await Promise.all(n.map(async o=>{try{let i=await this.getRepo(o,e);t.push(i.data)}catch(i){s.push({input:o,error:i})}})),{data:t,errors:s}}async getReposForWorkspace(n,e={}){let t=new URL(`${L}/repositories/${encodeURIComponent(n.workspace)}`);t.searchParams.set("page",n.page?.toString()||"1"),t.searchParams.set("pagelen",E.toString()),n.minimumRole&&t.searchParams.set("role",n.minimumRole);let s=await this.config.request({url:t.toString(),headers:D(this.config,e)}),o=!!s.body.next;return{pageInfo:{hasNextPage:o,nextPage:o?s.body.page+1:null},data:s.body.values.map(tt)}}async getAllReposForWorkspace(n,e={}){let t=[],s=1;for(;s!==null;){let o=await this.getReposForWorkspace({workspace:n.workspace,minimumRole:n.minimumRole,page:s},e);t.push(...o.data),s=o.pageInfo.hasNextPage?o.pageInfo.nextPage:null}return t}async getAllReposForWorkspaceWithPermissions(n,e={}){let t=new Map,s=[],o=ye[n.minimumRole||"member"];o<=ye.admin&&s.push("admin"),o<=ye.contributor&&s.push("contributor"),o<=ye.member&&s.push("member");let i=[];for(let a of s){i=await this.getAllReposForWorkspace({workspace:n.workspace,minimumRole:a},e);for(let u of i)t.has(u.id)||t.set(u.id,a)}return{data:i.map(a=>{let u=t.get(a.id)||"member";return{...a,permissions:Zr(u)}})}}async getReposForCurrentUser(n,e={}){let t=new URL(`${L}/repositories`);t.searchParams.set("role","member"),t.searchParams.set("pagelen",E.toString()),n.cursor&&t.searchParams.set("after",n.cursor);let s=await this.config.request({url:t.toString(),headers:D(this.config,e)}),o=!!s.body.next,i=null;return s.body.next&&(i=new URL(s.body.next).searchParams.get("after")),{pageInfo:{hasNextPage:o,endCursor:i},data:s.body.values.map(tt)}}async getBranches(n,e={}){let t=new URL(`${L}/repositories/${n.repo.namespace}/${n.repo.name}/refs/branches`);t.searchParams.set("page",n.page?.toString()||"1"),t.searchParams.set("pagelen",E.toString());let s=await this.config.request({url:t.toString(),headers:D(this.config,e)}),o=!!s.body.next;return{pageInfo:{hasNextPage:o,nextPage:o?s.body.page+1:null},data:s.body.values.map(i=>{let a=new Date(i.target.date);return{name:i.name,commit:{oid:i.target.hash,authoredDate:a,committedDate:a}}})}}async getTags(n,e={}){let t=new URL(`${L}/repositories/${n.repo.namespace}/${n.repo.name}/refs/tags`);t.searchParams.set("pagelen",E.toString()),n.cursor&&t.searchParams.set("page",n.cursor);let s=await this.config.request({url:t.toString(),headers:D(this.config,e)}),o=!!s.body.next,i=null;return s.body.next&&(i=new URL(s.body.next).searchParams.get("page")),{pageInfo:{hasNextPage:o,endCursor:i},data:s.body.values.map(a=>{let u=new Date(a.target.date);return{name:a.name,commit:{oid:a.target.hash,authoredDate:u,committedDate:u}}})}}async getWorkspacesForCurrentUser(n={},e={}){let t=new URL(`${L}/user/workspaces`);t.searchParams.set("page",n?.page?.toString()||"1"),t.searchParams.set("pagelen","50"),n?.administrator!==void 0&&t.searchParams.set("administrator",n.administrator.toString());let s=await this.config.request({url:t.toString(),headers:D(this.config,e)}),o=!!s.body.next;return{pageInfo:{hasNextPage:o,nextPage:o?s.body.page+1:null},data:s.body.values.map(i=>({id:i.workspace.uuid,slug:i.workspace.slug}))}}async getWorkspacesForUser(n,e={}){let t=new URL(`${L}/user/permissions/workspaces`);t.searchParams.set("page",n.page?.toString()||"1"),t.searchParams.set("pagelen","50");let s=await this.config.request({url:t.toString(),headers:D(this.config,e)}),o=!!s.body.next;return{pageInfo:{hasNextPage:o,nextPage:o?s.body.page+1:null},data:s.body.values.map(i=>({id:i.workspace.uuid,slug:i.workspace.slug,name:i.workspace.name}))}}async getPullRequestsForUserAndWorkspace(n,e={}){let t=new URL(`${L}/workspaces/${n.workspaceSlug}/pullrequests/${n.userId}`);if(t.searchParams.set("fields","+values.participants,+values.destination.repository.links.clone.*,+values.source.repository.links.clone.*"),t.searchParams.set("page",n.page?.toString()||"1"),t.searchParams.set("pagelen","50"),n.repos&&n.repos.length>0){let i=`state = "open" AND (${n.repos.map(a=>`source.repository.full_name = "${a.namespace}/${a.name}"`).join(" OR ")})`;t.searchParams.set("q",i)}let s=await this.config.request({url:t.toString(),headers:D(this.config,e)}),o=!!s.body.next;return{pageInfo:{hasNextPage:o,nextPage:o?s.body.page+1:null},data:s.body.values.map(rt)}}async getPullRequestsForRepoBase(n,e={}){let t=new URL(`${L}/repositories/${encodeURI(n.repo.namespace)}/${encodeURI(n.repo.name)}/pullrequests?state=OPEN`),s=[];n.reviewerId&&s.push(`reviewers.uuid="${n.reviewerId}"`),n.authorLogin&&s.push(`author.uuid="${n.authorLogin}"`);let o='state="OPEN"';return s.length&&(o+=` AND (${s.join(n.useOrFilter?" OR ":" AND ")})`),t.searchParams.set("fields","+values.participants,+values.destination.repository.links.clone.*,+values.source.repository.links.clone.*"),t.searchParams.set("page",n.page?.toString()||"1"),t.searchParams.set("pagelen","50"),t.searchParams.set("q",o),await this.config.request({url:t.toString(),headers:D(this.config,e)})}async getPullRequestsForRepo(n,e={}){let t=[],s=await this.getPullRequestsForRepoBase(n,e);s.body.values.forEach(i=>{t.push(rt(i))});let o=!!s.body.next;return{pageInfo:{hasNextPage:o,nextPage:o?s.body.page+1:null},data:t}}async getPullRequestsForRepos(n,e={}){let t=[];return await Promise.all(n.repos.map(async s=>{try{(await this.getPullRequestsForRepoBase({repo:s,...n},e)).body.values.forEach(i=>{t.push(rt(i))})}catch(o){if(o.statusCode!==404&&o.statusCode!==401)throw o}})),{data:t}}async getAccountsForWorkspace(n,e={}){let t=new URL(`${L}/workspaces/${encodeURI(n.workspace)}/members`);t.searchParams.set("page",n.page?.toString()||"1"),t.searchParams.set("pagelen","100");let s=await this.config.request({url:t.toString(),headers:D(this.config,e)}),o=!!s.body.next;return{pageInfo:{hasNextPage:o,nextPage:o?s.body.page+1:null},data:s.body.values.map(i=>Pe(i.user))}}async getReposPermissionsForCurrentUser(n,e={}){let t=new URL(`${L}/user/permissions/repositories`);t.searchParams.set("page",n.page?.toString()||"1"),t.searchParams.set("pagelen","100");let s=await this.config.request({url:t.toString(),headers:D(this.config,e)}),o=!!s.body.next;return{pageInfo:{hasNextPage:o,nextPage:o?s.body.page+1:null},data:s.body.values.reduce((i,a)=>({...i,[a.repository.uuid]:Xr(a.permission)}),{})}}async decorateReposWithPermissions(n,e={}){let t={},s=1;do{let o=await this.getReposPermissionsForCurrentUser({page:s},e);t={...o.data,...t},s=o.pageInfo.hasNextPage?o.pageInfo.nextPage:null}while(s!==null);return{data:n.repos.map(o=>({...o,permissions:t[o.id]??{canCreateWebhook:!1,canPush:!1,isAdmin:!1}}))}}async closePullRequest(n,e={}){let{pullRequest:t}=n;if(!(await this.config.request({method:"POST",url:`${L}/repositories/${t.repository.owner.login}/${t.repository.name}/pullrequests/${t.id}/decline`,headers:D(this.config,e)})).body.title)throw new Error("Could not close pull request")}async mergePullRequest(n,e={}){let{pullRequest:t,mergeStrategy:s}=n,o;switch(s){case"MERGE_COMMIT":{o="merge_commit";break}case"FAST_FORWARD":{o="fast_forward";break}case"SQUASH":{o="squash";break}}let i={merge_strategy:o,type:"pullrequest"};if(!(await this.config.request({method:"POST",url:`${L}/repositories/${t.repository.owner.login}/${t.repository.name}/pullrequests/${t.id}/merge`,body:JSON.stringify(i),headers:{...D(this.config,e),"Content-Type":"application/json"}})).body.title)throw new Error("Could not merge pull request")}async setPullRequestReviewers(n,e={}){let{pullRequest:t,reviewers:s}=n,o={reviewers:s.map(a=>{if(a.username)throw new Error('Bitbucket reviewer requires "username" for this function.');return{username:a.username}})};if(!(await this.config.request({method:"PUT",url:`${L}/repositories/${t.repository.owner.login}/${t.repository.name}/pullrequests/${t.id}`,body:JSON.stringify(o),headers:{...D(this.config,e),"Content-Type":"application/json"}})).body.title)throw new Error("Could not set pull request reviewers")}};var Qt=r=>r?r.find(n=>n.permission==="USER_ADMIN"||n.permission==="PROJECT_ADMIN"||n.permission==="ADMIN"||n.permission==="SYS_ADMIN"||n.permission==="REPO_ADMIN")?{canCreateWebhook:!0,canPush:!0,isAdmin:!0}:r.find(n=>n.permission==="REPO_WRITE"||n.permission==="REPO_CREATE"||n.permission==="PROJECT_CREATE"||n.permission==="PROJECT_WRITE")?{canCreateWebhook:!1,canPush:!0,isAdmin:!1}:{canCreateWebhook:!1,canPush:!1,isAdmin:!1}:{canCreateWebhook:!1,canPush:!1,isAdmin:!1};var ge=r=>{let n=r.links.self[0].href;return{name:r.displayName,email:r.emailAddress,avatarUrl:r.avatarUrl??(n&&`${n}/avatar.png`),id:r.id.toString(),username:r.name,url:n}},we=r=>{let n={OPEN:"OPEN",MERGED:"MERGED",DECLINED:"CLOSED"},e={UNAPPROVED:"REVIEW_REQUESTED",NEEDS_WORK:"CHANGES_REQUESTED",APPROVED:"APPROVED"},t=r.reviewers.map(u=>({reviewer:ge(u.user),state:e[u.status]})),s=r.toRef.repository.links.clone.find(u=>u.name==="ssh")?.href??null,o=r.toRef.repository.links.clone.find(u=>u.name==="https")?.href??null;o||(o=r.toRef.repository.links.clone.find(u=>u.name==="http")?.href??null);let i=r.fromRef.repository.links.clone.find(u=>u.name==="ssh")?.href??null,a=r.fromRef.repository.links.clone.find(u=>u.name==="https")?.href??null;return a||(a=r.fromRef.repository.links.clone.find(u=>u.name==="http")?.href??null),{id:r.id.toString(),number:r.id,title:r.title,description:r.description,url:r.links.self[0].href,state:n[r.state],isDraft:!1,createdDate:new Date(r.createdDate),updatedDate:new Date(r.updatedDate),closedDate:r.closedDate?new Date(r.closedDate):null,mergedDate:r.state=="MERGED"&&r.closedDate?new Date(r.closedDate):null,baseRef:{name:r.toRef.displayId,oid:r.toRef.latestCommit},headRef:{name:r.fromRef.displayId,oid:r.fromRef.latestCommit},commentCount:r.properties.commentCount,upvoteCount:null,commitCount:null,fileCount:null,additions:null,deletions:null,author:ge(r.author.user),assignees:null,reviews:t,reviewDecision:N(t),repository:{id:r.toRef.repository.id.toString(),name:r.toRef.repository.name,owner:{login:r.toRef.repository.project.key},remoteInfo:o&&s?{cloneUrlHTTPS:o,cloneUrlSSH:s}:null},headRepository:{id:r.fromRef.repository.id.toString(),name:r.fromRef.repository.name,owner:{login:r.fromRef.repository.project.key},remoteInfo:a&&i?{cloneUrlHTTPS:a,cloneUrlSSH:i}:null},headCommit:null,mergeableState:"MERGEABLE",permissions:null,version:r.version}},jt=r=>({id:r.id.toString(),namespace:r.project.key,name:r.slug,webUrl:r.links.self[0]?.href??null,httpsUrl:r.links.clone.find(n=>n.name==="https"||n.name==="http")?.href??null,sshUrl:r.links.clone.find(n=>n.name==="ssh")?.href??null,defaultBranch:null,permissions:null}),oe=class extends A{getBaseUrl(n){let e=n.baseUrl||this.config.baseUrl;if(!e)throw new Error('Bitbucket Server requires "baseUrl"');return e}getRequestHeaders(n){return I(n.token||this.config.token)}async getCurrentUser(n={},e={}){let t=await this.config.request({url:`${this.getBaseUrl(e)}/users?limit=2`,headers:this.getRequestHeaders(e)}),{headers:{"x-auserid":s,"x-ausername":o}}=t,i=s?parseInt(s,10):null,a=decodeURIComponent(o),p=(await this.config.request({url:`${this.getBaseUrl(e)}/users?filter=${o}&avatarSize=64`,headers:this.getRequestHeaders(e)})).body.values.find(({emailAddress:d,id:c,name:l,slug:g})=>i?i===c:a===l||a===d||a===g);if(!p)throw new Error("Could not find current Bitbucket Server user");return{data:ge(p)}}async getUserForCommit(n,e){let{repo:t,oid:s}=n,o=await this.config.request({url:`${this.getBaseUrl(e)}/projects/${t.namespace}/repos/${t.name}/commits/${s}`,headers:this.getRequestHeaders(e)});if(!o.body.author)throw new Error("Could not find user for commit");return{data:ge(o.body.author)}}async getRepo(n,e={}){let t=await this.config.request({url:`${this.getBaseUrl(e)}/projects/${n.namespace}/repos/${n.name}`,headers:this.getRequestHeaders(e)});return{data:jt(t.body)}}async getRepos(n,e={}){let t=[],s=[];return await Promise.all(n.map(async o=>{try{let i=await this.getRepo(o,e);t.push(i.data)}catch(i){s.push({input:o,error:i})}})),{data:t,errors:s}}async getReposForCurrentUser(n,e={}){let t=n.page??0,s=await this.config.request({url:`${this.getBaseUrl(e)}/repos?start=${t}`,headers:this.getRequestHeaders(e)});return{pageInfo:{hasNextPage:!s.body.isLastPage,nextPage:s.body.nextPageStart},data:s.body.values.map(jt)}}async getRepoPermissionsForUsername(n,e={}){let t=new URL(`${this.getBaseUrl(e)}/projects/${n.repo.namespace}/repos/${n.repo.name}/permissions/search?filterText=${n.username}`);try{let s=await this.config.request({url:t.toString(),headers:this.getRequestHeaders(e)});return{data:Qt(s.body.values)}}catch(s){if(s.response?.status===401)return{data:{canCreateWebhook:!1,canPush:!1,isAdmin:!1}};throw s}}async decorateReposWithPermissions(n,e={}){return await Promise.all(n.repos.map(async s=>{let o=await this.getRepoPermissionsForUsername({repo:s,username:n.username},e);return{...s,permissions:o.data}}))}async getPullRequestsForRepoBase(n,e={}){let t=new URL(`${this.getBaseUrl(e)}/projects/${encodeURI(n.repo.namespace)}/repos/${encodeURI(n.repo.name)}/pull-requests?state=OPEN`);return t.searchParams.set("start",n.page?.toString()||"0"),t.searchParams.set("limit","50"),await this.config.request({url:t.toString(),headers:this.getRequestHeaders(e)})}async getPullRequestsForRepo(n,e={}){let t=[],s=await this.getPullRequestsForRepoBase(n,e);s.body.values.forEach(i=>{if(n.authorLogin&&i.author.user.name!==n.authorLogin)return null;t.push(we(i))});let o=s.body.values.length!==0;return{pageInfo:{hasNextPage:o,nextPage:o?s.body.start+s.body.values.length:null},data:t}}async getPullRequestsForRepos(n,e={}){let t=[];return await Promise.all(n.repos.map(async s=>{try{(await this.getPullRequestsForRepoBase({repo:s,...n},e)).body.values.forEach(i=>{if(n.authorLogin&&i.author.user.name!==n.authorLogin)return null;t.push(we(i))})}catch(o){if(o.statusCode!==404&&o.statusCode!==401)throw o}})),{data:t}}async getPullRequestsForCurrentUser(n,e={}){let t=new URL(`${this.getBaseUrl(e)}/dashboard/pull-requests`);t.searchParams.set("state","OPEN"),t.searchParams.set("start",n.page?.toString()||"0"),t.searchParams.set("limit","50");let s=await this.config.request({url:t.toString(),headers:this.getRequestHeaders(e)}),o=s.body.values.length!==0;return{pageInfo:{hasNextPage:o,nextPage:o?s.body.start+s.body.values.length:null},data:s.body.values.map(we)}}async closePullRequest(n,e={}){let{pullRequest:t}=n;if(t.version===void 0)throw new Error('Bitbucket Server requires "version" for this function.');if(!(await this.config.request({method:"POST",url:`${this.getBaseUrl(e)}/projects/${t.repository.owner.login}/repos/${t.repository.name}/pull-requests/${t.id}/decline`,body:JSON.stringify({version:t.version}),headers:{...this.getRequestHeaders(e),"Content-Type":"application/json"}})).body.title)throw new Error("Could not close pull request")}async mergePullRequest(n,e={}){let{pullRequest:t,mergeStrategyId:s}=n;if(n.mergeStrategy)throw new Error('Bitbucket Server uses "mergeStrategyId" instead of "mergeStrategy".');if(t.version===void 0)throw new Error('Bitbucket Server requires "version" for this function.');if(!(await this.config.request({method:"POST",url:`${this.getBaseUrl(e)}/projects/${t.repository.owner.login}/repos/${t.repository.name}/pull-requests/${t.id}/merge`,body:JSON.stringify({strategyId:s,version:t.version}),headers:{...this.getRequestHeaders(e),"Content-Type":"application/json"}})).body.title)throw new Error("Could not merge pull request")}async getMergeStrategies(n={}){let e=await this.config.request({url:`${this.getBaseUrl(n)}/admin/pull-requests/git`,headers:{...this.getRequestHeaders(n),"Content-Type":"application/json"}});return{data:{defaultStrategy:e.body.mergeConfig.defaultStrategy,strategies:e.body.mergeConfig.strategies}}}async setPullRequestReviewers(n,e={}){let{pullRequest:t,reviewers:s}=n;if(t.version===void 0)throw new Error('Bitbucket Server requires "version" for this function.');let o={reviewers:s.map(a=>{if(a.username)throw new Error('Bitbucket Server reviewer requires "username" for this function.');return{user:{name:a.username}}}),version:t.version};if(!(await this.config.request({method:"PUT",url:`${this.getBaseUrl(e)}/projects/${t.repository.owner.login}/repos/${t.repository.name}/pull-requests/${t.id}`,body:JSON.stringify(o),headers:{...this.getRequestHeaders(e),"Content-Type":"application/json"}})).body.title)throw new Error("Could not set pull request reviewers")}async getAccountsForProject(n,e={}){let t=new URL(`${this.getBaseUrl(e)}/projects/${encodeURI(n.project)}/permissions/users`);t.searchParams.set("start",n.page?.toString()||"0"),t.searchParams.set("limit","50");let s=await this.config.request({url:t.toString(),headers:this.getRequestHeaders(e)}),o=s.body.values.length!==0;return{pageInfo:{hasNextPage:o,nextPage:o?s.body.start+s.body.values.length:null},data:s.body.values.map(i=>ge(i.user))}}};var sr=require("js-base64");var ve=(e=>(e.Open="OPEN",e.Closed="CLOSED",e))(ve||{});var h=class extends Error{constructor(e,t){let s=t?.map(i=>`'${i.message}'`).join(", "),o=s?`${e}: ${s}`:e;super(o);this.graphQLErrors=t??[]}};var Yr={AS_CODE_OWNER:[3,0,0],CHECK_RUN:[3,0,0],LATEST_REVIEWS:[3,0,0],VIEWER_CAN_MERGE_AS_ADMIN:[3,5,0],ISSUE_FULL_DATABASE_ID:[3,12,0],PR_FULL_DATABASE_ID:[3,13,0],PR_REVIEW_FULL_DATABASE_ID:[3,13,0],PR_REVIEW_COMMENT_FULL_DATABASE_ID:[3,13,0]},Bt=15,Mt=100,me={__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"},$=r=>!!r,_=(r,n)=>{let e=Yr[n];for(let t=0;t<3;t++){if(r[t]>e[t])return!0;if(r[t]<e[t])return!1}return!0},qe="https://api.github.com",es=`${qe}/graphql`,Ee=`
1
+ "use strict";var Ye=Object.defineProperty;var Fr=Object.getOwnPropertyDescriptor;var Qr=Object.getOwnPropertyNames;var jr=Object.prototype.hasOwnProperty;var Br=(s,n)=>{for(var e in n)Ye(s,e,{get:n[e],enumerable:!0})},Mr=(s,n,e,t)=>{if(n&&typeof n=="object"||typeof n=="function")for(let r of Qr(n))!jr.call(s,r)&&r!==e&&Ye(s,r,{get:()=>n[r],enumerable:!(t=Fr(n,r))||t.enumerable});return s};var zr=s=>Mr(Ye({},"__esModule",{value:!0}),s);var yn={};Br(yn,{AzureDevOps:()=>se,Bitbucket:()=>ne,BitbucketServer:()=>oe,EntityIdentifierProviderType:()=>xr,EntityType:()=>Or,EntityVersion:()=>Tr,GitBuildStatusStage:()=>Nt,GitBuildStatusState:()=>we,GitDiffLineType:()=>et,GitHub:()=>ie,GitHubIssueCloseReason:()=>kr,GitIssueState:()=>De,GitLab:()=>ue,GitMergeStrategy:()=>re,GitPullRequestMergeableState:()=>Y,GitPullRequestReviewState:()=>J,GitPullRequestState:()=>Z,GraphQLErrors:()=>h,Jira:()=>le,JiraServer:()=>pe,PullRequestAsyncStatus:()=>Gr,Trello:()=>de,default:()=>bn,isFetch:()=>ve});module.exports=zr(yn);var Wt=require("diff");var Nt=(r=>(r.Build="build",r.Production="production",r.Staging="staging",r.Test="test",r))(Nt||{}),we=(p=>(p.ActionRequired="ACTION_REQUIRED",p.Cancelled="CANCELLED",p.Error="ERROR",p.Failed="FAILED",p.Pending="PENDING",p.Running="RUNNING",p.Skipped="SKIPPED",p.Success="SUCCESS",p.Warning="WARNING",p.OptionalActionRequired="OPTIONAL_ACTION_REQUIRED",p))(we||{}),re=(o=>(o.MergeCommit="MERGE_COMMIT",o.Rebase="REBASE",o.RebaseThenMergeCommit="REBASE_THEN_MERGE_COMMIT",o.FastForward="FAST_FORWARD",o.Squash="SQUASH",o))(re||{}),Z=(t=>(t.Open="OPEN",t.Closed="CLOSED",t.Merged="MERGED",t))(Z||{}),J=(r=>(r.Approved="APPROVED",r.ChangesRequested="CHANGES_REQUESTED",r.Commented="COMMENTED",r.ReviewRequested="REVIEW_REQUESTED",r))(J||{}),Y=(u=>(u.Behind="BEHIND",u.Blocked="BLOCKED",u.Conflicts="CONFLICTS",u.FailingChecks="FAILING_CHECKS",u.Mergeable="MERGEABLE",u.Unknown="UNKNOWN",u.UnknownAndBlocked="UNKNOWN_AND_BLOCKED",u.Unstable="UNSTABLE",u))(Y||{}),et=(t=>(t.ADDED="ADDED",t.DELETED="DELETED",t.UNMODIFIED="UNMODIFIED",t))(et||{});var _t={APPROVED:0,COMMENTED:1,REVIEW_REQUESTED:2,CHANGES_REQUESTED:3},F=s=>!s||s.length===0?null:s.reduce((n,e)=>_t[e.state]>_t[n]?e.state:n,"APPROVED");var tt=(a=>(a[a.Unknown=0]="Unknown",a[a.Active=1]="Active",a[a.Fixed=2]="Fixed",a[a.WontFix=3]="WontFix",a[a.Closed=4]="Closed",a[a.ByDesign=5]="ByDesign",a[a.Pending=6]="Pending",a))(tt||{});var D=100;var Ft=globalThis.fetch;var Hr=async s=>{let n=s.headers.get("content-type")||"",e=null;if(n.startsWith("application/json")){let o=await s.text();e=o.trim().length>0?JSON.parse(o):null}else if(n.startsWith("text/")||n==="")e=await s.text();else if(n.startsWith("application/vnd.github.raw+json")||n.startsWith("application/octet-stream"))e=await s.arrayBuffer();else throw new Error(`Unsupported content-type: ${n}`);let t={};s.headers.forEach((o,i)=>{t[i]=o});let r={body:e,headers:t,status:s.status,statusText:s.statusText};if(!s.ok){let o=new Error(s.statusText);throw Object.assign(o,{response:r}),o}return r},rt=s=>async({url:n,...e})=>{let t=await s(n,e);return Hr(t)};var ve=(s,n=!1)=>s.name==="fetch"||n;var x=class{constructor(n){let e=n?.request||Ft;this.config={...n,request:ve(e,n?.forceIsFetch)?rt(e):e}}updateConfig(n){this.config={...this.config,...n,request:n.request&&ve(n.request,n?.forceIsFetch??this.config.forceIsFetch)?rt(n.request):this.config.request}}},T=class extends x{};var b=(s,n)=>{let e={};return s&&(e.Authorization=`${n?"Basic":"Bearer"} ${s}`),e},Qt=s=>s?s.reduce((n,e)=>(n[e]=!0,n),{}):void 0,V=(s,n,e)=>!s||n.some(t=>s[t])?e:"",jt=async s=>{let n=[],e=!0,t;for(;e;){let r=await s(t);n=n.concat(r.data),e=!!r?.pageInfo?.hasNextPage,t=r?.pageInfo?.endCursor||r?.pageInfo?.nextPage}return n};async function st(s){return(await Promise.allSettled(s)).map(e=>Wr(e)).filter(e=>e!=null)}function Wr(s,n=void 0){return s?.status==="fulfilled"?s.value:n}var Jr="https://app.vssps.visualstudio.com/_apis",Vr="https://vssps.dev.azure.com/",Kr="https://dev.azure.com",P=(s,n={})=>b(n.token||s.token,n.isPAT||s.isPAT),Bt=s=>s.url.replace("/_apis/git/repositories/","/_git/").replace(`/${s.repository.project.id}/`,`/${encodeURIComponent(s.repository.project.name)}/`).replace(`/${s.repository.id}/`,`/${encodeURIComponent(s.repository.name)}/`).replace("/pullRequests/","/pullrequest/"),nt=(s,n)=>{let e=n.baseUrl||s.baseUrl||Jr;return e=e.replace(/\/$/,""),e},S=(s,n)=>{let e=n.baseUrl||s.baseUrl||Kr;return e=e.replace(/\/$/,""),e},ot=(s,n)=>{let e=n.baseUrl||s.baseUrl||Vr;return e=e.replace(/\/$/,""),e};var Xr={active:"OPEN",completed:"MERGED",abandoned:"CLOSED"},Zr=s=>{if(typeof s!="string")return s;let n=s.charAt(0).toUpperCase()+s.slice(1);return tt[n]??0},Yr=new Set([2,3,4,5]),es={10:"APPROVED",5:"APPROVED",0:"REVIEW_REQUESTED",[-5]:"CHANGES_REQUESTED",[-10]:"CHANGES_REQUESTED"},ee=s=>({id:s.id,name:s.displayName??null,username:(s.uniqueName||s.displayName)??null,email:null,avatarUrl:s.imageUrl??null,url:null}),qe=s=>s.startsWith("refs/heads/")?s.replace("refs/heads/",""):s,ts=s=>{switch(s){case"conflicts":return"CONFLICTS";case"failure":return"FAILING_CHECKS";case"rejectedByPolicy":return"BLOCKED";case"succeeded":return"MERGEABLE";case"notSet":case"queued":default:return"UNKNOWN"}},it=(s,n,e,t,r,o)=>`${s}|${n}|${e}|${t}|${r}|${o}`,Mt=s=>{let n=s.split("|");if(n.length!==6)throw new Error("Invalid Azure comment ID format");return{namespace:n[0],project:n[1],repoName:n[2],prId:n[3],threadId:n[4],commentId:n[5]}},zt=(s,n,e,t,r)=>`${s}|${n}|${e}|${t}|${r}`,at=s=>{let n=s.split("|");if(n.length!==5)throw new Error("Invalid Azure thread ID format");return{namespace:n[0],project:n[1],repoName:n[2],prId:n[3],threadId:n[4]}},ge=(s,n)=>{let e=[],t=[];return n.reviewers.forEach(r=>{let o={reviewer:ee(r),state:es[r.vote??0]||"REVIEW_REQUESTED"};r.isRequired&&e.push(o),t.push(o)}),{id:n.pullRequestId.toString(),title:n.title,description:n.description??null,number:n.codeReviewId,state:Xr[n.status],isDraft:n.isDraft,commentCount:null,upvoteCount:null,author:ee(n.createdBy),createdDate:new Date(n.creationDate),updatedDate:new Date(n.closedDate||n.creationDate),closedDate:n.closedDate?new Date(n.closedDate):null,mergedDate:n.closedDate&&n.status==="completed"?new Date(n.closedDate):null,repository:{id:n.repository.id,name:n.repository.name,project:n.repository.project.name,owner:{login:s},remoteInfo:null},headCommit:{buildStatuses:null},baseRef:{name:qe(n.targetRefName),oid:n.lastMergeTargetCommit.commitId},headRef:{name:qe(n.sourceRefName),oid:n.lastMergeSourceCommit.commitId},url:Bt(n),assignees:n.reviewers.map(ee),reviews:t,reviewDecision:F(e),additions:null,deletions:null,fileCount:null,commitCount:null,headRepository:n.forkSource?{id:n.forkSource.repository.id,name:n.forkSource.repository.name,project:void 0,owner:{login:s},remoteInfo:null}:{id:n.repository.id,name:n.repository.name,project:n.repository.project.name,owner:{login:s},remoteInfo:null},mergeableState:ts(n.mergeStatus),labels:n.labels?.map(r=>({color:null,description:null,id:r.id,name:r.name}))??[],permissions:null}},Ht=(s,n)=>({id:n.id,name:n.name,namespace:s,project:n.project.name,projectId:n.project.id,webUrl:n.webUrl,httpsUrl:n.remoteUrl,sshUrl:n.sshUrl,defaultBranch:n.defaultBranch?{name:qe(n.defaultBranch)}:null,permissions:null}),rs=(s,n,e,t)=>{let r=e.fields,o=r["System.AssignedTo"],i=r["System.State"],a=r["System.WorkItemType"],u;return i&&a&&(u=t[a]?.[i]),{id:e.id.toString(),number:e.id.toString(),title:r["System.Title"],commentCount:r["System.CommentCount"],author:{avatarUrl:r["System.CreatedBy"]._links?.avatar?.href??null,email:null,id:r["System.CreatedBy"].id,name:r["System.CreatedBy"].uniqueName??null,username:r["System.CreatedBy"].displayName??null,url:null},closedDate:r["Microsoft.VSTS.Common.ClosedDate"]?new Date(r["Microsoft.VSTS.Common.ClosedDate"]):null,createdDate:new Date(r["System.CreatedDate"]),updatedDate:new Date(r["System.ChangedDate"]),url:e._links.html.href,assignees:o?[{avatarUrl:o._links?.avatar?.href??null,email:null,id:o.id,name:o.uniqueName??null,username:o.displayName??null,url:null}]:[],description:r["System.Description"]??null,state:{name:u?.title||i,color:null},type:r["System.WorkItemType"],repository:null,project:{namespace:s,name:n,resourceId:null,key:null,id:null},upvoteCount:0,labels:e.fields["System.Tags"]?.split(";").map(l=>({color:null,description:null,id:null,name:l.trim()}))??[]}},se=class extends T{constructor(){super(...arguments);this.cachedUserIds=new Map;this.inflightUserIds=new Map}getCurrentUserId(e,t){let r=JSON.stringify([e,t.token??null,t.isPAT??this.config.isPAT??!1,t.baseUrl??null]),o=this.cachedUserIds.get(r);if(o)return Promise.resolve(o);let i=this.inflightUserIds.get(r);if(i)return i;let a=this.fetchCurrentUserId(e,t,r);return this.inflightUserIds.set(r,a),a}async fetchCurrentUserId(e,t,r){try{let o=await this.getCurrentUserForInstance({namespace:e},t);return this.cachedUserIds.set(r,o.data.id),o.data.id}finally{this.inflightUserIds.delete(r)}}getRepoApiUrl(e,t,r,o){return`${S(this.config,o)}/${encodeURIComponent(e)}/${encodeURIComponent(t)}/_apis/git/repositories/${encodeURIComponent(r)}`}async getCurrentUser(e={},t={}){if(t.isPAT||this.config.isPAT)throw new Error("Azure DevOps does not support PATs for this function.");let r=`${nt(this.config,t)}/profile/profiles/me`,o=await this.config.request({url:r,headers:P(this.config,t)});return{data:{id:o.body.id,name:o.body.displayName,username:o.body.displayName,email:o.body.emailAddress,avatarUrl:null,url:null}}}async getCurrentUserForInstance(e,t={}){let o=(await this.config.request({url:`${S(this.config,t)}/${encodeURIComponent(e.namespace)}/_apis/ConnectionData`,headers:P(this.config,t)})).body.authorizedUser;if(o.providerDisplayName==="Anonymous")throw new Error("Current user not found.");return{data:{id:o.id,name:o.providerDisplayName,username:o.providerDisplayName,email:o.properties.Account.$value,avatarUrl:null,url:null}}}async getUserForCommit(e,t={}){if(!e.repo.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let o=(await this.config.request({url:`${S(this.config,t)}/${encodeURIComponent(e.repo.namespace)}/${encodeURIComponent(e.repo.project)}/_apis/git/repositories/${encodeURIComponent(e.repo.name)}/commits/${e.oid}`,headers:P(this.config,t)})).body.author;return{data:{name:o.name,email:o.email,avatarUrl:o.imageUrl}}}async getOrgsForUser(e,t={}){let r=`${nt(this.config,t)}/accounts?memberId=${e.userId}&api-version=6.0`;return{data:(await this.config.request({url:r,headers:P(this.config,t)})).body.value.map(i=>({id:i.accountId,name:i.accountName}))}}async getCollectionsForUser(e,t={}){let r=`${S(this.config,t)}/_apis/projectCollections`;return{data:(await this.config.request({url:r,headers:P(this.config,t)})).body.value.map(i=>({id:i.id,name:i.name}))}}async getAzureProjects(e,t={}){let r=new URL(`${S(this.config,t)}/${encodeURIComponent(e.namespace)}/_apis/projects`);r.searchParams.set("$top",D.toString()),e.cursor&&r.searchParams.set("$skip",e.cursor);let o=await this.config.request({url:r.toString(),headers:P(this.config,t)}),i=o.headers["x-ms-continuationtoken"];return{pageInfo:{hasNextPage:!!i,endCursor:i||null},data:o.body.value.map(a=>({id:a.id,name:a.name,namespace:e.namespace}))}}async getAzureProjectScopeDescriptor(e,t={}){let{namespace:r,projectId:o}=e;return{data:{scope:(await this.config.request({url:`${ot(this.config,t)}/${encodeURIComponent(r)}/_apis/graph/descriptors/${o}?api-version=6.0`,headers:P(this.config,t)})).body.value}}}async getAzureGraphAccountsForAzureProject(e,t={}){let{namespace:r,projectScopeDescriptor:o,cursor:i}=e,a=new URL(`${ot(this.config,t)}/${encodeURIComponent(r)}/_apis/graph/users`);o&&a.searchParams.set("scopeDescriptor",o),i&&a.searchParams.set("continuationToken",i);let u=await this.config.request({url:a.toString(),headers:P(this.config,t)}),l=u.headers["x-ms-continuationtoken"];return{pageInfo:{endCursor:l||null,hasNextPage:!!l},data:u.body.value.map(p=>({avatarUrl:p._links?.avatar?.href??null,descriptor:p.descriptor??null,email:p.mailAddress??null,name:p.displayName??null,storageKeyURL:p._links?.storageKey?.href??null,username:p.displayName??null}))}}async getAccountFromAzureGraphAccount(e,t={}){let{azureGraphAccount:r}=e;if(!r.storageKeyURL)throw new Error("Expected 'storageKeyURL' to not be null for 'azureGraphAccount'");let o=await this.config.request({url:r.storageKeyURL,headers:P(this.config,t)});return{data:{avatarUrl:r.avatarUrl,email:r.email,id:o.body.value,name:r.name,username:r.username,url:null}}}async getAccountsFromAzureGraphAccounts(e,t={}){let r=[];for(let o of e.azureGraphAccounts){let i=await this.getAccountFromAzureGraphAccount({azureGraphAccount:o},t);r.push(i.data)}return{data:r}}async getRepo(e,t={}){if(!e.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let r=await this.config.request({url:`${S(this.config,t)}/${encodeURIComponent(e.namespace)}/${encodeURIComponent(e.project)}/_apis/git/repositories/${encodeURIComponent(e.name)}`,headers:P(this.config,t)});return{data:Ht(e.namespace,r.body)}}async getRepos(e,t={}){let r=[],o=[];return await Promise.all(e.map(async i=>{try{let a=await this.getRepo(i,t);r.push(a.data)}catch(a){o.push({input:i,error:a})}})),{data:r,errors:o}}async getReposForAzureProject(e,t={}){if(!e.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');return{data:(await this.config.request({url:`${S(this.config,t)}/${encodeURIComponent(e.namespace)}/${encodeURIComponent(e.project)}/_apis/git/repositories`,headers:P(this.config,t)})).body.value.map(o=>Ht(e.namespace,o))}}async getRefs(e,t,r={}){if(!t.repo.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let o=new URL(`${S(this.config,r)}/${encodeURIComponent(t.repo.namespace)}/${encodeURIComponent(t.repo.project)}/_apis/git/repositories/${encodeURIComponent(t.repo.name)}/refs`);o.searchParams.set("filter",e),o.searchParams.set("$top",D.toString()),t.cursor&&o.searchParams.set("continuationToken",t.cursor);let i=await this.config.request({url:o.toString(),headers:P(this.config,r)}),a=i.headers["x-ms-continuationtoken"];return{pageInfo:{hasNextPage:!!a,endCursor:a||null},data:i.body.value.map(u=>({name:qe(u.name),commit:{oid:u.objectId,authoredDate:null,committedDate:null}}))}}async getBranches(e,t={}){return this.getRefs("heads",e,t)}async getTags(e,t={}){return this.getRefs("tags",e,t)}async getPullRequestsForRepoBase(e,t={},r=100){let{page:o,repo:i,assigneeLogins:a,authorLogin:u}=e||{},l=o||1;if(!i.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let p="searchCriteria.status=1";return a&&a.length&&(p+=`&searchCriteria.reviewerId=${a[0]}`),u&&(p+=`&searchCriteria.creatorId=${u}`),await this.config.request({url:`${S(this.config,t)}/${encodeURIComponent(i.namespace)}/${encodeURIComponent(i.project||"")}/_apis/git/repositories/${encodeURIComponent(i.name)}/pullRequests?${p}&%24top=${r}&%24skip=${(l-1)*r}`,headers:P(this.config,t)})}async getPullRequestsForRepo(e,t={}){let o=e.page||1,i=await this.getPullRequestsForRepoBase(e,t,100);return{pageInfo:{hasNextPage:i.body.value.length===100,nextPage:o+1},data:i.body.value.map(a=>ge(e.repo.namespace,a))}}async getPullRequestsForRepos(e,t={}){if(!e.repos.every(i=>i.project))throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let{repos:r}=e||{},o=[];return await Promise.all(r.map(async i=>{try{(await this.getPullRequestsForRepoBase({repo:i,...e},t)).body.value.forEach(u=>{o.push(ge(i.namespace,u))})}catch(a){if(a.statusCode!==404&&a.statusCode!==401)throw a}})),{data:o}}async getPullRequestsForProjectBase(e,t={},r=100){let{namespace:o,project:i,page:a,assigneeLogins:u,authorLogin:l,repo:p}=e;if(p?.project&&p.project!==i)throw new Error("Could not fetch pull requests, project mismatch");let c=a||1,d=new URL(`${S(this.config,t)}/${encodeURIComponent(o)}/${encodeURIComponent(i)}/_apis/git/pullRequests`);return d.searchParams.set("searchCriteria.status","1"),d.searchParams.set("$top",r.toString()),d.searchParams.set("$skip",((c-1)*r).toString()),p?.id&&p?.project===i&&d.searchParams.set("searchCriteria.repositoryId",p.id),u&&u.length&&d.searchParams.set("searchCriteria.reviewerId",u[0]),l&&d.searchParams.set("searchCriteria.creatorId",l),await this.config.request({url:d.toString(),headers:P(this.config,t)})}async getPullRequestsForProject(e,t={}){let o=e.page||1,i=await this.getPullRequestsForProjectBase(e,t,100);return{pageInfo:{hasNextPage:i?.body.value.length===100,nextPage:o+1},data:i?.body.value.map(a=>ge(e.namespace,a))||[]}}async getPullRequestsForProjects(e,t={}){let{projects:r}=e||{},o=[];return await Promise.all(r.map(async i=>{try{(!e.repo||e.repo.project&&e.repo.project===i.project)&&(await this.getPullRequestsForProjectBase({...i,...e},t))?.body.value.forEach(u=>{o.push(ge(i.namespace,u))})}catch(a){if(a.statusCode!==404&&a.statusCode!==401)throw a}})),{data:o}}async getAzurePullRequestLastMergeStatus(e,t={}){if(!e.repo.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let{repo:{namespace:r,project:o,name:i},pullRequestId:a}=e,u=await this.config.request({url:`${S(this.config,t)}/${encodeURIComponent(r)}/${encodeURIComponent(o||"")}/_apis/git/repositories/${i}/pullrequests/${a}?includeCommits=true?api-version=6.0`,headers:{...P(this.config,t)}});if(!u.body.mergeStatus)throw new Error("Could not fetch pull request");return{data:u.body.mergeStatus}}async updatePullRequest(e,t,r){return await this.config.request({method:"PATCH",url:`${S(this.config,r)}/${encodeURIComponent(e.repository.owner.login)}/${encodeURIComponent(e.repository.project)}/_apis/git/repositories/${e.repository.name}/pullrequests/${e.id}?api-version=6.0`,body:t,headers:{...P(this.config,r),"Content-Type":"application/json"}})}async closePullRequest(e,t={}){let{pullRequest:r}=e,o={status:"abandoned"};if(!(await this.updatePullRequest(r,JSON.stringify(o),t)).body.status)throw new Error("Could not close pull request")}async mergePullRequest(e,t={}){let{pullRequest:r,mergeStrategy:o}=e,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 a={completionOptions:{mergeStrategy:i},lastMergeSourceCommit:{commitId:r.headRef?.oid},status:"completed"};if(!(await this.updatePullRequest(r,JSON.stringify(a),t)).body.status)throw new Error("Could not merge pull request")}async addPullRequestLabel(e,t={}){let{pullRequest:r,label:o}=e;if(!r.repository.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let i={name:o.name};if(!(await this.config.request({method:"POST",url:`${S(this.config,t)}/${encodeURIComponent(r.repository.owner.login)}/${encodeURIComponent(r.repository.project)}/_apis/git/repositories/${r.repository.name}/pullrequests/${r.id}/labels?api-version=6.0`,body:JSON.stringify(i),headers:{...P(this.config,t),"Content-Type":"application/json"}})).body.id)throw new Error("Could not add pull request label")}async removePullRequestLabel(e,t={}){let{pullRequest:r,label:o}=e;if(!r.repository.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');await this.config.request({method:"DELETE",url:`${S(this.config,t)}/${encodeURIComponent(r.repository.owner.login)}/${encodeURIComponent(r.repository.project)}/_apis/git/repositories/${r.repository.name}/pullrequests/${r.id}/labels/${encodeURIComponent(o.name)}?api-version=6.0`,headers:{...P(this.config,t)}})}async setPullRequestLabels(e,t={}){let{pullRequest:r,labels:o}=e;if(!r.repository.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let i=r.labels;if(!i)throw new Error('Azure DevOps requires "labels" for this function.');for(let a of o)i.find(u=>u.id===a.id)||await this.addPullRequestLabel({pullRequest:r,label:a},t);for(let a of i)o.find(u=>a.id===u.id)||await this.removePullRequestLabel({pullRequest:r,label:a},t)}async setPullRequestAsDraft(e,t={}){let{pullRequest:r,isDraft:o}=e,i={isDraft:o};if(!(await this.updatePullRequest(r,JSON.stringify(i),t)).body.status)throw new Error("Could not set the pull request as draft")}async addPullRequestReviewer(e,t={}){let{pullRequest:r,reviewer:o,isRequired:i}=e,a={id:o.id,isRequired:i};if(!(await this.config.request({method:"PUT",url:`${S(this.config,t)}/${encodeURIComponent(r.repository.owner.login)}/${encodeURIComponent(r.repository.project)}/_apis/git/repositories/${r.repository.name}/pullrequests/${r.id}/reviewers/${o.id}?api-version=6.0`,body:JSON.stringify(a),headers:{...P(this.config,t),"Content-Type":"application/json"}})).body.id)throw new Error("Could not add pull request reviewer")}async removePullRequestReviewer(e,t={}){let{pullRequest:r,reviewer:o}=e;await this.config.request({method:"DELETE",url:`${S(this.config,t)}/${encodeURIComponent(r.repository.owner.login)}/${encodeURIComponent(r.repository.project)}/_apis/git/repositories/${r.repository.name}/pullrequests/${r.id}/reviewers/${o.id}?api-version=6.0`,headers:{...P(this.config,t),Accept:"application/json"}})}async setPullRequestReviewers(e,t={}){let{pullRequest:r,reviewers:o}=e;for(let i of o)r.assignees.find(a=>a.id===i.id)||await this.addPullRequestReviewer({pullRequest:r,reviewer:i,isRequired:!0},t);for(let i of r.assignees)o.find(a=>i.id===a.id)||await this.removePullRequestReviewer({pullRequest:r,reviewer:i},t)}async getIssuesForAzureProject(e,t={}){let{page:r,assigneeLogins:o,authorLogin:i,mentionLogin:a,labelNames:u,statusByWorkItemIdByStatusId:l}=e||{},p=r||1,c=200,d=["[Microsoft.VSTS.Common.ClosedDate] = ''","[System.TeamProject] = @project","[Microsoft.VSTS.Common.ResolvedDate] = ''"];i&&d.push(`[System.CreatedBy] = '${i.replace("'","''")}'`),o&&o[0]&&d.push(`[System.AssignedTo] = '${o[0].replace("'","''")}'`),a&&d.push("[System.Id] IN (@recentMentions)"),u&&u.forEach(R=>d.push(`[System.Tags] Contains '${R}'`));let m=`Select [Microsoft.VSTS.Common.ClosedDate], [Microsoft.VSTS.Common.ResolvedDate] From WorkItems Where ${d.join(" AND ")} order by [System.CreatedDate] desc`,g=await this.config.request({url:`${S(this.config,t)}/${encodeURIComponent(e.namespace)}/${encodeURIComponent(e.project)}/_apis/wit/wiql?api-version=6.0`,body:JSON.stringify({query:m}),method:"POST",headers:{...P(this.config,t),"Content-Type":"application/json"}}),y=g.body.workItems.slice((p-1)*c,c*p).map(R=>R.id);if(y.length==0)return{pageInfo:{hasNextPage:!1,nextPage:null},data:[]};let I=await this.config.request({url:`${S(this.config,t)}/${encodeURIComponent(e.namespace)}/${encodeURIComponent(e.project)}/_apis/wit/workitemsbatch?api-version=6.0`,body:JSON.stringify({ids:y,$expand:"Links"}),method:"POST",headers:{...P(this.config,t),"Content-Type":"application/json"}});return{pageInfo:{hasNextPage:g.body.workItems.length>c*p,nextPage:p+1},data:I.body.value.map(R=>rs(e.namespace,e.project,R,l||{}))}}async getPermissionsForRepos(e,t={}){let{namespace:r,repos:o}=e,i={4:["canPush","canCreateWebhook"],1024:["isAdmin"],2048:["isAdmin"],4096:["isAdmin"],8192:["isAdmin"]},a=c=>{let d="2e9eb7ed-3c0a-47d4-87c1-0ffdd275fd87",m=`repoV2/${c.projectId}/${c.id}`;return Object.keys(i).map(g=>({securityNamespaceId:d,token:m,permissions:g}))},u={alwaysAllowAdministrators:!1,evaluations:o.flatMap(a)};return{data:(await this.config.request({method:"POST",url:`${S(this.config,t)}/${encodeURIComponent(r)}/_apis/security/permissionevaluationbatch?api-version=7.0`,body:JSON.stringify(u),headers:{...P(this.config,t),"Content-Type":"application/json"}})).body.evaluations.reduce((c,d)=>{let[,m,g]=d.token.split("/"),y=`${m}/${g}`,I=i[d.permissions];for(let R of I)c[y]===void 0&&(c[y]={canCreateWebhook:!0,canPush:!0,isAdmin:!0}),d.value===!1&&(c[y][R]=!1);return c},{})}}async decorateReposWithPermissions(e,t={}){let{namespace:r,repos:o}=e,i=await this.getPermissionsForRepos({namespace:r,repos:o},t);return{data:o.map(a=>({...a,permissions:i.data[`${a.projectId}/${a.id}`]}))}}async updateIssue(e,t,r={}){return await this.config.request({method:"PATCH",url:`${S(this.config,r)}/${encodeURIComponent(e.project.namespace)}/${encodeURIComponent(e.project.name)}/_apis/wit/workitems/${e.id}?api-version=6.0`,body:JSON.stringify(t),headers:{...P(this.config,r),"Content-Type":"application/json-patch+json"}})}async setIssueStatus(e,t={}){let{issue:r,status:o}=e,i=[{op:"add",path:"/fields/System.State",value:o.name}];if(!(await this.updateIssue(r,i,t)).body.fields?.["System.State"])throw new Error("Could not set issue status")}async setIssueAssignee(e,t={}){let{issue:r,assignee:o}=e,i=[{op:"add",path:"/fields/System.AssignedTo",value:o?.name??""}];if(!(await this.updateIssue(r,i,t)).body.fields?.["System.State"])throw new Error("Could not set issue assignee")}async setIssueLabels(e,t={}){let{issue:r,labels:o}=e,a=[{op:"replace",path:"/fields/System.Tags",value:o.map(l=>l.name).join(";")}];if(!(await this.updateIssue(r,a,t)).body.fields?.["System.Tags"])throw new Error("Could not set issue tags")}async getIssueTypesForAzureProject(e,t={}){if(!e.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let{namespace:r,project:o}=e;return{data:(await this.config.request({url:`${S(this.config,t)}/${encodeURIComponent(r)}/${encodeURIComponent(o||"")}/_apis/wit/workitemtypes?api-version=6.0`,headers:{...P(this.config,t)}})).body.value}}async getLabelsForProject(e,t={}){let{namespace:r,project:o}=e;return{data:(await this.config.request({url:`${S(this.config,t)}/${encodeURIComponent(r)}/${encodeURIComponent(o||"")}/_apis/wit/tags?api-version=6.0`,headers:{...P(this.config,t)}})).body.value.map(a=>({color:null,description:null,id:a.id,name:a.name,url:a.url}))}}async getPullRequestForRepo(e,t={}){let{repo:r,number:o}=e;if(!r.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let i=await this.config.request({url:`${this.getRepoApiUrl(r.namespace,r.project,r.name,t)}/pullrequests/${o}?api-version=7.1`,headers:P(this.config,t)});return{data:ge(r.namespace,i.body)}}async getMergeBase(e,t={}){if(!e.repo.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let r=await this.config.request({url:`${this.getRepoApiUrl(e.repo.namespace,e.repo.project,e.repo.name,t)}/commits/${encodeURIComponent(e.base)}/mergebases?otherCommitId=${encodeURIComponent(e.head)}&api-version=7.1`,headers:P(this.config,t)});if(!r.body.value?.length)throw new Error("No merge base found between the specified commits.");return{data:r.body.value[0].commitId}}async getFileContents(e,t={}){if(!e.repo.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let r=await this.config.request({url:`${this.getRepoApiUrl(e.repo.namespace,e.repo.project,e.repo.name,t)}/items?path=${encodeURIComponent(e.path)}&versionDescriptor[version]=${encodeURIComponent(e.ref)}&versionDescriptor[versionType]=commit&api-version=7.1`,headers:{...P(this.config,t),Accept:"application/octet-stream"}});return{data:new Blob([r.body])}}async getPullRequestDiff(e,t={}){if(!e.repo.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let r=this.getRepoApiUrl(e.repo.namespace,e.repo.project,e.repo.name,t),o=P(this.config,t),i={...o,Accept:"application/octet-stream"},[a,u]=await Promise.all([this.config.request({url:`${r}/pullrequests/${e.pullRequestId}?api-version=7.1`,headers:o}),this.config.request({url:`${r}/pullrequests/${e.pullRequestId}/iterations?api-version=7.1`,headers:o})]),l=a.body.lastMergeTargetCommit.commitId,p=a.body.lastMergeSourceCommit.commitId,c=u.body.value;if(c.length===0)return"";let d=c[c.length-1],g=(await this.config.request({url:`${r}/pullrequests/${e.pullRequestId}/iterations/${d.id}/changes?api-version=7.1`,headers:o})).body.changeEntries;if(g.length===0)return"";let y=5,I=[],R=new TextDecoder,q=v=>v instanceof ArrayBuffer?R.decode(v):typeof v=="string"?v:"",C=async(v,ce)=>{try{let me=await this.config.request({url:`${r}/items?path=${encodeURIComponent(v)}&versionDescriptor[version]=${encodeURIComponent(ce)}&versionDescriptor[versionType]=commit&includeContent=true&api-version=7.1`,headers:i});return q(me.body)}catch{return""}},N=1,E=8,U=16;for(let v=0;v<g.length;v+=y){let ce=g.slice(v,v+y),me=await Promise.all(ce.map(async _=>{let be=_.item.path,ye=(_.changeType&N)!==0,Pe=(_.changeType&E)!==0,xt=(_.changeType&U)!==0&&_.item.originalPath?_.item.originalPath:be,kt=be,[Nr,_r]=await Promise.all([ye?Promise.resolve(""):C(xt,l),Pe?Promise.resolve(""):C(kt,p)]);return(0,Wt.createTwoFilesPatch)(`a${xt}`,`b${kt}`,Nr,_r)}));I.push(...me)}return I.join(`
2
+ `)}getPullRequestWriteHeaders(e){return{...P(this.config,e),"Content-Type":"application/json"}}setReviewerVote(e,t,r,o,i){return this.config.request({method:"PUT",url:`${e}/pullRequests/${t}/reviewers/${encodeURIComponent(r)}?api-version=7.1`,headers:this.getPullRequestWriteHeaders(i),body:JSON.stringify({vote:o})})}postPullRequestThread(e,t,r,o){return this.config.request({method:"POST",url:`${e}/pullRequests/${t}/threads?api-version=7.1`,headers:this.getPullRequestWriteHeaders(o),body:JSON.stringify({comments:[{parentCommentId:0,content:r,commentType:1}],status:1})})}async getCommentsForPullRequest(e,t={}){if(!e.repo.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let r=this.getRepoApiUrl(e.repo.namespace,e.repo.project,e.repo.name,t),o=P(this.config,t),i=await this.config.request({url:`${r}/pullRequests/${e.pullRequestNumber}/threads?api-version=7.1`,headers:o}),a=[];for(let u of i.body.value)if(!(u.isDeleted||u.threadContext))for(let l of u.comments)l.commentType==="system"||l.isDeleted||a.push({id:it(e.repo.namespace,e.repo.project,e.repo.name,e.pullRequestNumber,u.id,l.id),author:l.author?ee(l.author):null,body:l.content||"",createdAt:l.publishedDate?new Date(l.publishedDate):null,url:""});return{data:a,pageInfo:{hasNextPage:!1,endCursor:null}}}async addCommentToPullRequest(e,t={}){if(!e.pullRequest.repository.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let r=this.getRepoApiUrl(e.pullRequest.repository.owner.login,e.pullRequest.repository.project,e.pullRequest.repository.name,t);await this.postPullRequestThread(r,e.pullRequest.id,e.comment,t)}async addInlineCommentToPullRequest(e,t={}){if(!e.pullRequest.repository.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let r=this.getRepoApiUrl(e.pullRequest.repository.owner.login,e.pullRequest.repository.project,e.pullRequest.repository.name,t),o=this.getPullRequestWriteHeaders(t);if(e.threadId){let p=at(e.threadId),c=e.pullRequest.repository.owner.login,d=e.pullRequest.repository.project,m=e.pullRequest.repository.name,g=String(e.pullRequest.id);if(p.namespace!==c||p.project!==d||p.repoName!==m||p.prId!==g)throw new Error(`Azure thread ID context mismatch: threadId targets ${p.namespace}/${p.project}/${p.repoName} pull request ${p.prId}, but input.pullRequest targets ${c}/${d}/${m} pull request ${g}.`);let I=(await this.config.request({url:`${r}/pullRequests/${e.pullRequest.id}/threads/${p.threadId}?api-version=7.1`,headers:P(this.config,t)})).body.comments?.find(q=>q.parentCommentId===0);if(!I)throw new Error(`Could not determine root comment for Azure DevOps thread ${p.threadId}.`);let R=await this.config.request({method:"POST",url:`${r}/pullRequests/${e.pullRequest.id}/threads/${p.threadId}/comments?api-version=7.1`,headers:o,body:JSON.stringify({content:e.comment,parentCommentId:I.id,commentType:1})});return it(c,d,m,Number(g),Number(p.threadId),R.body.id)}let i=e.path.startsWith("/")?e.path:`/${e.path}`,a={line:e.line,offset:1},u={filePath:i};e.side==="LEFT"?(u.leftFileStart=a,u.leftFileEnd=a):(u.rightFileStart=a,u.rightFileEnd=a);let l=await this.config.request({method:"POST",url:`${r}/pullRequests/${e.pullRequest.id}/threads?api-version=7.1`,headers:o,body:JSON.stringify({comments:[{parentCommentId:0,content:e.comment,commentType:1}],status:1,threadContext:u})});return zt(e.pullRequest.repository.owner.login,e.pullRequest.repository.project,e.pullRequest.repository.name,Number(e.pullRequest.id),l.body.id)}async editComment(e,t={}){let r=Mt(e.commentId),o=this.getRepoApiUrl(r.namespace,r.project,r.repoName,t);await this.config.request({method:"PATCH",url:`${o}/pullRequests/${r.prId}/threads/${r.threadId}/comments/${r.commentId}?api-version=7.1`,headers:this.getPullRequestWriteHeaders(t),body:JSON.stringify({content:e.body})})}async editInlineComment(e,t={}){return this.editComment(e,t)}async deleteComment(e,t={}){let r=Mt(e.commentId),o=this.getRepoApiUrl(r.namespace,r.project,r.repoName,t);await this.config.request({method:"DELETE",url:`${o}/pullRequests/${r.prId}/threads/${r.threadId}/comments/${r.commentId}?api-version=7.1`,headers:P(this.config,t)})}async deleteInlineComment(e,t={}){return this.deleteComment(e,t)}async resolveReviewThread(e,t={}){let r=at(e.threadId),o=this.getRepoApiUrl(r.namespace,r.project,r.repoName,t);await this.config.request({method:"PATCH",url:`${o}/pullRequests/${r.prId}/threads/${r.threadId}?api-version=7.1`,headers:this.getPullRequestWriteHeaders(t),body:JSON.stringify({status:2})})}async unresolveReviewThread(e,t={}){let r=at(e.threadId),o=this.getRepoApiUrl(r.namespace,r.project,r.repoName,t);await this.config.request({method:"PATCH",url:`${o}/pullRequests/${r.prId}/threads/${r.threadId}?api-version=7.1`,headers:this.getPullRequestWriteHeaders(t),body:JSON.stringify({status:1})})}async approvePullRequest(e,t={}){if(!e.pullRequest.repository.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let r=e.pullRequest.repository.owner.login,o=this.getRepoApiUrl(r,e.pullRequest.repository.project,e.pullRequest.repository.name,t),i=await this.getCurrentUserId(r,t);await Promise.all([this.setReviewerVote(o,e.pullRequest.id,i,10,t),e.comment?this.postPullRequestThread(o,e.pullRequest.id,e.comment,t):null])}async requestPullRequestChanges(e,t={}){if(!e.pullRequest.repository.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let r=e.pullRequest.repository.owner.login,o=this.getRepoApiUrl(r,e.pullRequest.repository.project,e.pullRequest.repository.name,t),i=await this.getCurrentUserId(r,t);await this.postPullRequestThread(o,e.pullRequest.id,e.comment,t),await this.setReviewerVote(o,e.pullRequest.id,i,-5,t)}async commentOnPullRequest(e,t={}){if(!e.pullRequest.repository.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let r=this.getRepoApiUrl(e.pullRequest.repository.owner.login,e.pullRequest.repository.project,e.pullRequest.repository.name,t);await this.postPullRequestThread(r,e.pullRequest.id,e.comment,t)}async getReviewsForPullRequest(e,t={}){if(!e.repo.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let{namespace:r,project:o,name:i}=e.repo,{pullRequestId:a}=e,u=this.getRepoApiUrl(r,o,i,t),l=P(this.config,t),[p,c]=await Promise.all([this.config.request({url:`${u}/pullRequests/${a}/reviewers?api-version=7.1`,headers:l}),this.config.request({url:`${u}/pullRequests/${a}/threads?api-version=7.1`,headers:l})]),d=(R,q)=>it(r,o,i,a,R,q),m=R=>zt(r,o,i,a,R),g=new Map;for(let R of c.body.value){if(R.isDeleted)continue;let q=R.comments.filter(G=>!G.isDeleted&&G.commentType!=="system"),C=q.find(G=>G.parentCommentId===0)??q[0];if(!C)continue;let N=C.author?.id;if(!N)continue;let E=q.filter(G=>G.id!==C.id),U=R.threadContext,v=U?.rightFileStart?{side:"RIGHT",start:U.rightFileStart,end:U.rightFileEnd}:U?.leftFileStart?{side:"LEFT",start:U.leftFileStart,end:U.leftFileEnd}:null,ce=v?.end?.line??v?.start.line??null,me=v?.start&&v.end&&v.start.line!==v.end.line?v.start.line:null,_=U?.filePath??"",be=_.startsWith("/")?_.slice(1):_,ye={id:d(R.id,C.id),author:C.author?ee(C.author):null,body:C.content??"",createdAt:C.publishedDate?new Date(C.publishedDate):null,url:"",diffLines:[],filename:be,replies:E.map(G=>({id:d(R.id,G.id),author:G.author?ee(G.author):null,body:G.content??"",createdAt:G.publishedDate?new Date(G.publishedDate):null,url:""})),isOutdated:!1,isResolved:Yr.has(Zr(R.status)),line:ce,startLine:me,side:v?.side??null,threadId:m(R.id)},Pe=g.get(N);Pe?Pe.push(ye):g.set(N,[ye])}let y=[],I=new Set;for(let R of p.body.value){if(R.hasDeclined)continue;let q=R.vote??0,C=g.get(R.id);q===0&&!C?.length||(y.push({id:R.id,author:ee(R),body:"",createdAt:null,url:"",reviewComments:C??[]}),I.add(R.id))}for(let[R,q]of g){if(I.has(R)||!q.length)continue;let C=q[0].author;C&&y.push({id:R,author:C,body:"",createdAt:null,url:"",reviewComments:q})}return{data:y}}};var L=(s,n={})=>b(n.token||s.token,n.isPAT||s.isPAT);var $="https://api.bitbucket.org/2.0",ss={OPEN:"OPEN",MERGED:"MERGED",DECLINED:"CLOSED"},Se={owner:4,admin:3,contributor:2,member:1},Ee=s=>({id:s.uuid,name:s.display_name||s.nickname,username:s.nickname||s.display_name,email:null,avatarUrl:s.links.avatar.href,url:s.links.html.href}),Jt=s=>{let n=s.links.clone,e=n?.find(r=>r.name==="ssh"),t=n?.find(r=>r.name==="https");return e&&t?{cloneUrlHTTPS:t.href,cloneUrlSSH:e.href}:null},ut=s=>({id:s.uuid,namespace:s.workspace.slug,name:s.slug,webUrl:s.links.html.href,httpsUrl:s.links.clone.find(n=>n.name==="https")?.href??null,sshUrl:s.links.clone.find(n=>n.name==="ssh")?.href??null,defaultBranch:{name:s.mainbranch.name},permissions:null}),lt=s=>{let n=s.id,e=s.participants?.map(t=>{let r="REVIEW_REQUESTED";return t.approved?r="APPROVED":t.state==="changes_requested"?r="CHANGES_REQUESTED":t.participated_on!==null&&(r="COMMENTED"),{reviewer:Ee(t.user),state:r}})??[];return{id:n.toString(),title:s.title,description:s.description,number:n,state:ss[s.state],isDraft:!1,commentCount:s.comment_count,upvoteCount:null,author:Ee(s.author),createdDate:new Date(s.created_on),updatedDate:new Date(s.updated_on),closedDate:null,mergedDate:null,repository:{id:s.destination.repository.uuid,name:s.destination.repository.name,owner:{login:s.destination.repository.full_name.split("/")[0]},remoteInfo:Jt(s.destination.repository)},headCommit:{buildStatuses:null},baseRef:{name:s.destination.branch.name,oid:s.destination.commit.hash},headRef:{name:s.source.branch.name,oid:s.source.commit.hash},url:s.links.html.href,assignees:null,reviews:e,reviewDecision:F(e),additions:null,deletions:null,fileCount:null,commitCount:null,headRepository:{id:s.source.repository.uuid,name:s.source.repository.name,owner:{login:s.source.repository.full_name.split("/")[0]},remoteInfo:Jt(s.source.repository)},mergeableState:"MERGEABLE",permissions:null}},ns=s=>{switch(s){case"owner":case"admin":return{canCreateWebhook:!0,canPush:!0,isAdmin:!0};case"write":return{canCreateWebhook:!1,canPush:!0,isAdmin:!1};case"read":case"none":return{canCreateWebhook:!1,canPush:!1,isAdmin:!1}}},os=s=>{switch(s){case"owner":case"admin":return{canCreateWebhook:!0,canPush:!0,isAdmin:!0};case"contributor":return{canCreateWebhook:!1,canPush:!0,isAdmin:!1};default:return{canCreateWebhook:!1,canPush:!1,isAdmin:!1}}},ne=class extends x{async refreshToken(n){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 ${n.base64ClientIDColonClientSecret}`},body:`grant_type=refresh_token&refresh_token=${n.refreshToken}`})).body}}async getCurrentUser(n={},e={}){let t=await this.config.request({url:`${$}/user`,headers:L(this.config,e)});return{data:Ee(t.body)}}async getUserForCommit(n,e={}){let r=(await this.config.request({url:`${$}/repositories/${n.repo.namespace}/${n.repo.name}/commit/${n.oid}`,headers:L(this.config,e)})).body.author,o=r.raw.match(/([^<]+)<(.+)>/);return{data:{name:o?o[1].trim():null,email:o?o[2]:null,avatarUrl:r.user?.links.avatar.href||null}}}async getRepo(n,e={}){let t=await this.config.request({url:`${$}/repositories/${n.namespace}/${n.name}`,headers:L(this.config,e)});return{data:ut(t.body)}}async getRepos(n,e={}){let t=[],r=[];return await Promise.all(n.map(async o=>{try{let i=await this.getRepo(o,e);t.push(i.data)}catch(i){r.push({input:o,error:i})}})),{data:t,errors:r}}async getReposForWorkspace(n,e={}){let t=new URL(`${$}/repositories/${encodeURIComponent(n.workspace)}`);t.searchParams.set("page",n.page?.toString()||"1"),t.searchParams.set("pagelen",D.toString()),n.minimumRole&&t.searchParams.set("role",n.minimumRole);let r=await this.config.request({url:t.toString(),headers:L(this.config,e)}),o=!!r.body.next;return{pageInfo:{hasNextPage:o,nextPage:o?r.body.page+1:null},data:r.body.values.map(ut)}}async getAllReposForWorkspace(n,e={}){let t=[],r=1;for(;r!==null;){let o=await this.getReposForWorkspace({workspace:n.workspace,minimumRole:n.minimumRole,page:r},e);t.push(...o.data),r=o.pageInfo.hasNextPage?o.pageInfo.nextPage:null}return t}async getAllReposForWorkspaceWithPermissions(n,e={}){let t=new Map,r=[],o=Se[n.minimumRole||"member"];o<=Se.admin&&r.push("admin"),o<=Se.contributor&&r.push("contributor"),o<=Se.member&&r.push("member");let i=[];for(let a of r){i=await this.getAllReposForWorkspace({workspace:n.workspace,minimumRole:a},e);for(let u of i)t.has(u.id)||t.set(u.id,a)}return{data:i.map(a=>{let u=t.get(a.id)||"member";return{...a,permissions:os(u)}})}}async getReposForCurrentUser(n,e={}){let t=new URL(`${$}/repositories`);t.searchParams.set("role","member"),t.searchParams.set("pagelen",D.toString()),n.cursor&&t.searchParams.set("after",n.cursor);let r=await this.config.request({url:t.toString(),headers:L(this.config,e)}),o=!!r.body.next,i=null;return r.body.next&&(i=new URL(r.body.next).searchParams.get("after")),{pageInfo:{hasNextPage:o,endCursor:i},data:r.body.values.map(ut)}}async getBranches(n,e={}){let t=new URL(`${$}/repositories/${n.repo.namespace}/${n.repo.name}/refs/branches`);t.searchParams.set("page",n.page?.toString()||"1"),t.searchParams.set("pagelen",D.toString());let r=await this.config.request({url:t.toString(),headers:L(this.config,e)}),o=!!r.body.next;return{pageInfo:{hasNextPage:o,nextPage:o?r.body.page+1:null},data:r.body.values.map(i=>{let a=new Date(i.target.date);return{name:i.name,commit:{oid:i.target.hash,authoredDate:a,committedDate:a}}})}}async getTags(n,e={}){let t=new URL(`${$}/repositories/${n.repo.namespace}/${n.repo.name}/refs/tags`);t.searchParams.set("pagelen",D.toString()),n.cursor&&t.searchParams.set("page",n.cursor);let r=await this.config.request({url:t.toString(),headers:L(this.config,e)}),o=!!r.body.next,i=null;return r.body.next&&(i=new URL(r.body.next).searchParams.get("page")),{pageInfo:{hasNextPage:o,endCursor:i},data:r.body.values.map(a=>{let u=new Date(a.target.date);return{name:a.name,commit:{oid:a.target.hash,authoredDate:u,committedDate:u}}})}}async getWorkspacesForCurrentUser(n={},e={}){let t=new URL(`${$}/user/workspaces`);t.searchParams.set("page",n?.page?.toString()||"1"),t.searchParams.set("pagelen","50"),n?.administrator!==void 0&&t.searchParams.set("administrator",n.administrator.toString());let r=await this.config.request({url:t.toString(),headers:L(this.config,e)}),o=!!r.body.next;return{pageInfo:{hasNextPage:o,nextPage:o?r.body.page+1:null},data:r.body.values.map(i=>({id:i.workspace.uuid,slug:i.workspace.slug}))}}async getWorkspacesForUser(n,e={}){let t=new URL(`${$}/user/permissions/workspaces`);t.searchParams.set("page",n.page?.toString()||"1"),t.searchParams.set("pagelen","50");let r=await this.config.request({url:t.toString(),headers:L(this.config,e)}),o=!!r.body.next;return{pageInfo:{hasNextPage:o,nextPage:o?r.body.page+1:null},data:r.body.values.map(i=>({id:i.workspace.uuid,slug:i.workspace.slug,name:i.workspace.name}))}}async getPullRequestsForUserAndWorkspace(n,e={}){let t=new URL(`${$}/workspaces/${n.workspaceSlug}/pullrequests/${n.userId}`);if(t.searchParams.set("fields","+values.participants,+values.destination.repository.links.clone.*,+values.source.repository.links.clone.*"),t.searchParams.set("page",n.page?.toString()||"1"),t.searchParams.set("pagelen","50"),n.repos&&n.repos.length>0){let i=`state = "open" AND (${n.repos.map(a=>`source.repository.full_name = "${a.namespace}/${a.name}"`).join(" OR ")})`;t.searchParams.set("q",i)}let r=await this.config.request({url:t.toString(),headers:L(this.config,e)}),o=!!r.body.next;return{pageInfo:{hasNextPage:o,nextPage:o?r.body.page+1:null},data:r.body.values.map(lt)}}async getPullRequestsForRepoBase(n,e={}){let t=new URL(`${$}/repositories/${encodeURI(n.repo.namespace)}/${encodeURI(n.repo.name)}/pullrequests?state=OPEN`),r=[];n.reviewerId&&r.push(`reviewers.uuid="${n.reviewerId}"`),n.authorLogin&&r.push(`author.uuid="${n.authorLogin}"`);let o='state="OPEN"';return r.length&&(o+=` AND (${r.join(n.useOrFilter?" OR ":" AND ")})`),t.searchParams.set("fields","+values.participants,+values.destination.repository.links.clone.*,+values.source.repository.links.clone.*"),t.searchParams.set("page",n.page?.toString()||"1"),t.searchParams.set("pagelen","50"),t.searchParams.set("q",o),await this.config.request({url:t.toString(),headers:L(this.config,e)})}async getPullRequestsForRepo(n,e={}){let t=[],r=await this.getPullRequestsForRepoBase(n,e);r.body.values.forEach(i=>{t.push(lt(i))});let o=!!r.body.next;return{pageInfo:{hasNextPage:o,nextPage:o?r.body.page+1:null},data:t}}async getPullRequestsForRepos(n,e={}){let t=[];return await Promise.all(n.repos.map(async r=>{try{(await this.getPullRequestsForRepoBase({repo:r,...n},e)).body.values.forEach(i=>{t.push(lt(i))})}catch(o){if(o.statusCode!==404&&o.statusCode!==401)throw o}})),{data:t}}async getAccountsForWorkspace(n,e={}){let t=new URL(`${$}/workspaces/${encodeURI(n.workspace)}/members`);t.searchParams.set("page",n.page?.toString()||"1"),t.searchParams.set("pagelen","100");let r=await this.config.request({url:t.toString(),headers:L(this.config,e)}),o=!!r.body.next;return{pageInfo:{hasNextPage:o,nextPage:o?r.body.page+1:null},data:r.body.values.map(i=>Ee(i.user))}}async getReposPermissionsForCurrentUser(n,e={}){let t=new URL(`${$}/user/permissions/repositories`);t.searchParams.set("page",n.page?.toString()||"1"),t.searchParams.set("pagelen","100");let r=await this.config.request({url:t.toString(),headers:L(this.config,e)}),o=!!r.body.next;return{pageInfo:{hasNextPage:o,nextPage:o?r.body.page+1:null},data:r.body.values.reduce((i,a)=>({...i,[a.repository.uuid]:ns(a.permission)}),{})}}async decorateReposWithPermissions(n,e={}){let t={},r=1;do{let o=await this.getReposPermissionsForCurrentUser({page:r},e);t={...o.data,...t},r=o.pageInfo.hasNextPage?o.pageInfo.nextPage:null}while(r!==null);return{data:n.repos.map(o=>({...o,permissions:t[o.id]??{canCreateWebhook:!1,canPush:!1,isAdmin:!1}}))}}async closePullRequest(n,e={}){let{pullRequest:t}=n;if(!(await this.config.request({method:"POST",url:`${$}/repositories/${t.repository.owner.login}/${t.repository.name}/pullrequests/${t.id}/decline`,headers:L(this.config,e)})).body.title)throw new Error("Could not close pull request")}async mergePullRequest(n,e={}){let{pullRequest:t,mergeStrategy:r}=n,o;switch(r){case"MERGE_COMMIT":{o="merge_commit";break}case"FAST_FORWARD":{o="fast_forward";break}case"SQUASH":{o="squash";break}}let i={merge_strategy:o,type:"pullrequest"};if(!(await this.config.request({method:"POST",url:`${$}/repositories/${t.repository.owner.login}/${t.repository.name}/pullrequests/${t.id}/merge`,body:JSON.stringify(i),headers:{...L(this.config,e),"Content-Type":"application/json"}})).body.title)throw new Error("Could not merge pull request")}async setPullRequestReviewers(n,e={}){let{pullRequest:t,reviewers:r}=n,o={reviewers:r.map(a=>{if(a.username)throw new Error('Bitbucket reviewer requires "username" for this function.');return{username:a.username}})};if(!(await this.config.request({method:"PUT",url:`${$}/repositories/${t.repository.owner.login}/${t.repository.name}/pullrequests/${t.id}`,body:JSON.stringify(o),headers:{...L(this.config,e),"Content-Type":"application/json"}})).body.title)throw new Error("Could not set pull request reviewers")}};var Vt=s=>s?s.find(n=>n.permission==="USER_ADMIN"||n.permission==="PROJECT_ADMIN"||n.permission==="ADMIN"||n.permission==="SYS_ADMIN"||n.permission==="REPO_ADMIN")?{canCreateWebhook:!0,canPush:!0,isAdmin:!0}:s.find(n=>n.permission==="REPO_WRITE"||n.permission==="REPO_CREATE"||n.permission==="PROJECT_CREATE"||n.permission==="PROJECT_WRITE")?{canCreateWebhook:!1,canPush:!0,isAdmin:!1}:{canCreateWebhook:!1,canPush:!1,isAdmin:!1}:{canCreateWebhook:!1,canPush:!1,isAdmin:!1};var he=s=>{let n=s.links.self[0].href;return{name:s.displayName,email:s.emailAddress,avatarUrl:s.avatarUrl??(n&&`${n}/avatar.png`),id:s.id.toString(),username:s.name,url:n}},Ce=s=>{let n={OPEN:"OPEN",MERGED:"MERGED",DECLINED:"CLOSED"},e={UNAPPROVED:"REVIEW_REQUESTED",NEEDS_WORK:"CHANGES_REQUESTED",APPROVED:"APPROVED"},t=s.reviewers.map(u=>({reviewer:he(u.user),state:e[u.status]})),r=s.toRef.repository.links.clone.find(u=>u.name==="ssh")?.href??null,o=s.toRef.repository.links.clone.find(u=>u.name==="https")?.href??null;o||(o=s.toRef.repository.links.clone.find(u=>u.name==="http")?.href??null);let i=s.fromRef.repository.links.clone.find(u=>u.name==="ssh")?.href??null,a=s.fromRef.repository.links.clone.find(u=>u.name==="https")?.href??null;return a||(a=s.fromRef.repository.links.clone.find(u=>u.name==="http")?.href??null),{id:s.id.toString(),number:s.id,title:s.title,description:s.description,url:s.links.self[0].href,state:n[s.state],isDraft:!1,createdDate:new Date(s.createdDate),updatedDate:new Date(s.updatedDate),closedDate:s.closedDate?new Date(s.closedDate):null,mergedDate:s.state=="MERGED"&&s.closedDate?new Date(s.closedDate):null,baseRef:{name:s.toRef.displayId,oid:s.toRef.latestCommit},headRef:{name:s.fromRef.displayId,oid:s.fromRef.latestCommit},commentCount:s.properties.commentCount,upvoteCount:null,commitCount:null,fileCount:null,additions:null,deletions:null,author:he(s.author.user),assignees:null,reviews:t,reviewDecision:F(t),repository:{id:s.toRef.repository.id.toString(),name:s.toRef.repository.name,owner:{login:s.toRef.repository.project.key},remoteInfo:o&&r?{cloneUrlHTTPS:o,cloneUrlSSH:r}:null},headRepository:{id:s.fromRef.repository.id.toString(),name:s.fromRef.repository.name,owner:{login:s.fromRef.repository.project.key},remoteInfo:a&&i?{cloneUrlHTTPS:a,cloneUrlSSH:i}:null},headCommit:null,mergeableState:"MERGEABLE",permissions:null,version:s.version}},Kt=s=>({id:s.id.toString(),namespace:s.project.key,name:s.slug,webUrl:s.links.self[0]?.href??null,httpsUrl:s.links.clone.find(n=>n.name==="https"||n.name==="http")?.href??null,sshUrl:s.links.clone.find(n=>n.name==="ssh")?.href??null,defaultBranch:null,permissions:null}),oe=class extends T{getBaseUrl(n){let e=n.baseUrl||this.config.baseUrl;if(!e)throw new Error('Bitbucket Server requires "baseUrl"');return e}getRequestHeaders(n){return b(n.token||this.config.token)}async getCurrentUser(n={},e={}){let t=await this.config.request({url:`${this.getBaseUrl(e)}/users?limit=2`,headers:this.getRequestHeaders(e)}),{headers:{"x-auserid":r,"x-ausername":o}}=t,i=r?parseInt(r,10):null,a=decodeURIComponent(o),l=(await this.config.request({url:`${this.getBaseUrl(e)}/users?filter=${o}&avatarSize=64`,headers:this.getRequestHeaders(e)})).body.values.find(({emailAddress:p,id:c,name:d,slug:m})=>i?i===c:a===d||a===p||a===m);if(!l)throw new Error("Could not find current Bitbucket Server user");return{data:he(l)}}async getUserForCommit(n,e){let{repo:t,oid:r}=n,o=await this.config.request({url:`${this.getBaseUrl(e)}/projects/${t.namespace}/repos/${t.name}/commits/${r}`,headers:this.getRequestHeaders(e)});if(!o.body.author)throw new Error("Could not find user for commit");return{data:he(o.body.author)}}async getRepo(n,e={}){let t=await this.config.request({url:`${this.getBaseUrl(e)}/projects/${n.namespace}/repos/${n.name}`,headers:this.getRequestHeaders(e)});return{data:Kt(t.body)}}async getRepos(n,e={}){let t=[],r=[];return await Promise.all(n.map(async o=>{try{let i=await this.getRepo(o,e);t.push(i.data)}catch(i){r.push({input:o,error:i})}})),{data:t,errors:r}}async getReposForCurrentUser(n,e={}){let t=n.page??0,r=await this.config.request({url:`${this.getBaseUrl(e)}/repos?start=${t}`,headers:this.getRequestHeaders(e)});return{pageInfo:{hasNextPage:!r.body.isLastPage,nextPage:r.body.nextPageStart},data:r.body.values.map(Kt)}}async getRepoPermissionsForUsername(n,e={}){let t=new URL(`${this.getBaseUrl(e)}/projects/${n.repo.namespace}/repos/${n.repo.name}/permissions/search?filterText=${n.username}`);try{let r=await this.config.request({url:t.toString(),headers:this.getRequestHeaders(e)});return{data:Vt(r.body.values)}}catch(r){if(r.response?.status===401)return{data:{canCreateWebhook:!1,canPush:!1,isAdmin:!1}};throw r}}async decorateReposWithPermissions(n,e={}){return await Promise.all(n.repos.map(async r=>{let o=await this.getRepoPermissionsForUsername({repo:r,username:n.username},e);return{...r,permissions:o.data}}))}async getPullRequestsForRepoBase(n,e={}){let t=new URL(`${this.getBaseUrl(e)}/projects/${encodeURI(n.repo.namespace)}/repos/${encodeURI(n.repo.name)}/pull-requests?state=OPEN`);return t.searchParams.set("start",n.page?.toString()||"0"),t.searchParams.set("limit","50"),await this.config.request({url:t.toString(),headers:this.getRequestHeaders(e)})}async getPullRequestsForRepo(n,e={}){let t=[],r=await this.getPullRequestsForRepoBase(n,e);r.body.values.forEach(i=>{if(n.authorLogin&&i.author.user.name!==n.authorLogin)return null;t.push(Ce(i))});let o=r.body.values.length!==0;return{pageInfo:{hasNextPage:o,nextPage:o?r.body.start+r.body.values.length:null},data:t}}async getPullRequestsForRepos(n,e={}){let t=[];return await Promise.all(n.repos.map(async r=>{try{(await this.getPullRequestsForRepoBase({repo:r,...n},e)).body.values.forEach(i=>{if(n.authorLogin&&i.author.user.name!==n.authorLogin)return null;t.push(Ce(i))})}catch(o){if(o.statusCode!==404&&o.statusCode!==401)throw o}})),{data:t}}async getPullRequestsForCurrentUser(n,e={}){let t=new URL(`${this.getBaseUrl(e)}/dashboard/pull-requests`);t.searchParams.set("state","OPEN"),t.searchParams.set("start",n.page?.toString()||"0"),t.searchParams.set("limit","50");let r=await this.config.request({url:t.toString(),headers:this.getRequestHeaders(e)}),o=r.body.values.length!==0;return{pageInfo:{hasNextPage:o,nextPage:o?r.body.start+r.body.values.length:null},data:r.body.values.map(Ce)}}async closePullRequest(n,e={}){let{pullRequest:t}=n;if(t.version===void 0)throw new Error('Bitbucket Server requires "version" for this function.');if(!(await this.config.request({method:"POST",url:`${this.getBaseUrl(e)}/projects/${t.repository.owner.login}/repos/${t.repository.name}/pull-requests/${t.id}/decline`,body:JSON.stringify({version:t.version}),headers:{...this.getRequestHeaders(e),"Content-Type":"application/json"}})).body.title)throw new Error("Could not close pull request")}async mergePullRequest(n,e={}){let{pullRequest:t,mergeStrategyId:r}=n;if(n.mergeStrategy)throw new Error('Bitbucket Server uses "mergeStrategyId" instead of "mergeStrategy".');if(t.version===void 0)throw new Error('Bitbucket Server requires "version" for this function.');if(!(await this.config.request({method:"POST",url:`${this.getBaseUrl(e)}/projects/${t.repository.owner.login}/repos/${t.repository.name}/pull-requests/${t.id}/merge`,body:JSON.stringify({strategyId:r,version:t.version}),headers:{...this.getRequestHeaders(e),"Content-Type":"application/json"}})).body.title)throw new Error("Could not merge pull request")}async getMergeStrategies(n={}){let e=await this.config.request({url:`${this.getBaseUrl(n)}/admin/pull-requests/git`,headers:{...this.getRequestHeaders(n),"Content-Type":"application/json"}});return{data:{defaultStrategy:e.body.mergeConfig.defaultStrategy,strategies:e.body.mergeConfig.strategies}}}async setPullRequestReviewers(n,e={}){let{pullRequest:t,reviewers:r}=n;if(t.version===void 0)throw new Error('Bitbucket Server requires "version" for this function.');let o={reviewers:r.map(a=>{if(a.username)throw new Error('Bitbucket Server reviewer requires "username" for this function.');return{user:{name:a.username}}}),version:t.version};if(!(await this.config.request({method:"PUT",url:`${this.getBaseUrl(e)}/projects/${t.repository.owner.login}/repos/${t.repository.name}/pull-requests/${t.id}`,body:JSON.stringify(o),headers:{...this.getRequestHeaders(e),"Content-Type":"application/json"}})).body.title)throw new Error("Could not set pull request reviewers")}async getAccountsForProject(n,e={}){let t=new URL(`${this.getBaseUrl(e)}/projects/${encodeURI(n.project)}/permissions/users`);t.searchParams.set("start",n.page?.toString()||"0"),t.searchParams.set("limit","50");let r=await this.config.request({url:t.toString(),headers:this.getRequestHeaders(e)}),o=r.body.values.length!==0;return{pageInfo:{hasNextPage:o,nextPage:o?r.body.start+r.body.values.length:null},data:r.body.values.map(i=>he(i.user))}}};var dr=require("js-base64");var De=(e=>(e.Open="OPEN",e.Closed="CLOSED",e))(De||{});var h=class extends Error{constructor(e,t){let r=t?.map(i=>`'${i.message}'`).join(", "),o=r?`${e}: ${r}`:e;super(o);this.graphQLErrors=t??[]}};var is={AS_CODE_OWNER:[3,0,0],CHECK_RUN:[3,0,0],LATEST_REVIEWS:[3,0,0],VIEWER_CAN_MERGE_AS_ADMIN:[3,5,0],ISSUE_FULL_DATABASE_ID:[3,12,0],PR_FULL_DATABASE_ID:[3,13,0],PR_REVIEW_FULL_DATABASE_ID:[3,13,0],PR_REVIEW_COMMENT_FULL_DATABASE_ID:[3,13,0]},Xt=15,Zt=100,fe={__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"},A=s=>!!s,Q=(s,n)=>{let e=is[n];for(let t=0;t<3;t++){if(s[t]>e[t])return!0;if(s[t]<e[t])return!1}return!0},$e="https://api.github.com",as=`${$e}/graphql`,Ue=`
3
3
  description
4
4
  dueOn
5
5
  id
@@ -7,7 +7,7 @@ number
7
7
  state
8
8
  title
9
9
  url
10
- `,ts=`
10
+ `,us=`
11
11
  ... on CheckRun {
12
12
  completedAt
13
13
  conclusion
@@ -16,63 +16,63 @@ url
16
16
  permalink
17
17
  startedAt
18
18
  }
19
- `,Se=/\/api\/v\d+$/,Ce=`
19
+ `,Le=/\/api\/v\d+$/,Ae=`
20
20
  color
21
21
  description
22
22
  id
23
23
  name
24
- `,zt=r=>{if(r.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.")},rs=(r,n)=>{let e=n.baseUrl||r.baseUrl;return e?(e=e.replace(/\/$/,""),zt(e),Se.test(e)&&(e=e.replace(Se,"")),`${e}/api/graphql`):es},Y=(r,n)=>{let e=n.baseUrl||r.baseUrl;return e?(e=e.replace(/\/$/,""),zt(e),Se.test(e)&&(e=e.replace(Se,"")),`${e}/api/v3`):qe},f=(r,n,e)=>{let t=I(e.token||r.token);return t["X-Github-Next-Global-ID"]="1",t["Content-Type"]="application/json",t.Accept="application/vnd.github.merge-info-preview+json",r.request({url:rs(r,e),method:"POST",headers:t,body:JSON.stringify(n)})},ss={user:!0,"user:email":!0,"read:user":!0},j=r=>r.some(n=>ss[n]),G=(r=!1,n=!1,e)=>`
24
+ `,Yt=s=>{if(s.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.")},ls=(s,n)=>{let e=n.baseUrl||s.baseUrl;return e?(e=e.replace(/\/$/,""),Yt(e),Le.test(e)&&(e=e.replace(Le,"")),`${e}/api/graphql`):as},te=(s,n)=>{let e=n.baseUrl||s.baseUrl;return e?(e=e.replace(/\/$/,""),Yt(e),Le.test(e)&&(e=e.replace(Le,"")),`${e}/api/v3`):$e},f=(s,n,e)=>{let t=b(e.token||s.token);return t["X-Github-Next-Global-ID"]="1",t["Content-Type"]="application/json",t.Accept="application/vnd.github.merge-info-preview+json",s.request({url:ls(s,e),method:"POST",headers:t,body:JSON.stringify(n)})},ps={user:!0,"user:email":!0,"read:user":!0},M=s=>s.some(n=>ps[n]),O=(s=!1,n=!1,e)=>`
25
25
  __typename
26
- ${W(e,["graphQLId"],"id")}
27
- ${W(e,["id"],"databaseId")}
28
- ${W(e,["name"],"name")}
29
- ${W(e,["name","username"],"login")}
30
- ${n?W(e,["email"],"email"):""}
31
- ${W(e,["avatarUrl"],`avatarUrl${r?"(size: $avatarSize)":""}`)}
32
- ${W(e,["url"],"url")}
33
- `,ns=(r=!1)=>`
26
+ ${V(e,["graphQLId"],"id")}
27
+ ${V(e,["id"],"databaseId")}
28
+ ${V(e,["name"],"name")}
29
+ ${V(e,["name","username"],"login")}
30
+ ${n?V(e,["email"],"email"):""}
31
+ ${V(e,["avatarUrl"],`avatarUrl${s?"(size: $avatarSize)":""}`)}
32
+ ${V(e,["url"],"url")}
33
+ `,ds=(s=!1)=>`
34
34
  latestReviews(first: 100) {
35
35
  nodes {
36
36
  author {
37
37
  ... on User {
38
- ${G(!1,r)}
38
+ ${O(!1,s)}
39
39
  }
40
40
  ... on EnterpriseUserAccount {
41
- ${st(!1)}
41
+ ${pt(!1)}
42
42
  }
43
43
  }
44
44
  state
45
45
  }
46
46
  }
47
- `,Ht=(r=!1)=>`
47
+ `,er=(s=!1)=>`
48
48
  __typename
49
49
  id
50
50
  databaseId
51
51
  login
52
- avatarUrl${r?"(size: $avatarSize)":""}
52
+ avatarUrl${s?"(size: $avatarSize)":""}
53
53
  url
54
- `,st=(r=!1)=>`
54
+ `,pt=(s=!1)=>`
55
55
  __typename
56
56
  id
57
57
  login
58
- avatarUrl${r?"(size: $avatarSize)":""}
58
+ avatarUrl${s?"(size: $avatarSize)":""}
59
59
  url
60
- `,De=(r,n=!1,e)=>`
60
+ `,Ge=(s,n=!1,e)=>`
61
61
  id
62
- ${!e||_(e,"PR_FULL_DATABASE_ID")?"fullDatabaseId":"databaseId"}
62
+ ${!e||Q(e,"PR_FULL_DATABASE_ID")?"fullDatabaseId":"databaseId"}
63
63
  number
64
64
  title
65
65
  body
66
66
  state
67
67
  author {
68
68
  ... on User {
69
- ${G(!1,n)}
69
+ ${O(!1,n)}
70
70
  }
71
71
  ... on Bot {
72
- ${Ht(!1)}
72
+ ${er(!1)}
73
73
  }
74
74
  ... on EnterpriseUserAccount {
75
- ${st(!1)}
75
+ ${pt(!1)}
76
76
  }
77
77
  }
78
78
  commits(last: 1) {
@@ -85,7 +85,7 @@ commits(last: 1) {
85
85
  contexts(first: 100) {
86
86
  totalCount
87
87
  nodes {
88
- ${!e||_(e,"CHECK_RUN")?ts:""}
88
+ ${!e||Q(e,"CHECK_RUN")?us:""}
89
89
  ... on StatusContext {
90
90
  context
91
91
  createdAt
@@ -133,7 +133,7 @@ headRepository {
133
133
  url
134
134
  sshUrl
135
135
  }
136
- ${r?"isDraft":""}
136
+ ${s?"isDraft":""}
137
137
  url
138
138
  createdAt
139
139
  comments {
@@ -147,47 +147,47 @@ closedAt
147
147
  mergedAt
148
148
  assignees(first: 100) {
149
149
  nodes {
150
- ${G(!1,n)}
150
+ ${O(!1,n)}
151
151
  }
152
152
  }
153
153
  reviewRequests(first: 100) {
154
154
  nodes {
155
- ${!e||_(e,"AS_CODE_OWNER")?"asCodeOwner":""}
155
+ ${!e||Q(e,"AS_CODE_OWNER")?"asCodeOwner":""}
156
156
  requestedReviewer {
157
157
  ... on User {
158
- ${G(!1,n)}
158
+ ${O(!1,n)}
159
159
  }
160
160
  }
161
161
  }
162
162
  }
163
- ${!e||_(e,"LATEST_REVIEWS")?ns(n):""}
163
+ ${!e||Q(e,"LATEST_REVIEWS")?ds(n):""}
164
164
  additions
165
165
  deletions
166
166
  changedFiles
167
167
  mergeable
168
168
  mergeStateStatus
169
169
  milestone {
170
- ${Ee}
170
+ ${Ue}
171
171
  }
172
172
  labels(first: 100) {
173
173
  nodes {
174
- ${Ce}
174
+ ${Ae}
175
175
  }
176
176
  }
177
- ${!e||_(e,"VIEWER_CAN_MERGE_AS_ADMIN")?"viewerCanMergeAsAdmin":""}
178
- `,os=(r=!1,n)=>`
177
+ ${!e||Q(e,"VIEWER_CAN_MERGE_AS_ADMIN")?"viewerCanMergeAsAdmin":""}
178
+ `,cs=(s=!1,n)=>`
179
179
  id
180
- ${!n||_(n,"ISSUE_FULL_DATABASE_ID")?"fullDatabaseId":"databaseId"}
180
+ ${!n||Q(n,"ISSUE_FULL_DATABASE_ID")?"fullDatabaseId":"databaseId"}
181
181
  title
182
182
  author {
183
183
  ... on User {
184
- ${G(!1,r)}
184
+ ${O(!1,s)}
185
185
  }
186
186
  ... on Bot {
187
- ${Ht(!1)}
187
+ ${er(!1)}
188
188
  }
189
189
  ... on EnterpriseUserAccount {
190
- ${st(!1)}
190
+ ${pt(!1)}
191
191
  }
192
192
  }
193
193
  closedAt
@@ -211,19 +211,19 @@ comments {
211
211
  }
212
212
  assignees(first: 100) {
213
213
  nodes {
214
- ${G(!1,r)}
214
+ ${O(!1,s)}
215
215
  }
216
216
  }
217
217
  state
218
218
  milestone {
219
- ${Ee}
219
+ ${Ue}
220
220
  }
221
221
  labels(first: 100) {
222
222
  nodes {
223
- ${Ce}
223
+ ${Ae}
224
224
  }
225
225
  }
226
- `,is={"-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"},as=new RegExp('(([^\\s]+:)?\\"(?:[^\\"\\\\]|\\\\.)*\\"?)|([^\\"\\s]+)',"g"),nt=r=>{let n=[];return(r.match(as)??[]).forEach(t=>{if(t.includes(":")&&t!="is:closed"){let s=t.split(":")[0];is[s]&&n.push(t)}}),n},ot=(r,n,e,t)=>{let s=r==="issue";return{query:`
226
+ `,ms={"-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"},gs=new RegExp('(([^\\s]+:)?\\"(?:[^\\"\\\\]|\\\\.)*\\"?)|([^\\"\\s]+)',"g"),dt=s=>{let n=[];return(s.match(gs)??[]).forEach(t=>{if(t.includes(":")&&t!="is:closed"){let r=t.split(":")[0];ms[r]&&n.push(t)}}),n},ct=(s,n,e,t)=>{let r=s==="issue";return{query:`
227
227
  query SearchIssuesOrPullRequests($query: String! $after: String) {
228
228
  search(type:ISSUE query:$query first: ${t.maxPageSize} after:$after) {
229
229
  pageInfo {
@@ -231,19 +231,19 @@ query SearchIssuesOrPullRequests($query: String! $after: String) {
231
231
  endCursor
232
232
  }
233
233
  nodes {
234
- ... on ${s?"Issue":"PullRequest"} {
235
- ${s?os(t.supportsEmail,t.enterpriseVersion??null):De(t.supportsDrafts??!1,t.supportsEmail,t.enterpriseVersion??null)}
234
+ ... on ${r?"Issue":"PullRequest"} {
235
+ ${r?cs(t.supportsEmail,t.enterpriseVersion??null):Ge(t.supportsDrafts??!1,t.supportsEmail,t.enterpriseVersion??null)}
236
236
  }
237
237
  }
238
238
  }
239
- }`,variables:{query:`is:${r} is:open ${t.includeFromArchivedRepos?"":"archived:false"} ${n}`,after:e}}},us="Field 'isDraft' doesn't exist on type 'PullRequest'",Le=(r=[])=>r.some(n=>n?.message===us),ls=/@@ -(\d+)(?:,\d+ | )\+(\d+)(?:,\d+ | )@@(?:\\n)?/,ps=`
239
+ }`,variables:{query:`is:${s} is:open ${t.includeFromArchivedRepos?"":"archived:false"} ${n}`,after:e}}},hs="Field 'isDraft' doesn't exist on type 'PullRequest'",Te=(s=[])=>s.some(n=>n?.message===hs),fs=/@@ -(\d+)(?:,\d+ | )\+(\d+)(?:,\d+ | )@@(?:\\n)?/,Rs=`
240
240
  \
241
- +`,Wt=(r,n,e,t)=>{let s=ls.exec(r);if(!s||!s[0]||!s[1])return[];let o=parseInt(s[1],10),i=parseInt(s[2],10),a=r.replace(ps,`
241
+ +`,tr=(s,n,e,t)=>{let r=fs.exec(s);if(!r||!r[0]||!r[1])return[];let o=parseInt(r[1],10),i=parseInt(r[2],10),a=s.replace(Rs,`
242
242
  +`).split(`
243
- `).slice(1),u=o-1,p=i-1,d=a.map(g=>{let m,b;switch(g[0]){case"-":{m="DELETED",u+=1,b=`${g.slice(1)}
244
- `;break}case"+":{m="ADDED",p+=1,b=`${g.slice(1)}
245
- `;break}default:m="UNMODIFIED",p+=1,u+=1,b=`${g}
246
- `}return{line:b,oldLineNumber:m!=="ADDED"?u:null,newLineNumber:m!=="DELETED"?p:null,type:m}}),c=e,l=n;if(c!==null&&l!==null&&t!==null&&c<l){let g=0,m=d.length,b=t==="LEFT"?"oldLineNumber":"newLineNumber";for(let R=0;R<d.length;R++){let U=d[R][b];U===c?g=R:U===l&&(m=R)}d=d.slice(g,m+1)}return d},Jt=r=>{let n=r.author;return n||(n=me),{author:{id:"databaseId"in n?n.databaseId.toString():n.id,graphQLId:n.id,name:("name"in n?n.name:n.login)??n.login,username:n.login,email:("email"in n?n.email:null)??null,avatarUrl:n.avatarUrl,url:n.url},body:r.body,createdAt:r.publishedAt?new Date(r.publishedAt):null,graphQLId:r.id,id:r.fullDatabaseId??r.databaseId?.toString()??r.id,url:r.url}};var Vt=`mutation DeleteIssueComment(
243
+ `).slice(1),u=o-1,l=i-1,p=a.map(m=>{let g,y;switch(m[0]){case"-":{g="DELETED",u+=1,y=`${m.slice(1)}
244
+ `;break}case"+":{g="ADDED",l+=1,y=`${m.slice(1)}
245
+ `;break}default:g="UNMODIFIED",l+=1,u+=1,y=`${m}
246
+ `}return{line:y,oldLineNumber:g!=="ADDED"?u:null,newLineNumber:g!=="DELETED"?l:null,type:g}}),c=e,d=n;if(c!==null&&d!==null&&t!==null&&c<d){let m=0,g=p.length,y=t==="LEFT"?"oldLineNumber":"newLineNumber";for(let I=0;I<p.length;I++){let q=p[I][y];q===c?m=I:q===d&&(g=I)}p=p.slice(m,g+1)}return p},rr=s=>{let n=s.author;return n||(n=fe),{author:{id:"databaseId"in n?n.databaseId.toString():n.id,graphQLId:n.id,name:("name"in n?n.name:n.login)??n.login,username:n.login,email:("email"in n?n.email:null)??null,avatarUrl:n.avatarUrl,url:n.url},body:s.body,createdAt:s.publishedAt?new Date(s.publishedAt):null,graphQLId:s.id,id:s.fullDatabaseId??s.databaseId?.toString()??s.id,url:s.url}};var sr=`mutation DeleteIssueComment(
247
247
  $issueCommentId: ID!
248
248
  ) {
249
249
  deleteIssueComment(input: {
@@ -251,7 +251,7 @@ query SearchIssuesOrPullRequests($query: String! $after: String) {
251
251
  }) {
252
252
  clientMutationId
253
253
  }
254
- }`,Kt=`mutation DeletePullRequestReviewComment(
254
+ }`,nr=`mutation DeletePullRequestReviewComment(
255
255
  $pullRequestReviewCommentId: ID!
256
256
  ) {
257
257
  deletePullRequestReviewComment(input: {
@@ -261,7 +261,7 @@ query SearchIssuesOrPullRequests($query: String! $after: String) {
261
261
  id
262
262
  }
263
263
  }
264
- }`,Xt=`mutation UpdateIssueComment(
264
+ }`,or=`mutation UpdateIssueComment(
265
265
  $issueCommentId: ID!,
266
266
  $body: String!
267
267
  ) {
@@ -274,7 +274,7 @@ query SearchIssuesOrPullRequests($query: String! $after: String) {
274
274
  body
275
275
  }
276
276
  }
277
- }`,Zt=`mutation ResolveReviewThread(
277
+ }`,ir=`mutation ResolveReviewThread(
278
278
  $pullRequestReviewThreadId: ID!
279
279
  ) {
280
280
  resolveReviewThread(input: {
@@ -285,7 +285,7 @@ query SearchIssuesOrPullRequests($query: String! $after: String) {
285
285
  isResolved
286
286
  }
287
287
  }
288
- }`,Yt=`mutation UnresolveReviewThread(
288
+ }`,ar=`mutation UnresolveReviewThread(
289
289
  $pullRequestReviewThreadId: ID!
290
290
  ) {
291
291
  unresolveReviewThread(input: {
@@ -296,7 +296,7 @@ query SearchIssuesOrPullRequests($query: String! $after: String) {
296
296
  isResolved
297
297
  }
298
298
  }
299
- }`,er=`mutation UpdatePullRequestReviewComment(
299
+ }`,ur=`mutation UpdatePullRequestReviewComment(
300
300
  $pullRequestReviewCommentId: ID!,
301
301
  $body: String!
302
302
  ) {
@@ -309,7 +309,7 @@ query SearchIssuesOrPullRequests($query: String! $after: String) {
309
309
  body
310
310
  }
311
311
  }
312
- }`;var tr=r=>`
312
+ }`;var lr=s=>`
313
313
  query GetPullRequestComments(
314
314
  $namespace: String!
315
315
  $name: String!
@@ -322,7 +322,7 @@ query GetPullRequestComments(
322
322
  comments(first: $first, after: $cursor) {
323
323
  nodes {
324
324
  id
325
- ${r?"fullDatabaseId":"databaseId"}
325
+ ${s?"fullDatabaseId":"databaseId"}
326
326
  author {
327
327
  ... on User {
328
328
  id
@@ -355,7 +355,7 @@ query GetPullRequestComments(
355
355
  }
356
356
  }
357
357
  }
358
- `;var it=`
358
+ `;var mt=`
359
359
  id
360
360
  databaseId
361
361
  owner {
@@ -368,18 +368,18 @@ defaultBranchRef {
368
368
  name
369
369
  }
370
370
  viewerPermission
371
- `,ds={APPROVED:"APPROVED",CHANGES_REQUESTED:"CHANGES_REQUESTED",COMMENTED:"COMMENTED",REVIEW_REQUESTED:"REVIEW_REQUESTED"},cs={MERGEABLE:"MERGEABLE",CONFLICTING:"CONFLICTS",UNKNOWN:"UNKNOWN"},gs={BEHIND:"BEHIND",BLOCKED:"BLOCKED",UNKNOWN:"UNKNOWN_AND_BLOCKED",UNSTABLE:"UNSTABLE",CLEAN:null,DIRTY:null,DRAFT:null,HAS_HOOKS:null},ms={OPEN:"OPEN",CLOSED:"CLOSED"},hs=["ADMIN","MAINTAIN","TRIAGE","WRITE"],lt=r=>({color:`#${r.color}`,description:r.description,graphQLId:r.id,id:null,name:r.name}),fs=r=>({canCreateWebhook:r==="ADMIN",canPush:r==="ADMIN"||r==="MAINTAIN"||r==="WRITE",isAdmin:r==="ADMIN"}),at=r=>({id:r.databaseId.toString(),graphQLId:r.id,namespace:r.owner.login,name:r.name,webUrl:r.url,httpsUrl:r.url.endsWith(".git")?r.url:`${r.url}.git`,sshUrl:r.sshUrl,defaultBranch:r.defaultBranchRef,permissions:fs(r.viewerPermission)}),Rs=r=>({canCreateWebhook:r.admin,canPush:r.admin||r.maintain||r.push,isAdmin:r.admin}),rr=r=>({id:r.id.toString(),graphQLId:r.node_id,namespace:r.owner.login,name:r.name,webUrl:r.html_url,httpsUrl:r.clone_url,sshUrl:r.ssh_url,defaultBranch:{name:r.default_branch},permissions:Rs(r.permissions)}),Is=r=>({path:r.path,isDirectory:r.type==="tree"}),bs={OPEN:"OPEN",CLOSED:"CLOSED",MERGED:"MERGED"},ys={id:!0,graphQLId:!0,name:!0,username:!0,email:!0,avatarUrl:!0,url:!0},O=(r,n=ys)=>{let e={};return n.id&&(e.id="databaseId"in r?r.databaseId.toString():r.id),n.graphQLId&&(e.graphQLId=r.id),n.name&&(e.name=r.name??r.login),n.username&&(e.username=r.login),n.email&&(e.email=r.email??null),n.avatarUrl&&(e.avatarUrl=r.avatarUrl),n.url&&(e.url=r.url),e},Ps=(r,n)=>{let e={IN_PROGRESS:"RUNNING",PENDING:"PENDING",QUEUED:"PENDING",REQUESTED:"PENDING",WAITING:"PENDING"};return r!=="COMPLETED"?e[r]:{ACTION_REQUIRED:"ACTION_REQUIRED",CANCELLED:"CANCELLED",FAILURE:"FAILED",NEUTRAL:null,SKIPPED:"SKIPPED",STALE:"FAILED",STARTUP_FAILURE:"FAILED",SUCCESS:"SUCCESS",TIMED_OUT:"ERROR"}[n]},ws=r=>({ERROR:"ERROR",EXPECTED:"PENDING",FAILURE:"FAILED",PENDING:"PENDING",SUCCESS:"SUCCESS"})[r],ut=r=>{let n=null;r.author?n=r.author:n=me;let e=(r.reviewRequests?.nodes||[]).filter($).filter(i=>!i.asCodeOwner),t=r.headRepository?.url;t&&!t.endsWith(".git")&&(t=`${t}.git`);let s=r.repository?.url;s&&!s.endsWith(".git")&&(s=`${s}.git`);let o=e.filter(i=>i.requestedReviewer&&"__typename"in i.requestedReviewer).map(i=>({reviewer:O(i.requestedReviewer),state:"REVIEW_REQUESTED"})).concat((r.latestReviews?.nodes||[]).filter($).map(i=>{let a=me;return i.author&&i.author.__typename&&(a=i.author),{reviewer:O(a),state:ds[i.state]}}));return{id:r.fullDatabaseId!==void 0?r.fullDatabaseId:r.databaseId.toString(),graphQLId:r.id,title:r.title,description:r.body,number:r.number,state:bs[r.state],commentCount:r.comments.totalCount,upvoteCount:r.reactions.totalCount,author:n&&n.__typename?O(n):null,createdDate:new Date(r.createdAt),isDraft:r.isDraft,repository:{id:r.repository.databaseId.toString(),graphQLId:r.repository.id,name:r.repository.name,owner:{login:r.repository.owner.login},remoteInfo:{cloneUrlHTTPS:s,cloneUrlSSH:r.repository.sshUrl}},headRepository:r.headRepository?{id:r.headRepository.databaseId.toString(),graphQLId:r.headRepository.id,name:r.headRepository.name,owner:{login:r.headRepository.owner.login},remoteInfo:{cloneUrlHTTPS:t,cloneUrlSSH:r.headRepository.sshUrl}}:null,headCommit:{buildStatuses:r.commits.nodes?.filter($)[0]?.commit.statusCheckRollup?.contexts.nodes?.filter($).map(i=>"context"in i?{completedAt:null,description:i.description,name:i.context,state:ws(i.state),startedAt:new Date(i.createdAt),stage:null,url:i.targetUrl}:{completedAt:i.completedAt?new Date(i.completedAt):null,description:null,name:i.name,state:Ps(i.status,i.conclusion),startedAt:i.startedAt?new Date(i.startedAt):null,stage:null,url:i.permalink})??[]},headRef:r.headRef?{name:r.headRef.name,oid:r.headRef.target?.oid??null}:null,baseRef:r.baseRef?{name:r.baseRef.name,oid:r.baseRef.target?.oid??null}:null,url:r.url,updatedDate:new Date(r.updatedAt),closedDate:r.closedAt?new Date(r.closedAt):null,mergedDate:r.mergedAt?new Date(r.mergedAt):null,assignees:r.assignees.nodes?r.assignees.nodes.filter($).map(i=>O(i)):null,reviews:o,reviewDecision:N(o),additions:r.additions,deletions:r.deletions,fileCount:r.changedFiles,commitCount:r.commits.totalCount,mergeableState:gs[r.mergeStateStatus]??cs[r.mergeable],milestone:r.milestone?pt(r.milestone):null,labels:r.labels?.nodes?.filter($).map(lt)??[],permissions:{canMerge:hs.includes(r.repository.viewerPermission),canMergeAndBypassProtections:r.viewerCanMergeAsAdmin??!1}}},vs=r=>{let{id:n,comments:e,isOutdated:t,isResolved:s,line:o,startLine:i,diffSide:a,originalLine:u,originalStartLine:p,startDiffSide:d}=r,c=e.nodes?.[0];if(!c)return null;let{author:l,body:g,databaseId:m,fullDatabaseId:b,id:R,path:P,publishedAt:U,url:K}=c,x=o??u,S=i??p,k=a??d;return{author:l?{avatarUrl:l.avatarUrl,email:null,name:l.login}:null,body:g,createdAt:U?new Date(U):null,diffLines:Wt(c.diffHunk,x,S,k),id:b??m.toString(),isOutdated:t,isResolved:s,graphQLId:R,threadId:n,filename:P,replies:e.nodes?.filter($).slice(1).map(Ss)??[],url:K,line:x,startLine:S,side:k}},Ss=r=>({author:r.author?{avatarUrl:r.author.avatarUrl,email:null,name:r.author.login}:null,body:r.body,createdAt:r.publishedAt?new Date(r.publishedAt):null,graphQLId:r.id,id:r.fullDatabaseId??r.databaseId.toString(),url:r.url}),qs=r=>{let n=null;return r.author?n=r.author:n=me,{id:r.fullDatabaseId!==void 0?r.fullDatabaseId:r.databaseId.toString(),graphQLId:r.id,number:r.number,title:r.title,author:n&&n.__typename?O(n):null,commentCount:r.comments.totalCount,closedDate:r.closedAt?new Date(r.closedAt):null,createdDate:new Date(r.createdAt),description:null,state:{name:ms[r.state],color:null},type:null,repository:{id:r.repository.databaseId.toString(),graphQLId:r.repository.id,name:r.repository.name,owner:{login:r.repository.owner.login}},url:r.url,updatedDate:new Date(r.updatedAt),assignees:r.assignees.nodes?.filter($).map(e=>O(e))??[],upvoteCount:r.reactions.totalCount,milestone:r.milestone?pt(r.milestone):null,labels:r.labels?.nodes?.filter($).map(lt)??[]}},pt=r=>({id:r.number.toString(),graphQLId:r.id.toString(),number:r.number,title:r.title,description:r.description,isOpen:r.state=="OPEN",url:r.url,startDate:null,dueDate:r.dueOn?new Date(r.dueOn):null}),ie=class extends A{constructor(){super(...arguments);this._scopesCache={};this._enterpriseVersionsCache={}}async getScopes(e){let t=e.token||this.config.token;if(!t)return[];let s=this._scopesCache[t];if(!s){let i=(await f(this.config,{query:"query { rateLimit(dryRun: true) { __typename } }"},e)).headers["x-oauth-scopes"];s=i?i.split(", "):[],this._scopesCache[t]=s}return s}async getEnterpriseVersion(e){let t=e.baseUrl||this.config.baseUrl;if(!t)return null;let s=this._enterpriseVersionsCache[t];if(!s){let o=await this.config.request({url:`${Y(this.config,e)}/meta`,headers:I(e.token||this.config.token)});if(!o.body.installed_version)return null;s=o.body.installed_version.split(".").slice(0,3).map(i=>parseInt(i,10)),this._enterpriseVersionsCache[t]=s}return s}getEnterpriseAvatarUrlIfNeeded(e,t,s){let o=s.baseUrl||this.config.baseUrl;return!o||o.startsWith(qe)?e:t?`https://avatars.githubusercontent.com/u/e?email=${encodeURIComponent(t)}`:""}async getCurrentUser(e={},t={}){if(e.fields&&!e.fields.length)throw new Error('"fields" must contain at least one field or be omitted');let s=Ot(e.fields),o=await this.getScopes(t),i=await f(this.config,{query:`
371
+ `,Is={APPROVED:"APPROVED",CHANGES_REQUESTED:"CHANGES_REQUESTED",COMMENTED:"COMMENTED",REVIEW_REQUESTED:"REVIEW_REQUESTED"},bs={MERGEABLE:"MERGEABLE",CONFLICTING:"CONFLICTS",UNKNOWN:"UNKNOWN"},ys={BEHIND:"BEHIND",BLOCKED:"BLOCKED",UNKNOWN:"UNKNOWN_AND_BLOCKED",UNSTABLE:"UNSTABLE",CLEAN:null,DIRTY:null,DRAFT:null,HAS_HOOKS:null},Ps={OPEN:"OPEN",CLOSED:"CLOSED"},ws=["ADMIN","MAINTAIN","TRIAGE","WRITE"],ft=s=>({color:`#${s.color}`,description:s.description,graphQLId:s.id,id:null,name:s.name}),vs=s=>({canCreateWebhook:s==="ADMIN",canPush:s==="ADMIN"||s==="MAINTAIN"||s==="WRITE",isAdmin:s==="ADMIN"}),gt=s=>({id:s.databaseId.toString(),graphQLId:s.id,namespace:s.owner.login,name:s.name,webUrl:s.url,httpsUrl:s.url.endsWith(".git")?s.url:`${s.url}.git`,sshUrl:s.sshUrl,defaultBranch:s.defaultBranchRef,permissions:vs(s.viewerPermission)}),qs=s=>({canCreateWebhook:s.admin,canPush:s.admin||s.maintain||s.push,isAdmin:s.admin}),pr=s=>({id:s.id.toString(),graphQLId:s.node_id,namespace:s.owner.login,name:s.name,webUrl:s.html_url,httpsUrl:s.clone_url,sshUrl:s.ssh_url,defaultBranch:{name:s.default_branch},permissions:qs(s.permissions)}),Ss=s=>({path:s.path,isDirectory:s.type==="tree"}),Es={OPEN:"OPEN",CLOSED:"CLOSED",MERGED:"MERGED"},Cs={id:!0,graphQLId:!0,name:!0,username:!0,email:!0,avatarUrl:!0,url:!0},k=(s,n=Cs)=>{let e={};return n.id&&(e.id="databaseId"in s?s.databaseId.toString():s.id),n.graphQLId&&(e.graphQLId=s.id),n.name&&(e.name=s.name??s.login),n.username&&(e.username=s.login),n.email&&(e.email=s.email??null),n.avatarUrl&&(e.avatarUrl=s.avatarUrl),n.url&&(e.url=s.url),e},Ds=(s,n)=>{let e={IN_PROGRESS:"RUNNING",PENDING:"PENDING",QUEUED:"PENDING",REQUESTED:"PENDING",WAITING:"PENDING"};return s!=="COMPLETED"?e[s]:{ACTION_REQUIRED:"ACTION_REQUIRED",CANCELLED:"CANCELLED",FAILURE:"FAILED",NEUTRAL:null,SKIPPED:"SKIPPED",STALE:"FAILED",STARTUP_FAILURE:"FAILED",SUCCESS:"SUCCESS",TIMED_OUT:"ERROR"}[n]},Ls=s=>({ERROR:"ERROR",EXPECTED:"PENDING",FAILURE:"FAILED",PENDING:"PENDING",SUCCESS:"SUCCESS"})[s],ht=s=>{let n=null;s.author?n=s.author:n=fe;let e=(s.reviewRequests?.nodes||[]).filter(A).filter(i=>!i.asCodeOwner),t=s.headRepository?.url;t&&!t.endsWith(".git")&&(t=`${t}.git`);let r=s.repository?.url;r&&!r.endsWith(".git")&&(r=`${r}.git`);let o=e.filter(i=>i.requestedReviewer&&"__typename"in i.requestedReviewer).map(i=>({reviewer:k(i.requestedReviewer),state:"REVIEW_REQUESTED"})).concat((s.latestReviews?.nodes||[]).filter(A).map(i=>{let a=fe;return i.author&&i.author.__typename&&(a=i.author),{reviewer:k(a),state:Is[i.state]}}));return{id:s.fullDatabaseId!==void 0?s.fullDatabaseId:s.databaseId.toString(),graphQLId:s.id,title:s.title,description:s.body,number:s.number,state:Es[s.state],commentCount:s.comments.totalCount,upvoteCount:s.reactions.totalCount,author:n&&n.__typename?k(n):null,createdDate:new Date(s.createdAt),isDraft:s.isDraft,repository:{id:s.repository.databaseId.toString(),graphQLId:s.repository.id,name:s.repository.name,owner:{login:s.repository.owner.login},remoteInfo:{cloneUrlHTTPS:r,cloneUrlSSH:s.repository.sshUrl}},headRepository:s.headRepository?{id:s.headRepository.databaseId.toString(),graphQLId:s.headRepository.id,name:s.headRepository.name,owner:{login:s.headRepository.owner.login},remoteInfo:{cloneUrlHTTPS:t,cloneUrlSSH:s.headRepository.sshUrl}}:null,headCommit:{buildStatuses:s.commits.nodes?.filter(A)[0]?.commit.statusCheckRollup?.contexts.nodes?.filter(A).map(i=>"context"in i?{completedAt:null,description:i.description,name:i.context,state:Ls(i.state),startedAt:new Date(i.createdAt),stage:null,url:i.targetUrl}:{completedAt:i.completedAt?new Date(i.completedAt):null,description:null,name:i.name,state:Ds(i.status,i.conclusion),startedAt:i.startedAt?new Date(i.startedAt):null,stage:null,url:i.permalink})??[]},headRef:s.headRef?{name:s.headRef.name,oid:s.headRef.target?.oid??null}:null,baseRef:s.baseRef?{name:s.baseRef.name,oid:s.baseRef.target?.oid??null}:null,url:s.url,updatedDate:new Date(s.updatedAt),closedDate:s.closedAt?new Date(s.closedAt):null,mergedDate:s.mergedAt?new Date(s.mergedAt):null,assignees:s.assignees.nodes?s.assignees.nodes.filter(A).map(i=>k(i)):null,reviews:o,reviewDecision:F(o),additions:s.additions,deletions:s.deletions,fileCount:s.changedFiles,commitCount:s.commits.totalCount,mergeableState:ys[s.mergeStateStatus]??bs[s.mergeable],milestone:s.milestone?Rt(s.milestone):null,labels:s.labels?.nodes?.filter(A).map(ft)??[],permissions:{canMerge:ws.includes(s.repository.viewerPermission),canMergeAndBypassProtections:s.viewerCanMergeAsAdmin??!1}}},$s=s=>{let{id:n,comments:e,isOutdated:t,isResolved:r,line:o,startLine:i,diffSide:a,originalLine:u,originalStartLine:l,startDiffSide:p}=s,c=e.nodes?.[0];if(!c)return null;let{author:d,body:m,databaseId:g,fullDatabaseId:y,id:I,path:R,publishedAt:q,url:C}=c,N=o??u,E=i??l,U=a??p;return{author:d?{avatarUrl:d.avatarUrl,email:null,name:d.login}:null,body:m,createdAt:q?new Date(q):null,diffLines:tr(c.diffHunk,N,E,U),id:y??g.toString(),isOutdated:t,isResolved:r,graphQLId:I,threadId:n,filename:R,replies:e.nodes?.filter(A).slice(1).map(Us)??[],url:C,line:N,startLine:E,side:U}},Us=s=>({author:s.author?{avatarUrl:s.author.avatarUrl,email:null,name:s.author.login}:null,body:s.body,createdAt:s.publishedAt?new Date(s.publishedAt):null,graphQLId:s.id,id:s.fullDatabaseId??s.databaseId.toString(),url:s.url}),As=s=>{let n=null;return s.author?n=s.author:n=fe,{id:s.fullDatabaseId!==void 0?s.fullDatabaseId:s.databaseId.toString(),graphQLId:s.id,number:s.number,title:s.title,author:n&&n.__typename?k(n):null,commentCount:s.comments.totalCount,closedDate:s.closedAt?new Date(s.closedAt):null,createdDate:new Date(s.createdAt),description:null,state:{name:Ps[s.state],color:null},type:null,repository:{id:s.repository.databaseId.toString(),graphQLId:s.repository.id,name:s.repository.name,owner:{login:s.repository.owner.login}},url:s.url,updatedDate:new Date(s.updatedAt),assignees:s.assignees.nodes?.filter(A).map(e=>k(e))??[],upvoteCount:s.reactions.totalCount,milestone:s.milestone?Rt(s.milestone):null,labels:s.labels?.nodes?.filter(A).map(ft)??[]}},Rt=s=>({id:s.number.toString(),graphQLId:s.id.toString(),number:s.number,title:s.title,description:s.description,isOpen:s.state=="OPEN",url:s.url,startDate:null,dueDate:s.dueOn?new Date(s.dueOn):null}),ie=class extends T{constructor(){super(...arguments);this._scopesCache={};this._enterpriseVersionsCache={}}async getScopes(e){let t=e.token||this.config.token;if(!t)return[];let r=this._scopesCache[t];if(!r){let i=(await f(this.config,{query:"query { rateLimit(dryRun: true) { __typename } }"},e)).headers["x-oauth-scopes"];r=i?i.split(", "):[],this._scopesCache[t]=r}return r}async getEnterpriseVersion(e){let t=e.baseUrl||this.config.baseUrl;if(!t)return null;let r=this._enterpriseVersionsCache[t];if(!r){let o=await this.config.request({url:`${te(this.config,e)}/meta`,headers:b(e.token||this.config.token)});if(!o.body.installed_version)return null;r=o.body.installed_version.split(".").slice(0,3).map(i=>parseInt(i,10)),this._enterpriseVersionsCache[t]=r}return r}getEnterpriseAvatarUrlIfNeeded(e,t,r){let o=r.baseUrl||this.config.baseUrl;return!o||o.startsWith($e)?e:t?`https://avatars.githubusercontent.com/u/e?email=${encodeURIComponent(t)}`:""}async getCurrentUser(e={},t={}){if(e.fields&&!e.fields.length)throw new Error('"fields" must contain at least one field or be omitted');let r=Qt(e.fields),o=await this.getScopes(t),i=await f(this.config,{query:`
372
372
  query getCurrentUser {
373
373
  viewer {
374
- ${G(!1,j(o),s)}
374
+ ${O(!1,M(o),r)}
375
375
  }
376
376
  }
377
- `},t),a=i.body.data?.viewer;if(!a)throw new h("Current user not found.",i.body.errors);return{data:O(a,s)}}async getAccountsForRepo(e,t={}){let s=await this.getScopes(t),{repo:{namespace:o,name:i},cursor:a}=e,u=await f(this.config,{query:`
377
+ `},t),a=i.body.data?.viewer;if(!a)throw new h("Current user not found.",i.body.errors);return{data:k(a,r)}}async getAccountsForRepo(e,t={}){let r=await this.getScopes(t),{repo:{namespace:o,name:i},cursor:a}=e,u=await f(this.config,{query:`
378
378
  query getAccountsForRepo($owner: String!, $name: String! $cursor: String, $first: Int!) {
379
379
  repository(owner: $owner, name: $name) {
380
380
  assignableUsers(first: $first, after: $cursor) {
381
381
  nodes {
382
- ${G(!1,j(s))}
382
+ ${O(!1,M(r))}
383
383
  }
384
384
  pageInfo {
385
385
  endCursor
@@ -388,7 +388,7 @@ query getAccountsForRepo($owner: String!, $name: String! $cursor: String, $first
388
388
  }
389
389
  }
390
390
  }
391
- `,variables:{owner:o,name:i,cursor:a,first:E}},t);if(!u.body.data)throw new h("Could not fetch accounts for repo",u.body.errors);return{pageInfo:u.body.data.repository?.assignableUsers?.pageInfo??{endCursor:null,hasNextPage:!1},data:u.body.data.repository?.assignableUsers?.nodes?.map(p=>O(p))??[]}}async getUserForCommit(e,t={}){let s=await f(this.config,{query:`
391
+ `,variables:{owner:o,name:i,cursor:a,first:D}},t);if(!u.body.data)throw new h("Could not fetch accounts for repo",u.body.errors);return{pageInfo:u.body.data.repository?.assignableUsers?.pageInfo??{endCursor:null,hasNextPage:!1},data:u.body.data.repository?.assignableUsers?.nodes?.map(l=>k(l))??[]}}async getUserForCommit(e,t={}){let r=await f(this.config,{query:`
392
392
  query getUserForCommit(
393
393
  $owner: String!
394
394
  $name: String!
@@ -407,7 +407,7 @@ query getUserForCommit(
407
407
  }
408
408
  }
409
409
  }
410
- `,variables:{owner:e.repo.namespace,name:e.repo.name,oid:e.oid,avatarSize:e.avatarSize}},t),o=s.body.data?.repository;if(!o)throw new h("Repository not found.",s.body.errors);let i=o.object?.author;if(!i)throw new h("Commit not found.",s.body.errors);return{data:{name:i.name,email:i.email,avatarUrl:this.getEnterpriseAvatarUrlIfNeeded(i.avatarUrl,i.email,t)}}}async createCommit(e,t={}){let{commitMessage:s,deletedFiles:o,newOrModifiedFiles:i,repo:a,target:u}=e,p=await f(this.config,{query:`
410
+ `,variables:{owner:e.repo.namespace,name:e.repo.name,oid:e.oid,avatarSize:e.avatarSize}},t),o=r.body.data?.repository;if(!o)throw new h("Repository not found.",r.body.errors);let i=o.object?.author;if(!i)throw new h("Commit not found.",r.body.errors);return{data:{name:i.name,email:i.email,avatarUrl:this.getEnterpriseAvatarUrlIfNeeded(i.avatarUrl,i.email,t)}}}async createCommit(e,t={}){let{commitMessage:r,deletedFiles:o,newOrModifiedFiles:i,repo:a,target:u}=e,l=await f(this.config,{query:`
411
411
  mutation createCommitOnBranch(
412
412
  $branchName: String!,
413
413
  $expectedHeadOid: GitObjectID!,
@@ -434,23 +434,23 @@ mutation createCommitOnBranch(
434
434
  }
435
435
  }
436
436
  }
437
- `,variables:{branchName:u.name,expectedHeadOid:u.oid,fileChanges:{additions:Object.entries(i).map(([d,c])=>({contents:sr.Base64.encode(c),path:d})),deletions:o.map(d=>({path:d}))},message:{body:s.description,headline:s.summary},repositoryNameWithOwner:`${a.namespace}/${a.name}`}},t);if(!p.body.data)throw new h("Could not create commit",p.body.errors);return{data:{name:p.body.data.createCommitOnBranch.ref.name,commit:{authoredDate:new Date(p.body.data.createCommitOnBranch.commit.authoredDate),committedDate:new Date(p.body.data.createCommitOnBranch.commit.committedDate),oid:p.body.data.createCommitOnBranch.commit.oid}}}}async getAccountForEmail(e,t={}){let s=await this.getScopes(t),o=await f(this.config,{query:`
437
+ `,variables:{branchName:u.name,expectedHeadOid:u.oid,fileChanges:{additions:Object.entries(i).map(([p,c])=>({contents:dr.Base64.encode(c),path:p})),deletions:o.map(p=>({path:p}))},message:{body:r.description,headline:r.summary},repositoryNameWithOwner:`${a.namespace}/${a.name}`}},t);if(!l.body.data)throw new h("Could not create commit",l.body.errors);return{data:{name:l.body.data.createCommitOnBranch.ref.name,commit:{authoredDate:new Date(l.body.data.createCommitOnBranch.commit.authoredDate),committedDate:new Date(l.body.data.createCommitOnBranch.commit.committedDate),oid:l.body.data.createCommitOnBranch.commit.oid}}}}async getAccountForEmail(e,t={}){let r=await this.getScopes(t),o=await f(this.config,{query:`
438
438
  query getAccountForEmail($query: String! $avatarSize: Int) {
439
439
  search(query: $query, type: USER, first: 1) {
440
440
  nodes {
441
441
  ... on User {
442
- ${G(!0,j(s))}
442
+ ${O(!0,M(r))}
443
443
  }
444
444
  }
445
445
  }
446
446
  }
447
- `,variables:{query:`in:email ${e.email}`,avatarSize:e.avatarSize}},t),i=o.body.data?.search?.nodes?.[0];if(!i)throw new h("Could not find user via email",o.body.errors);return{data:O({...i,avatarUrl:this.getEnterpriseAvatarUrlIfNeeded(i.avatarUrl,i.email,t)})}}async getAccountForUsername(e,t={}){let s=await this.getScopes(t),o=await f(this.config,{query:`
447
+ `,variables:{query:`in:email ${e.email}`,avatarSize:e.avatarSize}},t),i=o.body.data?.search?.nodes?.[0];if(!i)throw new h("Could not find user via email",o.body.errors);return{data:k({...i,avatarUrl:this.getEnterpriseAvatarUrlIfNeeded(i.avatarUrl,i.email,t)})}}async getAccountForUsername(e,t={}){let r=await this.getScopes(t),o=await f(this.config,{query:`
448
448
  query getUserForUsername($login: String! $avatarSize: Int) {
449
449
  user(login: $login) {
450
- ${G(!0,j(s))}
450
+ ${O(!0,M(r))}
451
451
  }
452
452
  }
453
- `,variables:{login:e.username,avatarSize:e.avatarSize}},t),i=o.body.data?.user;if(!i)throw new h("Could not find user via username",o.body.errors);return{data:O({...i,avatarUrl:this.getEnterpriseAvatarUrlIfNeeded(i.avatarUrl,i.email,t)})}}async getOrgsForCurrentUser(e={},t={}){let s=await f(this.config,{query:`
453
+ `,variables:{login:e.username,avatarSize:e.avatarSize}},t),i=o.body.data?.user;if(!i)throw new h("Could not find user via username",o.body.errors);return{data:k({...i,avatarUrl:this.getEnterpriseAvatarUrlIfNeeded(i.avatarUrl,i.email,t)})}}async getOrgsForCurrentUser(e={},t={}){let r=await f(this.config,{query:`
454
454
  query getOrgsForCurrentUser($cursor: String, $first: Int!) {
455
455
  viewer {
456
456
  organizations(first: $first after: $cursor) {
@@ -469,7 +469,7 @@ query getOrgsForCurrentUser($cursor: String, $first: Int!) {
469
469
  }
470
470
  }
471
471
  }
472
- `,variables:{cursor:e.cursor,first:E}},t);if(!s.body.data)throw new h("Could not fetch orgs for current user",s.body.errors);let o=s.body.data.viewer.organizations.nodes||[];return{pageInfo:s.body.data.viewer.organizations.pageInfo,data:o.map(i=>({id:i.databaseId.toString(),graphQLId:i.id,username:i.login,name:i.name||null,email:i.email||null,avatarUrl:i.avatarUrl}))}}async getOrgMembers(e,t={}){let s=await f(this.config,{query:`
472
+ `,variables:{cursor:e.cursor,first:D}},t);if(!r.body.data)throw new h("Could not fetch orgs for current user",r.body.errors);let o=r.body.data.viewer.organizations.nodes||[];return{pageInfo:r.body.data.viewer.organizations.pageInfo,data:o.map(i=>({id:i.databaseId.toString(),graphQLId:i.id,username:i.login,name:i.name||null,email:i.email||null,avatarUrl:i.avatarUrl}))}}async getOrgMembers(e,t={}){let r=await f(this.config,{query:`
473
473
  query getOrgMember($cursor: String, $first: Int!, $login: String!) {
474
474
  viewer {
475
475
  organization(login: $login) {
@@ -479,28 +479,28 @@ query getOrgMember($cursor: String, $first: Int!, $login: String!) {
479
479
  hasNextPage
480
480
  }
481
481
  nodes {
482
- ${G(!1,!0)}
482
+ ${O(!1,!0)}
483
483
  }
484
484
  }
485
485
  }
486
486
  }
487
487
  }
488
- `,variables:{cursor:e.cursor,first:E,login:e.org}},t);if(!s.body.data?.viewer.organization?.membersWithRole&&s.body.errors?.length)throw new h("Could not read the members of the organization",s.body.errors);let o=s.body.data?.viewer.organization?.membersWithRole.nodes||[];return{pageInfo:{hasNextPage:s.body.data?.viewer.organization?.membersWithRole.pageInfo.hasNextPage??!1,endCursor:s.body.data?.viewer.organization?.membersWithRole.pageInfo.endCursor??null},data:o.map(i=>O({...i,avatarUrl:this.getEnterpriseAvatarUrlIfNeeded(i.avatarUrl,i.email,t)}))}}async getRepo(e,t={}){let s=await f(this.config,{query:`
488
+ `,variables:{cursor:e.cursor,first:D,login:e.org}},t);if(!r.body.data?.viewer.organization?.membersWithRole&&r.body.errors?.length)throw new h("Could not read the members of the organization",r.body.errors);let o=r.body.data?.viewer.organization?.membersWithRole.nodes||[];return{pageInfo:{hasNextPage:r.body.data?.viewer.organization?.membersWithRole.pageInfo.hasNextPage??!1,endCursor:r.body.data?.viewer.organization?.membersWithRole.pageInfo.endCursor??null},data:o.map(i=>k({...i,avatarUrl:this.getEnterpriseAvatarUrlIfNeeded(i.avatarUrl,i.email,t)}))}}async getRepo(e,t={}){let r=await f(this.config,{query:`
489
489
  query getRepo($owner: String!, $name: String!) {
490
490
  repository(owner: $owner, name: $name) {
491
- ${it}
491
+ ${mt}
492
492
  }
493
493
  }
494
- `,variables:{owner:e.namespace,name:e.name}},t);if(!s.body.data?.repository)throw new h(`Repository ${e.namespace}/${e.name} not found`,s.body.errors);return{data:at(s.body.data.repository)}}async getRepos(e,t={}){let s=e.map(({namespace:u,name:p},d)=>`
495
- getRepo_${d}: repository(owner: "${u}", name: "${p}") {
496
- ${it}
494
+ `,variables:{owner:e.namespace,name:e.name}},t);if(!r.body.data?.repository)throw new h(`Repository ${e.namespace}/${e.name} not found`,r.body.errors);return{data:gt(r.body.data.repository)}}async getRepos(e,t={}){let r=e.map(({namespace:u,name:l},p)=>`
495
+ getRepo_${p}: repository(owner: "${u}", name: "${l}") {
496
+ ${mt}
497
497
  }
498
498
  `).join(`
499
499
  `),o=await f(this.config,{query:`
500
500
  query batchGetRepos {
501
- ${s}
501
+ ${r}
502
502
  }
503
- `},t);if(!o.body.data)throw new h("Could not fetch repos",o.body.errors);let i=[],a=[];return e.forEach((u,p)=>{let d=o.body.data[`getRepo_${p}`];d?i.push(at(d)):a.push({input:u})}),{data:i,errors:a}}async fetchMultipleRESTPages(e,t,s,o){let i=[];for(let c=0;c<t;c++)i.push(s(e+c));let a=await Promise.all(i),u=[];for(let c of a){if(!c.body)throw new Error(c.statusText||"Unknown error");u=u.concat(c.body.map(l=>o(l)))}let p=a.every(c=>c.body.length===100),d=e+t;return{data:u,pageInfo:{hasNextPage:p,nextPage:p?d:null}}}async getReposForCurrentUser(e,t={}){if(e.simultaneousPagesToFetch&&e.simultaneousPagesToFetch>40)throw new Error("The argument 'simultaneousPagesToFetch' cannot exceed 40 for 'getReposForCurrentUser'");let s=new URLSearchParams;s.append("per_page","100"),e.affiliations&&s.append("affiliation",e.affiliations.join(","));let o=i=>this.config.request({url:`${Y(this.config,t)}/user/repos?${s.toString()}&page=${i}`,headers:{...I(t.token||this.config.token),Accept:"application/vnd.github.raw+json","X-Github-Next-Global-ID":1}});return await this.fetchMultipleRESTPages(e.page??1,e.simultaneousPagesToFetch??4,o,rr)}async getReposForOrg(e,t={}){if(e.simultaneousPagesToFetch&&e.simultaneousPagesToFetch>40)throw new Error("The argument 'simultaneousPagesToFetch' cannot exceed 40 for 'getReposForOrg'");let s=o=>this.config.request({url:`${Y(this.config,t)}/orgs/${e.orgName}/repos?per_page=100&page=${o}`,headers:{...I(t.token||this.config.token),Accept:"application/vnd.github.raw+json","X-Github-Next-Global-ID":1}});return await this.fetchMultipleRESTPages(e.page??1,e.simultaneousPagesToFetch??4,s,rr)}async getReposForUsernames(e,t={}){if(!e.usernames.length)return{pageInfo:{endCursor:null,hasNextPage:!1},data:[]};let s=await f(this.config,{query:`
503
+ `},t);if(!o.body.data)throw new h("Could not fetch repos",o.body.errors);let i=[],a=[];return e.forEach((u,l)=>{let p=o.body.data[`getRepo_${l}`];p?i.push(gt(p)):a.push({input:u})}),{data:i,errors:a}}async fetchMultipleRESTPages(e,t,r,o){let i=[];for(let c=0;c<t;c++)i.push(r(e+c));let a=await Promise.all(i),u=[];for(let c of a){if(!c.body)throw new Error(c.statusText||"Unknown error");u=u.concat(c.body.map(d=>o(d)))}let l=a.every(c=>c.body.length===100),p=e+t;return{data:u,pageInfo:{hasNextPage:l,nextPage:l?p:null}}}async getReposForCurrentUser(e,t={}){if(e.simultaneousPagesToFetch&&e.simultaneousPagesToFetch>40)throw new Error("The argument 'simultaneousPagesToFetch' cannot exceed 40 for 'getReposForCurrentUser'");let r=new URLSearchParams;r.append("per_page","100"),e.affiliations&&r.append("affiliation",e.affiliations.join(","));let o=i=>this.config.request({url:`${te(this.config,t)}/user/repos?${r.toString()}&page=${i}`,headers:{...b(t.token||this.config.token),Accept:"application/vnd.github.raw+json","X-Github-Next-Global-ID":1}});return await this.fetchMultipleRESTPages(e.page??1,e.simultaneousPagesToFetch??4,o,pr)}async getReposForOrg(e,t={}){if(e.simultaneousPagesToFetch&&e.simultaneousPagesToFetch>40)throw new Error("The argument 'simultaneousPagesToFetch' cannot exceed 40 for 'getReposForOrg'");let r=o=>this.config.request({url:`${te(this.config,t)}/orgs/${e.orgName}/repos?per_page=100&page=${o}`,headers:{...b(t.token||this.config.token),Accept:"application/vnd.github.raw+json","X-Github-Next-Global-ID":1}});return await this.fetchMultipleRESTPages(e.page??1,e.simultaneousPagesToFetch??4,r,pr)}async getReposForUsernames(e,t={}){if(!e.usernames.length)return{pageInfo:{endCursor:null,hasNextPage:!1},data:[]};let r=await f(this.config,{query:`
504
504
  query getReposForUsernames($query: String!, $cursor: String, $first: Int!) {
505
505
  search(query: $query, type: REPOSITORY, first: $first, after: $cursor) {
506
506
  pageInfo {
@@ -509,12 +509,12 @@ query getReposForUsernames($query: String!, $cursor: String, $first: Int!) {
509
509
  }
510
510
  nodes {
511
511
  ... on Repository {
512
- ${it}
512
+ ${mt}
513
513
  }
514
514
  }
515
515
  }
516
516
  }
517
- `,variables:{query:`fork:true ${e.usernames.map(i=>`user:${i}`).join(" ")}`,cursor:e.cursor,first:E}},t);if(!s.body.data)throw new h("Could not fetch repos for usernames",s.body.errors);let o=s.body.data.search.nodes||[];return{pageInfo:s.body.data.search.pageInfo,data:o.map(at)}}async getReposForOwners(e,t={}){return this.getReposForUsernames({usernames:e.owners.filter(s=>s.username).map(s=>s.username),cursor:e.cursor},t)}async getRefs(e,t,s={}){let o=await f(this.config,{query:`
517
+ `,variables:{query:`fork:true ${e.usernames.map(i=>`user:${i}`).join(" ")}`,cursor:e.cursor,first:D}},t);if(!r.body.data)throw new h("Could not fetch repos for usernames",r.body.errors);let o=r.body.data.search.nodes||[];return{pageInfo:r.body.data.search.pageInfo,data:o.map(gt)}}async getReposForOwners(e,t={}){return this.getReposForUsernames({usernames:e.owners.filter(r=>r.username).map(r=>r.username),cursor:e.cursor},t)}async getRefs(e,t,r={}){let o=await f(this.config,{query:`
518
518
  query getRefs($owner: String!, $name: String!, $refPrefix: String!, $cursor: String, $first: Int!) {
519
519
  repository(owner: $owner, name: $name) {
520
520
  refs(refPrefix: $refPrefix first: $first after: $cursor) {
@@ -535,7 +535,7 @@ query getRefs($owner: String!, $name: String!, $refPrefix: String!, $cursor: Str
535
535
  }
536
536
  }
537
537
  }
538
- `,variables:{owner:t.repo.namespace,name:t.repo.name,refPrefix:e,cursor:t.cursor,first:E}},s),i=o.body.data?.repository;if(!i)throw new h("Ref repository not found.",o.body.errors);let a=i.refs;return a?{pageInfo:a.pageInfo,data:(a.nodes||[]).map(u=>{let p=u.target?.oid?u.target:null;return{name:u.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,t={}){return this.getRefs("refs/heads/",e,t)}async getTags(e,t={}){return this.getRefs("refs/tags/",e,t)}async getBlame(e,t={}){let s=await f(this.config,{query:`
538
+ `,variables:{owner:t.repo.namespace,name:t.repo.name,refPrefix:e,cursor:t.cursor,first:D}},r),i=o.body.data?.repository;if(!i)throw new h("Ref repository not found.",o.body.errors);let a=i.refs;return a?{pageInfo:a.pageInfo,data:(a.nodes||[]).map(u=>{let l=u.target?.oid?u.target:null;return{name:u.name,commit:l?{oid:l.oid,authoredDate:new Date(l.authoredDate),committedDate:new Date(l.committedDate)}:null}})}:{pageInfo:{endCursor:null,hasNextPage:!1},data:[]}}async getBranches(e,t={}){return this.getRefs("refs/heads/",e,t)}async getTags(e,t={}){return this.getRefs("refs/tags/",e,t)}async getBlame(e,t={}){let r=await f(this.config,{query:`
539
539
  query getBlame($owner: String!, $name: String!, $ref: String!, $path: String!) {
540
540
  repository(owner: $owner, name: $name) {
541
541
  object(expression: $ref) {
@@ -574,7 +574,7 @@ query getBlame($owner: String!, $name: String!, $ref: String!, $path: String!) {
574
574
  }
575
575
  }
576
576
  }
577
- `,variables:{owner:e.repo.namespace,name:e.repo.name,ref:e.ref,path:e.path}},t),o=s.body.data?.repository;if(!o)throw new h("Blame repository not found.",s.body.errors);let i=o.object;if(!i||!("blame"in i))throw new h("Ref not found.",s.body.errors);if(i.blame.ranges.length===0)throw new h("File not found.",s.body.errors);return{data:{ranges:i.blame.ranges.map(a=>({startingLine:a.startingLine,endingLine:a.endingLine,commit:{oid:a.commit.oid,parentOids:a.commit.parents.nodes?.map(u=>u.oid)||[],authoredDate:new Date(a.commit.authoredDate),author:a.commit.author?{name:a.commit.author.name,email:a.commit.author.email,avatarUrl:a.commit.author.avatarUrl}:null,committedDate:new Date(a.commit.committedDate),committer:a.commit.committer?{name:a.commit.committer.name,email:a.commit.committer.email,avatarUrl:a.commit.committer.avatarUrl}:null,message:a.commit.message,fileCount:a.commit.changedFilesIfAvailable,additions:a.commit.additions,deletions:a.commit.deletions}}))}}}async getFileContents(e,t={}){let s=await this.config.request({url:`${Y(this.config,t)}/repos/${e.repo.namespace}/${e.repo.name}/contents/${encodeURIComponent(e.path)}?ref=${e.ref}`,headers:{...I(t.token||this.config.token),Accept:"application/vnd.github.raw+json"}});if(s.headers["content-type"].startsWith("application/json"))throw new Error(`GitHub: got directory when fetching "${e.path}", getFileContents does not support fetching directories`);if(!s.headers["content-type"].startsWith("application/vnd.github.raw+json"))throw new Error(`GitHub: unsupported content type "${s.headers["content-type"]}" when fetching "${e.path}"`);return{data:new Blob([s.body])}}async getMergeBase(e,t={}){return{data:(await this.config.request({url:`${Y(this.config,t)}/repos/${e.repo.namespace}/${e.repo.name}/compare/${encodeURIComponent(e.base)}...${encodeURIComponent(e.head)}`,headers:I(t.token||this.config.token)})).body.merge_base_commit.sha}}async searchPullRequests(e,t={}){let s=await this.getEnterpriseVersion(t),o=await this.getScopes(t),i=j(o),a=d=>{let c=d&&typeof e.isDraft=="boolean"?`${e.query} draft:${e.isDraft}`:e.query;return ot("pr",c,e.cursor,{maxPageSize:e.maxPageSize??Bt,supportsEmail:i,supportsDrafts:d,enterpriseVersion:s,includeFromArchivedRepos:e.includeFromArchivedRepos})},u=await f(this.config,a(!0),t);u.body.errors&&Le(u.body.errors)&&(this.config.baseUrl||t.baseUrl)&&(u=await f(this.config,a(!1),t));let{data:p}=u.body;if(!p)throw new h("Could not search pull requests",u.body.errors);return{pageInfo:{hasNextPage:p.search.pageInfo.hasNextPage,endCursor:p.search.pageInfo.endCursor},data:p.search.nodes?.filter($).map(ut)||[]}}async searchIssues(e,t={}){let s=await this.getEnterpriseVersion(t),o=await this.getScopes(t),i=j(o),a=await f(this.config,ot("issue",e.query,e.cursor,{supportsEmail:i,includeFromArchivedRepos:e.includeFromArchivedRepos,maxPageSize:e.maxPageSize??Mt,enterpriseVersion:s}),t),{data:u}=a.body;if(!u)throw new h("Could not search issues",a.body.errors);return{pageInfo:{hasNextPage:u.search.pageInfo.hasNextPage,endCursor:u.search.pageInfo.endCursor},data:u.search.nodes?.filter($).map(qs)||[]}}async getPullRequestsAssociatedWithUser(e,t={}){let s=[`involves:${e.username}`];return e.repos?.length&&e.repos.forEach(o=>{s.push(`repo:${o.namespace}/${o.name}`)}),e.labelNames&&e.labelNames.forEach(o=>{s.push(`label:"${o}"`)}),this.searchPullRequests({query:s.join(" "),cursor:e.cursor,includeFromArchivedRepos:e.includeFromArchivedRepos,maxPageSize:e.maxPageSize},t)}async getPullRequestsForRepos(e,t={}){let{assigneeLogins:s,updatedBefore:o,authorLogin:i,repos:a,reviewRequestedLogin:u,startQuery:p,mentionLogin:d,labelNames:c,maxPageSize:l}=e,g=nt(p||"");return a.forEach(m=>{g.push(`repo:${m.namespace}/${m.name}`)}),s&&s.forEach(m=>{g.push(`assignee:${m}`)}),o&&g.push(`updated:<${o}`),i&&g.push(`author:${i}`),u&&g.push(`review-requested:${u}`),d&&g.push(`mentions:${d}`),c&&c.forEach(m=>{g.push(`label:"${m}"`)}),this.searchPullRequests({query:`sort:updated ${g.join(" ")}`,isDraft:e.isDraft,cursor:e.cursor,includeFromArchivedRepos:e.includeFromArchivedRepos,maxPageSize:l},t)}async getPullRequestForRepo(e,t={}){let s=await this.getEnterpriseVersion(t),o=await this.getScopes(t),i=j(o),a=c=>({query:`query getPullRequest(
577
+ `,variables:{owner:e.repo.namespace,name:e.repo.name,ref:e.ref,path:e.path}},t),o=r.body.data?.repository;if(!o)throw new h("Blame repository not found.",r.body.errors);let i=o.object;if(!i||!("blame"in i))throw new h("Ref not found.",r.body.errors);if(i.blame.ranges.length===0)throw new h("File not found.",r.body.errors);return{data:{ranges:i.blame.ranges.map(a=>({startingLine:a.startingLine,endingLine:a.endingLine,commit:{oid:a.commit.oid,parentOids:a.commit.parents.nodes?.map(u=>u.oid)||[],authoredDate:new Date(a.commit.authoredDate),author:a.commit.author?{name:a.commit.author.name,email:a.commit.author.email,avatarUrl:a.commit.author.avatarUrl}:null,committedDate:new Date(a.commit.committedDate),committer:a.commit.committer?{name:a.commit.committer.name,email:a.commit.committer.email,avatarUrl:a.commit.committer.avatarUrl}:null,message:a.commit.message,fileCount:a.commit.changedFilesIfAvailable,additions:a.commit.additions,deletions:a.commit.deletions}}))}}}async getFileContents(e,t={}){let r=await this.config.request({url:`${te(this.config,t)}/repos/${e.repo.namespace}/${e.repo.name}/contents/${encodeURIComponent(e.path)}?ref=${e.ref}`,headers:{...b(t.token||this.config.token),Accept:"application/vnd.github.raw+json"}});if(r.headers["content-type"].startsWith("application/json"))throw new Error(`GitHub: got directory when fetching "${e.path}", getFileContents does not support fetching directories`);if(!r.headers["content-type"].startsWith("application/vnd.github.raw+json"))throw new Error(`GitHub: unsupported content type "${r.headers["content-type"]}" when fetching "${e.path}"`);return{data:new Blob([r.body])}}async getMergeBase(e,t={}){return{data:(await this.config.request({url:`${te(this.config,t)}/repos/${e.repo.namespace}/${e.repo.name}/compare/${encodeURIComponent(e.base)}...${encodeURIComponent(e.head)}`,headers:b(t.token||this.config.token)})).body.merge_base_commit.sha}}async searchPullRequests(e,t={}){let r=await this.getEnterpriseVersion(t),o=await this.getScopes(t),i=M(o),a=p=>{let c=p&&typeof e.isDraft=="boolean"?`${e.query} draft:${e.isDraft}`:e.query;return ct("pr",c,e.cursor,{maxPageSize:e.maxPageSize??Xt,supportsEmail:i,supportsDrafts:p,enterpriseVersion:r,includeFromArchivedRepos:e.includeFromArchivedRepos})},u=await f(this.config,a(!0),t);u.body.errors&&Te(u.body.errors)&&(this.config.baseUrl||t.baseUrl)&&(u=await f(this.config,a(!1),t));let{data:l}=u.body;if(!l)throw new h("Could not search pull requests",u.body.errors);return{pageInfo:{hasNextPage:l.search.pageInfo.hasNextPage,endCursor:l.search.pageInfo.endCursor},data:l.search.nodes?.filter(A).map(ht)||[]}}async searchIssues(e,t={}){let r=await this.getEnterpriseVersion(t),o=await this.getScopes(t),i=M(o),a=await f(this.config,ct("issue",e.query,e.cursor,{supportsEmail:i,includeFromArchivedRepos:e.includeFromArchivedRepos,maxPageSize:e.maxPageSize??Zt,enterpriseVersion:r}),t),{data:u}=a.body;if(!u)throw new h("Could not search issues",a.body.errors);return{pageInfo:{hasNextPage:u.search.pageInfo.hasNextPage,endCursor:u.search.pageInfo.endCursor},data:u.search.nodes?.filter(A).map(As)||[]}}async getPullRequestsAssociatedWithUser(e,t={}){let r=[`involves:${e.username}`];return e.repos?.length&&e.repos.forEach(o=>{r.push(`repo:${o.namespace}/${o.name}`)}),e.labelNames&&e.labelNames.forEach(o=>{r.push(`label:"${o}"`)}),this.searchPullRequests({query:r.join(" "),cursor:e.cursor,includeFromArchivedRepos:e.includeFromArchivedRepos,maxPageSize:e.maxPageSize},t)}async getPullRequestsForRepos(e,t={}){let{assigneeLogins:r,updatedBefore:o,authorLogin:i,repos:a,reviewRequestedLogin:u,startQuery:l,mentionLogin:p,labelNames:c,maxPageSize:d}=e,m=dt(l||"");return a.forEach(g=>{m.push(`repo:${g.namespace}/${g.name}`)}),r&&r.forEach(g=>{m.push(`assignee:${g}`)}),o&&m.push(`updated:<${o}`),i&&m.push(`author:${i}`),u&&m.push(`review-requested:${u}`),p&&m.push(`mentions:${p}`),c&&c.forEach(g=>{m.push(`label:"${g}"`)}),this.searchPullRequests({query:`sort:updated ${m.join(" ")}`,isDraft:e.isDraft,cursor:e.cursor,includeFromArchivedRepos:e.includeFromArchivedRepos,maxPageSize:d},t)}async getPullRequestForRepo(e,t={}){let r=await this.getEnterpriseVersion(t),o=await this.getScopes(t),i=M(o),a=c=>({query:`query getPullRequest(
578
578
  $owner: String!
579
579
  $name: String!
580
580
  $number: Int!
@@ -584,24 +584,24 @@ query getBlame($owner: String!, $name: String!, $ref: String!, $path: String!) {
584
584
  name: $name
585
585
  ) {
586
586
  pullRequest(number: $number) {
587
- ${De(c,i,s)}
587
+ ${Ge(c,i,r)}
588
588
  }
589
589
  }
590
- }`,variables:{owner:e.repo.namespace,name:e.repo.name,number:e.number}}),u=await f(this.config,a(!0),t);u.body.errors&&Le(u.body.errors)&&(this.config.baseUrl||t.baseUrl)&&(u=await f(this.config,a(!1),t));let{data:p}=u.body;if(!p)throw new h("Could not fetch pull request by number",u.body.errors);let d=u.body.data?.repository.pullRequest;return{data:d?ut(d):null}}async getPullRequestByGraphQLId(e,t={}){let s=await this.getEnterpriseVersion(t),o=await this.getScopes(t),i=j(o),a=c=>({query:`query getPullRequest(
590
+ }`,variables:{owner:e.repo.namespace,name:e.repo.name,number:e.number}}),u=await f(this.config,a(!0),t);u.body.errors&&Te(u.body.errors)&&(this.config.baseUrl||t.baseUrl)&&(u=await f(this.config,a(!1),t));let{data:l}=u.body;if(!l)throw new h("Could not fetch pull request by number",u.body.errors);let p=u.body.data?.repository.pullRequest;return{data:p?ht(p):null}}async getPullRequestByGraphQLId(e,t={}){let r=await this.getEnterpriseVersion(t),o=await this.getScopes(t),i=M(o),a=c=>({query:`query getPullRequest(
591
591
  $graphQLId: ID!
592
592
  ) {
593
593
  node(id: $graphQLId) {
594
594
  ... on PullRequest {
595
- ${De(c,i,s)}
595
+ ${Ge(c,i,r)}
596
596
  }
597
597
  }
598
- }`,variables:{graphQLId:e.graphQLId}}),u=await f(this.config,a(!0),t);u.body.errors&&Le(u.body.errors)&&(this.config.baseUrl||t.baseUrl)&&(u=await f(this.config,a(!1),t));let{data:p}=u.body;if(!p)throw new h("Could not fetch pull request by id",u.body.errors);let d=u.body.data?.node;return{data:d?ut(d):null}}async closePullRequest(e,t={}){let{pullRequest:{graphQLId:s}}=e;if(!s)throw new Error('GitHub requires "graphQLId" for this function.');let o=`mutation ClosePullRequest($pullRequestGraphQLId: ID!) {
598
+ }`,variables:{graphQLId:e.graphQLId}}),u=await f(this.config,a(!0),t);u.body.errors&&Te(u.body.errors)&&(this.config.baseUrl||t.baseUrl)&&(u=await f(this.config,a(!1),t));let{data:l}=u.body;if(!l)throw new h("Could not fetch pull request by id",u.body.errors);let p=u.body.data?.node;return{data:p?ht(p):null}}async closePullRequest(e,t={}){let{pullRequest:{graphQLId:r}}=e;if(!r)throw new Error('GitHub requires "graphQLId" for this function.');let o=`mutation ClosePullRequest($pullRequestGraphQLId: ID!) {
599
599
  closePullRequest(input: { pullRequestId: $pullRequestGraphQLId }) {
600
600
  pullRequest {
601
601
  id
602
602
  }
603
603
  }
604
- }`,i=await f(this.config,{query:`${o}`,variables:{pullRequestGraphQLId:s}},t);if(!i.body.data?.closePullRequest?.pullRequest?.id)throw new h("Could not close pull request",i.body.errors)}async mergePullRequest(e,t={}){let{pullRequest:s,mergeStrategy:o}=e;if(!s.graphQLId)throw new Error('GitHub requires "graphQLId" for this function.');if(!s.headRef?.oid)throw new Error('GitHub requires "headRef.oid" for this function.');let i;switch(o){case"MERGE_COMMIT":{i="MERGE";break}case"REBASE":{i="REBASE";break}case"SQUASH":{i="SQUASH";break}}let a=`mutation MergePullRequest(
604
+ }`,i=await f(this.config,{query:`${o}`,variables:{pullRequestGraphQLId:r}},t);if(!i.body.data?.closePullRequest?.pullRequest?.id)throw new h("Could not close pull request",i.body.errors)}async mergePullRequest(e,t={}){let{pullRequest:r,mergeStrategy:o}=e;if(!r.graphQLId)throw new Error('GitHub requires "graphQLId" for this function.');if(!r.headRef?.oid)throw new Error('GitHub requires "headRef.oid" for this function.');let i;switch(o){case"MERGE_COMMIT":{i="MERGE";break}case"REBASE":{i="REBASE";break}case"SQUASH":{i="SQUASH";break}}let a=`mutation MergePullRequest(
605
605
  $pullRequestGraphQLId: ID!,
606
606
  $expectedSourceSha: GitObjectID!,
607
607
  $mergeStrategy: PullRequestMergeMethod,
@@ -615,7 +615,7 @@ query getBlame($owner: String!, $name: String!, $ref: String!, $path: String!) {
615
615
  id
616
616
  }
617
617
  }
618
- }`,u=await f(this.config,{query:`${a}`,variables:{pullRequestGraphQLId:s.graphQLId,expectedSourceSha:s.headRef.oid,mergeStrategy:i}},t);if(!u.body.data?.mergePullRequest?.pullRequest?.id)throw new h("Could not merge pull request",u.body.errors)}async approvePullRequest(e,t={}){let{pullRequest:s,comment:o}=e;if(!s.graphQLId)throw new Error('GitHub requires "graphQLId" for this function.');let i=`mutation ApprovePullRequest(
618
+ }`,u=await f(this.config,{query:`${a}`,variables:{pullRequestGraphQLId:r.graphQLId,expectedSourceSha:r.headRef.oid,mergeStrategy:i}},t);if(!u.body.data?.mergePullRequest?.pullRequest?.id)throw new h("Could not merge pull request",u.body.errors)}async approvePullRequest(e,t={}){let{pullRequest:r,comment:o}=e;if(!r.graphQLId)throw new Error('GitHub requires "graphQLId" for this function.');let i=`mutation ApprovePullRequest(
619
619
  $pullRequestId: ID!,
620
620
  $body: String
621
621
  ) {
@@ -628,7 +628,7 @@ query getBlame($owner: String!, $name: String!, $ref: String!, $path: String!) {
628
628
  id
629
629
  }
630
630
  }
631
- }`,a=await f(this.config,{query:i,variables:{pullRequestId:s.graphQLId,body:o||null}},t);if(!a.body.data?.addPullRequestReview?.pullRequestReview?.id)throw new h("Could not approve pull request",a.body.errors)}async requestPullRequestChanges(e,t={}){let{pullRequest:s,comment:o}=e;if(!s.graphQLId)throw new Error('GitHub requires "graphQLId" for this function.');if(!o||o.trim()==="")throw new Error("GitHub requires a comment when requesting changes.");let i=`mutation RequestPullRequestChanges(
631
+ }`,a=await f(this.config,{query:i,variables:{pullRequestId:r.graphQLId,body:o||null}},t);if(!a.body.data?.addPullRequestReview?.pullRequestReview?.id)throw new h("Could not approve pull request",a.body.errors)}async requestPullRequestChanges(e,t={}){let{pullRequest:r,comment:o}=e;if(!r.graphQLId)throw new Error('GitHub requires "graphQLId" for this function.');if(!o||o.trim()==="")throw new Error("GitHub requires a comment when requesting changes.");let i=`mutation RequestPullRequestChanges(
632
632
  $pullRequestId: ID!,
633
633
  $body: String!
634
634
  ) {
@@ -641,7 +641,7 @@ query getBlame($owner: String!, $name: String!, $ref: String!, $path: String!) {
641
641
  id
642
642
  }
643
643
  }
644
- }`,a=await f(this.config,{query:i,variables:{pullRequestId:s.graphQLId,body:o}},t);if(!a.body.data?.addPullRequestReview?.pullRequestReview?.id)throw new h("Could not request pull request changes",a.body.errors)}async commentOnPullRequest(e,t={}){let{pullRequest:s,comment:o}=e;if(!s.graphQLId)throw new Error('GitHub requires "graphQLId" for this function.');if(!o||o.trim()==="")throw new Error("GitHub requires a comment when commenting on a pull request.");let i=`mutation CommentOnPullRequest(
644
+ }`,a=await f(this.config,{query:i,variables:{pullRequestId:r.graphQLId,body:o}},t);if(!a.body.data?.addPullRequestReview?.pullRequestReview?.id)throw new h("Could not request pull request changes",a.body.errors)}async commentOnPullRequest(e,t={}){let{pullRequest:r,comment:o}=e;if(!r.graphQLId)throw new Error('GitHub requires "graphQLId" for this function.');if(!o||o.trim()==="")throw new Error("GitHub requires a comment when commenting on a pull request.");let i=`mutation CommentOnPullRequest(
645
645
  $pullRequestId: ID!,
646
646
  $body: String!
647
647
  ) {
@@ -654,7 +654,7 @@ query getBlame($owner: String!, $name: String!, $ref: String!, $path: String!) {
654
654
  id
655
655
  }
656
656
  }
657
- }`,a=await f(this.config,{query:i,variables:{pullRequestId:s.graphQLId,body:o}},t);if(!a.body.data?.addPullRequestReview?.pullRequestReview?.id)throw new h("Could not comment on pull request",a.body.errors)}async addCommentToPullRequest(e,t={}){let{pullRequest:s,comment:o}=e;if(!s.graphQLId)throw new Error('GitHub requires "graphQLId" for this function.');if(!o||o.trim()==="")throw new Error("GitHub requires a comment when adding a comment to a pull request.");let i=`mutation AddCommentToPullRequest(
657
+ }`,a=await f(this.config,{query:i,variables:{pullRequestId:r.graphQLId,body:o}},t);if(!a.body.data?.addPullRequestReview?.pullRequestReview?.id)throw new h("Could not comment on pull request",a.body.errors)}async addCommentToPullRequest(e,t={}){let{pullRequest:r,comment:o}=e;if(!r.graphQLId)throw new Error('GitHub requires "graphQLId" for this function.');if(!o||o.trim()==="")throw new Error("GitHub requires a comment when adding a comment to a pull request.");let i=`mutation AddCommentToPullRequest(
658
658
  $subjectId: ID!,
659
659
  $body: String!
660
660
  ) {
@@ -668,7 +668,7 @@ query getBlame($owner: String!, $name: String!, $ref: String!, $path: String!) {
668
668
  }
669
669
  }
670
670
  }
671
- }`,a=await f(this.config,{query:i,variables:{subjectId:s.graphQLId,body:o}},t);if(!a.body.data?.addComment?.commentEdge?.node?.id)throw new h("Could not add comment to pull request",a.body.errors)}async addInlineCommentToPullRequest(e,t={}){let{pullRequest:s,comment:o,path:i,line:a,side:u="RIGHT",threadId:p}=e;if(!s.graphQLId)throw new Error('GitHub requires "graphQLId" for this function.');if(!o?.trim())throw new Error("GitHub requires a comment when adding an inline comment to a pull request.");if(p)return this.addReplyToReviewThread({threadId:p,comment:o},t);if(!i?.trim())throw new Error("GitHub requires a file path when adding an inline comment to a pull request.");if(!Number.isInteger(a)||a<1)throw new Error("GitHub requires a positive line number when adding an inline comment to a pull request.");if(u!=="LEFT"&&u!=="RIGHT")throw new Error('GitHub requires side to be either "LEFT" or "RIGHT".');return this.createReviewThread({pullRequest:s,comment:o,path:i,line:a,side:u},t)}async deleteInlineComment(e,t={}){let{commentId:s}=e;if(!s)throw new Error('GitHub requires "commentId" for this function.');let o=await f(this.config,{query:Kt,variables:{pullRequestReviewCommentId:s}},t);if(!o.body.data?.deletePullRequestReviewComment)throw new h("Could not delete inline comment",o.body.errors)}async deleteComment(e,t={}){let{commentId:s}=e;if(!s)throw new Error('GitHub requires "commentId" for this function.');let o=await f(this.config,{query:Vt,variables:{issueCommentId:s}},t);if(!o.body.data?.deleteIssueComment)throw new h("Could not delete comment",o.body.errors)}async editComment(e,t={}){let{commentId:s,body:o}=e;if(!s)throw new Error('GitHub requires "commentId" for this function.');if(!o?.trim())throw new Error("GitHub requires a body when editing a comment.");let i=await f(this.config,{query:Xt,variables:{issueCommentId:s,body:o}},t);if(!i.body.data?.updateIssueComment?.issueComment?.id)throw new h("Could not edit comment",i.body.errors)}async editInlineComment(e,t={}){let{commentId:s,body:o}=e;if(!s)throw new Error('GitHub requires "commentId" for this function.');if(!o?.trim())throw new Error("GitHub requires a body when editing an inline comment.");let i=await f(this.config,{query:er,variables:{pullRequestReviewCommentId:s,body:o}},t);if(!i.body.data?.updatePullRequestReviewComment?.pullRequestReviewComment?.id)throw new h("Could not edit inline comment",i.body.errors)}async resolveReviewThread(e,t={}){let{threadId:s}=e;if(!s)throw new Error('GitHub requires "threadId" for this function.');let o=await f(this.config,{query:Zt,variables:{pullRequestReviewThreadId:s}},t);if(!o.body.data?.resolveReviewThread?.thread?.id)throw new h("Could not resolve review thread",o.body.errors)}async unresolveReviewThread(e,t={}){let{threadId:s}=e;if(!s)throw new Error('GitHub requires "threadId" for this function.');let o=await f(this.config,{query:Yt,variables:{pullRequestReviewThreadId:s}},t);if(!o.body.data?.unresolveReviewThread?.thread?.id)throw new h("Could not unresolve review thread",o.body.errors)}async addReplyToReviewThread(e,t){let{threadId:s,comment:o}=e,i=`mutation AddPullRequestReviewThreadReply(
671
+ }`,a=await f(this.config,{query:i,variables:{subjectId:r.graphQLId,body:o}},t);if(!a.body.data?.addComment?.commentEdge?.node?.id)throw new h("Could not add comment to pull request",a.body.errors)}async addInlineCommentToPullRequest(e,t={}){let{pullRequest:r,comment:o,path:i,line:a,side:u="RIGHT",threadId:l}=e;if(!r.graphQLId)throw new Error('GitHub requires "graphQLId" for this function.');if(!o?.trim())throw new Error("GitHub requires a comment when adding an inline comment to a pull request.");if(l)return this.addReplyToReviewThread({threadId:l,comment:o},t);if(!i?.trim())throw new Error("GitHub requires a file path when adding an inline comment to a pull request.");if(!Number.isInteger(a)||a<1)throw new Error("GitHub requires a positive line number when adding an inline comment to a pull request.");if(u!=="LEFT"&&u!=="RIGHT")throw new Error('GitHub requires side to be either "LEFT" or "RIGHT".');return this.createReviewThread({pullRequest:r,comment:o,path:i,line:a,side:u},t)}async deleteInlineComment(e,t={}){let{commentId:r}=e;if(!r)throw new Error('GitHub requires "commentId" for this function.');let o=await f(this.config,{query:nr,variables:{pullRequestReviewCommentId:r}},t);if(!o.body.data?.deletePullRequestReviewComment)throw new h("Could not delete inline comment",o.body.errors)}async deleteComment(e,t={}){let{commentId:r}=e;if(!r)throw new Error('GitHub requires "commentId" for this function.');let o=await f(this.config,{query:sr,variables:{issueCommentId:r}},t);if(!o.body.data?.deleteIssueComment)throw new h("Could not delete comment",o.body.errors)}async editComment(e,t={}){let{commentId:r,body:o}=e;if(!r)throw new Error('GitHub requires "commentId" for this function.');if(!o?.trim())throw new Error("GitHub requires a body when editing a comment.");let i=await f(this.config,{query:or,variables:{issueCommentId:r,body:o}},t);if(!i.body.data?.updateIssueComment?.issueComment?.id)throw new h("Could not edit comment",i.body.errors)}async editInlineComment(e,t={}){let{commentId:r,body:o}=e;if(!r)throw new Error('GitHub requires "commentId" for this function.');if(!o?.trim())throw new Error("GitHub requires a body when editing an inline comment.");let i=await f(this.config,{query:ur,variables:{pullRequestReviewCommentId:r,body:o}},t);if(!i.body.data?.updatePullRequestReviewComment?.pullRequestReviewComment?.id)throw new h("Could not edit inline comment",i.body.errors)}async resolveReviewThread(e,t={}){let{threadId:r}=e;if(!r)throw new Error('GitHub requires "threadId" for this function.');let o=await f(this.config,{query:ir,variables:{pullRequestReviewThreadId:r}},t);if(!o.body.data?.resolveReviewThread?.thread?.id)throw new h("Could not resolve review thread",o.body.errors)}async unresolveReviewThread(e,t={}){let{threadId:r}=e;if(!r)throw new Error('GitHub requires "threadId" for this function.');let o=await f(this.config,{query:ar,variables:{pullRequestReviewThreadId:r}},t);if(!o.body.data?.unresolveReviewThread?.thread?.id)throw new h("Could not unresolve review thread",o.body.errors)}async addReplyToReviewThread(e,t){let{threadId:r,comment:o}=e,i=`mutation AddPullRequestReviewThreadReply(
672
672
  $threadId: ID!,
673
673
  $body: String!
674
674
  ) {
@@ -680,7 +680,7 @@ query getBlame($owner: String!, $name: String!, $ref: String!, $path: String!) {
680
680
  id
681
681
  }
682
682
  }
683
- }`,a=await f(this.config,{query:i,variables:{threadId:s,body:o}},t);if(!a.body.data?.addPullRequestReviewThreadReply?.comment?.id)throw new h("Could not add reply to pull request review thread",a.body.errors);return s}async createReviewThread(e,t){let{pullRequest:s,comment:o,path:i,line:a,side:u}=e,p=`mutation AddInlineCommentToPullRequest(
683
+ }`,a=await f(this.config,{query:i,variables:{threadId:r,body:o}},t);if(!a.body.data?.addPullRequestReviewThreadReply?.comment?.id)throw new h("Could not add reply to pull request review thread",a.body.errors);return r}async createReviewThread(e,t){let{pullRequest:r,comment:o,path:i,line:a,side:u}=e,l=`mutation AddInlineCommentToPullRequest(
684
684
  $pullRequestId: ID!,
685
685
  $body: String!,
686
686
  $path: String!,
@@ -706,43 +706,43 @@ query getBlame($owner: String!, $name: String!, $ref: String!, $path: String!) {
706
706
  }
707
707
  }
708
708
  }
709
- }`,d=await f(this.config,{query:p,variables:{pullRequestId:s.graphQLId,body:o,path:i,line:a,side:u}},t);if(!d.body.data?.addPullRequestReview?.pullRequestReview?.id)throw new h("Could not add inline comment to pull request",d.body.errors);return d.body.data?.addPullRequestReview?.pullRequestReview?.comments?.nodes?.[0]?.id}async setPullRequestMilestone(e,t={}){let{pullRequest:s,milestone:o}=e;if(!s.graphQLId)throw new Error('GitHub requires "graphQLId" for this function.');let i=`mutation SetPullRequestMilestone($pullRequestGraphQLId: ID!, $milestoneGraphQLId: ID) {
709
+ }`,p=await f(this.config,{query:l,variables:{pullRequestId:r.graphQLId,body:o,path:i,line:a,side:u}},t);if(!p.body.data?.addPullRequestReview?.pullRequestReview?.id)throw new h("Could not add inline comment to pull request",p.body.errors);return p.body.data?.addPullRequestReview?.pullRequestReview?.comments?.nodes?.[0]?.id}async setPullRequestMilestone(e,t={}){let{pullRequest:r,milestone:o}=e;if(!r.graphQLId)throw new Error('GitHub requires "graphQLId" for this function.');let i=`mutation SetPullRequestMilestone($pullRequestGraphQLId: ID!, $milestoneGraphQLId: ID) {
710
710
  updatePullRequest(input: { pullRequestId: $pullRequestGraphQLId, milestoneId: $milestoneGraphQLId }) {
711
711
  pullRequest {
712
712
  id
713
713
  }
714
714
  }
715
- }`,a=await f(this.config,{query:`${i}`,variables:{pullRequestGraphQLId:s.graphQLId,milestoneGraphQLId:o?.graphQLId??null}},t);if(!a.body.data?.updatePullRequest?.pullRequest?.id)throw new h("Could not set milestone of pull request",a.body.errors)}async markPullRequestReadyForReview(e,t){let s=`mutation MarkReadyToReview($pullRequestGraphQLId: ID!) {
715
+ }`,a=await f(this.config,{query:`${i}`,variables:{pullRequestGraphQLId:r.graphQLId,milestoneGraphQLId:o?.graphQLId??null}},t);if(!a.body.data?.updatePullRequest?.pullRequest?.id)throw new h("Could not set milestone of pull request",a.body.errors)}async markPullRequestReadyForReview(e,t){let r=`mutation MarkReadyToReview($pullRequestGraphQLId: ID!) {
716
716
  markPullRequestReadyForReview(input: { pullRequestId: $pullRequestGraphQLId }) {
717
717
  pullRequest {
718
718
  id
719
719
  }
720
720
  }
721
- }`,o=await f(this.config,{query:s,variables:{pullRequestGraphQLId:e}},t);if(!o.body.data?.markPullRequestReadyForReview?.pullRequest?.id)throw new h("Could not mark pull request ready to review",o.body.errors)}async convertPullRequestToDraft(e,t){let s=`mutation ConvertToDraft($pullRequestGraphQLId: ID!) {
721
+ }`,o=await f(this.config,{query:r,variables:{pullRequestGraphQLId:e}},t);if(!o.body.data?.markPullRequestReadyForReview?.pullRequest?.id)throw new h("Could not mark pull request ready to review",o.body.errors)}async convertPullRequestToDraft(e,t){let r=`mutation ConvertToDraft($pullRequestGraphQLId: ID!) {
722
722
  convertPullRequestToDraft(input: { pullRequestId: $pullRequestGraphQLId }) {
723
723
  pullRequest {
724
724
  id
725
725
  }
726
726
  }
727
- }`,o=await f(this.config,{query:s,variables:{pullRequestGraphQLId:e}},t);if(!o.body.data?.convertPullRequestToDraft?.pullRequest?.id)throw new h("Could not convert pull request to draft",o.body.errors)}async setPullRequestAsDraft(e,t={}){let{pullRequest:{graphQLId:s},isDraft:o}=e;if(!s)throw new Error('GitHub requires "graphQLId" for this function.');if(o){await this.convertPullRequestToDraft(s,t);return}await this.markPullRequestReadyForReview(s,t)}async setPullRequestReviewers(e,t={}){let{pullRequest:{reviews:s,graphQLId:o},reviewers:i}=e;if(!s)throw new Error('GitHub requires "reviews" for this function');if(!o)throw new Error('GitHub requires "graphQLId" for this function.');let a=s.filter(c=>c.state!=="REVIEW_REQUESTED").map(c=>{if(!c.reviewer.graphQLId)throw new Error('GitHub requires reviewer "graphQLId" for this function.');return c.reviewer.graphQLId}),u=i.map(c=>{if(!c.graphQLId)throw new Error('GitHub requires reviewer "graphQLId" for this function.');return c.graphQLId}).filter(c=>a.indexOf(c)===-1),p=`mutation SetPullRequestReviewers($pullRequestGraphQLId: ID!, $reviewerGraphQLIds: [ID!]!) {
727
+ }`,o=await f(this.config,{query:r,variables:{pullRequestGraphQLId:e}},t);if(!o.body.data?.convertPullRequestToDraft?.pullRequest?.id)throw new h("Could not convert pull request to draft",o.body.errors)}async setPullRequestAsDraft(e,t={}){let{pullRequest:{graphQLId:r},isDraft:o}=e;if(!r)throw new Error('GitHub requires "graphQLId" for this function.');if(o){await this.convertPullRequestToDraft(r,t);return}await this.markPullRequestReadyForReview(r,t)}async setPullRequestReviewers(e,t={}){let{pullRequest:{reviews:r,graphQLId:o},reviewers:i}=e;if(!r)throw new Error('GitHub requires "reviews" for this function');if(!o)throw new Error('GitHub requires "graphQLId" for this function.');let a=r.filter(c=>c.state!=="REVIEW_REQUESTED").map(c=>{if(!c.reviewer.graphQLId)throw new Error('GitHub requires reviewer "graphQLId" for this function.');return c.reviewer.graphQLId}),u=i.map(c=>{if(!c.graphQLId)throw new Error('GitHub requires reviewer "graphQLId" for this function.');return c.graphQLId}).filter(c=>a.indexOf(c)===-1),l=`mutation SetPullRequestReviewers($pullRequestGraphQLId: ID!, $reviewerGraphQLIds: [ID!]!) {
728
728
  requestReviews(input: { pullRequestId: $pullRequestGraphQLId, userIds: $reviewerGraphQLIds }) {
729
729
  pullRequest {
730
730
  id
731
731
  }
732
732
  }
733
- }`,d=await f(this.config,{query:p,variables:{pullRequestGraphQLId:o,reviewerGraphQLIds:u}},t);if(!d.body.data?.requestReviews?.pullRequest?.id)throw new h("Could not set pull request reviewers",d.body.errors)}async reRequestPullRequestReviews(e,t={}){let{pullRequest:{reviews:s,graphQLId:o},reviewers:i}=e;if(!o)throw new Error('GitHub requires "graphQLId" for this function.');if(!s)throw new Error('GitHub requires "reviews" for this function.');let a=[];for(let d of i){if(!d.graphQLId)throw new Error('GitHub requires reviwer "graphQLId" for this function.');if(!s.find(c=>c.reviewer.graphQLId===d.graphQLId))throw new Error("Can only re-request review from existing reviewer.");a.push(d.graphQLId)}let u=`mutation SetPullRequestReviewers($pullRequestGraphQLId: ID!, $reviewerGraphQLIds: [ID!]!) {
733
+ }`,p=await f(this.config,{query:l,variables:{pullRequestGraphQLId:o,reviewerGraphQLIds:u}},t);if(!p.body.data?.requestReviews?.pullRequest?.id)throw new h("Could not set pull request reviewers",p.body.errors)}async reRequestPullRequestReviews(e,t={}){let{pullRequest:{reviews:r,graphQLId:o},reviewers:i}=e;if(!o)throw new Error('GitHub requires "graphQLId" for this function.');if(!r)throw new Error('GitHub requires "reviews" for this function.');let a=[];for(let p of i){if(!p.graphQLId)throw new Error('GitHub requires reviwer "graphQLId" for this function.');if(!r.find(c=>c.reviewer.graphQLId===p.graphQLId))throw new Error("Can only re-request review from existing reviewer.");a.push(p.graphQLId)}let u=`mutation SetPullRequestReviewers($pullRequestGraphQLId: ID!, $reviewerGraphQLIds: [ID!]!) {
734
734
  requestReviews(input: { pullRequestId: $pullRequestGraphQLId, userIds: $reviewerGraphQLIds, union: true }) {
735
735
  pullRequest {
736
736
  id
737
737
  }
738
738
  }
739
- }`,p=await f(this.config,{query:u,variables:{pullRequestGraphQLId:o,reviewerGraphQLIds:a}},t);if(!p.body.data?.requestReviews?.pullRequest?.id)throw new h("Could not re-request pull request reviews",p.body.errors)}async setPullRequestAssignees(e,t={}){let{pullRequest:s,assignees:o}=e;if(!s.graphQLId)throw new Error('GitHub requires "graphQLId" for this function.');let i=o.map(p=>{if(!p.graphQLId)throw new Error('GitHub requires assignee "graphQLId" for this function.');return p.graphQLId}),a=`mutation SetPullRequestAssignees($pullRequestGraphQLId: ID!, $assigneeGraphQLIds: [ID!]!) {
739
+ }`,l=await f(this.config,{query:u,variables:{pullRequestGraphQLId:o,reviewerGraphQLIds:a}},t);if(!l.body.data?.requestReviews?.pullRequest?.id)throw new h("Could not re-request pull request reviews",l.body.errors)}async setPullRequestAssignees(e,t={}){let{pullRequest:r,assignees:o}=e;if(!r.graphQLId)throw new Error('GitHub requires "graphQLId" for this function.');let i=o.map(l=>{if(!l.graphQLId)throw new Error('GitHub requires assignee "graphQLId" for this function.');return l.graphQLId}),a=`mutation SetPullRequestAssignees($pullRequestGraphQLId: ID!, $assigneeGraphQLIds: [ID!]!) {
740
740
  updatePullRequest(input: { pullRequestId: $pullRequestGraphQLId, assigneeIds: $assigneeGraphQLIds }) {
741
741
  pullRequest {
742
742
  id
743
743
  }
744
744
  }
745
- }`,u=await f(this.config,{query:a,variables:{pullRequestGraphQLId:s.graphQLId,assigneeGraphQLIds:i}},t);if(!u.body.data?.updatePullRequest?.pullRequest?.id)throw new h("Could not set pull request assignees",u.body.errors)}async getReviewsForPullRequest(e,t={}){let s=await this.getEnterpriseVersion(t),{repo:{namespace:o,name:i},pullRequestId:a}=e,u=`query getPullRequests(
745
+ }`,u=await f(this.config,{query:a,variables:{pullRequestGraphQLId:r.graphQLId,assigneeGraphQLIds:i}},t);if(!u.body.data?.updatePullRequest?.pullRequest?.id)throw new h("Could not set pull request assignees",u.body.errors)}async getReviewsForPullRequest(e,t={}){let r=await this.getEnterpriseVersion(t),{repo:{namespace:o,name:i},pullRequestId:a}=e,u=`query getPullRequests(
746
746
  $namespace: String!
747
747
  $name: String!
748
748
  $pullRequestId: Int!
@@ -770,7 +770,7 @@ query getBlame($owner: String!, $name: String!, $ref: String!, $path: String!) {
770
770
  login
771
771
  }
772
772
  body
773
- ${!s||_(s,"PR_REVIEW_COMMENT_FULL_DATABASE_ID")?"fullDatabaseId":"databaseId"}
773
+ ${!r||Q(r,"PR_REVIEW_COMMENT_FULL_DATABASE_ID")?"fullDatabaseId":"databaseId"}
774
774
  diffHunk
775
775
  id
776
776
  path
@@ -790,7 +790,7 @@ query getBlame($owner: String!, $name: String!, $ref: String!, $path: String!) {
790
790
  login
791
791
  }
792
792
  body
793
- ${!s||_(s,"PR_REVIEW_FULL_DATABASE_ID")?"fullDatabaseId":"databaseId"}
793
+ ${!r||Q(r,"PR_REVIEW_FULL_DATABASE_ID")?"fullDatabaseId":"databaseId"}
794
794
  id
795
795
  publishedAt
796
796
  url
@@ -798,54 +798,54 @@ query getBlame($owner: String!, $name: String!, $ref: String!, $path: String!) {
798
798
  }
799
799
  }
800
800
  }
801
- }`,p=await f(this.config,{query:u,variables:{namespace:o,name:i,pullRequestId:a}},t),d=p.body.data?.repository.pullRequest.reviewThreads.nodes?.filter($).reduce((l,g)=>{if(!g.comments.nodes?.[0]?.pullRequestReview)return l;let m=g.comments.nodes[0].pullRequestReview,b=vs(g);return b&&(l[m.id]||(l[m.id]=[]),l[m.id].push(b)),l},{})??{};return{data:p.body.data?.repository.pullRequest.reviews.nodes?.filter($).filter(l=>d[l.id]).map(l=>({author:l.author?{avatarUrl:l.author.avatarUrl,email:null,name:l.author.login}:null,body:l.body,createdAt:l.publishedAt?new Date(l.publishedAt):null,id:l.fullDatabaseId??l.databaseId.toString(),graphQLId:l.id,reviewComments:d[l.id],url:l.url}))??[]}}async getCommentsForPullRequest(e,t={}){let s=await this.getEnterpriseVersion(t),o=!s||_(s,"ISSUE_FULL_DATABASE_ID"),{repo:{namespace:i,name:a},pullRequestNumber:u,cursor:p}=e,d=await f(this.config,{query:tr(o),variables:{namespace:i,name:a,pullRequestNumber:u,cursor:p,first:E}},t),c=d.body.data?.repository;if(!c)throw new h("Could not fetch pull request comments",d.body.errors);return{data:c.pullRequest.comments.nodes?.filter($).map(Jt)??[],pageInfo:c.pullRequest.comments.pageInfo}}async getIssuesAssociatedWithUser(e,t={}){let[s,o]=e.cursor?.split(";")||[void 0,void 0],i=[];e.labelNames&&e.labelNames.forEach(l=>{i.push(`label:"${l}"`)});let[a,u]=await Promise.all([s==="null"?null:this.searchIssues({query:`author:${e.username} ${i.join(" ")}`,cursor:s,includeFromArchivedRepos:e.includeFromArchivedRepos,maxPageSize:e.maxPageSize},t),o==="null"?null:this.searchIssues({query:`assignee:${e.username} ${i.join(" ")}`,cursor:o,includeFromArchivedRepos:e.includeFromArchivedRepos,maxPageSize:e.maxPageSize},t)]),p={},d=[],c=l=>{p[l.id]||(p[l.id]=!0,d.push(l))};return a?.data.forEach(c),u?.data.forEach(c),{pageInfo:{hasNextPage:a?.pageInfo.hasNextPage||u?.pageInfo.hasNextPage||!1,endCursor:`${a?.pageInfo.hasNextPage&&a?.pageInfo.endCursor||"null"};${u?.pageInfo.hasNextPage&&u?.pageInfo.endCursor||"null"}`},data:d}}async setPullRequestLabels(e,t={}){let{pullRequest:s,labels:o}=e;if(!s.graphQLId)throw new Error('GitHub requires "graphQLId" for this function.');let i=`mutation SetPullRequestLabels($pullRequestGraphQLId: ID!, $labelGraphQLIds: [ID!]) {
801
+ }`,l=await f(this.config,{query:u,variables:{namespace:o,name:i,pullRequestId:a}},t),p=l.body.data?.repository.pullRequest.reviewThreads.nodes?.filter(A).reduce((d,m)=>{if(!m.comments.nodes?.[0]?.pullRequestReview)return d;let g=m.comments.nodes[0].pullRequestReview,y=$s(m);return y&&(d[g.id]||(d[g.id]=[]),d[g.id].push(y)),d},{})??{};return{data:l.body.data?.repository.pullRequest.reviews.nodes?.filter(A).filter(d=>p[d.id]).map(d=>({author:d.author?{avatarUrl:d.author.avatarUrl,email:null,name:d.author.login}:null,body:d.body,createdAt:d.publishedAt?new Date(d.publishedAt):null,id:d.fullDatabaseId??d.databaseId.toString(),graphQLId:d.id,reviewComments:p[d.id],url:d.url}))??[]}}async getCommentsForPullRequest(e,t={}){let r=await this.getEnterpriseVersion(t),o=!r||Q(r,"ISSUE_FULL_DATABASE_ID"),{repo:{namespace:i,name:a},pullRequestNumber:u,cursor:l}=e,p=await f(this.config,{query:lr(o),variables:{namespace:i,name:a,pullRequestNumber:u,cursor:l,first:D}},t),c=p.body.data?.repository;if(!c)throw new h("Could not fetch pull request comments",p.body.errors);return{data:c.pullRequest.comments.nodes?.filter(A).map(rr)??[],pageInfo:c.pullRequest.comments.pageInfo}}async getIssuesAssociatedWithUser(e,t={}){let[r,o]=e.cursor?.split(";")||[void 0,void 0],i=[];e.labelNames&&e.labelNames.forEach(d=>{i.push(`label:"${d}"`)});let[a,u]=await Promise.all([r==="null"?null:this.searchIssues({query:`author:${e.username} ${i.join(" ")}`,cursor:r,includeFromArchivedRepos:e.includeFromArchivedRepos,maxPageSize:e.maxPageSize},t),o==="null"?null:this.searchIssues({query:`assignee:${e.username} ${i.join(" ")}`,cursor:o,includeFromArchivedRepos:e.includeFromArchivedRepos,maxPageSize:e.maxPageSize},t)]),l={},p=[],c=d=>{l[d.id]||(l[d.id]=!0,p.push(d))};return a?.data.forEach(c),u?.data.forEach(c),{pageInfo:{hasNextPage:a?.pageInfo.hasNextPage||u?.pageInfo.hasNextPage||!1,endCursor:`${a?.pageInfo.hasNextPage&&a?.pageInfo.endCursor||"null"};${u?.pageInfo.hasNextPage&&u?.pageInfo.endCursor||"null"}`},data:p}}async setPullRequestLabels(e,t={}){let{pullRequest:r,labels:o}=e;if(!r.graphQLId)throw new Error('GitHub requires "graphQLId" for this function.');let i=`mutation SetPullRequestLabels($pullRequestGraphQLId: ID!, $labelGraphQLIds: [ID!]) {
802
802
  updatePullRequest(input: { pullRequestId: $pullRequestGraphQLId, labelIds: $labelGraphQLIds }) {
803
803
  pullRequest {
804
804
  id
805
805
  }
806
806
  }
807
- }`,a=await f(this.config,{query:i,variables:{pullRequestGraphQLId:s.graphQLId,labelGraphQLIds:o.map(u=>{if(!u.graphQLId)throw new Error('GitHub requires label "graphQLId" for this function.');return u.graphQLId})}},t);if(!a.body.data?.updatePullRequest?.pullRequest?.id)throw new h("Could not set pull request labels",a.body.errors)}async getIssuesForRepos(e,t={}){let s=nt(e.startQuery||""),{cursor:o,assigneeLogins:i,updatedBefore:a,authorLogin:u,mentionLogin:p,labelNames:d}=e;return e.repos.forEach(c=>{s.push(`repo:${c.namespace}/${c.name}`)}),i&&i.forEach(c=>{s.push(`assignee:${c}`)}),a&&s.push(`updated:<${a}`),u&&s.push(`author:${u}`),p&&s.push(`mentions:${p}`),d&&d.forEach(c=>{s.push(`label:"${c}"`)}),this.searchIssues({query:`sort:updated ${s.join(" ")}`,cursor:o,includeFromArchivedRepos:e.includeFromArchivedRepos,maxPageSize:e.maxPageSize},t)}async closeIssueWithReason(e,t={}){let{issue:s,reason:o}=e;if(!s.graphQLId)throw new Error('GitHub requires "graphQLId" for this function.');let i=`mutation CloseIssueWithReason($issueGraphQLId: ID!, $reason: IssueClosedStateReason!) {
807
+ }`,a=await f(this.config,{query:i,variables:{pullRequestGraphQLId:r.graphQLId,labelGraphQLIds:o.map(u=>{if(!u.graphQLId)throw new Error('GitHub requires label "graphQLId" for this function.');return u.graphQLId})}},t);if(!a.body.data?.updatePullRequest?.pullRequest?.id)throw new h("Could not set pull request labels",a.body.errors)}async getIssuesForRepos(e,t={}){let r=dt(e.startQuery||""),{cursor:o,assigneeLogins:i,updatedBefore:a,authorLogin:u,mentionLogin:l,labelNames:p}=e;return e.repos.forEach(c=>{r.push(`repo:${c.namespace}/${c.name}`)}),i&&i.forEach(c=>{r.push(`assignee:${c}`)}),a&&r.push(`updated:<${a}`),u&&r.push(`author:${u}`),l&&r.push(`mentions:${l}`),p&&p.forEach(c=>{r.push(`label:"${c}"`)}),this.searchIssues({query:`sort:updated ${r.join(" ")}`,cursor:o,includeFromArchivedRepos:e.includeFromArchivedRepos,maxPageSize:e.maxPageSize},t)}async closeIssueWithReason(e,t={}){let{issue:r,reason:o}=e;if(!r.graphQLId)throw new Error('GitHub requires "graphQLId" for this function.');let i=`mutation CloseIssueWithReason($issueGraphQLId: ID!, $reason: IssueClosedStateReason!) {
808
808
  closeIssue(input: { issueId: $issueGraphQLId, stateReason: $reason }) {
809
809
  issue {
810
810
  id
811
811
  }
812
812
  }
813
- }`,a=await f(this.config,{query:i,variables:{issueGraphQLId:s.graphQLId,reason:o}},t);if(!a.body.data?.closeIssue?.issue?.id)throw new h("Could not close issue with reason",a.body.errors)}async closeIssue(e,t={}){let{issue:s}=e;if(!s.graphQLId)throw new Error('GitHub requires "graphQLId" for this function.');let o=`mutation SetIssueState($issueGraphQLId: ID!) {
813
+ }`,a=await f(this.config,{query:i,variables:{issueGraphQLId:r.graphQLId,reason:o}},t);if(!a.body.data?.closeIssue?.issue?.id)throw new h("Could not close issue with reason",a.body.errors)}async closeIssue(e,t={}){let{issue:r}=e;if(!r.graphQLId)throw new Error('GitHub requires "graphQLId" for this function.');let o=`mutation SetIssueState($issueGraphQLId: ID!) {
814
814
  updateIssue(input: { id: $issueGraphQLId, state: CLOSED }) {
815
815
  issue {
816
816
  id
817
817
  }
818
818
  }
819
- }`,i=await f(this.config,{query:o,variables:{issueGraphQLId:s.graphQLId}},t);if(!i.body.data?.updateIssue?.issue?.id)throw new h("Could not close issue",i.body.errors)}async reOpenIssue(e,t={}){let{issue:s}=e;if(!s.graphQLId)throw new Error('GitHub requires "graphQLId" for this function.');let o=`mutation ReOpenIssue($issueGraphQLId: ID!) {
819
+ }`,i=await f(this.config,{query:o,variables:{issueGraphQLId:r.graphQLId}},t);if(!i.body.data?.updateIssue?.issue?.id)throw new h("Could not close issue",i.body.errors)}async reOpenIssue(e,t={}){let{issue:r}=e;if(!r.graphQLId)throw new Error('GitHub requires "graphQLId" for this function.');let o=`mutation ReOpenIssue($issueGraphQLId: ID!) {
820
820
  reopenIssue(input: { issueId: $issueGraphQLId }) {
821
821
  issue {
822
822
  id
823
823
  }
824
824
  }
825
- }`,i=await f(this.config,{query:o,variables:{issueGraphQLId:s.graphQLId}},t);if(!i.body.data?.reopenIssue?.issue?.id)throw new h("Could not reopen issue",i.body.errors)}async setIssueLabels(e,t={}){let{issue:s,labels:o}=e;if(!s.graphQLId)throw new Error('GitHub requires "graphQLId" for this function.');let i=o.map(p=>p.graphQLId),a=`mutation SetIssueLabels($issueGraphQLId: ID!, $labelGraphQLIds: [ID!]) {
825
+ }`,i=await f(this.config,{query:o,variables:{issueGraphQLId:r.graphQLId}},t);if(!i.body.data?.reopenIssue?.issue?.id)throw new h("Could not reopen issue",i.body.errors)}async setIssueLabels(e,t={}){let{issue:r,labels:o}=e;if(!r.graphQLId)throw new Error('GitHub requires "graphQLId" for this function.');let i=o.map(l=>l.graphQLId),a=`mutation SetIssueLabels($issueGraphQLId: ID!, $labelGraphQLIds: [ID!]) {
826
826
  updateIssue(input: { id: $issueGraphQLId, labelIds: $labelGraphQLIds }) {
827
827
  issue {
828
828
  id
829
829
  }
830
830
  }
831
- }`,u=await f(this.config,{query:a,variables:{issueGraphQLId:s.graphQLId,labelGraphQLIds:i}},t);if(!u.body.data?.updateIssue?.issue?.id)throw new h("Could not set issue labels",u.body.errors)}async setIssueMilestone(e,t={}){let{issue:s,milestone:o}=e;if(!s.graphQLId)throw new Error('GitHub requires "graphQLId" for this function.');if(o&&!o.graphQLId)throw new Error('GitHub requires milestone "graphQLId" for this function.');let i=`mutation SetIssueMilestone($issueGraphQLId: ID!, $milestoneGraphQLId: ID) {
831
+ }`,u=await f(this.config,{query:a,variables:{issueGraphQLId:r.graphQLId,labelGraphQLIds:i}},t);if(!u.body.data?.updateIssue?.issue?.id)throw new h("Could not set issue labels",u.body.errors)}async setIssueMilestone(e,t={}){let{issue:r,milestone:o}=e;if(!r.graphQLId)throw new Error('GitHub requires "graphQLId" for this function.');if(o&&!o.graphQLId)throw new Error('GitHub requires milestone "graphQLId" for this function.');let i=`mutation SetIssueMilestone($issueGraphQLId: ID!, $milestoneGraphQLId: ID) {
832
832
  updateIssue(input: { id: $issueGraphQLId, milestoneId: $milestoneGraphQLId }) {
833
833
  issue {
834
834
  id
835
835
  }
836
836
  }
837
- }`,a=await f(this.config,{query:`${i}`,variables:{issueGraphQLId:s.graphQLId,milestoneGraphQLId:o?.graphQLId??null}},t);if(!a.body.data?.updateIssue?.issue?.id)throw new h("Could not set milestone of issue",a.body.errors)}async setIssueAssignees(e,t={}){let{issue:s,assignees:o}=e;if(!s.graphQLId)throw new Error('GitHub requires "graphQLId" for this function.');let i=o.map(p=>{if(!p.graphQLId)throw new Error('GitHub requires assignee "graphQLId" for this function.');return p.graphQLId}),a=`mutation SetIssueAssignees($issueGraphQLId: ID!, $assigneeGraphQLIds: [ID!]!) {
837
+ }`,a=await f(this.config,{query:`${i}`,variables:{issueGraphQLId:r.graphQLId,milestoneGraphQLId:o?.graphQLId??null}},t);if(!a.body.data?.updateIssue?.issue?.id)throw new h("Could not set milestone of issue",a.body.errors)}async setIssueAssignees(e,t={}){let{issue:r,assignees:o}=e;if(!r.graphQLId)throw new Error('GitHub requires "graphQLId" for this function.');let i=o.map(l=>{if(!l.graphQLId)throw new Error('GitHub requires assignee "graphQLId" for this function.');return l.graphQLId}),a=`mutation SetIssueAssignees($issueGraphQLId: ID!, $assigneeGraphQLIds: [ID!]!) {
838
838
  updateIssue(input: { id: $issueGraphQLId, assigneeIds: $assigneeGraphQLIds }) {
839
839
  issue {
840
840
  id
841
841
  }
842
842
  }
843
- }`,u=await f(this.config,{query:a,variables:{issueGraphQLId:s.graphQLId,assigneeGraphQLIds:i}},t);if(!u.body.data?.updateIssue?.issue?.id)throw new h("Could not set issue assignees",u.body.errors)}async getMilestonesForRepo(e,t={}){let{repo:{namespace:s,name:o},cursor:i}=e,a=await f(this.config,{query:`
843
+ }`,u=await f(this.config,{query:a,variables:{issueGraphQLId:r.graphQLId,assigneeGraphQLIds:i}},t);if(!u.body.data?.updateIssue?.issue?.id)throw new h("Could not set issue assignees",u.body.errors)}async getMilestonesForRepo(e,t={}){let{repo:{namespace:r,name:o},cursor:i}=e,a=await f(this.config,{query:`
844
844
  query getLabelsForRepo($owner: String!, $name: String! $cursor: String, $first: Int!) {
845
845
  repository(owner: $owner, name: $name) {
846
846
  milestones(first: $first, after: $cursor) {
847
847
  nodes {
848
- ${Ee}
848
+ ${Ue}
849
849
  }
850
850
  pageInfo {
851
851
  endCursor
@@ -854,12 +854,12 @@ query getLabelsForRepo($owner: String!, $name: String! $cursor: String, $first:
854
854
  }
855
855
  }
856
856
  }
857
- `,variables:{owner:s,name:o,cursor:i,first:E}},t);if(!a.body.data)throw new h("Could not fetch milestones",a.body.errors);return{pageInfo:a.body.data.repository.milestones?.pageInfo??{endCursor:null,hasNextPage:!1},data:a.body.data.repository.milestones?.nodes?.map(pt)??[]}}async getLabelsForRepo(e,t={}){let{repo:{namespace:s,name:o},cursor:i}=e,a=await f(this.config,{query:`
857
+ `,variables:{owner:r,name:o,cursor:i,first:D}},t);if(!a.body.data)throw new h("Could not fetch milestones",a.body.errors);return{pageInfo:a.body.data.repository.milestones?.pageInfo??{endCursor:null,hasNextPage:!1},data:a.body.data.repository.milestones?.nodes?.map(Rt)??[]}}async getLabelsForRepo(e,t={}){let{repo:{namespace:r,name:o},cursor:i}=e,a=await f(this.config,{query:`
858
858
  query getLabelsForRepo($owner: String!, $name: String! $cursor: String, $first: Int!) {
859
859
  repository(owner: $owner, name: $name) {
860
860
  labels(first: $first, after: $cursor) {
861
861
  nodes {
862
- ${Ce}
862
+ ${Ae}
863
863
  }
864
864
  pageInfo {
865
865
  endCursor
@@ -868,7 +868,7 @@ query getLabelsForRepo($owner: String!, $name: String! $cursor: String, $first:
868
868
  }
869
869
  }
870
870
  }
871
- `,variables:{owner:s,name:o,cursor:i,first:E}},t);if(!a.body.data)throw new h("Could not fetch labels",a.body.errors);return{pageInfo:a.body.data.repository.labels?.pageInfo??{endCursor:null,hasNextPage:!1},data:a.body.data.repository.labels?.nodes?.map(lt)??[]}}async getTreeForRepo(e,t={}){let s=await this.config.request({url:`${Y(this.config,t)}/repos/${e.repo.namespace}/${e.repo.name}/git/trees/${e.branch}?recursive=1`,headers:{...I(t.token||this.config.token)}});if(!s.body)throw new Error("Could not fetch trees");return{data:s.body.tree.map(Is)}}};var Es="https://gitlab.com/api/v4",Cs="https://gitlab.com/api/graphql",dt=/\/api\/v\d+$/,nr=r=>{if(r.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=(r,n)=>{let e=n.baseUrl||r.baseUrl;return e?(e=e.replace(/\/$/,""),nr(e),dt.test(e)||(e=e+"/api/v4"),e):Es},Ds=(r,n)=>{let e=n.baseUrl||r.baseUrl;return e?(e=e.replace(/\/$/,""),nr(e),dt.test(e)&&(e=e.replace(dt,"")),`${e}/api/graphql`):Cs},w=(r,n,e)=>{let t=I(e.token||r.token);return r.request({url:Ds(r,e),method:"POST",headers:{...t,"Content-Type":"application/json"},body:JSON.stringify(n)})},Ue=r=>r?.map(n=>`"${n.message}"`).join(", ");var ft=r=>r.split("/").slice(0,-1).join("/"),Rt=r=>r.split("/").at(-1)??"",Ae=r=>({id:r.id.replace(ae,""),graphQLId:r.id,namespace:ft(r.fullPath),name:Rt(r.fullPath),webUrl:r.webUrl}),or=r=>({id:r.id.replace(ae,""),graphQLId:r.id,httpsUrl:r.httpUrlToRepo,namespace:ft(r.fullPath),name:Rt(r.fullPath),sshUrl:r.sshUrlToRepo,webUrl:r.webUrl}),Ls={assigned:"assignedMergeRequests",authored:"authoredMergeRequests",reviewRequested:"reviewRequestedMergeRequests"},$s={CAN_BE_MERGED:"MERGEABLE",CANNOT_BE_MERGED:"CONFLICTS",CANNOT_BE_MERGED_RECHECK:"UNKNOWN",UNCHECKED:"UNKNOWN",CHECKING:"UNKNOWN"};var Us="gid://gitlab/User/",ae="gid://gitlab/Project/",As="gid://gitlab/MergeRequest/",Gs="gid://gitlab/Issue/",Ts="gid://gitlab/ProjectLabel/",Os="gid://gitlab/Milestone/",xs="gid://gitlab/Ci::Build/",It=`
871
+ `,variables:{owner:r,name:o,cursor:i,first:D}},t);if(!a.body.data)throw new h("Could not fetch labels",a.body.errors);return{pageInfo:a.body.data.repository.labels?.pageInfo??{endCursor:null,hasNextPage:!1},data:a.body.data.repository.labels?.nodes?.map(ft)??[]}}async getTreeForRepo(e,t={}){let r=await this.config.request({url:`${te(this.config,t)}/repos/${e.repo.namespace}/${e.repo.name}/git/trees/${e.branch}?recursive=1`,headers:{...b(t.token||this.config.token)}});if(!r.body)throw new Error("Could not fetch trees");return{data:r.body.tree.map(Ss)}}};var Gs="https://gitlab.com/api/v4",Ts="https://gitlab.com/api/graphql",It=/\/api\/v\d+$/,cr=s=>{if(s.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.")},Oe=(s,n)=>{let e=n.baseUrl||s.baseUrl;return e?(e=e.replace(/\/$/,""),cr(e),It.test(e)||(e=e+"/api/v4"),e):Gs},Os=(s,n)=>{let e=n.baseUrl||s.baseUrl;return e?(e=e.replace(/\/$/,""),cr(e),It.test(e)&&(e=e.replace(It,"")),`${e}/api/graphql`):Ts},w=(s,n,e)=>{let t=b(e.token||s.token);return s.request({url:Os(s,e),method:"POST",headers:{...t,"Content-Type":"application/json"},body:JSON.stringify(n)})},xe=s=>s?.map(n=>`"${n.message}"`).join(", ");var vt=s=>s.split("/").slice(0,-1).join("/"),qt=s=>s.split("/").at(-1)??"",ke=s=>({id:s.id.replace(ae,""),graphQLId:s.id,namespace:vt(s.fullPath),name:qt(s.fullPath),webUrl:s.webUrl}),mr=s=>({id:s.id.replace(ae,""),graphQLId:s.id,httpsUrl:s.httpUrlToRepo,namespace:vt(s.fullPath),name:qt(s.fullPath),sshUrl:s.sshUrlToRepo,webUrl:s.webUrl}),xs={assigned:"assignedMergeRequests",authored:"authoredMergeRequests",reviewRequested:"reviewRequestedMergeRequests"},ks={CAN_BE_MERGED:"MERGEABLE",CANNOT_BE_MERGED:"CONFLICTS",CANNOT_BE_MERGED_RECHECK:"UNKNOWN",UNCHECKED:"UNKNOWN",CHECKING:"UNKNOWN"};var Ns="gid://gitlab/User/",ae="gid://gitlab/Project/",_s="gid://gitlab/MergeRequest/",Fs="gid://gitlab/Issue/",Qs="gid://gitlab/ProjectLabel/",js="gid://gitlab/Milestone/",Bs="gid://gitlab/Ci::Build/",St=`
872
872
  description
873
873
  dueDate
874
874
  id
@@ -877,7 +877,7 @@ startDate
877
877
  state
878
878
  title
879
879
  webPath
880
- `,ct=`
880
+ `,bt=`
881
881
  id
882
882
  fullPath
883
883
  webUrl
@@ -891,25 +891,25 @@ userPermissions {
891
891
  downloadCode
892
892
  pushCode
893
893
  }
894
- `,B=`
894
+ `,z=`
895
895
  id
896
896
  name
897
897
  username
898
898
  publicEmail
899
899
  avatarUrl
900
900
  webUrl
901
- `,bt=`
901
+ `,Et=`
902
902
  color
903
903
  description
904
904
  id
905
905
  title
906
- `,gt=`
906
+ `,yt=`
907
907
  author {
908
- ${B}
908
+ ${z}
909
909
  }
910
910
  assignees {
911
911
  nodes {
912
- ${B}
912
+ ${z}
913
913
  }
914
914
  }
915
915
  closedAt
@@ -920,7 +920,7 @@ id
920
920
  iid
921
921
  labels {
922
922
  nodes {
923
- ${bt}
923
+ ${Et}
924
924
  }
925
925
  }
926
926
  state
@@ -931,9 +931,9 @@ upvotes
931
931
  userNotesCount
932
932
  webUrl
933
933
  milestone {
934
- ${It}
934
+ ${St}
935
935
  }
936
- `,ks=`
936
+ `,Ms=`
937
937
  stages {
938
938
  nodes {
939
939
  jobs {
@@ -949,11 +949,11 @@ stages {
949
949
  name
950
950
  }
951
951
  }
952
- `,ir=(r,n,e)=>`
952
+ `,gr=(s,n,e)=>`
953
953
  id
954
954
  state
955
955
  author {
956
- ${B}
956
+ ${z}
957
957
  }
958
958
  diffRefs {
959
959
  baseSha
@@ -979,12 +979,12 @@ targetBranch
979
979
  sourceBranch
980
980
  assignees {
981
981
  nodes {
982
- ${B}
982
+ ${z}
983
983
  }
984
984
  }
985
985
  reviewers {
986
986
  nodes {
987
- ${B}
987
+ ${z}
988
988
  mergeRequestInteraction {
989
989
  approved
990
990
  reviewState
@@ -994,19 +994,19 @@ reviewers {
994
994
  mergeStatusEnum
995
995
  labels {
996
996
  nodes {
997
- ${bt}
997
+ ${Et}
998
998
  }
999
999
  }
1000
- ${r?"project { id httpUrlToRepo fullPath sshUrlToRepo webUrl archived } sourceProject { id httpUrlToRepo fullPath sshUrlToRepo webUrl }":""}
1001
- ${n?`milestone { ${It} }`:""}
1002
- ${e?`headPipeline { ${ks} }`:""}
1003
- `,J=r=>`${r.namespace}/${r.name}`,Ns=r=>`${r.namespace}/${r.name}`,_s=r=>({canCreateWebhook:r.adminOperations,canPush:r.pushCode,isAdmin:r.adminOperations}),mt=r=>({id:r.id.replace(ae,""),graphQLId:r.id,namespace:ft(r.fullPath),name:Rt(r.fullPath),webUrl:r.webUrl,httpsUrl:r.httpUrlToRepo,sshUrl:r.sshUrlToRepo,defaultBranch:r.repository?.rootRef?{name:r.repository.rootRef}:null,permissions:_s(r.userPermissions)}),Fs=r=>({path:r.path,isDirectory:r.type==="tree"}),Qs={opened:"OPEN",merged:"MERGED",closed:"CLOSED"},ur=(r,n,e)=>!n&&r?.startsWith("/")?`https://gitlab.com${r}`:n&&r?.startsWith("/")&&e?`${e.replace(/\/+?$/,"")}${r}`:r,M=(r,n,e)=>{let t=ur(r.avatarUrl,n,e);return{id:r.id.replace(Us,""),graphQLId:r.id,name:r.name,username:r.username,email:r.publicEmail??null,avatarUrl:t,url:r.webUrl}},yt=r=>({color:r.color,description:r.description,id:r.id.replace(Ts,""),graphQLId:r.id,name:r.title}),js=(r,n)=>r?r==="FAILED"&&n?"WARNING":{CANCELED:"CANCELLED",CREATED:"PENDING",FAILED:"FAILED",MANUAL:"OPTIONAL_ACTION_REQUIRED",PENDING:"PENDING",PREPARING:"RUNNING",RUNNING:"RUNNING",SCHEDULED:"PENDING",SKIPPED:"SKIPPED",SUCCESS:"SUCCESS",WAITING_FOR_CALLBACK:"PENDING",WAITING_FOR_RESOURCE:"PENDING"}[r]:null,Bs=(r,n,e)=>{let t={APPROVED:"APPROVED",REQUESTED_CHANGES:"CHANGES_REQUESTED",REVIEWED:"COMMENTED",UNAPPROVED:"REVIEW_REQUESTED",UNREVIEWED:"REVIEW_REQUESTED"};return{reviewer:M(r,n,e),state:r.mergeRequestInteraction?.reviewState?t[r.mergeRequestInteraction.reviewState]:"REVIEW_REQUESTED"}},ar=(r,n,e,t,s)=>{let o=r.reviewers?.nodes?r.reviewers.nodes.map(i=>Bs(i,t,s)):null;return{id:r.id.replace(As,""),graphQLId:r.id,title:r.title,description:r.description,number:parseInt(r.iid,10),state:Qs[r.state],commentCount:r.userNotesCount||0,upvoteCount:r.upvotes,author:r.author?M(r.author,t,s):null,createdDate:new Date(r.createdAt),isDraft:r.draft,repository:{id:n.id,graphQLId:n.graphQLId,name:n.name,owner:{login:n.namespace},remoteInfo:n.httpsUrl&&n.sshUrl?{cloneUrlHTTPS:n.httpsUrl,cloneUrlSSH:n.sshUrl}:null},headRepository:e?{id:e.id,graphQLId:e.graphQLId,name:e.name,owner:{login:e.namespace},remoteInfo:{cloneUrlHTTPS:e.httpsUrl,cloneUrlSSH:e.sshUrl}}:null,headCommit:{buildStatuses:r.headPipeline?.stages?.nodes?.flatMap(i=>i.jobs?.nodes?.map(a=>({completedAt:a.finishedAt?new Date(a.finishedAt):null,description:null,name:a.name??null,state:js(a.status,a.allowFailure),stage:i.name??null,startedAt:new Date(a.createdAt),url:`${n.webUrl}/-/jobs/${a.id.replace(xs,"")}`}))??[])??[]},baseRef:{name:r.targetBranch,oid:r.diffRefs?.baseSha??null},headRef:{name:r.sourceBranch,oid:r.diffRefs?.headSha??null},url:r.webUrl,updatedDate:new Date(r.updatedAt),closedDate:r.mergedAt?new Date(r.mergedAt):null,mergedDate:r.mergedAt?new Date(r.mergedAt):null,assignees:r.assignees?.nodes?r.assignees.nodes.map(i=>M(i,t,s)):null,reviews:o,reviewDecision:N(o),additions:r.diffStatsSummary?.additions||0,deletions:r.diffStatsSummary?.deletions||0,fileCount:r.diffStatsSummary?.fileCount||0,commitCount:r.commitCount||0,mergeableState:$s[r.mergeStatusEnum],milestone:r.milestone?Pt(r.milestone,n.webUrl):null,labels:r.labels?.nodes?.map(yt)??[],permissions:null}},ht=(r,n,e,t)=>({author:M(r.author,e,t),assignees:r.assignees.nodes.map(s=>M(s,e,t)),commentCount:r.userNotesCount,closedDate:r.closedAt?new Date(r.closedAt):null,createdDate:new Date(r.createdAt),description:r.description,graphQLId:r.id,id:r.id.replace(Gs,""),labels:r.labels?.nodes?.map(yt)??[],number:r.iid,repository:{id:n.id.replace(ae,""),graphQLId:n.id,name:n.name,owner:{login:n.namespace}},updatedDate:new Date(r.updatedAt),upvoteCount:r.upvotes,state:{name:r.state,color:null},type:r.type,title:r.title,url:r.webUrl,milestone:r.milestone?Pt(r.milestone,n.webUrl):null}),Pt=(r,n)=>({id:r.id.replace(Os,""),graphQLId:r.id,number:parseInt(r.iid,10),title:r.title,description:r.description,isOpen:r.state==="active",url:`${n}/-/${r.webPath.replace(/.+?\/-\//,"")}`,startDate:r.startDate?new Date(r.startDate):null,dueDate:r.dueDate?new Date(r.dueDate):null}),ue=class extends A{getIsSelfHosted(n){return!!n.baseUrl||!!this.config.baseUrl}async getCurrentUser(n={},e={}){let s=(await w(this.config,{query:`
1000
+ ${s?"project { id httpUrlToRepo fullPath sshUrlToRepo webUrl archived } sourceProject { id httpUrlToRepo fullPath sshUrlToRepo webUrl }":""}
1001
+ ${n?`milestone { ${St} }`:""}
1002
+ ${e?`headPipeline { ${Ms} }`:""}
1003
+ `,K=s=>`${s.namespace}/${s.name}`,zs=s=>`${s.namespace}/${s.name}`,Hs=s=>({canCreateWebhook:s.adminOperations,canPush:s.pushCode,isAdmin:s.adminOperations}),Pt=s=>({id:s.id.replace(ae,""),graphQLId:s.id,namespace:vt(s.fullPath),name:qt(s.fullPath),webUrl:s.webUrl,httpsUrl:s.httpUrlToRepo,sshUrl:s.sshUrlToRepo,defaultBranch:s.repository?.rootRef?{name:s.repository.rootRef}:null,permissions:Hs(s.userPermissions)}),Ws=s=>({path:s.path,isDirectory:s.type==="tree"}),Js={opened:"OPEN",merged:"MERGED",closed:"CLOSED"},fr=(s,n,e)=>!n&&s?.startsWith("/")?`https://gitlab.com${s}`:n&&s?.startsWith("/")&&e?`${e.replace(/\/+?$/,"")}${s}`:s,H=(s,n,e)=>{let t=fr(s.avatarUrl,n,e);return{id:s.id.replace(Ns,""),graphQLId:s.id,name:s.name,username:s.username,email:s.publicEmail??null,avatarUrl:t,url:s.webUrl}},Ct=s=>({color:s.color,description:s.description,id:s.id.replace(Qs,""),graphQLId:s.id,name:s.title}),Vs=(s,n)=>s?s==="FAILED"&&n?"WARNING":{CANCELED:"CANCELLED",CREATED:"PENDING",FAILED:"FAILED",MANUAL:"OPTIONAL_ACTION_REQUIRED",PENDING:"PENDING",PREPARING:"RUNNING",RUNNING:"RUNNING",SCHEDULED:"PENDING",SKIPPED:"SKIPPED",SUCCESS:"SUCCESS",WAITING_FOR_CALLBACK:"PENDING",WAITING_FOR_RESOURCE:"PENDING"}[s]:null,Ks=(s,n,e)=>{let t={APPROVED:"APPROVED",REQUESTED_CHANGES:"CHANGES_REQUESTED",REVIEWED:"COMMENTED",UNAPPROVED:"REVIEW_REQUESTED",UNREVIEWED:"REVIEW_REQUESTED"};return{reviewer:H(s,n,e),state:s.mergeRequestInteraction?.reviewState?t[s.mergeRequestInteraction.reviewState]:"REVIEW_REQUESTED"}},hr=(s,n,e,t,r)=>{let o=s.reviewers?.nodes?s.reviewers.nodes.map(i=>Ks(i,t,r)):null;return{id:s.id.replace(_s,""),graphQLId:s.id,title:s.title,description:s.description,number:parseInt(s.iid,10),state:Js[s.state],commentCount:s.userNotesCount||0,upvoteCount:s.upvotes,author:s.author?H(s.author,t,r):null,createdDate:new Date(s.createdAt),isDraft:s.draft,repository:{id:n.id,graphQLId:n.graphQLId,name:n.name,owner:{login:n.namespace},remoteInfo:n.httpsUrl&&n.sshUrl?{cloneUrlHTTPS:n.httpsUrl,cloneUrlSSH:n.sshUrl}:null},headRepository:e?{id:e.id,graphQLId:e.graphQLId,name:e.name,owner:{login:e.namespace},remoteInfo:{cloneUrlHTTPS:e.httpsUrl,cloneUrlSSH:e.sshUrl}}:null,headCommit:{buildStatuses:s.headPipeline?.stages?.nodes?.flatMap(i=>i.jobs?.nodes?.map(a=>({completedAt:a.finishedAt?new Date(a.finishedAt):null,description:null,name:a.name??null,state:Vs(a.status,a.allowFailure),stage:i.name??null,startedAt:new Date(a.createdAt),url:`${n.webUrl}/-/jobs/${a.id.replace(Bs,"")}`}))??[])??[]},baseRef:{name:s.targetBranch,oid:s.diffRefs?.baseSha??null},headRef:{name:s.sourceBranch,oid:s.diffRefs?.headSha??null},url:s.webUrl,updatedDate:new Date(s.updatedAt),closedDate:s.mergedAt?new Date(s.mergedAt):null,mergedDate:s.mergedAt?new Date(s.mergedAt):null,assignees:s.assignees?.nodes?s.assignees.nodes.map(i=>H(i,t,r)):null,reviews:o,reviewDecision:F(o),additions:s.diffStatsSummary?.additions||0,deletions:s.diffStatsSummary?.deletions||0,fileCount:s.diffStatsSummary?.fileCount||0,commitCount:s.commitCount||0,mergeableState:ks[s.mergeStatusEnum],milestone:s.milestone?Dt(s.milestone,n.webUrl):null,labels:s.labels?.nodes?.map(Ct)??[],permissions:null}},wt=(s,n,e,t)=>({author:H(s.author,e,t),assignees:s.assignees.nodes.map(r=>H(r,e,t)),commentCount:s.userNotesCount,closedDate:s.closedAt?new Date(s.closedAt):null,createdDate:new Date(s.createdAt),description:s.description,graphQLId:s.id,id:s.id.replace(Fs,""),labels:s.labels?.nodes?.map(Ct)??[],number:s.iid,repository:{id:n.id.replace(ae,""),graphQLId:n.id,name:n.name,owner:{login:n.namespace}},updatedDate:new Date(s.updatedAt),upvoteCount:s.upvotes,state:{name:s.state,color:null},type:s.type,title:s.title,url:s.webUrl,milestone:s.milestone?Dt(s.milestone,n.webUrl):null}),Dt=(s,n)=>({id:s.id.replace(js,""),graphQLId:s.id,number:parseInt(s.iid,10),title:s.title,description:s.description,isOpen:s.state==="active",url:`${n}/-/${s.webPath.replace(/.+?\/-\//,"")}`,startDate:s.startDate?new Date(s.startDate):null,dueDate:s.dueDate?new Date(s.dueDate):null}),ue=class extends T{getIsSelfHosted(n){return!!n.baseUrl||!!this.config.baseUrl}async getCurrentUser(n={},e={}){let r=(await w(this.config,{query:`
1004
1004
  query getCurrentUser {
1005
1005
  currentUser {
1006
- ${B}
1006
+ ${z}
1007
1007
  }
1008
1008
  }
1009
- `},e)).body.data?.currentUser;if(!s)throw new Error("Current user not found.");return{data:M(s,this.getIsSelfHosted(e),this.config.baseUrl??e.baseUrl)}}async getUserForCommit(n,e={}){let t=J(n.repo),o=(await w(this.config,{query:`
1009
+ `},e)).body.data?.currentUser;if(!r)throw new Error("Current user not found.");return{data:H(r,this.getIsSelfHosted(e),this.config.baseUrl??e.baseUrl)}}async getUserForCommit(n,e={}){let t=K(n.repo),o=(await w(this.config,{query:`
1010
1010
  query getUserForCommit($fullPath: ID!, $oid: String!) {
1011
1011
  project(fullPath: $fullPath) {
1012
1012
  repository {
@@ -1022,21 +1022,21 @@ query getUserForCommit($fullPath: ID!, $oid: String!) {
1022
1022
  }
1023
1023
  }
1024
1024
  }
1025
- `,variables:{fullPath:t,oid:n.oid}},e)).body.data?.project?.repository?.tree?.lastCommit;if(!o)throw new Error("Commit not found.");let i=ur(o.author.avatarUrl,this.getIsSelfHosted(e),this.config.baseUrl??e.baseUrl);return{data:{name:o.authorName,email:o.authorEmail,avatarUrl:i}}}async getAccountForEmail(n,e={}){let s=(await w(this.config,{query:`
1025
+ `,variables:{fullPath:t,oid:n.oid}},e)).body.data?.project?.repository?.tree?.lastCommit;if(!o)throw new Error("Commit not found.");let i=fr(o.author.avatarUrl,this.getIsSelfHosted(e),this.config.baseUrl??e.baseUrl);return{data:{name:o.authorName,email:o.authorEmail,avatarUrl:i}}}async getAccountForEmail(n,e={}){let r=(await w(this.config,{query:`
1026
1026
  query getAccountForEmail($email: String!) {
1027
1027
  users(search: $email) {
1028
1028
  nodes {
1029
- ${B}
1029
+ ${z}
1030
1030
  }
1031
1031
  }
1032
1032
  }
1033
- `,variables:{email:n.email}},e)).body.data?.users?.nodes?.[0];if(!s)throw new Error("User not found.");return{data:M(s,this.getIsSelfHosted(e),this.config.baseUrl??e.baseUrl)}}async getAccountForUsername(n,e={}){let s=(await w(this.config,{query:`
1033
+ `,variables:{email:n.email}},e)).body.data?.users?.nodes?.[0];if(!r)throw new Error("User not found.");return{data:H(r,this.getIsSelfHosted(e),this.config.baseUrl??e.baseUrl)}}async getAccountForUsername(n,e={}){let r=(await w(this.config,{query:`
1034
1034
  query getAccountForUsername($username: String!) {
1035
1035
  user(username: $username) {
1036
- ${B}
1036
+ ${z}
1037
1037
  }
1038
1038
  }
1039
- `,variables:{username:n.username}},e)).body.data?.user;if(!s)throw new Error("User not found.");return{data:M(s,this.getIsSelfHosted(e),this.config.baseUrl??e.baseUrl)}}async getAccountsForRepo(n,e={}){let{repo:{namespace:t,name:s},cursor:o}=n,i=await w(this.config,{query:`
1039
+ `,variables:{username:n.username}},e)).body.data?.user;if(!r)throw new Error("User not found.");return{data:H(r,this.getIsSelfHosted(e),this.config.baseUrl??e.baseUrl)}}async getAccountsForRepo(n,e={}){let{repo:{namespace:t,name:r},cursor:o}=n,i=await w(this.config,{query:`
1040
1040
  query getAccountsForRepo(
1041
1041
  $fullPath: ID!
1042
1042
  $after: String
@@ -1047,7 +1047,7 @@ query getAccountsForRepo(
1047
1047
  projectMembers(after: $after) {
1048
1048
  nodes {
1049
1049
  user {
1050
- ${B}
1050
+ ${z}
1051
1051
  }
1052
1052
  }
1053
1053
  pageInfo {
@@ -1057,22 +1057,22 @@ query getAccountsForRepo(
1057
1057
  }
1058
1058
  }
1059
1059
  }
1060
- `,variables:{fullPath:`${t}/${s}`,after:o}},e),a=i.body.data?.project?.projectMembers?.nodes?.map(u=>u.user).filter(u=>u!==null);return{pageInfo:i.body.data?.project?.projectMembers?.pageInfo??{endCursor:null,hasNextPage:!1},data:a?.map(u=>M(u,this.getIsSelfHosted(e),this.config.baseUrl??e.baseUrl))??[]}}async getRepo(n,e={}){let t=J(n),s=await w(this.config,{query:`
1060
+ `,variables:{fullPath:`${t}/${r}`,after:o}},e),a=i.body.data?.project?.projectMembers?.nodes?.map(u=>u.user).filter(u=>u!==null);return{pageInfo:i.body.data?.project?.projectMembers?.pageInfo??{endCursor:null,hasNextPage:!1},data:a?.map(u=>H(u,this.getIsSelfHosted(e),this.config.baseUrl??e.baseUrl))??[]}}async getRepo(n,e={}){let t=K(n),r=await w(this.config,{query:`
1061
1061
  query getRepo($fullPath: ID!) {
1062
1062
  project(fullPath: $fullPath) {
1063
- ${ct}
1063
+ ${bt}
1064
1064
  }
1065
1065
  }
1066
- `,variables:{fullPath:t}},e);if(!s.body.data?.project)throw new Error(`Repository ${t} not found`);return{data:mt(s.body.data.project)}}async getReposBase(n,e={}){let s=n.map(J).map((u,p)=>`
1067
- getRepo_${p}: project(fullPath: "${u}") {
1068
- ${ct}
1066
+ `,variables:{fullPath:t}},e);if(!r.body.data?.project)throw new Error(`Repository ${t} not found`);return{data:Pt(r.body.data.project)}}async getReposBase(n,e={}){let r=n.map(K).map((u,l)=>`
1067
+ getRepo_${l}: project(fullPath: "${u}") {
1068
+ ${bt}
1069
1069
  }
1070
1070
  `).join(`
1071
1071
  `),o=await w(this.config,{query:`
1072
1072
  query batchGetRepos {
1073
- ${s}
1073
+ ${r}
1074
1074
  }
1075
- `},e);if(!o.body.data)throw new Error(Ue(o.body.errors)||o.statusText||"Unknown error");let i=[],a=[];return n.forEach((u,p)=>{let d=o.body.data[`getRepo_${p}`];d?i.push(mt(d)):a.push({input:u})}),{data:i,errors:a}}async getRepos(n,e={}){let t=[];for(let i=0;i<n.length;i+=15)t.push(n.slice(i,i+15));return(await Promise.all(t.map(i=>this.getReposBase(i,e)))).reduce((i,a)=>({data:[...i.data,...a.data],errors:[...i.errors,...a.errors]}),{data:[],errors:[]})}async getReposForCurrentUser(n,e={}){let t=await w(this.config,{query:`
1075
+ `},e);if(!o.body.data)throw new Error(xe(o.body.errors)||o.statusText||"Unknown error");let i=[],a=[];return n.forEach((u,l)=>{let p=o.body.data[`getRepo_${l}`];p?i.push(Pt(p)):a.push({input:u})}),{data:i,errors:a}}async getRepos(n,e={}){let t=[];for(let i=0;i<n.length;i+=15)t.push(n.slice(i,i+15));return(await Promise.all(t.map(i=>this.getReposBase(i,e)))).reduce((i,a)=>({data:[...i.data,...a.data],errors:[...i.errors,...a.errors]}),{data:[],errors:[]})}async getReposForCurrentUser(n,e={}){let t=await w(this.config,{query:`
1076
1076
  query getReposForCurrentUser($after: String) {
1077
1077
  projects(membership: true first: 100 after: $after) {
1078
1078
  pageInfo {
@@ -1080,25 +1080,25 @@ query getReposForCurrentUser($after: String) {
1080
1080
  hasNextPage
1081
1081
  }
1082
1082
  nodes {
1083
- ${ct}
1083
+ ${bt}
1084
1084
  }
1085
1085
  }
1086
1086
  }
1087
- `,variables:{after:n.cursor}},e);if(!t.body.data?.projects)throw new Error(Ue(t.body.errors)||t.statusText||"Unknown error");let s=t.body.data?.projects?.nodes||[];return{pageInfo:t.body.data?.projects?.pageInfo,data:s.map(mt)}}async getRefs(n,e,t={}){let s=J(e.repo),o=new URL(`${$e(this.config,t)}/projects/${encodeURIComponent(s)}/repository/${n}`);o.searchParams.set("page",e.page?.toString()||"1"),o.searchParams.set("per_page",E.toString());let i=await this.config.request({url:o.toString(),headers:I(t.token||this.config.token)}),a=i.headers["x-next-page"];return{pageInfo:{hasNextPage:!!a,nextPage:a?parseInt(a,10):null},data:i.body.map(u=>({name:u.name,commit:{oid:u.commit.id,authoredDate:new Date(u.commit.authored_date),committedDate:new Date(u.commit.committed_date)}}))}}async getBranches(n,e={}){return this.getRefs("branches",n,e)}async getTags(n,e={}){return this.getRefs("tags",n,e)}async getBlame(n,e={}){let t=J(n.repo),s=new URL(`${$e(this.config,e)}/projects/${encodeURIComponent(t)}/repository/files/${encodeURIComponent(n.path)}/blame`);s.searchParams.set("ref",n.ref);let o=await this.config.request({url:s.toString(),headers:I(e.token||this.config.token)}),i=0;return{data:{ranges:o.body.map(a=>{let u=i+1;return i+=a.lines.length,{startingLine:u,endingLine:i,commit:{oid:a.commit.id,parentOids:a.commit.parent_ids,authoredDate:new Date(a.commit.authored_date),author:{name:a.commit.author_name,email:a.commit.author_email,avatarUrl:null},committedDate:new Date(a.commit.committed_date),committer:{name:a.commit.committer_name,email:a.commit.committer_email,avatarUrl:null},message:a.commit.message,fileCount:null,additions:null,deletions:null}}})}}}async getPullRequestsForUser(n,e={}){let t="";n.repo?.id?t=`projectId:"${n.repo.id}"`:n.repo?.namespace&&n.repo?.name&&(t=`projectPath:"${n.repo.namespace}/${n.repo.name}"`);let s=Ls[n.association],o=await w(this.config,{query:`
1087
+ `,variables:{after:n.cursor}},e);if(!t.body.data?.projects)throw new Error(xe(t.body.errors)||t.statusText||"Unknown error");let r=t.body.data?.projects?.nodes||[];return{pageInfo:t.body.data?.projects?.pageInfo,data:r.map(Pt)}}async getRefs(n,e,t={}){let r=K(e.repo),o=new URL(`${Oe(this.config,t)}/projects/${encodeURIComponent(r)}/repository/${n}`);o.searchParams.set("page",e.page?.toString()||"1"),o.searchParams.set("per_page",D.toString());let i=await this.config.request({url:o.toString(),headers:b(t.token||this.config.token)}),a=i.headers["x-next-page"];return{pageInfo:{hasNextPage:!!a,nextPage:a?parseInt(a,10):null},data:i.body.map(u=>({name:u.name,commit:{oid:u.commit.id,authoredDate:new Date(u.commit.authored_date),committedDate:new Date(u.commit.committed_date)}}))}}async getBranches(n,e={}){return this.getRefs("branches",n,e)}async getTags(n,e={}){return this.getRefs("tags",n,e)}async getBlame(n,e={}){let t=K(n.repo),r=new URL(`${Oe(this.config,e)}/projects/${encodeURIComponent(t)}/repository/files/${encodeURIComponent(n.path)}/blame`);r.searchParams.set("ref",n.ref);let o=await this.config.request({url:r.toString(),headers:b(e.token||this.config.token)}),i=0;return{data:{ranges:o.body.map(a=>{let u=i+1;return i+=a.lines.length,{startingLine:u,endingLine:i,commit:{oid:a.commit.id,parentOids:a.commit.parent_ids,authoredDate:new Date(a.commit.authored_date),author:{name:a.commit.author_name,email:a.commit.author_email,avatarUrl:null},committedDate:new Date(a.commit.committed_date),committer:{name:a.commit.committer_name,email:a.commit.committer_email,avatarUrl:null},message:a.commit.message,fileCount:null,additions:null,deletions:null}}})}}}async getPullRequestsForUser(n,e={}){let t="";n.repo?.id?t=`projectId:"${n.repo.id}"`:n.repo?.namespace&&n.repo?.name&&(t=`projectPath:"${n.repo.namespace}/${n.repo.name}"`);let r=xs[n.association],o=await w(this.config,{query:`
1088
1088
  query getPullRequestsForUser($username: String! $cursor: String $labelNames: [String!]) {
1089
1089
  user(username: $username) {
1090
- ${s}(state:opened first:100 after:$cursor labels: $labelNames${t?` ${t}`:""}) {
1090
+ ${r}(state:opened first:100 after:$cursor labels: $labelNames${t?` ${t}`:""}) {
1091
1091
  pageInfo {
1092
1092
  endCursor
1093
1093
  hasNextPage
1094
1094
  }
1095
1095
  nodes {
1096
- ${ir(!0,!0,!0)}
1096
+ ${gr(!0,!0,!0)}
1097
1097
  }
1098
1098
  }
1099
1099
  }
1100
1100
  }
1101
- `,variables:{username:n.username,cursor:n.cursor,labelNames:n.labelNames}},e);if(!o.body.data)throw new Error(Ue(o.body.errors)||o.statusText||"Unknown error");if(!o.body.data.user)throw new Error("User not found");let i=o.body.data.user[s];if(!i)throw new Error("Unexpected response");return{pageInfo:i.pageInfo,data:i.nodes?.filter(a=>n.includeFromArchivedRepos||!a.project.archived).map(a=>ar(a,or(a.project),or(a.sourceProject),this.getIsSelfHosted(e),this.config.baseUrl??e.baseUrl))||[]}}async getPullRequestsAssociatedWithUser(n,e={}){let[t,s,o]=n.cursor?.split(";")||[void 0,void 0,void 0],i=t?.split("-")||[],a=s?.split("-")||[],u=o?.split("-")||[],p=[],d=[],c=[],l=0;do{let S=n.repos&&n.repos[l];i[l]==="null"?p.push(null):p.push(this.getPullRequestsForUser({username:n.username,association:"authored",cursor:i[l],includeFromArchivedRepos:n.includeFromArchivedRepos,labelNames:n.labelNames,...S&&{repo:S}},e)),a[l]==="null"?d.push(null):d.push(this.getPullRequestsForUser({username:n.username,association:"assigned",cursor:a[l],includeFromArchivedRepos:n.includeFromArchivedRepos,labelNames:n.labelNames,...S&&{repo:S}},e)),u[l]==="null"?c.push(null):c.push(this.getPullRequestsForUser({username:n.username,association:"reviewRequested",cursor:u[l],includeFromArchivedRepos:n.includeFromArchivedRepos,labelNames:n.labelNames,...S&&{repo:S}},e)),l++}while(l<(n.repos?.length||0));let g=[p,d,c].flat(),m=await Promise.all(g),b={},R=[],P=S=>{b[S.id]||(b[S.id]=!0,R.push(S))},U=!1,x=m.map((S,k)=>{let q="";return S&&S.data.forEach(P),S?.pageInfo.hasNextPage?(U=!0,q+=`${S.pageInfo.endCursor||"null"}`):q+="null",n.repos?.length&&(k+1)%n.repos.length!==0?q+="-":k+1<m.length&&(q+=";"),q}).join("");return{pageInfo:{hasNextPage:U,endCursor:x},data:R}}getVariablesForPullRequests(n){let{updatedBefore:e,isDraft:t,authorLogin:s,assigneeLogins:o,labelNames:i,reviewRequestedLogin:a}=n||{},u={},p=[],d=[],c=(l,g,m)=>{p.push(`$${l}: ${m}`),d.push(`${l}: $${l}`),u[l]=g};return e&&c("updatedBefore",e,"Time"),s&&c("authorUsername",s,"String"),o&&c("assigneeUsername",o[0],"String"),i&&c("labelName",i,"[String]"),t!=null&&c("draft",t,"Boolean"),a&&c("reviewerUsername",a,"String"),{variables:u,variableTypes:p,mergeRequestArguments:d}}async getPullRequestsForRepoBase(n,e={},t){let{cursor:s,repo:o}=n||{},i=J(o),{variables:a,variableTypes:u,mergeRequestArguments:p}=this.getVariablesForPullRequests(n),d={fullPath:i,...a},c=await w(this.config,{query:`
1101
+ `,variables:{username:n.username,cursor:n.cursor,labelNames:n.labelNames}},e);if(!o.body.data)throw new Error(xe(o.body.errors)||o.statusText||"Unknown error");if(!o.body.data.user)throw new Error("User not found");let i=o.body.data.user[r];if(!i)throw new Error("Unexpected response");return{pageInfo:i.pageInfo,data:i.nodes?.filter(a=>n.includeFromArchivedRepos||!a.project.archived).map(a=>hr(a,mr(a.project),mr(a.sourceProject),this.getIsSelfHosted(e),this.config.baseUrl??e.baseUrl))||[]}}async getPullRequestsAssociatedWithUser(n,e={}){let[t,r,o]=n.cursor?.split(";")||[void 0,void 0,void 0],i=t?.split("-")||[],a=r?.split("-")||[],u=o?.split("-")||[],l=[],p=[],c=[],d=0;do{let E=n.repos&&n.repos[d];i[d]==="null"?l.push(null):l.push(this.getPullRequestsForUser({username:n.username,association:"authored",cursor:i[d],includeFromArchivedRepos:n.includeFromArchivedRepos,labelNames:n.labelNames,...E&&{repo:E}},e)),a[d]==="null"?p.push(null):p.push(this.getPullRequestsForUser({username:n.username,association:"assigned",cursor:a[d],includeFromArchivedRepos:n.includeFromArchivedRepos,labelNames:n.labelNames,...E&&{repo:E}},e)),u[d]==="null"?c.push(null):c.push(this.getPullRequestsForUser({username:n.username,association:"reviewRequested",cursor:u[d],includeFromArchivedRepos:n.includeFromArchivedRepos,labelNames:n.labelNames,...E&&{repo:E}},e)),d++}while(d<(n.repos?.length||0));let m=[l,p,c].flat(),g=await Promise.all(m),y={},I=[],R=E=>{y[E.id]||(y[E.id]=!0,I.push(E))},q=!1,N=g.map((E,U)=>{let v="";return E&&E.data.forEach(R),E?.pageInfo.hasNextPage?(q=!0,v+=`${E.pageInfo.endCursor||"null"}`):v+="null",n.repos?.length&&(U+1)%n.repos.length!==0?v+="-":U+1<g.length&&(v+=";"),v}).join("");return{pageInfo:{hasNextPage:q,endCursor:N},data:I}}getVariablesForPullRequests(n){let{updatedBefore:e,isDraft:t,authorLogin:r,assigneeLogins:o,labelNames:i,reviewRequestedLogin:a}=n||{},u={},l=[],p=[],c=(d,m,g)=>{l.push(`$${d}: ${g}`),p.push(`${d}: $${d}`),u[d]=m};return e&&c("updatedBefore",e,"Time"),r&&c("authorUsername",r,"String"),o&&c("assigneeUsername",o[0],"String"),i&&c("labelName",i,"[String]"),t!=null&&c("draft",t,"Boolean"),a&&c("reviewerUsername",a,"String"),{variables:u,variableTypes:l,mergeRequestArguments:p}}async getPullRequestsForRepoBase(n,e={},t){let{cursor:r,repo:o}=n||{},i=K(o),{variables:a,variableTypes:u,mergeRequestArguments:l}=this.getVariablesForPullRequests(n),p={fullPath:i,...a},c=await w(this.config,{query:`
1102
1102
  query getPullRequestsForRepo(
1103
1103
  $fullPath: ID!
1104
1104
  $after: String
@@ -1116,26 +1116,26 @@ query getPullRequestsForRepo(
1116
1116
  state: opened
1117
1117
  sort: UPDATED_DESC
1118
1118
  after: $after
1119
- ${p.length?p.join(" "):""}
1119
+ ${l.length?l.join(" "):""}
1120
1120
  ) {
1121
1121
  pageInfo {
1122
1122
  endCursor
1123
1123
  hasNextPage
1124
1124
  }
1125
1125
  nodes {
1126
- ${ir(!1,!0,!0)}
1126
+ ${gr(!1,!0,!0)}
1127
1127
  }
1128
1128
  }
1129
1129
  }
1130
1130
  }
1131
- `,variables:{...d,after:s}},e),l=[],g=c.body.data?.project;if(!t&&g?.archived)return{pageInfo:null,data:[]};let m=Ae(g||{id:"",fullPath:"",webUrl:""});return(g?.mergeRequests?.nodes||[]).forEach(R=>{l.push(ar(R,m,null,this.getIsSelfHosted(e),this.config.baseUrl??e.baseUrl))}),{pageInfo:g?.mergeRequests?.pageInfo,data:l}}async getPullRequestsForRepo(n,e={}){return this.getPullRequestsForRepoBase(n,e,!1)}async getPullRequestsForRepos(n,e={}){let{repos:t,assigneeLogins:s,updatedBefore:o,authorLogin:i,labelNames:a,isDraft:u,reviewRequestedLogin:p}=n;return{data:(await Promise.all(t.map(c=>this.getPullRequestsForRepoBase({repo:c,assigneeLogins:s,updatedBefore:o,authorLogin:i,labelNames:a,isDraft:u,reviewRequestedLogin:p},e,n.includeFromArchivedRepos??!1)))).flatMap(c=>c.data)}}async closePullRequest(n,e={}){let{pullRequest:t}=n,s=`mutation ClosePullRequest($fullPath: ID!, $pullRequestId: String!) {
1131
+ `,variables:{...p,after:r}},e),d=[],m=c.body.data?.project;if(!t&&m?.archived)return{pageInfo:null,data:[]};let g=ke(m||{id:"",fullPath:"",webUrl:""});return(m?.mergeRequests?.nodes||[]).forEach(I=>{d.push(hr(I,g,null,this.getIsSelfHosted(e),this.config.baseUrl??e.baseUrl))}),{pageInfo:m?.mergeRequests?.pageInfo,data:d}}async getPullRequestsForRepo(n,e={}){return this.getPullRequestsForRepoBase(n,e,!1)}async getPullRequestsForRepos(n,e={}){let{repos:t,assigneeLogins:r,updatedBefore:o,authorLogin:i,labelNames:a,isDraft:u,reviewRequestedLogin:l}=n;return{data:(await Promise.all(t.map(c=>this.getPullRequestsForRepoBase({repo:c,assigneeLogins:r,updatedBefore:o,authorLogin:i,labelNames:a,isDraft:u,reviewRequestedLogin:l},e,n.includeFromArchivedRepos??!1)))).flatMap(c=>c.data)}}async closePullRequest(n,e={}){let{pullRequest:t}=n,r=`mutation ClosePullRequest($fullPath: ID!, $pullRequestId: String!) {
1132
1132
  mergeRequestUpdate(input: { projectPath: $fullPath, iid: $pullRequestId, state: CLOSED }) {
1133
1133
  errors,
1134
1134
  mergeRequest {
1135
1135
  id
1136
1136
  }
1137
1137
  }
1138
- }`,i=(await w(this.config,{query:s,variables:{fullPath:`${t.repository.owner.login}/${t.repository.name}`,pullRequestId:t.number.toString()}},e)).body.data?.mergeRequestUpdate;if(!i?.mergeRequest?.id||i?.errors?.length!==0)throw new Error("Could not close pull request")}async mergePullRequest(n,e={}){let{pullRequest:t,mergeStrategy:s}=n;if(!t.headRef?.oid)throw new Error('GitLab requires "headRef.oid" for this function.');let o=`mutation MergePullRequest(
1138
+ }`,i=(await w(this.config,{query:r,variables:{fullPath:`${t.repository.owner.login}/${t.repository.name}`,pullRequestId:t.number.toString()}},e)).body.data?.mergeRequestUpdate;if(!i?.mergeRequest?.id||i?.errors?.length!==0)throw new Error("Could not close pull request")}async mergePullRequest(n,e={}){let{pullRequest:t,mergeStrategy:r}=n;if(!t.headRef?.oid)throw new Error('GitLab requires "headRef.oid" for this function.');let o=`mutation MergePullRequest(
1139
1139
  $fullPath: ID!,
1140
1140
  $pullRequestId: String!,
1141
1141
  $expectedSourceSha: String!,
@@ -1152,59 +1152,59 @@ query getPullRequestsForRepo(
1152
1152
  id
1153
1153
  }
1154
1154
  }
1155
- }`,a=(await w(this.config,{query:o,variables:{fullPath:`${t.repository.owner.login}/${t.repository.name}`,pullRequestId:t.number.toString(),expectedSourceSha:t.headRef.oid,squash:s==="SQUASH"}},e)).body.data?.mergeRequestAccept;if(!a?.mergeRequest?.id||a?.errors?.length!==0)throw new Error("Could not merge pull request")}async setPullRequestMilestone(n,e={}){let{pullRequest:t,milestone:s}=n;if(!t.graphQLId)throw new Error('GitHub requires "graphQLId" for this function.');let o=`mutation SetPullRequestMilestone($fullPath: ID!, $pullRequestId: String!, $milestoneGraphQLId: MilestoneID) {
1155
+ }`,a=(await w(this.config,{query:o,variables:{fullPath:`${t.repository.owner.login}/${t.repository.name}`,pullRequestId:t.number.toString(),expectedSourceSha:t.headRef.oid,squash:r==="SQUASH"}},e)).body.data?.mergeRequestAccept;if(!a?.mergeRequest?.id||a?.errors?.length!==0)throw new Error("Could not merge pull request")}async setPullRequestMilestone(n,e={}){let{pullRequest:t,milestone:r}=n;if(!t.graphQLId)throw new Error('GitHub requires "graphQLId" for this function.');let o=`mutation SetPullRequestMilestone($fullPath: ID!, $pullRequestId: String!, $milestoneGraphQLId: MilestoneID) {
1156
1156
  mergeRequestSetMilestone(input: { projectPath: $fullPath, iid: $pullRequestId, milestoneId: $milestoneGraphQLId }) {
1157
1157
  errors,
1158
1158
  mergeRequest {
1159
1159
  id
1160
1160
  }
1161
1161
  }
1162
- }`,i=await w(this.config,{query:o,variables:{fullPath:`${t.repository.owner.login}/${t.repository.name}`,pullRequestId:t.number.toString(),milestoneGraphQLId:s?.graphQLId}},e),a=i.body.data?.mergeRequestSetMilestone;if(!a?.mergeRequest?.id||i.body.errors||a?.errors?.length!==0)throw new Error("Could not set milestone of pull request")}async setPullRequestAsDraft(n,e={}){let{pullRequest:t,isDraft:s}=n,o=`mutation MergeRequestSetDraft($fullPath: ID!, $pullRequestId: String!, $isDraft: Boolean!) {
1162
+ }`,i=await w(this.config,{query:o,variables:{fullPath:`${t.repository.owner.login}/${t.repository.name}`,pullRequestId:t.number.toString(),milestoneGraphQLId:r?.graphQLId}},e),a=i.body.data?.mergeRequestSetMilestone;if(!a?.mergeRequest?.id||i.body.errors||a?.errors?.length!==0)throw new Error("Could not set milestone of pull request")}async setPullRequestAsDraft(n,e={}){let{pullRequest:t,isDraft:r}=n,o=`mutation MergeRequestSetDraft($fullPath: ID!, $pullRequestId: String!, $isDraft: Boolean!) {
1163
1163
  mergeRequestSetDraft(input: { projectPath: $fullPath, iid: $pullRequestId, draft: $isDraft }) {
1164
1164
  errors,
1165
1165
  mergeRequest {
1166
1166
  id
1167
1167
  }
1168
1168
  }
1169
- }`,a=(await w(this.config,{query:o,variables:{fullPath:`${t.repository.owner.login}/${t.repository.name}`,pullRequestId:t.number.toString(),isDraft:s}},e)).body.data?.mergeRequestSetDraft;if(!a?.mergeRequest?.id||a?.errors?.length!==0)throw new Error("Could not set pull request as draft")}async setPullRequestReviewers(n,e={}){let{pullRequest:t,reviewers:s}=n,o=s.map(p=>{if(!p.username)throw new Error('GitLab requires reviewer "username" for this function.');return p.username}),i=`mutation MergeRequestSetReviewers($fullPath: ID!, $pullRequestId: String!, $reviewerUsernames: [String!]!) {
1169
+ }`,a=(await w(this.config,{query:o,variables:{fullPath:`${t.repository.owner.login}/${t.repository.name}`,pullRequestId:t.number.toString(),isDraft:r}},e)).body.data?.mergeRequestSetDraft;if(!a?.mergeRequest?.id||a?.errors?.length!==0)throw new Error("Could not set pull request as draft")}async setPullRequestReviewers(n,e={}){let{pullRequest:t,reviewers:r}=n,o=r.map(l=>{if(!l.username)throw new Error('GitLab requires reviewer "username" for this function.');return l.username}),i=`mutation MergeRequestSetReviewers($fullPath: ID!, $pullRequestId: String!, $reviewerUsernames: [String!]!) {
1170
1170
  mergeRequestSetReviewers(input: { projectPath: $fullPath, iid: $pullRequestId, reviewerUsernames: $reviewerUsernames }) {
1171
1171
  errors,
1172
1172
  mergeRequest {
1173
1173
  id
1174
1174
  }
1175
1175
  }
1176
- }`,u=(await w(this.config,{query:i,variables:{fullPath:`${t.repository.owner.login}/${t.repository.name}`,pullRequestId:t.number.toString(),reviewerUsernames:o}},e)).body.data?.mergeRequestSetReviewers;if(!u?.mergeRequest?.id||u?.errors?.length!==0)throw new Error("Could not set pull request reviewers")}async reRequestPullRequestReview(n,e={}){let{pullRequest:t,reviewer:s}=n;if(!s.graphQLId)throw new Error('GitLab requires reviwer "graphQLId" for this function.');let o=`mutation MergeRequestReviewerRereview($fullPath: ID!, $pullRequestId: String!, $reviewerUserId: UserID!) {
1176
+ }`,u=(await w(this.config,{query:i,variables:{fullPath:`${t.repository.owner.login}/${t.repository.name}`,pullRequestId:t.number.toString(),reviewerUsernames:o}},e)).body.data?.mergeRequestSetReviewers;if(!u?.mergeRequest?.id||u?.errors?.length!==0)throw new Error("Could not set pull request reviewers")}async reRequestPullRequestReview(n,e={}){let{pullRequest:t,reviewer:r}=n;if(!r.graphQLId)throw new Error('GitLab requires reviwer "graphQLId" for this function.');let o=`mutation MergeRequestReviewerRereview($fullPath: ID!, $pullRequestId: String!, $reviewerUserId: UserID!) {
1177
1177
  mergeRequestReviewerRereview(input: { projectPath: $fullPath, iid: $pullRequestId, userId: $reviewerUserId }) {
1178
1178
  errors,
1179
1179
  mergeRequest {
1180
1180
  id
1181
1181
  }
1182
1182
  }
1183
- }`,a=(await w(this.config,{query:o,variables:{fullPath:`${t.repository.owner.login}/${t.repository.name}`,pullRequestId:t.number.toString(),reviewerUserId:s.graphQLId}},e)).body.data?.mergeRequestReviewerRereview;if(!a?.mergeRequest?.id||a?.errors?.length!==0)throw new Error("Could not set pull request reviewers")}async reRequestPullRequestReviews(n,e={}){let{pullRequest:t,reviewers:s}=n,o=t.reviews;if(!o)throw new Error('GitLab requires "reviews" for this function.');let i=s.filter(a=>o.find(u=>u.reviewer.graphQLId===a.graphQLId));await Promise.all(i.map(a=>this.reRequestPullRequestReview({pullRequest:t,reviewer:a},e)))}async setPullRequestAssignees(n,e={}){let{pullRequest:t,assignees:s}=n,o=s.map(p=>{if(!p.username)throw new Error('GitLab requires assignee "username" for this function.');return p.username}),i=`mutation MergeRequestSetAssignees($fullPath: ID!, $pullRequestId: String!, $assigneeUsernames: [String!]!) {
1183
+ }`,a=(await w(this.config,{query:o,variables:{fullPath:`${t.repository.owner.login}/${t.repository.name}`,pullRequestId:t.number.toString(),reviewerUserId:r.graphQLId}},e)).body.data?.mergeRequestReviewerRereview;if(!a?.mergeRequest?.id||a?.errors?.length!==0)throw new Error("Could not set pull request reviewers")}async reRequestPullRequestReviews(n,e={}){let{pullRequest:t,reviewers:r}=n,o=t.reviews;if(!o)throw new Error('GitLab requires "reviews" for this function.');let i=r.filter(a=>o.find(u=>u.reviewer.graphQLId===a.graphQLId));await Promise.all(i.map(a=>this.reRequestPullRequestReview({pullRequest:t,reviewer:a},e)))}async setPullRequestAssignees(n,e={}){let{pullRequest:t,assignees:r}=n,o=r.map(l=>{if(!l.username)throw new Error('GitLab requires assignee "username" for this function.');return l.username}),i=`mutation MergeRequestSetAssignees($fullPath: ID!, $pullRequestId: String!, $assigneeUsernames: [String!]!) {
1184
1184
  mergeRequestSetAssignees(input: { projectPath: $fullPath, iid: $pullRequestId, assigneeUsernames: $assigneeUsernames }) {
1185
1185
  errors,
1186
1186
  mergeRequest {
1187
1187
  id
1188
1188
  }
1189
1189
  }
1190
- }`,u=(await w(this.config,{query:i,variables:{fullPath:`${t.repository.owner.login}/${t.repository.name}`,pullRequestId:t.number.toString(),assigneeUsernames:o}},e)).body.data?.mergeRequestSetAssignees;if(!u?.mergeRequest?.id||u?.errors?.length!==0)throw new Error("Could not set pull request assignees")}async setPullRequestLabels(n,e={}){let{pullRequest:t,labels:s}=n,o=s.map(u=>{if(!u.graphQLId)throw new Error('GitLab requires "graphQLId" for labels in this function.');return u.graphQLId}),i=`mutation SetPullRequestLabels($fullPath: ID!, $pullRequestId: String!, $labelGraphQLIds: [LabelID!]!) {
1190
+ }`,u=(await w(this.config,{query:i,variables:{fullPath:`${t.repository.owner.login}/${t.repository.name}`,pullRequestId:t.number.toString(),assigneeUsernames:o}},e)).body.data?.mergeRequestSetAssignees;if(!u?.mergeRequest?.id||u?.errors?.length!==0)throw new Error("Could not set pull request assignees")}async setPullRequestLabels(n,e={}){let{pullRequest:t,labels:r}=n,o=r.map(u=>{if(!u.graphQLId)throw new Error('GitLab requires "graphQLId" for labels in this function.');return u.graphQLId}),i=`mutation SetPullRequestLabels($fullPath: ID!, $pullRequestId: String!, $labelGraphQLIds: [LabelID!]!) {
1191
1191
  mergeRequestSetLabels(input: { projectPath: $fullPath, iid: $pullRequestId, labelIds: $labelGraphQLIds }) {
1192
1192
  mergeRequest {
1193
1193
  id
1194
1194
  }
1195
1195
  }
1196
- }`;if(!(await w(this.config,{query:i,variables:{fullPath:`${t.repository.owner.login}/${t.repository.name}`,pullRequestId:t.number.toString(),labelGraphQLIds:o}},e)).body.data?.mergeRequestSetLabels?.mergeRequest?.id)throw new Error("Could not set pull request labels")}async getIssue(n,e={}){let t=Ns(n),s=await w(this.config,{query:`
1196
+ }`;if(!(await w(this.config,{query:i,variables:{fullPath:`${t.repository.owner.login}/${t.repository.name}`,pullRequestId:t.number.toString(),labelGraphQLIds:o}},e)).body.data?.mergeRequestSetLabels?.mergeRequest?.id)throw new Error("Could not set pull request labels")}async getIssue(n,e={}){let t=zs(n),r=await w(this.config,{query:`
1197
1197
  query GetSingleIssue($projectId: ID!, $issueNumber: String!) {
1198
1198
  project(fullPath: $projectId) {
1199
1199
  id
1200
1200
  fullPath
1201
1201
  webUrl
1202
1202
  issue(iid: $issueNumber) {
1203
- ${gt}
1203
+ ${yt}
1204
1204
  }
1205
1205
  }
1206
1206
  }
1207
- `,variables:{issueNumber:n.number,projectId:t}},e);if(!s.body.data?.project)throw new Error(`Repository ${t} not found`);if(!s.body.data?.project?.issue)throw new Error(`Issue ${n.number} not found`);return{data:ht(s.body.data.project.issue,Ae(s.body.data.project),this.getIsSelfHosted(e),this.config.baseUrl??e.baseUrl)}}getVariablesForIssues(n){let{updatedBefore:e,authorLogin:t,assigneeLogins:s,labelNames:o}=n||{},i={},a=[],u=[],p=(d,c,l)=>{a.push(`$${d}: ${l}`),u.push(`${d}: $${d}`),i[d]=c};return e&&p("updatedBefore",e,"Time"),t&&p("authorUsername",t,"String"),s&&p("assigneeUsername",s[0],"String"),o&&p("labelName",o,"[String]"),{variables:i,variableTypes:a,issueArguments:u}}async getIssuesForRepo(n,e={}){let{cursor:t,repo:s}=n||{},o=J(s),{variables:i,variableTypes:a,issueArguments:u}=this.getVariablesForIssues(n),p={fullPath:o,...i},d=`
1207
+ `,variables:{issueNumber:n.number,projectId:t}},e);if(!r.body.data?.project)throw new Error(`Repository ${t} not found`);if(!r.body.data?.project?.issue)throw new Error(`Issue ${n.number} not found`);return{data:wt(r.body.data.project.issue,ke(r.body.data.project),this.getIsSelfHosted(e),this.config.baseUrl??e.baseUrl)}}getVariablesForIssues(n){let{updatedBefore:e,authorLogin:t,assigneeLogins:r,labelNames:o}=n||{},i={},a=[],u=[],l=(p,c,d)=>{a.push(`$${p}: ${d}`),u.push(`${p}: $${p}`),i[p]=c};return e&&l("updatedBefore",e,"Time"),t&&l("authorUsername",t,"String"),r&&l("assigneeUsername",r[0],"String"),o&&l("labelName",o,"[String]"),{variables:i,variableTypes:a,issueArguments:u}}async getIssuesForRepo(n,e={}){let{cursor:t,repo:r}=n||{},o=K(r),{variables:i,variableTypes:a,issueArguments:u}=this.getVariablesForIssues(n),l={fullPath:o,...i},p=`
1208
1208
  query GetIssuesFromProject(
1209
1209
  $fullPath: ID!
1210
1210
  $after: String
@@ -1224,7 +1224,7 @@ query GetSingleIssue($projectId: ID!, $issueNumber: String!) {
1224
1224
  ${u.length?u.join(" "):""}
1225
1225
  ) {
1226
1226
  nodes {
1227
- ${gt}
1227
+ ${yt}
1228
1228
  }
1229
1229
  pageInfo {
1230
1230
  endCursor
@@ -1232,7 +1232,7 @@ query GetSingleIssue($projectId: ID!, $issueNumber: String!) {
1232
1232
  }
1233
1233
  }
1234
1234
  }
1235
- }`,c=await w(this.config,{query:d,variables:{...p,after:t}},e),l=[],g=c.body.data?.project,m=Ae(g||{id:"",fullPath:"",webUrl:""});return(g?.issues?.nodes||[]).forEach(R=>{l.push(ht(R,m,this.getIsSelfHosted(e),this.config.baseUrl??e.baseUrl))}),{pageInfo:g?.issues?.pageInfo??{endCursor:null,hasNextPage:!1},data:l.sort((R,P)=>(R.updatedDate||R.createdDate).getTime()-(P.updatedDate||P.createdDate).getTime())}}async getIssuesForRepos(n,e={}){let{cursor:t}=n||{},s=n.repoIds.map(g=>g.toString().startsWith(ae)?g:`${ae}${g}`),{variables:o,variableTypes:i,mergeRequestArguments:a}=this.getVariablesForPullRequests(n),u={projectIds:s,...o},p=`
1235
+ }`,c=await w(this.config,{query:p,variables:{...l,after:t}},e),d=[],m=c.body.data?.project,g=ke(m||{id:"",fullPath:"",webUrl:""});return(m?.issues?.nodes||[]).forEach(I=>{d.push(wt(I,g,this.getIsSelfHosted(e),this.config.baseUrl??e.baseUrl))}),{pageInfo:m?.issues?.pageInfo??{endCursor:null,hasNextPage:!1},data:d.sort((I,R)=>(I.updatedDate||I.createdDate).getTime()-(R.updatedDate||R.createdDate).getTime())}}async getIssuesForRepos(n,e={}){let{cursor:t}=n||{},r=n.repoIds.map(m=>m.toString().startsWith(ae)?m:`${ae}${m}`),{variables:o,variableTypes:i,mergeRequestArguments:a}=this.getVariablesForPullRequests(n),u={projectIds:r,...o},l=`
1236
1236
  query GetIssuesFromProject(
1237
1237
  $projectIds: [ID!]
1238
1238
  $after: String
@@ -1258,24 +1258,24 @@ query GetSingleIssue($projectId: ID!, $issueNumber: String!) {
1258
1258
  ${a.length?a.join(" "):""}
1259
1259
  ) {
1260
1260
  nodes {
1261
- ${gt}
1261
+ ${yt}
1262
1262
  }
1263
1263
  }
1264
1264
  }
1265
1265
  }
1266
- }`,d=await w(this.config,{query:p,variables:{...u,after:t}},e),c=[];return(d.body.data?.projects?.nodes||[]).forEach(g=>{if(!n.includeFromArchivedRepos&&g.archived)return;let m=Ae(g);(g.issues?.nodes||[]).forEach(R=>c.push(ht(R,m,this.getIsSelfHosted(e),this.config.baseUrl??e.baseUrl)))}),{pageInfo:d.body?.data?.projects?.pageInfo??{endCursor:null,hasNextPage:!1},data:c.sort((g,m)=>(g.updatedDate||g.createdDate).getTime()-(m.updatedDate||m.createdDate).getTime())}}async setIssueState(n,e={}){let{issue:t,state:s}=n;if(!t.repository)throw new Error('GitLab requires "repository" for this function.');let o=`mutation SetIssueState($fullPath: ID!, $issueId: String!, $status: IssueStateEvent!) {
1266
+ }`,p=await w(this.config,{query:l,variables:{...u,after:t}},e),c=[];return(p.body.data?.projects?.nodes||[]).forEach(m=>{if(!n.includeFromArchivedRepos&&m.archived)return;let g=ke(m);(m.issues?.nodes||[]).forEach(I=>c.push(wt(I,g,this.getIsSelfHosted(e),this.config.baseUrl??e.baseUrl)))}),{pageInfo:p.body?.data?.projects?.pageInfo??{endCursor:null,hasNextPage:!1},data:c.sort((m,g)=>(m.updatedDate||m.createdDate).getTime()-(g.updatedDate||g.createdDate).getTime())}}async setIssueState(n,e={}){let{issue:t,state:r}=n;if(!t.repository)throw new Error('GitLab requires "repository" for this function.');let o=`mutation SetIssueState($fullPath: ID!, $issueId: String!, $status: IssueStateEvent!) {
1267
1267
  updateIssue(input: { projectPath: $fullPath, iid: $issueId, stateEvent: $status }) {
1268
1268
  issue {
1269
1269
  id
1270
1270
  }
1271
1271
  }
1272
- }`;if(!(await w(this.config,{query:o,variables:{fullPath:`${t.repository.owner.login}/${t.repository.name}`,issueId:t.number,status:s==="OPEN"?"REOPEN":"CLOSE"}},e)).body.data?.updateIssue?.issue?.id)throw new Error("Could not set issue status")}async closeIssue(n,e={}){await this.setIssueState({...n,state:"CLOSED"},e)}async reOpenIssue(n,e={}){await this.setIssueState({...n,state:"OPEN"},e)}async setIssueLabels(n,e={}){let{issue:t,labels:s}=n;if(!t.repository)throw new Error('GitLab requires a "repository" for this function.');let o=s.map(u=>{if(!u.graphQLId)throw new Error('GitLab requires label "graphQLId" for this function.');return u.graphQLId}),i=`mutation SetIssueLabels($fullPath: ID!, $issueId: String!, $labelGraphQLIds: [ID!]) {
1272
+ }`;if(!(await w(this.config,{query:o,variables:{fullPath:`${t.repository.owner.login}/${t.repository.name}`,issueId:t.number,status:r==="OPEN"?"REOPEN":"CLOSE"}},e)).body.data?.updateIssue?.issue?.id)throw new Error("Could not set issue status")}async closeIssue(n,e={}){await this.setIssueState({...n,state:"CLOSED"},e)}async reOpenIssue(n,e={}){await this.setIssueState({...n,state:"OPEN"},e)}async setIssueLabels(n,e={}){let{issue:t,labels:r}=n;if(!t.repository)throw new Error('GitLab requires a "repository" for this function.');let o=r.map(u=>{if(!u.graphQLId)throw new Error('GitLab requires label "graphQLId" for this function.');return u.graphQLId}),i=`mutation SetIssueLabels($fullPath: ID!, $issueId: String!, $labelGraphQLIds: [ID!]) {
1273
1273
  updateIssue(input: { projectPath: $fullPath, iid: $issueId, labelIds: $labelGraphQLIds }) {
1274
1274
  issue {
1275
1275
  id
1276
1276
  }
1277
1277
  }
1278
- }`;if(!(await w(this.config,{query:i,variables:{fullPath:`${t.repository.owner.login}/${t.repository.name}`,issueId:t.number,labelGraphQLIds:o}},e)).body.data?.updateIssue?.issue?.id)throw new Error("Could not set issue labels")}async setIssueMilestone(n,e={}){let{issue:t,milestone:s}=n;if(!t.repository)throw new Error('GitLab requires "repository" for this function.');let o=`mutation SetIssueMilestone($fullPath: ID!, $issueId: String!, $milestoneId: ID) {
1278
+ }`;if(!(await w(this.config,{query:i,variables:{fullPath:`${t.repository.owner.login}/${t.repository.name}`,issueId:t.number,labelGraphQLIds:o}},e)).body.data?.updateIssue?.issue?.id)throw new Error("Could not set issue labels")}async setIssueMilestone(n,e={}){let{issue:t,milestone:r}=n;if(!t.repository)throw new Error('GitLab requires "repository" for this function.');let o=`mutation SetIssueMilestone($fullPath: ID!, $issueId: String!, $milestoneId: ID) {
1279
1279
  updateIssue(input: { projectPath: $fullPath, iid: $issueId, milestoneId: $milestoneId }) {
1280
1280
  errors
1281
1281
  issue {
@@ -1285,14 +1285,14 @@ query GetSingleIssue($projectId: ID!, $issueNumber: String!) {
1285
1285
  }
1286
1286
  }
1287
1287
  }
1288
- }`,i=await w(this.config,{query:o,variables:{fullPath:`${t.repository.owner.login}/${t.repository.name}`,issueId:t.number,milestoneId:s?.id??null}},e),a=i.body.data?.updateIssue;if(!a?.issue?.id||i.body.errors||a?.errors?.length!==0)throw new Error("Could not set milestone of issue")}async setIssueAssignees(n,e={}){let{issue:t,assignees:s}=n;if(!t.repository)throw new Error('GitLab requires "repository" for this function.');let o=s.map(p=>p.username),i=`mutation SetIssueAssignees($fullPath: ID!, $issueId: String!, $assigneeUsernames: [String!]!) {
1288
+ }`,i=await w(this.config,{query:o,variables:{fullPath:`${t.repository.owner.login}/${t.repository.name}`,issueId:t.number,milestoneId:r?.id??null}},e),a=i.body.data?.updateIssue;if(!a?.issue?.id||i.body.errors||a?.errors?.length!==0)throw new Error("Could not set milestone of issue")}async setIssueAssignees(n,e={}){let{issue:t,assignees:r}=n;if(!t.repository)throw new Error('GitLab requires "repository" for this function.');let o=r.map(l=>l.username),i=`mutation SetIssueAssignees($fullPath: ID!, $issueId: String!, $assigneeUsernames: [String!]!) {
1289
1289
  issueSetAssignees(input: { projectPath: $fullPath, iid: $issueId, assigneeUsernames: $assigneeUsernames }) {
1290
1290
  errors,
1291
1291
  issue {
1292
1292
  id
1293
1293
  }
1294
1294
  }
1295
- }`,u=(await w(this.config,{query:i,variables:{fullPath:`${t.repository.owner.login}/${t.repository.name}`,issueId:t.number,assigneeUsernames:o}},e)).body.data?.issueSetAssignees;if(!u?.issue?.id||u?.errors?.length!==0)throw new Error("Could not set issue assignees")}async getMilestonesForRepo(n,e={}){let{repo:{namespace:t,name:s},cursor:o}=n,i=await w(this.config,{query:`
1295
+ }`,u=(await w(this.config,{query:i,variables:{fullPath:`${t.repository.owner.login}/${t.repository.name}`,issueId:t.number,assigneeUsernames:o}},e)).body.data?.issueSetAssignees;if(!u?.issue?.id||u?.errors?.length!==0)throw new Error("Could not set issue assignees")}async getMilestonesForRepo(n,e={}){let{repo:{namespace:t,name:r},cursor:o}=n,i=await w(this.config,{query:`
1296
1296
  query getLabelsForRepo(
1297
1297
  $fullPath: ID!
1298
1298
  $after: String
@@ -1303,7 +1303,7 @@ query getLabelsForRepo(
1303
1303
  webUrl
1304
1304
  milestones(after: $after) {
1305
1305
  nodes {
1306
- ${It}
1306
+ ${St}
1307
1307
  }
1308
1308
  pageInfo {
1309
1309
  endCursor
@@ -1312,7 +1312,7 @@ query getLabelsForRepo(
1312
1312
  }
1313
1313
  }
1314
1314
  }
1315
- `,variables:{fullPath:`${t}/${s}`,after:o}},e);return{pageInfo:i.body.data?.project?.milestones?.pageInfo??{endCursor:null,hasNextPage:!1},data:i.body.data?.project?.milestones?.nodes?.map(a=>Pt(a,i.body.data?.project?.webUrl||""))??[]}}async getLabelsForRepo(n,e={}){let{repo:{namespace:t,name:s},cursor:o}=n,i=await w(this.config,{query:`
1315
+ `,variables:{fullPath:`${t}/${r}`,after:o}},e);return{pageInfo:i.body.data?.project?.milestones?.pageInfo??{endCursor:null,hasNextPage:!1},data:i.body.data?.project?.milestones?.nodes?.map(a=>Dt(a,i.body.data?.project?.webUrl||""))??[]}}async getLabelsForRepo(n,e={}){let{repo:{namespace:t,name:r},cursor:o}=n,i=await w(this.config,{query:`
1316
1316
  query getLabelsForRepo(
1317
1317
  $fullPath: ID!
1318
1318
  $after: String
@@ -1322,7 +1322,7 @@ query getLabelsForRepo(
1322
1322
  ) {
1323
1323
  labels(after: $after) {
1324
1324
  nodes {
1325
- ${bt}
1325
+ ${Et}
1326
1326
  }
1327
1327
  pageInfo {
1328
1328
  endCursor
@@ -1331,8 +1331,8 @@ query getLabelsForRepo(
1331
1331
  }
1332
1332
  }
1333
1333
  }
1334
- `,variables:{fullPath:`${t}/${s}`,after:o}},e);return{pageInfo:i.body.data?.project?.labels?.pageInfo??{endCursor:null,hasNextPage:!1},data:i.body.data?.project?.labels?.nodes?.map(yt)??[]}}async getTreeForRepo(n,e={}){let t=J(n.repo),s=new URL(n.cursor??`${$e(this.config,e)}/projects/${encodeURIComponent(t)}/repository/tree`);s.searchParams.set("per_page","10000"),s.searchParams.set("recursive","true"),s.searchParams.set("pagination","keyset"),s.searchParams.set("ref",n.branch);let o=await this.config.request({url:s.toString(),headers:I(e.token||this.config.token)}),i=o.headers.link;return{data:o.body.map(Fs),pageInfo:{endCursor:i?i.substring(1,i.indexOf(">")):null,hasNextPage:!!i}}}};var Ms="https://api.atlassian.com/ex/jira",Ge=100,wt=["assignee","comment","summary","created","creator","updated","votes","issuetype","status","labels","components","project","fixVersions","description"],lr="/rest/api/2/search/jql",pr="/rest/api/2/search",vt=(r,n,e,t)=>{let s=r.fields.assignee,o=!t,i=(r.fields[n?.Sprint??""]??[]).filter(a=>typeof a=="object");return{id:r.id,commentCount:r.fields.comment.comments.length,number:r.key,title:r.fields.summary,url:e?`${e}/browse/${r.key}`:null,closedDate:null,createdDate:new Date(r.fields.created),author:Te(r.fields.creator,e,o),updatedDate:new Date(r.fields.updated),assignees:s?[Te(s,e,o)]:[],description:r.fields.description,repository:null,project:{name:r.fields.project.name,resourceId:t??null,key:r.fields.project.key,namespace:null,id:r.fields.project.id},state:Js(r.fields.status),statusTransitions:r.transitions?.map(zs)??[],components:r.fields.components?.map(Hs)??[],type:r.fields.issuetype.name,upvoteCount:r.fields.votes?.votes||0,labels:r.fields.labels?.map(a=>({color:null,description:null,id:null,name:a}))??[],sprints:i.map(Vs),fixVersions:r.fields.fixVersions.map(Ks)}},zs=r=>{let n;switch(r.to.statusCategory.name){case"To Do":n="TO_DO";break;case"In Progress":n="IN_PROGRESS";break;default:n="DONE";break}return{name:r.name,id:r.id,to:{id:r.to.id,name:r.to.name,color:r.to.statusCategory.colorName,category:n}}},Hs=r=>({description:r.description??null,id:r.id,name:r.name}),Ws=(r,n,e)=>e&&r.name?`${n}/secure/ViewProfile.jspa?name=${encodeURIComponent(r.name)}`:`${n}/jira/people/${r.accountId}`,Te=(r,n,e)=>({id:(e?r.key:r.accountId)??"",name:r.displayName,email:r.emailAddress,avatarUrl:r.avatarUrls["48x48"],username:r.displayName,url:Ws(r,n,e)}),Js=r=>{let n;switch(r.statusCategory.name){case"To Do":n="TO_DO";break;case"In Progress":n="IN_PROGRESS";break;default:n="DONE";break}return{id:r.id,name:r.name,color:r.statusCategory.colorName,category:n}},Vs=r=>({id:r.id.toString(),name:r.name,isActive:r.state==="active",startDate:r.startDate?new Date(r.startDate):null,endDate:r.endDate?new Date(r.endDate):null,completedDate:r.completeDate?new Date(r.completeDate):null}),Ks=r=>({id:r.id,description:r.description,name:r.name,archived:r.archived,released:r.released,releaseDate:r.releaseDate?new Date(r.releaseDate):null}),V=(r,n,e)=>e?`${n.baseUrl||Ms}/${e}`:`${n?.baseUrl||r.baseUrl}`,Oe=async(r,n,e={})=>{let{resourceId:t}=n;return(await r.request({url:`${V(r,e,t)}/rest/api/2/field`,headers:I(e.token||r.token)})).body},xe=async(r,n,e,t={})=>{let{number:s,resourceId:o,fields:i}=n||{},a=await r.request({url:`${V(r,t,o)}/rest/api/2/issue/${s}?fields=${wt.join(",")}&expand=transitions`,headers:I(t.token||r.token)});return{data:vt(a.body,i,e,o)}},ke=async(r,n,e,t={})=>{let{cursor:s,resourceId:o,labelNames:i,fields:a}=n||{},u=["statusCategory != Done",`(creator = currentUser() OR assignee = currentUser()
1335
- OR comment ~ currentUser() OR summary ~ currentUser() OR description ~ currentUser())`];i&&i.forEach(P=>u.push(`labels = "${P}"`));let p=`${u.join(" AND ")} ORDER BY updated DESC`,d=!o,c=d?pr:lr,l=new URL(`${V(r,t,o)}${c}`);l.searchParams.set("jql",p),l.searchParams.set("maxResults",Ge.toString()),l.searchParams.set("fields",wt.join(",")),l.searchParams.set("expand","transitions"),s&&(d?l.searchParams.set("startAt",s):l.searchParams.set("nextPageToken",s));let g=await r.request({url:l.toString(),headers:I(t.token||r.token)}),m=g.body.issues.map(P=>vt(P,a,e,o)),b=!1,R="";return d?(b=m.length==Ge,R=(parseInt(s??"0",10)+m.length).toString()):(b=!!g.body.nextPageToken,R=g.body.nextPageToken??null),{data:m,pageInfo:{hasNextPage:b,endCursor:R}}},dr=async(r,n,e,t={})=>{let{cursor:s,resourceId:o,jql:i,fields:a}=n||{},u=[...wt],p=a?.Sprint;p&&u.push(p);let d=!o,c=d?pr:lr,l=new URL(`${V(r,t,o)}${c}`);l.searchParams.set("jql",i.join(" AND ")),l.searchParams.set("maxResults",Ge.toString()),l.searchParams.set("fields",u.join(",")),l.searchParams.set("expand","transitions"),s&&(d?l.searchParams.set("startAt",s):l.searchParams.set("nextPageToken",s));let g=await r.request({url:l.toString(),headers:I(t.token||r.token)}),m=g.body.issues.map(P=>vt(P,a,e,o)),b=!1,R="";return d?(b=m.length==Ge,R=(parseInt(s??"0",10)+m.length).toString()):(b=!!g.body.nextPageToken,R=g.body.nextPageToken??null),{data:m,pageInfo:{hasNextPage:b,endCursor:R}}},Ne=async(r,n,e,t={})=>{let{assigneeLogins:s,authorLogin:o,mentionLogin:i,labelNames:a,cursor:u,projectKey:p,resourceId:d,fields:c}=n||{},l=[`project = "${p}"`,"statusCategory != Done"];return o&&l.push(`creator in ("${o}")`),s&&s.length!==0&&l.push(`assignee in ("${s.join('", "')}")`),i&&l.push(`comment ~ "${i}"`),a&&a.forEach(g=>l.push(`labels = "${g}"`)),dr(r,{resourceId:d,jql:l,cursor:u,fields:c},e,t)},_e=async(r,n,e,t={})=>{let{assigneeLogins:s,authorLogin:o,mentionLogin:i,labelNames:a,cursor:u,projectKeys:p,resourceId:d,fields:c}=n||{},g=["("+p.map(m=>`project = "${m}"`).join(" OR ")+")","statusCategory != Done"];return o&&g.push(`creator in ("${o}")`),s&&s.length!==0&&g.push(`assignee in ("${s.join('", "')}")`),i&&g.push(`comment ~ "${i}"`),a&&a.forEach(m=>g.push(`labels = "${m}"`)),dr(r,{resourceId:d,jql:g,fields:c,cursor:u},e,t)},Fe=async(r,n,e={})=>{let{issue:t,labels:s}=n;if(!t.project)throw new Error('Jira requires a "project" for this function.');let o={fields:{labels:s.map(i=>i.name)}};await r.request({method:"PUT",url:`${V(r,e,t.project.resourceId??void 0)}/rest/api/2/issue/${t.id}`,body:JSON.stringify(o),headers:{...I(e.token||r.token),"Content-Type":"application/json"}})},Qe=async(r,n,e={})=>{let{issue:t,components:s}=n;if(!t.project)throw new Error('Jira requires a "project" for this function.');let o={fields:{components:s.map(i=>({id:i.id}))}};await r.request({method:"PUT",url:`${V(r,e,t.project.resourceId??void 0)}/rest/api/2/issue/${t.id}`,body:JSON.stringify(o),headers:{...I(e.token||r.token),"Content-Type":"application/json"}})},je=async(r,n,e={})=>{let{issue:t,status:s}=n;if(!t.project)throw new Error('Jira requires a "project" for this function.');if(!s.id)throw new Error('Jira requires a status "id" for this function.');let o={transition:{id:s.id}};await r.request({method:"POST",url:`${V(r,e,t.project.resourceId??void 0)}/rest/api/2/issue/${t.id}/transitions`,body:JSON.stringify(o),headers:{...I(e.token||r.token),"Content-Type":"application/json"}})},Be=async(r,n,e={})=>{let{resourceId:t,projectIdOrKey:s}=n,o=new URL(`${V(r,e,t)}/rest/api/2/project/${s}/components`);return{data:(await r.request({url:o.toString(),headers:I(e.token||r.token)})).body}};var he="https://api.atlassian.com/ex/jira",St=100,le=class extends T{constructor(){super(...arguments);this._resourceUrlCache={};this._issueFieldsCache={}}async getIssueFieldsForResource(e,t={}){if(!this._issueFieldsCache[e.resourceId]){let s=await Oe(this.config,e,t);this._issueFieldsCache[e.resourceId]=s.reduce((o,i)=>({...o,[i.name]:i.id}),{})}return this._issueFieldsCache[e.resourceId]??null}async getResourceUrl(e,t={}){let s=t.token||this.config.token;if(!s)return null;let o=this._resourceUrlCache[s];return o?o[e.resourceId]??null:(await this.getJiraResourcesForCurrentUser(t),this._resourceUrlCache[s]?.[e.resourceId]??null)}async getCurrentUserForResource(e,t={}){let s=await this.getResourceUrl({resourceId:e.resourceId},t),o=await this.config.request({url:`${t.baseUrl||he}/${e.resourceId}/rest/api/2/myself`,headers:I(t.token||this.config.token)});return{data:{name:o.body.displayName,email:o.body.emailAddress,avatarUrl:o.body.avatarUrls["48x48"],id:o.body.accountId,username:o.body.displayName,url:s?`${s}/jira/people/${o.body.accountId}`:null}}}async getJiraResourcesForCurrentUser(e={}){let t=await this.config.request({url:`${e.baseUrl||"https://api.atlassian.com/"}/oauth/token/accessible-resources`,headers:I(e.token||this.config.token)}),s=e.token||this.config.token,o=s?this._resourceUrlCache[s]||{}:void 0,i=t.body.map(a=>(o&&(o[a.id]=a.url),{avatarUrl:a.avatarUrl,id:a.id,name:a.name,url:a.url}));return s&&(this._resourceUrlCache[s]=o),{data:i}}async getJiraProjectsForResource(e,t={}){let s=new URL(`${t.baseUrl||he}/${e.resourceId}/rest/api/2/project/search`);s.searchParams.set("maxResults",St.toString()),e.cursor&&s.searchParams.set("startAt",e.cursor);let o=await this.config.request({url:s.toString(),headers:I(t.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(i=>({id:i.id,key:i.key,name:i.name,resourceId:e.resourceId}))}}async getJiraProjectsForResources(e,t={}){let s=[];return await Promise.all(e.resourceIds.map(async o=>{try{return await xt(i=>this.getJiraProjectsForResource({resourceId:o,cursor:i},t))}catch{return[]}})).then((...o)=>{o.forEach(i=>{s=s.concat(...i)})}),{data:s}}async getAccountsForJiraProject(e,t={}){let{resourceId:s,projectKey:o,cursor:i}=e,a=await this.getResourceUrl({resourceId:s},t),u=new URL(`${t.baseUrl||he}/${s}/rest/api/2/user/assignable/search`);u.searchParams.set("maxResults",St.toString()),i&&u.searchParams.set("startAt",i),u.searchParams.set("project",o);let p=await this.config.request({url:u.toString(),headers:I(t.token||this.config.token)});return{pageInfo:{hasNextPage:p.body.length!==0,endCursor:((i?parseInt(i):0)+p.body.length).toString()},data:p.body.filter(d=>d.accountType!=="app"&&d.active).map(d=>Te(d,a,!1))}}async getComponentsForJiraProject(e,t={}){return await Be(this.config,e,t)}async getIssue(e,t={}){let s=await this.getIssueFieldsForResource({resourceId:e.resourceId},t),o=await this.getResourceUrl({resourceId:e.resourceId},t);return await xe(this.config,{...e,fields:s},o,t)}async getIssuesForProject(e,t={}){let s=await this.getIssueFieldsForResource({resourceId:e.resourceId},t),o=await this.getResourceUrl({resourceId:e.resourceId},t);return await Ne(this.config,{...e,fields:s},o,t)}async getIssuesForProjects(e,t={}){let s=await this.getIssueFieldsForResource({resourceId:e.resourceId},t),o=await this.getResourceUrl({resourceId:e.resourceId},t);return await _e(this.config,{...e,fields:s},o,t)}async getIssuesForResourceForCurrentUser(e,t={}){let s=await this.getIssueFieldsForResource({resourceId:e.resourceId},t),o=await this.getResourceUrl({resourceId:e.resourceId},t);return await ke(this.config,{...e,fields:s},o,t)}async setIssueStatus(e,t={}){await je(this.config,e,t)}async setIssueAssignee(e,t={}){let{issue:s,assignee:o}=e;if(!s.project)throw new Error('Jira Cloud requires a "project" for this function.');if(!s.project.resourceId)throw new Error('Jira Cloud requires a project "resourceId" for this function.');let i={accountId:o?.id};await this.config.request({method:"PUT",url:`${t.baseUrl||he}/${s.project.resourceId}/rest/api/2/issue/${s.id}/assignee`,body:JSON.stringify(i),headers:{...I(t.token||this.config.token),"Content-Type":"application/json"}})}async setIssueComponents(e,t={}){await Qe(this.config,e,t)}async setIssueLabels(e,t={}){await Fe(this.config,e,t)}async getLabelsForResource(e,t={}){let{resourceId:s,cursor:o}=e,i=new URL(`${t.baseUrl||he}/${s}/rest/api/2/label`);i.searchParams.set("maxResults",St.toString()),o&&i.searchParams.set("startAt",o);let a=await this.config.request({url:i.toString(),headers:I(t.token||this.config.token)});return{pageInfo:{hasNextPage:!a.body.isLast,endCursor:(a.body.startAt+a.body.values.length).toString()},data:a.body.values.map(u=>({color:null,description:null,id:null,name:u}))}}};var pe=class extends A{constructor(){super(...arguments);this._issueFieldsCache={}}async getIssueFieldsForResource(e={}){let t=e?.baseUrl||this.config.baseUrl||"";if(!this._issueFieldsCache[t]){let s=await Oe(this.config,{},e);this._issueFieldsCache[t]=s.reduce((o,i)=>({...o,[i.name]:i.id}),{})}return this._issueFieldsCache[t]??null}async getCurrentUser(e={}){let t=await this.config.request({url:`${e?.baseUrl||this.config.baseUrl}/rest/api/2/myself`,headers:I(e?.token||this.config.token)});return{data:{name:t.body.displayName,email:t.body.emailAddress,avatarUrl:t.body.avatarUrls["48x48"],id:t.body.key,username:t.body.displayName,url:null}}}async getJiraProjects(e={}){return{data:(await this.config.request({url:`${e?.baseUrl||this.config.baseUrl}/rest/api/2/project`,headers:I(e?.token||this.config.token)})).body.map(s=>({id:s.id,name:s.name}))}}async getIssue(e,t={}){let s=e.resourceUrl||t.baseUrl||this.config.baseUrl;if(!s)throw new Error('Jira Server requires a "resourceUrl" or "baseUrl" for this function.');let o=await this.getIssueFieldsForResource(t);return await xe(this.config,{...e,fields:o},s,t)}async getIssuesForProject(e,t={}){let s=e.resourceUrl||t.baseUrl||this.config.baseUrl;if(!s)throw new Error('Jira Server requires a "resourceUrl" or "baseUrl" for this function.');let o=await this.getIssueFieldsForResource(t);return await Ne(this.config,{...e,fields:o},s,t)}async getIssuesForProjects(e,t={}){let s=e.resourceUrl||t.baseUrl||this.config.baseUrl;if(!s)throw new Error('Jira Server requires a "resourceUrl" or "baseUrl" for this function.');let o=await this.getIssueFieldsForResource(t);return await _e(this.config,{...e,fields:o},s,t)}async getIssuesForResourceForCurrentUser(e,t={}){let s=e.resourceUrl||t.baseUrl||this.config.baseUrl;if(!s)throw new Error('Jira Server requires a "resourceUrl" or "baseUrl" for this function.');let o=await this.getIssueFieldsForResource(t);return await ke(this.config,{...e,fields:o},s,t)}async setIssueStatus(e,t={}){await je(this.config,e,t)}async setIssueLabels(e,t={}){await Fe(this.config,e,t)}async setIssueComponents(e,t={}){await Qe(this.config,e,t)}async getLabels(e={}){return{data:(await this.config.request({url:`${e?.baseUrl||this.config.baseUrl}/rest/api/2/jql/autocompletedata/suggestions?fieldName=labels`,headers:I(e.token||this.config.token)})).body.results.map(({displayName:s})=>({color:null,description:null,id:null,name:s}))}}async getComponentsForJiraProject(e,t={}){return await Be(this.config,e,t)}};var F="https://api.trello.com",Xs=1e3,Q=(r,n)=>({...I(n),Authorization:`OAuth oauth_consumer_key="${r}", oauth_token="${n}"`}),Zs=r=>({id:r.id,username:r.username,url:r.url,name:r.fullName,email:r.email,avatarUrl:r.avatarUrl}),Ys=(r,n)=>{let e=new Date(1e3*parseInt(r.id.substring(0,8),16));return{id:r.id,commentCount:r.badges.comments,number:r.idShort.toString(),title:r.name,url:r.url,closedDate:null,createdDate:new Date(e.toISOString()),author:null,updatedDate:new Date(r.dateLastActivity),assignees:r.members.map(t=>({id:t.id,username:t.username,name:t.fullName,email:null,avatarUrl:t.avatarUrl,url:null})),description:null,state:n[r.idList??""]?{id:r.idList,name:n[r.idList].name,color:null}:null,type:null,repository:null,upvoteCount:r.badges.votes,labels:r.labels.map(t=>({color:t.color,description:null,id:t.id,name:t.name}))}},de=class extends T{async getCurrentUser(n,e={}){let t=await this.config.request({url:`${e.baseUrl||F}/1/members/me`,headers:Q(n.appKey,e.token||this.config.token)});return{data:{name:t.body.fullName,email:t.body.email,avatarUrl:t.body.avatarHash?`https://trello-members.s3.amazonaws.com/${t.body.id}/${t.body.avatarHash}/50.png`:null,id:t.body.id,username:t.body.username,url:t.body.url}}}async getBoardsForCurrentUser(n,e={}){return{data:(await this.config.request({url:`${e.baseUrl||F}/1/members/me/boards?fields=name&filter=open`,headers:Q(n.appKey,e.token||this.config.token)})).body.map(s=>({id:s.id,name:s.name}))}}async getListsForTrelloBoard(n,e={}){let{appKey:t,boardId:s}=n;return{data:(await this.config.request({url:`${e.baseUrl||F}/1/boards/${s}/lists`,headers:Q(t,e.token||this.config.token)})).body}}async getAccountForId(n,e={}){let{appKey:t,memberId:s}=n,o=await this.config.request({url:`${e.baseUrl||F}/1/members/${s}`,headers:Q(t,e.token||this.config.token)});return{data:Zs(o.body)}}async getAccountsForTrelloBoard(n,e={}){let{appKey:t,boardId:s}=n;return{data:(await this.config.request({url:`${e.baseUrl||F}/1/boards/${s}/members`,headers:Q(t,e.token||this.config.token)})).body.map(i=>({id:i.id,name:i.fullName,username:i.username,email:null,avatarUrl:null,url:null}))}}async getIssuesForBoard(n,e={}){let t=["-is:archived","sort:edited"],{appKey:s,boardId:o,filterText:i,assigneeLogins:a,labelNamesOrColors:u,trelloBoardListsById:p}=n||{};a&&t.push("@me"),u&&u.forEach(l=>t.push(`label:"${l}"`));let d=`${i?`${i}`:""}${t.join(" ")} board:${o}`;return{data:(await this.config.request({url:`${e.baseUrl||F}/1/search?query=${d}&cards_limit=${Xs}&card_members=true`,headers:Q(s,e.token||this.config.token)})).body.cards.map(l=>Ys(l,p||{}))}}async updateIssue(n,e,t,s){return await this.config.request({method:"PUT",url:`${s.baseUrl||F}/1/cards/${e.id}?${t}`,headers:Q(n,s.token||this.config.token)})}async setIssueStatus(n,e={}){let{appKey:t,issue:s,status:o}=n;if(!o.id)throw new Error('Trello requires a status "id" for this function.');let i=`idList=${o.id}`;if(!(await this.updateIssue(t,s,i,e)).body.id)throw new Error("Could not set issue status")}async setIssueAssignees(n,e={}){let{appKey:t,issue:s,assignees:o}=n,i=o.map(p=>p.id),a=`idMembers=${encodeURIComponent(i.join(","))}`;if(!(await this.updateIssue(t,s,a,e)).body.id)throw new Error("Could not set issue status")}async setIssueLabels(n,e={}){let{appKey:t,issue:s,labels:o}=n,i=o.map(u=>u.id).join(",");if(!(await this.config.request({method:"PUT",url:`${e.baseUrl||F}/1/cards/${s.id}?idLabels=${encodeURIComponent(i)}`,headers:Q(t,e.token||this.config.token)})).body.id)throw new Error("Could not set issue status")}async setIssueArchived(n,e={}){let{appKey:t,issue:s,archived:o}=n;if(!(await this.config.request({method:"PUT",url:`${e.baseUrl||F}/1/cards/${s.id}?closed=${o}`,headers:Q(t,e.token||this.config.token)})).body.id)throw new Error("Could not update issue archived status")}async archiveIssue(n,e={}){await this.setIssueArchived({...n,archived:!0},e)}async unArchiveIssue(n,e={}){await this.setIssueArchived({...n,archived:!1},e)}async getLabelsForBoard(n,e={}){let{appKey:t,boardId:s}=n;return{data:(await this.config.request({url:`${e.baseUrl||F}/1/boards/${s}/labels`,headers:Q(t,e.token||this.config.token)})).body.map(i=>({color:i.color,description:null,id:i.id,name:i.name}))}}};var Et=100,Me=class{constructor(){this.set=new Set;this.arr=[]}push(...n){let e=n.filter(t=>!this.set.has(t.id));this.arr.push(...e),e.forEach(t=>this.set.add(t.id))}get length(){return this.arr.length}get items(){return this.arr}},z=async(r,n,e,t)=>{let s=n.token||r.token;if(!s)throw new Error("Linear API key is required");let o=await r.request({url:"https://api.linear.app/graphql",method:"POST",headers:{Authorization:s,"Content-Type":"application/json"},body:JSON.stringify({query:e,variables:t})});if(o.status>=400)throw new Error(`Linear API request failed: ${o.status} ${o.statusText}`);let i=o.body;if(i.errors)throw new Error(`Linear GraphQL errors: ${i.errors.map(a=>a.message).join(", ")}`);return i.data},qt=r=>r?r instanceof Date?r:new Date(r):null,en=`
1334
+ `,variables:{fullPath:`${t}/${r}`,after:o}},e);return{pageInfo:i.body.data?.project?.labels?.pageInfo??{endCursor:null,hasNextPage:!1},data:i.body.data?.project?.labels?.nodes?.map(Ct)??[]}}async getTreeForRepo(n,e={}){let t=K(n.repo),r=new URL(n.cursor??`${Oe(this.config,e)}/projects/${encodeURIComponent(t)}/repository/tree`);r.searchParams.set("per_page","10000"),r.searchParams.set("recursive","true"),r.searchParams.set("pagination","keyset"),r.searchParams.set("ref",n.branch);let o=await this.config.request({url:r.toString(),headers:b(e.token||this.config.token)}),i=o.headers.link;return{data:o.body.map(Ws),pageInfo:{endCursor:i?i.substring(1,i.indexOf(">")):null,hasNextPage:!!i}}}};var Xs="https://api.atlassian.com/ex/jira",Ne=100,Lt=["assignee","comment","summary","created","creator","updated","votes","issuetype","status","labels","components","project","fixVersions","description"],Rr="/rest/api/2/search/jql",Ir="/rest/api/2/search",$t=(s,n,e,t)=>{let r=s.fields.assignee,o=!t,i=(s.fields[n?.Sprint??""]??[]).filter(a=>typeof a=="object");return{id:s.id,commentCount:s.fields.comment.comments.length,number:s.key,title:s.fields.summary,url:e?`${e}/browse/${s.key}`:null,closedDate:null,createdDate:new Date(s.fields.created),author:_e(s.fields.creator,e,o),updatedDate:new Date(s.fields.updated),assignees:r?[_e(r,e,o)]:[],description:s.fields.description,repository:null,project:{name:s.fields.project.name,resourceId:t??null,key:s.fields.project.key,namespace:null,id:s.fields.project.id},state:tn(s.fields.status),statusTransitions:s.transitions?.map(Zs)??[],components:s.fields.components?.map(Ys)??[],type:s.fields.issuetype.name,upvoteCount:s.fields.votes?.votes||0,labels:s.fields.labels?.map(a=>({color:null,description:null,id:null,name:a}))??[],sprints:i.map(rn),fixVersions:s.fields.fixVersions.map(sn)}},Zs=s=>{let n;switch(s.to.statusCategory.name){case"To Do":n="TO_DO";break;case"In Progress":n="IN_PROGRESS";break;default:n="DONE";break}return{name:s.name,id:s.id,to:{id:s.to.id,name:s.to.name,color:s.to.statusCategory.colorName,category:n}}},Ys=s=>({description:s.description??null,id:s.id,name:s.name}),en=(s,n,e)=>e&&s.name?`${n}/secure/ViewProfile.jspa?name=${encodeURIComponent(s.name)}`:`${n}/jira/people/${s.accountId}`,_e=(s,n,e)=>({id:(e?s.key:s.accountId)??"",name:s.displayName,email:s.emailAddress,avatarUrl:s.avatarUrls["48x48"],username:s.displayName,url:en(s,n,e)}),tn=s=>{let n;switch(s.statusCategory.name){case"To Do":n="TO_DO";break;case"In Progress":n="IN_PROGRESS";break;default:n="DONE";break}return{id:s.id,name:s.name,color:s.statusCategory.colorName,category:n}},rn=s=>({id:s.id.toString(),name:s.name,isActive:s.state==="active",startDate:s.startDate?new Date(s.startDate):null,endDate:s.endDate?new Date(s.endDate):null,completedDate:s.completeDate?new Date(s.completeDate):null}),sn=s=>({id:s.id,description:s.description,name:s.name,archived:s.archived,released:s.released,releaseDate:s.releaseDate?new Date(s.releaseDate):null}),X=(s,n,e)=>e?`${n.baseUrl||Xs}/${e}`:`${n?.baseUrl||s.baseUrl}`,Fe=async(s,n,e={})=>{let{resourceId:t}=n;return(await s.request({url:`${X(s,e,t)}/rest/api/2/field`,headers:b(e.token||s.token)})).body},Qe=async(s,n,e,t={})=>{let{number:r,resourceId:o,fields:i}=n||{},a=await s.request({url:`${X(s,t,o)}/rest/api/2/issue/${r}?fields=${Lt.join(",")}&expand=transitions`,headers:b(t.token||s.token)});return{data:$t(a.body,i,e,o)}},je=async(s,n,e,t={})=>{let{cursor:r,resourceId:o,labelNames:i,fields:a}=n||{},u=["statusCategory != Done",`(creator = currentUser() OR assignee = currentUser()
1335
+ OR comment ~ currentUser() OR summary ~ currentUser() OR description ~ currentUser())`];i&&i.forEach(R=>u.push(`labels = "${R}"`));let l=`${u.join(" AND ")} ORDER BY updated DESC`,p=!o,c=p?Ir:Rr,d=new URL(`${X(s,t,o)}${c}`);d.searchParams.set("jql",l),d.searchParams.set("maxResults",Ne.toString()),d.searchParams.set("fields",Lt.join(",")),d.searchParams.set("expand","transitions"),r&&(p?d.searchParams.set("startAt",r):d.searchParams.set("nextPageToken",r));let m=await s.request({url:d.toString(),headers:b(t.token||s.token)}),g=m.body.issues.map(R=>$t(R,a,e,o)),y=!1,I="";return p?(y=g.length==Ne,I=(parseInt(r??"0",10)+g.length).toString()):(y=!!m.body.nextPageToken,I=m.body.nextPageToken??null),{data:g,pageInfo:{hasNextPage:y,endCursor:I}}},br=async(s,n,e,t={})=>{let{cursor:r,resourceId:o,jql:i,fields:a}=n||{},u=[...Lt],l=a?.Sprint;l&&u.push(l);let p=!o,c=p?Ir:Rr,d=new URL(`${X(s,t,o)}${c}`);d.searchParams.set("jql",i.join(" AND ")),d.searchParams.set("maxResults",Ne.toString()),d.searchParams.set("fields",u.join(",")),d.searchParams.set("expand","transitions"),r&&(p?d.searchParams.set("startAt",r):d.searchParams.set("nextPageToken",r));let m=await s.request({url:d.toString(),headers:b(t.token||s.token)}),g=m.body.issues.map(R=>$t(R,a,e,o)),y=!1,I="";return p?(y=g.length==Ne,I=(parseInt(r??"0",10)+g.length).toString()):(y=!!m.body.nextPageToken,I=m.body.nextPageToken??null),{data:g,pageInfo:{hasNextPage:y,endCursor:I}}},Be=async(s,n,e,t={})=>{let{assigneeLogins:r,authorLogin:o,mentionLogin:i,labelNames:a,cursor:u,projectKey:l,resourceId:p,fields:c}=n||{},d=[`project = "${l}"`,"statusCategory != Done"];return o&&d.push(`creator in ("${o}")`),r&&r.length!==0&&d.push(`assignee in ("${r.join('", "')}")`),i&&d.push(`comment ~ "${i}"`),a&&a.forEach(m=>d.push(`labels = "${m}"`)),br(s,{resourceId:p,jql:d,cursor:u,fields:c},e,t)},Me=async(s,n,e,t={})=>{let{assigneeLogins:r,authorLogin:o,mentionLogin:i,labelNames:a,cursor:u,projectKeys:l,resourceId:p,fields:c}=n||{},m=["("+l.map(g=>`project = "${g}"`).join(" OR ")+")","statusCategory != Done"];return o&&m.push(`creator in ("${o}")`),r&&r.length!==0&&m.push(`assignee in ("${r.join('", "')}")`),i&&m.push(`comment ~ "${i}"`),a&&a.forEach(g=>m.push(`labels = "${g}"`)),br(s,{resourceId:p,jql:m,fields:c,cursor:u},e,t)},ze=async(s,n,e={})=>{let{issue:t,labels:r}=n;if(!t.project)throw new Error('Jira requires a "project" for this function.');let o={fields:{labels:r.map(i=>i.name)}};await s.request({method:"PUT",url:`${X(s,e,t.project.resourceId??void 0)}/rest/api/2/issue/${t.id}`,body:JSON.stringify(o),headers:{...b(e.token||s.token),"Content-Type":"application/json"}})},He=async(s,n,e={})=>{let{issue:t,components:r}=n;if(!t.project)throw new Error('Jira requires a "project" for this function.');let o={fields:{components:r.map(i=>({id:i.id}))}};await s.request({method:"PUT",url:`${X(s,e,t.project.resourceId??void 0)}/rest/api/2/issue/${t.id}`,body:JSON.stringify(o),headers:{...b(e.token||s.token),"Content-Type":"application/json"}})},We=async(s,n,e={})=>{let{issue:t,status:r}=n;if(!t.project)throw new Error('Jira requires a "project" for this function.');if(!r.id)throw new Error('Jira requires a status "id" for this function.');let o={transition:{id:r.id}};await s.request({method:"POST",url:`${X(s,e,t.project.resourceId??void 0)}/rest/api/2/issue/${t.id}/transitions`,body:JSON.stringify(o),headers:{...b(e.token||s.token),"Content-Type":"application/json"}})},Je=async(s,n,e={})=>{let{resourceId:t,projectIdOrKey:r}=n,o=new URL(`${X(s,e,t)}/rest/api/2/project/${r}/components`);return{data:(await s.request({url:o.toString(),headers:b(e.token||s.token)})).body}};var Re="https://api.atlassian.com/ex/jira",Ut=100,le=class extends x{constructor(){super(...arguments);this._resourceUrlCache={};this._issueFieldsCache={}}async getIssueFieldsForResource(e,t={}){if(!this._issueFieldsCache[e.resourceId]){let r=await Fe(this.config,e,t);this._issueFieldsCache[e.resourceId]=r.reduce((o,i)=>({...o,[i.name]:i.id}),{})}return this._issueFieldsCache[e.resourceId]??null}async getResourceUrl(e,t={}){let r=t.token||this.config.token;if(!r)return null;let o=this._resourceUrlCache[r];return o?o[e.resourceId]??null:(await this.getJiraResourcesForCurrentUser(t),this._resourceUrlCache[r]?.[e.resourceId]??null)}async getCurrentUserForResource(e,t={}){let r=await this.getResourceUrl({resourceId:e.resourceId},t),o=await this.config.request({url:`${t.baseUrl||Re}/${e.resourceId}/rest/api/2/myself`,headers:b(t.token||this.config.token)});return{data:{name:o.body.displayName,email:o.body.emailAddress,avatarUrl:o.body.avatarUrls["48x48"],id:o.body.accountId,username:o.body.displayName,url:r?`${r}/jira/people/${o.body.accountId}`:null}}}async getJiraResourcesForCurrentUser(e={}){let t=await this.config.request({url:`${e.baseUrl||"https://api.atlassian.com/"}/oauth/token/accessible-resources`,headers:b(e.token||this.config.token)}),r=e.token||this.config.token,o=r?this._resourceUrlCache[r]||{}:void 0,i=t.body.map(a=>(o&&(o[a.id]=a.url),{avatarUrl:a.avatarUrl,id:a.id,name:a.name,url:a.url}));return r&&(this._resourceUrlCache[r]=o),{data:i}}async getJiraProjectsForResource(e,t={}){let r=new URL(`${t.baseUrl||Re}/${e.resourceId}/rest/api/2/project/search`);r.searchParams.set("maxResults",Ut.toString()),e.cursor&&r.searchParams.set("startAt",e.cursor);let o=await this.config.request({url:r.toString(),headers:b(t.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(i=>({id:i.id,key:i.key,name:i.name,resourceId:e.resourceId}))}}async getJiraProjectsForResources(e,t={}){let r=[];return await Promise.all(e.resourceIds.map(async o=>{try{return await jt(i=>this.getJiraProjectsForResource({resourceId:o,cursor:i},t))}catch{return[]}})).then((...o)=>{o.forEach(i=>{r=r.concat(...i)})}),{data:r}}async getAccountsForJiraProject(e,t={}){let{resourceId:r,projectKey:o,cursor:i}=e,a=await this.getResourceUrl({resourceId:r},t),u=new URL(`${t.baseUrl||Re}/${r}/rest/api/2/user/assignable/search`);u.searchParams.set("maxResults",Ut.toString()),i&&u.searchParams.set("startAt",i),u.searchParams.set("project",o);let l=await this.config.request({url:u.toString(),headers:b(t.token||this.config.token)});return{pageInfo:{hasNextPage:l.body.length!==0,endCursor:((i?parseInt(i):0)+l.body.length).toString()},data:l.body.filter(p=>p.accountType!=="app"&&p.active).map(p=>_e(p,a,!1))}}async getComponentsForJiraProject(e,t={}){return await Je(this.config,e,t)}async getIssue(e,t={}){let r=await this.getIssueFieldsForResource({resourceId:e.resourceId},t),o=await this.getResourceUrl({resourceId:e.resourceId},t);return await Qe(this.config,{...e,fields:r},o,t)}async getIssuesForProject(e,t={}){let r=await this.getIssueFieldsForResource({resourceId:e.resourceId},t),o=await this.getResourceUrl({resourceId:e.resourceId},t);return await Be(this.config,{...e,fields:r},o,t)}async getIssuesForProjects(e,t={}){let r=await this.getIssueFieldsForResource({resourceId:e.resourceId},t),o=await this.getResourceUrl({resourceId:e.resourceId},t);return await Me(this.config,{...e,fields:r},o,t)}async getIssuesForResourceForCurrentUser(e,t={}){let r=await this.getIssueFieldsForResource({resourceId:e.resourceId},t),o=await this.getResourceUrl({resourceId:e.resourceId},t);return await je(this.config,{...e,fields:r},o,t)}async setIssueStatus(e,t={}){await We(this.config,e,t)}async setIssueAssignee(e,t={}){let{issue:r,assignee:o}=e;if(!r.project)throw new Error('Jira Cloud requires a "project" for this function.');if(!r.project.resourceId)throw new Error('Jira Cloud requires a project "resourceId" for this function.');let i={accountId:o?.id};await this.config.request({method:"PUT",url:`${t.baseUrl||Re}/${r.project.resourceId}/rest/api/2/issue/${r.id}/assignee`,body:JSON.stringify(i),headers:{...b(t.token||this.config.token),"Content-Type":"application/json"}})}async setIssueComponents(e,t={}){await He(this.config,e,t)}async setIssueLabels(e,t={}){await ze(this.config,e,t)}async getLabelsForResource(e,t={}){let{resourceId:r,cursor:o}=e,i=new URL(`${t.baseUrl||Re}/${r}/rest/api/2/label`);i.searchParams.set("maxResults",Ut.toString()),o&&i.searchParams.set("startAt",o);let a=await this.config.request({url:i.toString(),headers:b(t.token||this.config.token)});return{pageInfo:{hasNextPage:!a.body.isLast,endCursor:(a.body.startAt+a.body.values.length).toString()},data:a.body.values.map(u=>({color:null,description:null,id:null,name:u}))}}};var pe=class extends T{constructor(){super(...arguments);this._issueFieldsCache={}}async getIssueFieldsForResource(e={}){let t=e?.baseUrl||this.config.baseUrl||"";if(!this._issueFieldsCache[t]){let r=await Fe(this.config,{},e);this._issueFieldsCache[t]=r.reduce((o,i)=>({...o,[i.name]:i.id}),{})}return this._issueFieldsCache[t]??null}async getCurrentUser(e={}){let t=await this.config.request({url:`${e?.baseUrl||this.config.baseUrl}/rest/api/2/myself`,headers:b(e?.token||this.config.token)});return{data:{name:t.body.displayName,email:t.body.emailAddress,avatarUrl:t.body.avatarUrls["48x48"],id:t.body.key,username:t.body.displayName,url:null}}}async getJiraProjects(e={}){return{data:(await this.config.request({url:`${e?.baseUrl||this.config.baseUrl}/rest/api/2/project`,headers:b(e?.token||this.config.token)})).body.map(r=>({id:r.id,name:r.name}))}}async getIssue(e,t={}){let r=e.resourceUrl||t.baseUrl||this.config.baseUrl;if(!r)throw new Error('Jira Server requires a "resourceUrl" or "baseUrl" for this function.');let o=await this.getIssueFieldsForResource(t);return await Qe(this.config,{...e,fields:o},r,t)}async getIssuesForProject(e,t={}){let r=e.resourceUrl||t.baseUrl||this.config.baseUrl;if(!r)throw new Error('Jira Server requires a "resourceUrl" or "baseUrl" for this function.');let o=await this.getIssueFieldsForResource(t);return await Be(this.config,{...e,fields:o},r,t)}async getIssuesForProjects(e,t={}){let r=e.resourceUrl||t.baseUrl||this.config.baseUrl;if(!r)throw new Error('Jira Server requires a "resourceUrl" or "baseUrl" for this function.');let o=await this.getIssueFieldsForResource(t);return await Me(this.config,{...e,fields:o},r,t)}async getIssuesForResourceForCurrentUser(e,t={}){let r=e.resourceUrl||t.baseUrl||this.config.baseUrl;if(!r)throw new Error('Jira Server requires a "resourceUrl" or "baseUrl" for this function.');let o=await this.getIssueFieldsForResource(t);return await je(this.config,{...e,fields:o},r,t)}async setIssueStatus(e,t={}){await We(this.config,e,t)}async setIssueLabels(e,t={}){await ze(this.config,e,t)}async setIssueComponents(e,t={}){await He(this.config,e,t)}async getLabels(e={}){return{data:(await this.config.request({url:`${e?.baseUrl||this.config.baseUrl}/rest/api/2/jql/autocompletedata/suggestions?fieldName=labels`,headers:b(e.token||this.config.token)})).body.results.map(({displayName:r})=>({color:null,description:null,id:null,name:r}))}}async getComponentsForJiraProject(e,t={}){return await Je(this.config,e,t)}};var j="https://api.trello.com",nn=1e3,B=(s,n)=>({...b(n),Authorization:`OAuth oauth_consumer_key="${s}", oauth_token="${n}"`}),on=s=>({id:s.id,username:s.username,url:s.url,name:s.fullName,email:s.email,avatarUrl:s.avatarUrl}),an=(s,n)=>{let e=new Date(1e3*parseInt(s.id.substring(0,8),16));return{id:s.id,commentCount:s.badges.comments,number:s.idShort.toString(),title:s.name,url:s.url,closedDate:null,createdDate:new Date(e.toISOString()),author:null,updatedDate:new Date(s.dateLastActivity),assignees:s.members.map(t=>({id:t.id,username:t.username,name:t.fullName,email:null,avatarUrl:t.avatarUrl,url:null})),description:null,state:n[s.idList??""]?{id:s.idList,name:n[s.idList].name,color:null}:null,type:null,repository:null,upvoteCount:s.badges.votes,labels:s.labels.map(t=>({color:t.color,description:null,id:t.id,name:t.name}))}},de=class extends x{async getCurrentUser(n,e={}){let t=await this.config.request({url:`${e.baseUrl||j}/1/members/me`,headers:B(n.appKey,e.token||this.config.token)});return{data:{name:t.body.fullName,email:t.body.email,avatarUrl:t.body.avatarHash?`https://trello-members.s3.amazonaws.com/${t.body.id}/${t.body.avatarHash}/50.png`:null,id:t.body.id,username:t.body.username,url:t.body.url}}}async getBoardsForCurrentUser(n,e={}){return{data:(await this.config.request({url:`${e.baseUrl||j}/1/members/me/boards?fields=name&filter=open`,headers:B(n.appKey,e.token||this.config.token)})).body.map(r=>({id:r.id,name:r.name}))}}async getListsForTrelloBoard(n,e={}){let{appKey:t,boardId:r}=n;return{data:(await this.config.request({url:`${e.baseUrl||j}/1/boards/${r}/lists`,headers:B(t,e.token||this.config.token)})).body}}async getAccountForId(n,e={}){let{appKey:t,memberId:r}=n,o=await this.config.request({url:`${e.baseUrl||j}/1/members/${r}`,headers:B(t,e.token||this.config.token)});return{data:on(o.body)}}async getAccountsForTrelloBoard(n,e={}){let{appKey:t,boardId:r}=n;return{data:(await this.config.request({url:`${e.baseUrl||j}/1/boards/${r}/members`,headers:B(t,e.token||this.config.token)})).body.map(i=>({id:i.id,name:i.fullName,username:i.username,email:null,avatarUrl:null,url:null}))}}async getIssuesForBoard(n,e={}){let t=["-is:archived","sort:edited"],{appKey:r,boardId:o,filterText:i,assigneeLogins:a,labelNamesOrColors:u,trelloBoardListsById:l}=n||{};a&&t.push("@me"),u&&u.forEach(d=>t.push(`label:"${d}"`));let p=`${i?`${i}`:""}${t.join(" ")} board:${o}`;return{data:(await this.config.request({url:`${e.baseUrl||j}/1/search?query=${p}&cards_limit=${nn}&card_members=true`,headers:B(r,e.token||this.config.token)})).body.cards.map(d=>an(d,l||{}))}}async updateIssue(n,e,t,r){return await this.config.request({method:"PUT",url:`${r.baseUrl||j}/1/cards/${e.id}?${t}`,headers:B(n,r.token||this.config.token)})}async setIssueStatus(n,e={}){let{appKey:t,issue:r,status:o}=n;if(!o.id)throw new Error('Trello requires a status "id" for this function.');let i=`idList=${o.id}`;if(!(await this.updateIssue(t,r,i,e)).body.id)throw new Error("Could not set issue status")}async setIssueAssignees(n,e={}){let{appKey:t,issue:r,assignees:o}=n,i=o.map(l=>l.id),a=`idMembers=${encodeURIComponent(i.join(","))}`;if(!(await this.updateIssue(t,r,a,e)).body.id)throw new Error("Could not set issue status")}async setIssueLabels(n,e={}){let{appKey:t,issue:r,labels:o}=n,i=o.map(u=>u.id).join(",");if(!(await this.config.request({method:"PUT",url:`${e.baseUrl||j}/1/cards/${r.id}?idLabels=${encodeURIComponent(i)}`,headers:B(t,e.token||this.config.token)})).body.id)throw new Error("Could not set issue status")}async setIssueArchived(n,e={}){let{appKey:t,issue:r,archived:o}=n;if(!(await this.config.request({method:"PUT",url:`${e.baseUrl||j}/1/cards/${r.id}?closed=${o}`,headers:B(t,e.token||this.config.token)})).body.id)throw new Error("Could not update issue archived status")}async archiveIssue(n,e={}){await this.setIssueArchived({...n,archived:!0},e)}async unArchiveIssue(n,e={}){await this.setIssueArchived({...n,archived:!1},e)}async getLabelsForBoard(n,e={}){let{appKey:t,boardId:r}=n;return{data:(await this.config.request({url:`${e.baseUrl||j}/1/boards/${r}/labels`,headers:B(t,e.token||this.config.token)})).body.map(i=>({color:i.color,description:null,id:i.id,name:i.name}))}}};var Gt=100,Ve=class{constructor(){this.set=new Set;this.arr=[]}push(...n){let e=n.filter(t=>!this.set.has(t.id));this.arr.push(...e),e.forEach(t=>this.set.add(t.id))}get length(){return this.arr.length}get items(){return this.arr}},W=async(s,n,e,t)=>{let r=n.token||s.token;if(!r)throw new Error("Linear API key is required");let o=await s.request({url:"https://api.linear.app/graphql",method:"POST",headers:{Authorization:r,"Content-Type":"application/json"},body:JSON.stringify({query:e,variables:t})});if(o.status>=400)throw new Error(`Linear API request failed: ${o.status} ${o.statusText}`);let i=o.body;if(i.errors)throw new Error(`Linear GraphQL errors: ${i.errors.map(a=>a.message).join(", ")}`);return i.data},At=s=>s?s instanceof Date?s:new Date(s):null,un=`
1336
1336
  id
1337
1337
  name
1338
1338
  description
@@ -1340,11 +1340,11 @@ OR comment ~ currentUser() OR summary ~ currentUser() OR description ~ currentUs
1340
1340
  startDate
1341
1341
  targetDate
1342
1342
  url
1343
- `,cr=r=>({id:r.id,name:r.name,description:r.description??null,state:r.state,startDate:qt(r.startDate),targetDate:qt(r.targetDate),url:r.url}),gr=async(r,n,e)=>{let t=`
1343
+ `,yr=s=>({id:s.id,name:s.name,description:s.description??null,state:s.state,startDate:At(s.startDate),targetDate:At(s.targetDate),url:s.url}),Pr=async(s,n,e)=>{let t=`
1344
1344
  query GetProjects($first: Int!, $after: String) {
1345
1345
  projects(first: $first, after: $after) {
1346
1346
  nodes {
1347
- ${en}
1347
+ ${un}
1348
1348
  }
1349
1349
  pageInfo {
1350
1350
  hasNextPage
@@ -1352,7 +1352,7 @@ OR comment ~ currentUser() OR summary ~ currentUser() OR description ~ currentUs
1352
1352
  }
1353
1353
  }
1354
1354
  }
1355
- `;return(await z(r,n,t,{first:Et,after:e})).projects},tn=`
1355
+ `;return(await W(s,n,t,{first:Gt,after:e})).projects},ln=`
1356
1356
  id
1357
1357
  name
1358
1358
  number
@@ -1360,11 +1360,11 @@ OR comment ~ currentUser() OR summary ~ currentUser() OR description ~ currentUs
1360
1360
  startsAt
1361
1361
  endsAt
1362
1362
  completedAt
1363
- `,mr=r=>({id:r.id,name:r.name??`Cycle ${r.number}`,number:r.number,description:r.description??null,startsAt:new Date(r.startsAt),endsAt:new Date(r.endsAt),completedAt:qt(r.completedAt),url:""}),hr=async(r,n,e)=>{let t=`
1363
+ `,wr=s=>({id:s.id,name:s.name??`Cycle ${s.number}`,number:s.number,description:s.description??null,startsAt:new Date(s.startsAt),endsAt:new Date(s.endsAt),completedAt:At(s.completedAt),url:""}),vr=async(s,n,e)=>{let t=`
1364
1364
  query GetCycles($first: Int!, $after: String) {
1365
1365
  cycles(first: $first, after: $after) {
1366
1366
  nodes {
1367
- ${tn}
1367
+ ${ln}
1368
1368
  }
1369
1369
  pageInfo {
1370
1370
  hasNextPage
@@ -1372,16 +1372,16 @@ OR comment ~ currentUser() OR summary ~ currentUser() OR description ~ currentUs
1372
1372
  }
1373
1373
  }
1374
1374
  }
1375
- `;return(await z(r,n,t,{first:Et,after:e})).cycles},rn=`
1375
+ `;return(await W(s,n,t,{first:Gt,after:e})).cycles},pn=`
1376
1376
  id
1377
1377
  name
1378
1378
  color
1379
1379
  description
1380
- `,fr=r=>({id:r.id,name:r.name,color:r.color,description:r.description??null}),Rr=async(r,n,e)=>{let t=`
1380
+ `,qr=s=>({id:s.id,name:s.name,color:s.color,description:s.description??null}),Sr=async(s,n,e)=>{let t=`
1381
1381
  query GetLabels($first: Int!, $after: String) {
1382
1382
  projectLabels(first: $first, after: $after) {
1383
1383
  nodes {
1384
- ${rn}
1384
+ ${pn}
1385
1385
  }
1386
1386
  pageInfo {
1387
1387
  hasNextPage
@@ -1389,36 +1389,36 @@ OR comment ~ currentUser() OR summary ~ currentUser() OR description ~ currentUs
1389
1389
  }
1390
1390
  }
1391
1391
  }
1392
- `;return(await z(r,n,t,{first:Et,after:e})).projectLabels};var fe=(i=>(i[i.None=0]="None",i[i.Assignee=1]="Assignee",i[i.Creator=2]="Creator",i[i.Mention=3]="Mention",i[i.MentionInDescription=4]="MentionInDescription",i[i.MentionInComments=5]="MentionInComments",i))(fe||{});function Ir(r,n){return r?`${fe[r]}:${n||""}`:n??null}function br(r){if(!r)return{category:0};let[n,e]=r.split(":");return n in fe?{category:fe[n],cursor:e||void 0}:{category:0,cursor:r}}var yr=100;function He(r){return r?r instanceof Date?r:new Date(r):null}var vr=`
1392
+ `;return(await W(s,n,t,{first:Gt,after:e})).projectLabels};var Ie=(i=>(i[i.None=0]="None",i[i.Assignee=1]="Assignee",i[i.Creator=2]="Creator",i[i.Mention=3]="Mention",i[i.MentionInDescription=4]="MentionInDescription",i[i.MentionInComments=5]="MentionInComments",i))(Ie||{});function Er(s,n){return s?`${Ie[s]}:${n||""}`:n??null}function Cr(s){if(!s)return{category:0};let[n,e]=s.split(":");return n in Ie?{category:Ie[n],cursor:e||void 0}:{category:0,cursor:s}}var Dr=100;function Xe(s){return s?s instanceof Date?s:new Date(s):null}var Ur=`
1393
1393
  id
1394
1394
  name
1395
1395
  key
1396
1396
  icon
1397
- `;function sn(r){return{id:r.id,name:r.name,key:r.key,iconUrl:r.icon}}var Pr=`
1397
+ `;function dn(s){return{id:s.id,name:s.name,key:s.key,iconUrl:s.icon}}var Lr=`
1398
1398
  id
1399
1399
  name
1400
1400
  avatarUrl
1401
- `;function wr(r){return r?{id:r.id,name:r.name,username:r.name,email:null,avatarUrl:r.avatarUrl??null,url:null}:null}var nn=`
1401
+ `;function $r(s){return s?{id:s.id,name:s.name,username:s.name,email:null,avatarUrl:s.avatarUrl??null,url:null}:null}var cn=`
1402
1402
  id
1403
1403
  name
1404
- `;function on(r,n){if(r)return{id:r.id,name:r.name,key:n?.key||null,namespace:null,resourceId:n?.id||null}}var an=`
1404
+ `;function mn(s,n){if(s)return{id:s.id,name:s.name,key:n?.key||null,namespace:null,resourceId:n?.id||null}}var gn=`
1405
1405
  id
1406
1406
  sortOrder
1407
1407
  name
1408
1408
  description
1409
1409
  status
1410
1410
  targetDate
1411
- `;function un(r){return r?{id:r.id,number:r.sortOrder,title:r.name,description:r.description??null,isOpen:r.status!=="done",url:"",startDate:null,dueDate:He(r.targetDate)}:null}function ln(r){switch(r){case"completed":case"canceled":return"DONE";case"started":return"IN_PROGRESS";default:return"TO_DO"}}var pn=`
1411
+ `;function hn(s){return s?{id:s.id,number:s.sortOrder,title:s.name,description:s.description??null,isOpen:s.status!=="done",url:"",startDate:null,dueDate:Xe(s.targetDate)}:null}function fn(s){switch(s){case"completed":case"canceled":return"DONE";case"started":return"IN_PROGRESS";default:return"TO_DO"}}var Rn=`
1412
1412
  id
1413
1413
  name
1414
1414
  color
1415
1415
  type
1416
- `;function dn(r){return r?{id:r.id,name:r.name,color:r.color,category:ln(r.type)}:null}var Dt=`
1416
+ `;function In(s){return s?{id:s.id,name:s.name,color:s.color,category:fn(s.type)}:null}var Ot=`
1417
1417
  creator {
1418
- ${Pr}
1418
+ ${Lr}
1419
1419
  }
1420
1420
  assignee {
1421
- ${Pr}
1421
+ ${Lr}
1422
1422
  }
1423
1423
  archivedAt
1424
1424
  createdAt
@@ -1426,35 +1426,35 @@ OR comment ~ currentUser() OR summary ~ currentUser() OR description ~ currentUs
1426
1426
  id
1427
1427
  identifier
1428
1428
  project {
1429
- ${nn}
1429
+ ${cn}
1430
1430
  }
1431
1431
  team {
1432
- ${vr}
1432
+ ${Ur}
1433
1433
  }
1434
1434
  state {
1435
- ${pn}
1435
+ ${Rn}
1436
1436
  }
1437
1437
  title
1438
1438
  updatedAt
1439
1439
  url
1440
1440
  projectMilestone {
1441
- ${an}
1441
+ ${gn}
1442
1442
  }
1443
- `;async function Ct(r){return{author:wr(await r.creator),assignees:[wr(await r.assignee)].filter(n=>n!=null),commentCount:null,closedDate:He(r.archivedAt),createdDate:He(r.createdAt),description:r.description??null,id:r.id,labels:[],number:r.identifier,repository:null,project:on(await r.project,await r.team),state:dn(await r.state),title:r.title,type:null,updatedDate:He(r.updatedAt),upvoteCount:null,url:r.url,milestone:un(await r.projectMilestone)}}var ze=`
1443
+ `;async function Tt(s){return{author:$r(await s.creator),assignees:[$r(await s.assignee)].filter(n=>n!=null),commentCount:null,closedDate:Xe(s.archivedAt),createdDate:Xe(s.createdAt),description:s.description??null,id:s.id,labels:[],number:s.identifier,repository:null,project:mn(await s.project,await s.team),state:In(await s.state),title:s.title,type:null,updatedDate:Xe(s.updatedAt),upvoteCount:null,url:s.url,milestone:hn(await s.projectMilestone)}}var Ke=`
1444
1444
  nodes {
1445
- ${Dt}
1445
+ ${Ot}
1446
1446
  }
1447
1447
  pageInfo {
1448
1448
  hasNextPage
1449
1449
  endCursor
1450
1450
  }
1451
- `,We=class extends T{async fetchIssue(n,e){let t=`
1451
+ `,Ze=class extends x{async fetchIssue(n,e){let t=`
1452
1452
  query GetIssue($identifier: String!) {
1453
1453
  issue(id: $identifier) {
1454
- ${Dt}
1454
+ ${Ot}
1455
1455
  }
1456
1456
  }
1457
- `;return(await z(this.config,e,t,{identifier:n})).issue}async fetchOrganization(n){let e=`
1457
+ `;return(await W(this.config,e,t,{identifier:n})).issue}async fetchOrganization(n){let e=`
1458
1458
  query GetOrganization {
1459
1459
  organization {
1460
1460
  id
@@ -1462,15 +1462,15 @@ OR comment ~ currentUser() OR summary ~ currentUser() OR description ~ currentUs
1462
1462
  urlKey
1463
1463
  }
1464
1464
  }
1465
- `;return(await z(this.config,n,e)).organization}async fetchTeams(n){let e=`
1465
+ `;return(await W(this.config,n,e)).organization}async fetchTeams(n){let e=`
1466
1466
  query GetTeams {
1467
1467
  teams {
1468
1468
  nodes {
1469
- ${vr}
1469
+ ${Ur}
1470
1470
  }
1471
1471
  }
1472
1472
  }
1473
- `;return(await z(this.config,n,e)).teams}async rawRequest(n,e,t){return{data:await z(this.config,n,e,t)}}async fetchViewer(n){let e=`
1473
+ `;return(await W(this.config,n,e)).teams}async rawRequest(n,e,t){return{data:await W(this.config,n,e,t)}}async fetchViewer(n){let e=`
1474
1474
  query GetViewer {
1475
1475
  viewer {
1476
1476
  id
@@ -1479,23 +1479,23 @@ OR comment ~ currentUser() OR summary ~ currentUser() OR description ~ currentUs
1479
1479
  displayName
1480
1480
  }
1481
1481
  }
1482
- `;return(await z(this.config,n,e)).viewer}async getIssue(n,e={}){let t=await this.fetchIssue(n.number,e);return{data:await Ct(t)}}async getLinearOrganization(n={}){let e=await this.fetchOrganization(n);return{data:{id:e.id,name:e.name,key:e.urlKey,url:`https://linear.app/${e.urlKey}`}}}async getTeamsForCurrentUser(n={}){return{data:(await this.fetchTeams(n)).nodes.map(sn)}}async getProjects(n={},e={}){let t=await gr(this.config,e,n.cursor??void 0);return{data:t.nodes.map(cr),pageInfo:{hasNextPage:t.pageInfo.hasNextPage,endCursor:t.pageInfo.endCursor??null}}}async getCycles(n={},e={}){let t=await hr(this.config,e,n.cursor??void 0);return{data:t.nodes.map(mr),pageInfo:{hasNextPage:t.pageInfo.hasNextPage,endCursor:t.pageInfo.endCursor??null}}}async getLabels(n={},e={}){let t=await Rr(this.config,e,n.cursor??void 0);return{data:t.nodes.map(fr),pageInfo:{hasNextPage:t.pageInfo.hasNextPage,endCursor:t.pageInfo.endCursor??null}}}async getCurrentUser(n={}){return{data:await this.fetchViewer(n)}}async getIssuesForCurrentUser(n,e={}){let{cursor:t}=n,{category:s,cursor:o}=br(t),i=await this.fetchViewer(e),a,u,p=new Me,d=async(c,l)=>{if(u||s>c)return;let g=await l(Math.max(yr-p.length,1),s===c?o:void 0);if(!g)return;let m=await Ze(g.nodes.map(Ct));p.push(...m),g.pageInfo.hasNextPage&&(a=c,u=g.pageInfo.endCursor)};return await d(1,async(c,l)=>(await this.rawRequest(e,`
1482
+ `;return(await W(this.config,n,e)).viewer}async getIssue(n,e={}){let t=await this.fetchIssue(n.number,e);return{data:await Tt(t)}}async getLinearOrganization(n={}){let e=await this.fetchOrganization(n);return{data:{id:e.id,name:e.name,key:e.urlKey,url:`https://linear.app/${e.urlKey}`}}}async getTeamsForCurrentUser(n={}){return{data:(await this.fetchTeams(n)).nodes.map(dn)}}async getProjects(n={},e={}){let t=await Pr(this.config,e,n.cursor??void 0);return{data:t.nodes.map(yr),pageInfo:{hasNextPage:t.pageInfo.hasNextPage,endCursor:t.pageInfo.endCursor??null}}}async getCycles(n={},e={}){let t=await vr(this.config,e,n.cursor??void 0);return{data:t.nodes.map(wr),pageInfo:{hasNextPage:t.pageInfo.hasNextPage,endCursor:t.pageInfo.endCursor??null}}}async getLabels(n={},e={}){let t=await Sr(this.config,e,n.cursor??void 0);return{data:t.nodes.map(qr),pageInfo:{hasNextPage:t.pageInfo.hasNextPage,endCursor:t.pageInfo.endCursor??null}}}async getCurrentUser(n={}){return{data:await this.fetchViewer(n)}}async getIssuesForCurrentUser(n,e={}){let{cursor:t}=n,{category:r,cursor:o}=Cr(t),i=await this.fetchViewer(e),a,u,l=new Ve,p=async(c,d)=>{if(u||r>c)return;let m=await d(Math.max(Dr-l.length,1),r===c?o:void 0);if(!m)return;let g=await st(m.nodes.map(Tt));l.push(...g),m.pageInfo.hasNextPage&&(a=c,u=m.pageInfo.endCursor)};return await p(1,async(c,d)=>(await this.rawRequest(e,`
1483
1483
  query GetAssignedIssues($first: Int!, $after: String) {
1484
1484
  viewer {
1485
1485
  issues: assignedIssues(first: $first, after: $after) {
1486
- ${ze}
1486
+ ${Ke}
1487
1487
  }
1488
1488
  }
1489
1489
  }
1490
- `,{first:c,after:l})).data?.viewer?.issues),await d(2,async(c,l)=>(await this.rawRequest(e,`
1490
+ `,{first:c,after:d})).data?.viewer?.issues),await p(2,async(c,d)=>(await this.rawRequest(e,`
1491
1491
  query GetCreatedIssues($first: Int!, $after: String) {
1492
1492
  viewer {
1493
1493
  issues: createdIssues(first: $first, after: $after) {
1494
- ${ze}
1494
+ ${Ke}
1495
1495
  }
1496
1496
  }
1497
1497
  }
1498
- `,{first:c,after:l})).data?.viewer?.issues),await d(4,async(c,l)=>(await this.rawRequest(e,`
1498
+ `,{first:c,after:d})).data?.viewer?.issues),await p(4,async(c,d)=>(await this.rawRequest(e,`
1499
1499
  query GetMentionedIssues($first: Int!, $after: String) {
1500
1500
  issues(
1501
1501
  first: $first
@@ -1516,10 +1516,10 @@ OR comment ~ currentUser() OR summary ~ currentUser() OR description ~ currentUs
1516
1516
  }]
1517
1517
  }
1518
1518
  ){
1519
- ${ze}
1519
+ ${Ke}
1520
1520
  }
1521
1521
  }
1522
- `,{first:c,after:l})).data?.issues),await d(5,async(c,l)=>{let m=(await this.rawRequest(e,`
1522
+ `,{first:c,after:d})).data?.issues),await p(5,async(c,d)=>{let g=(await this.rawRequest(e,`
1523
1523
  query GetCommentedIssues($first: Int!, $after: String) {
1524
1524
  comments(
1525
1525
  first: $first
@@ -1542,7 +1542,7 @@ OR comment ~ currentUser() OR summary ~ currentUser() OR description ~ currentUs
1542
1542
  ){
1543
1543
  nodes {
1544
1544
  issue {
1545
- ${Dt}
1545
+ ${Ot}
1546
1546
  }
1547
1547
  }
1548
1548
  pageInfo {
@@ -1551,10 +1551,10 @@ OR comment ~ currentUser() OR summary ~ currentUser() OR description ~ currentUs
1551
1551
  }
1552
1552
  }
1553
1553
  }
1554
- `,{first:c,after:l})).data?.comments;return m?{nodes:m.nodes.map(R=>R.issue),pageInfo:m.pageInfo}:void 0}),{data:p.items,pageInfo:{hasNextPage:!!u,endCursor:Ir(a,u)}}}async getIssues(n,e={}){let{teams:t,projects:s,labels:o,cursor:i}=n,a=[];if(t&&t.length>0){let g=t.map(m=>`"${m}"`).join(", ");a.push(`team: { id: { in: [${g}] } }`)}if(s&&s.length>0){let g=s.map(m=>`"${m}"`).join(", ");a.push(`project: { id: { in: [${g}] } }`)}if(o&&o.length>0){let g=o.map(m=>`"${m}"`).join(", ");a.push(`labels: { name: { in: [${g}] } }`)}let u=a.length>0?`filter: { ${a.join(", ")} }`:"",p=`
1554
+ `,{first:c,after:d})).data?.comments;return g?{nodes:g.nodes.map(I=>I.issue),pageInfo:g.pageInfo}:void 0}),{data:l.items,pageInfo:{hasNextPage:!!u,endCursor:Er(a,u)}}}async getIssues(n,e={}){let{teams:t,projects:r,labels:o,cursor:i}=n,a=[];if(t&&t.length>0){let m=t.map(g=>`"${g}"`).join(", ");a.push(`team: { id: { in: [${m}] } }`)}if(r&&r.length>0){let m=r.map(g=>`"${g}"`).join(", ");a.push(`project: { id: { in: [${m}] } }`)}if(o&&o.length>0){let m=o.map(g=>`"${g}"`).join(", ");a.push(`labels: { name: { in: [${m}] } }`)}let u=a.length>0?`filter: { ${a.join(", ")} }`:"",l=`
1555
1555
  query GetIssues($first: Int!, $after: String) {
1556
1556
  issues(first: $first, after: $after${u?", ":""}${u}) {
1557
- ${ze}
1557
+ ${Ke}
1558
1558
  }
1559
1559
  }
1560
- `,c=(await this.rawRequest(e,p,{first:yr,after:i})).data?.issues;return c?{data:await Ze(c.nodes.map(Ct)),pageInfo:{hasNextPage:c.pageInfo.hasNextPage,endCursor:c.pageInfo.endCursor??null}}:{data:[],pageInfo:{hasNextPage:!1,endCursor:null}}}};var Sr=r=>{let n={request:r?.request};return{azureDevOps:new se({...n,...r?.azureDevOps}),bitbucket:new ne({...n,...r?.bitbucket}),bitbucketServer:new oe({...n,...r?.bitbucketServer}),github:new ie({...n,...r?.github}),gitlab:new ue({...n,...r?.gitlab}),jira:new le({...n,...r?.jira}),jiraServer:new pe({...n,...r?.jiraServer}),linear:new We({...n,...r?.linear}),trello:new de({...n,...r?.trello})}};var qr=(i=>(i.Conflicts="conflicts",i.Failure="failure",i.NotSet="notSet",i.Queued="queued",i.RejectedByPolicy="rejectedByPolicy",i.Succeeded="succeeded",i))(qr||{});var Er=(e=>(e.Zero="0",e.One="1",e))(Er||{}),Cr=(e=>(e.PullRequest="pr",e.Issue="issue",e))(Cr||{}),Dr=(l=>(l.Azure="azure",l.AzureDevOpsServer="azureDevOpsServer",l.Github="github",l.GithubEnterprise="githubEnterprise",l.Gitlab="gitlab",l.GitlabSelfHosted="gitlabSelfHosted",l.Bitbucket="bitbucket",l.BitbucketServer="bitbucketServer",l.Jira="jira",l.JiraServer="jiraServer",l.Linear="linear",l.Trello="trello",l))(Dr||{});var Lr=(e=>(e.Completed="COMPLETED",e.NotPlanned="NOT_PLANNED",e))(Lr||{});var cn=Sr;
1560
+ `,c=(await this.rawRequest(e,l,{first:Dr,after:i})).data?.issues;return c?{data:await st(c.nodes.map(Tt)),pageInfo:{hasNextPage:c.pageInfo.hasNextPage,endCursor:c.pageInfo.endCursor??null}}:{data:[],pageInfo:{hasNextPage:!1,endCursor:null}}}};var Ar=s=>{let n={request:s?.request};return{azureDevOps:new se({...n,...s?.azureDevOps}),bitbucket:new ne({...n,...s?.bitbucket}),bitbucketServer:new oe({...n,...s?.bitbucketServer}),github:new ie({...n,...s?.github}),gitlab:new ue({...n,...s?.gitlab}),jira:new le({...n,...s?.jira}),jiraServer:new pe({...n,...s?.jiraServer}),linear:new Ze({...n,...s?.linear}),trello:new de({...n,...s?.trello})}};var Gr=(i=>(i.Conflicts="conflicts",i.Failure="failure",i.NotSet="notSet",i.Queued="queued",i.RejectedByPolicy="rejectedByPolicy",i.Succeeded="succeeded",i))(Gr||{});var Tr=(e=>(e.Zero="0",e.One="1",e))(Tr||{}),Or=(e=>(e.PullRequest="pr",e.Issue="issue",e))(Or||{}),xr=(d=>(d.Azure="azure",d.AzureDevOpsServer="azureDevOpsServer",d.Github="github",d.GithubEnterprise="githubEnterprise",d.Gitlab="gitlab",d.GitlabSelfHosted="gitlabSelfHosted",d.Bitbucket="bitbucket",d.BitbucketServer="bitbucketServer",d.Jira="jira",d.JiraServer="jiraServer",d.Linear="linear",d.Trello="trello",d))(xr||{});var kr=(e=>(e.Completed="COMPLETED",e.NotPlanned="NOT_PLANNED",e))(kr||{});var bn=Ar;