@gitkraken/provider-apis 0.24.3 → 0.25.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- "use strict";var Pr=Object.create;var pe=Object.defineProperty;var Er=Object.getOwnPropertyDescriptor;var vr=Object.getOwnPropertyNames;var qr=Object.getPrototypeOf,Sr=Object.prototype.hasOwnProperty;var k=(s,e)=>{for(var t in e)pe(s,t,{get:e[t],enumerable:!0})},Qt=(s,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of vr(e))!Sr.call(s,n)&&n!==t&&pe(s,n,{get:()=>e[n],enumerable:!(r=Er(e,n))||r.enumerable});return s};var Cr=(s,e,t)=>(t=s!=null?Pr(qr(s)):{},Qt(e||!s||!s.__esModule?pe(t,"default",{value:s,enumerable:!0}):t,s)),Dr=s=>Qt(pe({},"__esModule",{value:!0}),s);var Fs={};k(Fs,{AzureDevOps:()=>ee,AzureDevopsUtils:()=>Te,Bitbucket:()=>te,BitbucketServer:()=>se,BitbucketServerUtils:()=>xe,BitbucketUtils:()=>Oe,EntityIdentifierProviderType:()=>U,EntityIdentifierUtils:()=>Je,EntityType:()=>L,EntityVersion:()=>D,GitBuildStatusStage:()=>Bt,GitBuildStatusState:()=>Z,GitDiffLineType:()=>et,GitHub:()=>ne,GitHubIssueCloseReason:()=>wr,GitHubUtils:()=>Ke,GitIssueState:()=>me,GitLab:()=>oe,GitLabUtils:()=>Xe,GitMergeStrategy:()=>K,GitProviderUtils:()=>Ve,GitPullRequestMergeableState:()=>Q,GitPullRequestReviewState:()=>_,GitPullRequestState:()=>W,Jira:()=>ae,JiraServer:()=>ue,JiraUtils:()=>Ye,PullRequestAsyncStatus:()=>br,Trello:()=>le,TrelloUtils:()=>Ze,Utils:()=>js,default:()=>Bs,isFetch:()=>de});module.exports=Dr(Fs);var Bt=(n=>(n.Build="build",n.Production="production",n.Staging="staging",n.Test="test",n))(Bt||{}),Z=(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))(Z||{}),K=(o=>(o.MergeCommit="MERGE_COMMIT",o.Rebase="REBASE",o.RebaseThenMergeCommit="REBASE_THEN_MERGE_COMMIT",o.FastForward="FAST_FORWARD",o.Squash="SQUASH",o))(K||{}),W=(r=>(r.Open="OPEN",r.Closed="CLOSED",r.Merged="MERGED",r))(W||{}),_=(n=>(n.Approved="APPROVED",n.ChangesRequested="CHANGES_REQUESTED",n.Commented="COMMENTED",n.ReviewRequested="REVIEW_REQUESTED",n))(_||{}),Q=(a=>(a.Behind="BEHIND",a.Blocked="BLOCKED",a.Conflicts="CONFLICTS",a.Mergeable="MERGEABLE",a.Unknown="UNKNOWN",a.UnknownAndBlocked="UNKNOWN_AND_BLOCKED",a.Unstable="UNSTABLE",a))(Q||{}),et=(r=>(r.ADDED="ADDED",r.DELETED="DELETED",r.UNMODIFIED="UNMODIFIED",r))(et||{});var jt={APPROVED:0,COMMENTED:1,REVIEW_REQUESTED:2,CHANGES_REQUESTED:3},z=s=>!s||s.length===0?null:s.reduce((e,t)=>jt[t.state]>jt[e]?t.state:e,"APPROVED");var S=100;var Ft=Cr(require("node-fetch")),Mt=globalThis.fetch||Ft.default;var Lr=async s=>{let e=s.headers.get("content-type")||"",t=null;if(e.startsWith("application/json")){let n=await s.text();t=n.trim().length>0?JSON.parse(n):null}else if(e.startsWith("text/")||e==="")t=await s.text();else if(e.startsWith("application/vnd.github.raw+json"))t=await s.arrayBuffer();else throw new Error(`Unsupported content-type: ${e}`);let r={body:t,headers:Object.fromEntries(s.headers.entries()),status:s.status,statusText:s.statusText};if(!s.ok){let n=new Error(s.statusText);throw Object.assign(n,{response:r}),n}return r},tt=s=>async({url:e,...t})=>{let r=await s(e,t);return Lr(r)};var de=(s,e=!1)=>s.name==="fetch"||e;var T=class{constructor(e){let t=(e==null?void 0:e.request)||Mt;this.config={...e,request:de(t,e==null?void 0:e.forceIsFetch)?tt(t):t}}updateConfig(e){this.config={...this.config,...e,request:e.request&&de(e.request,(e==null?void 0:e.forceIsFetch)??this.config.forceIsFetch)?tt(e.request):this.config.request}}},N=class extends T{};var f=(s,e)=>{let t={};return s&&(t.Authorization=`${e?"Basic":"Bearer"} ${s}`),t},zt=s=>s?s.reduce((e,t)=>(e[t]=!0,e),{}):void 0,H=(s,e,t)=>!s||e.some(r=>s[r])?t:"",Ht=async s=>{var n,o,i;let e=[],t=!0,r;for(;t;){let a=await s(r);e=e.concat(a.data),t=!!((n=a==null?void 0:a.pageInfo)!=null&&n.hasNextPage),r=((o=a==null?void 0:a.pageInfo)==null?void 0:o.endCursor)||((i=a==null?void 0:a.pageInfo)==null?void 0:i.nextPage)}return e};var P=(s,e={})=>f(e.token||s.token,e.isPAT||s.isPAT),Wt=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/");var Jt="https://app.vssps.visualstudio.com/_apis",v="https://dev.azure.com",Ur={active:"OPEN",completed:"MERGED",abandoned:"CLOSED"},Ar={10:"APPROVED",5:"APPROVED",0:"REVIEW_REQUESTED",[-5]:"CHANGES_REQUESTED",[-10]:"CHANGES_REQUESTED"},rt=s=>({id:s.id,name:s.displayName??null,username:(s.uniqueName||s.displayName)??null,email:null,avatarUrl:s.imageUrl??null,url:null}),ge=s=>s.startsWith("refs/heads/")?s.replace("refs/heads/",""):s,ce=(s,e)=>{var n;let t=[],r=[];return e.reviewers.forEach(o=>{let i={reviewer:rt(o),state:Ar[o.vote??0]||"REVIEW_REQUESTED"};o.isRequired&&t.push(i),r.push(i)}),{id:e.pullRequestId.toString(),title:e.title,number:e.codeReviewId,state:Ur[e.status],isDraft:e.isDraft,commentCount:null,upvoteCount:null,author:rt(e.createdBy),createdDate:new Date(e.creationDate),updatedDate:new Date(e.closedDate||e.creationDate),closedDate:e.closedDate?new Date(e.closedDate):null,mergedDate:e.closedDate&&e.status==="completed"?new Date(e.closedDate):null,repository:{id:e.repository.id,name:e.repository.name,project:e.repository.project.name,owner:{login:s},remoteInfo:null},headCommit:{buildStatuses:null},baseRef:{name:ge(e.targetRefName),oid:e.lastMergeTargetCommit.commitId},headRef:{name:ge(e.sourceRefName),oid:e.lastMergeSourceCommit.commitId},url:Wt(e),assignees:e.reviewers.map(rt),reviews:r,reviewDecision:z(t),additions:null,deletions:null,fileCount:null,commitCount:null,headRepository:null,mergeableState:"UNKNOWN",labels:((n=e.labels)==null?void 0:n.map(o=>({color:null,description:null,id:o.id,name:o.name})))??[],permissions:null}},Vt=(s,e)=>({id:e.id,name:e.name,namespace:s,project:e.project.name,webUrl:e.webUrl,httpsUrl:e.remoteUrl,sshUrl:e.sshUrl,defaultBranch:e.defaultBranch?{name:ge(e.defaultBranch)}:null,permission:null}),$r=(s,e,t,r)=>{var l,p,d,c,g,m;let n=t.fields,o=n["System.AssignedTo"],i=n["System.State"],a=n["System.WorkItemType"],u;return i&&a&&(u=(l=r[a])==null?void 0:l[i]),{id:t.id.toString(),number:t.id.toString(),title:n["System.Title"],commentCount:n["System.CommentCount"],author:{avatarUrl:((d=(p=n["System.CreatedBy"]._links)==null?void 0:p.avatar)==null?void 0:d.href)??null,email:null,id:n["System.CreatedBy"].id,name:n["System.CreatedBy"].uniqueName??null,username:n["System.CreatedBy"].displayName??null,url:null},closedDate:n["Microsoft.VSTS.Common.ClosedDate"]?new Date(n["Microsoft.VSTS.Common.ClosedDate"]):null,createdDate:new Date(n["System.CreatedDate"]),updatedDate:new Date(n["System.ChangedDate"]),url:t._links.html.href,assignees:o?[{avatarUrl:((g=(c=o._links)==null?void 0:c.avatar)==null?void 0:g.href)??null,email:null,id:o.id,name:o.uniqueName??null,username:o.displayName??null,url:null}]:[],description:null,state:{name:(u==null?void 0:u.title)||i,color:null},type:n["System.WorkItemType"],repository:null,project:{namespace:s,name:e,resourceId:null,key:null,id:null},upvoteCount:0,labels:((m=t.fields["System.Tags"])==null?void 0:m.split(";").map(I=>({color:null,description:null,id:null,name:I.trim()})))??[]}},ee=class extends T{async getCurrentUser(e={},t={}){if(t.isPAT||this.config.isPAT)throw new Error("Azure DevOps does not support PATs for this function.");let r=await this.config.request({url:`${Jt}/profile/profiles/me`,headers:P(this.config,t)});return{data:{id:r.body.id,name:r.body.displayName,username:r.body.displayName,email:r.body.emailAddress,avatarUrl:null,url:null}}}async getCurrentUserForInstance(e,t={}){let n=(await this.config.request({url:`${v}/${encodeURIComponent(e.namespace)}/_apis/ConnectionData`,headers:P(this.config,t)})).body.authorizedUser;if(n.providerDisplayName==="Anonymous")throw new Error("Current user not found.");return{data:{id:n.id,name:n.providerDisplayName,username:n.providerDisplayName,email:n.properties.Account.$value,avatarUrl:null}}}async getUserForCommit(e,t={}){if(!e.repo.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let n=(await this.config.request({url:`${v}/${encodeURIComponent(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:n.name,email:n.email,avatarUrl:n.imageUrl}}}async getOrgsForUser(e,t={}){return{data:(await this.config.request({url:`${Jt}/accounts?memberId=${e.userId}&api-version=6.0`,headers:P(this.config,t)})).body.value.map(n=>({id:n.accountId,name:n.accountName}))}}async getAzureProjects(e,t={}){let r=new URL(`${v}/${encodeURIComponent(e.namespace)}/_apis/projects`);r.searchParams.set("$top",S.toString()),e.cursor&&r.searchParams.set("$skip",e.cursor);let n=await this.config.request({url:r.toString(),headers:P(this.config,t)}),o=n.headers["x-ms-continuationtoken"];return{pageInfo:{hasNextPage:!!o,endCursor:o||null},data:n.body.value.map(i=>({id:i.id,name:i.name,namespace:e.namespace}))}}async getAzureProjectScopeDescriptor(e,t={}){let{namespace:r,projectId:n}=e;return{data:{scope:(await this.config.request({url:`https://vssps.dev.azure.com/${encodeURIComponent(r)}/_apis/graph/descriptors/${n}?api-version=6.0`,headers:P(this.config,t)})).body.value}}}async getAzureGraphAccountsForAzureProject(e,t={}){let{namespace:r,projectScopeDescriptor:n,cursor:o}=e,i=new URL(`https://vssps.dev.azure.com/${encodeURIComponent(r)}/_apis/graph/users`);n&&i.searchParams.set("scopeDescriptor",n),o&&i.searchParams.set("continuationToken",o);let a=await this.config.request({url:i.toString(),headers:P(this.config,t)}),u=a.headers["x-ms-continuationtoken"];return{pageInfo:{endCursor:u||null,hasNextPage:!!u},data:a.body.value.map(l=>{var p,d,c,g;return{avatarUrl:((d=(p=l._links)==null?void 0:p.avatar)==null?void 0:d.href)??null,descriptor:l.descriptor??null,email:l.mailAddress??null,name:l.displayName??null,storageKeyURL:((g=(c=l._links)==null?void 0:c.storageKey)==null?void 0:g.href)??null,username:l.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 n=await this.config.request({url:r.storageKeyURL,headers:P(this.config,t)});return{data:{avatarUrl:r.avatarUrl,email:r.email,id:n.body.value,name:r.name,username:r.username,url:null}}}async getAccountsFromAzureGraphAccounts(e,t={}){let r=[];for(let n of e.azureGraphAccounts){let o=await this.getAccountFromAzureGraphAccount({azureGraphAccount:n},t);r.push(o.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:`${v}/${encodeURIComponent(e.namespace)}/${encodeURIComponent(e.project)}/_apis/git/repositories/${encodeURIComponent(e.name)}`,headers:P(this.config,t)});return{data:Vt(e.namespace,r.body)}}async getRepos(e,t={}){let r=[],n=[];return await Promise.all(e.map(async o=>{try{let i=await this.getRepo(o,t);r.push(i.data)}catch(i){n.push({input:o,error:i})}})),{data:r,errors:n}}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}/${encodeURIComponent(e.namespace)}/${encodeURIComponent(e.project)}/_apis/git/repositories`,headers:P(this.config,t)})).body.value.map(n=>Vt(e.namespace,n))}}async getRefs(e,t,r={}){if(!t.repo.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let n=new URL(`${v}/${encodeURIComponent(t.repo.namespace)}/${encodeURIComponent(t.repo.project)}/_apis/git/repositories/${encodeURIComponent(t.repo.name)}/refs`);n.searchParams.set("filter",e),n.searchParams.set("$top",S.toString()),t.cursor&&n.searchParams.set("continuationToken",t.cursor);let o=await this.config.request({url:n.toString(),headers:P(this.config,r)}),i=o.headers["x-ms-continuationtoken"];return{pageInfo:{hasNextPage:!!i,endCursor:i||null},data:o.body.value.map(a=>({name:ge(a.name),commit:{oid:a.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:n,repo:o,assigneeLogins:i,authorLogin:a}=e||{},u=n||1;if(!o.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let l="searchCriteria.status=1";return i&&i.length&&(l+=`&searchCriteria.reviewerId=${i[0]}`),a&&(l+=`&searchCriteria.creatorId=${a}`),await this.config.request({url:`${t.baseUrl||v}/${encodeURIComponent(o.namespace)}/${encodeURIComponent(o.project||"")}/_apis/git/repositories/${encodeURIComponent(o.name)}/pullRequests?${l}&%24top=${r}&%24skip=${(u-1)*r}`,headers:P(this.config,t)})}async getPullRequestsForRepo(e,t={}){let n=e.page||1,o=await this.getPullRequestsForRepoBase(e,t,100);return{pageInfo:{hasNextPage:o.body.value.length===100,nextPage:n+1},data:o.body.value.map(i=>ce(e.repo.namespace,i))}}async getPullRequestsForRepos(e,t={}){if(!e.repos.every(o=>o.project))throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let{repos:r}=e||{},n=[];return await Promise.all(r.map(async o=>{try{(await this.getPullRequestsForRepoBase({repo:o,...e},t)).body.value.forEach(a=>{n.push(ce(o.namespace,a))})}catch(i){if(i.statusCode!==404&&i.statusCode!==401)throw i}})),{data:n}}async getPullRequestsForProjectBase(e,t={},r=100){let{namespace:n,project:o,page:i,assigneeLogins:a,authorLogin:u}=e,l=i||1,p=new URL(`${t.baseUrl||v}/${encodeURIComponent(n)}/${encodeURIComponent(o)}/_apis/git/pullRequests`);return p.searchParams.set("searchCriteria.status","1"),p.searchParams.set("$top",r.toString()),p.searchParams.set("$skip",((l-1)*r).toString()),a&&a.length&&p.searchParams.set("searchCriteria.reviewerId",a[0]),u&&p.searchParams.set("searchCriteria.creatorId",u),await this.config.request({url:p.toString(),headers:P(this.config,t)})}async getPullRequestsForProject(e,t={}){let n=e.page||1,o=await this.getPullRequestsForProjectBase(e,t,100);return{pageInfo:{hasNextPage:o.body.value.length===100,nextPage:n+1},data:o.body.value.map(i=>ce(e.namespace,i))}}async getPullRequestsForProjects(e,t={}){let{projects:r}=e||{},n=[];return await Promise.all(r.map(async o=>{try{(await this.getPullRequestsForProjectBase({...o,...e},t)).body.value.forEach(a=>{n.push(ce(o.namespace,a))})}catch(i){if(i.statusCode!==404&&i.statusCode!==401)throw i}})),{data:n}}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:n,name:o},pullRequestId:i}=e,a=await this.config.request({url:`${t.baseUrl||v}/${encodeURIComponent(r)}/${encodeURIComponent(n||"")}/_apis/git/repositories/${o}/pullrequests/${i}?includeCommits=true?api-version=6.0`,headers:{...P(this.config,t)}});if(!a.body.mergeStatus)throw new Error("Could not fetch pull request");return{data:a.body.mergeStatus}}async updatePullRequest(e,t,r){return await this.config.request({method:"PATCH",url:`${r.baseUrl||v}/${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,n={status:"abandoned"};if(!(await this.updatePullRequest(r,JSON.stringify(n),t)).body.status)throw new Error("Could not close pull request")}async mergePullRequest(e,t={}){var u;let{pullRequest:r,mergeStrategy:n}=e,o;switch(n){case"MERGE_COMMIT":{o="noFastForward";break}case"REBASE":{o="rebase";break}case"REBASE_THEN_MERGE_COMMIT":{o="rebaseMerge";break}case"SQUASH":{o="squash";break}}let i={completionOptions:{mergeStrategy:o},lastMergeSourceCommit:{commitId:(u=r.headRef)==null?void 0:u.oid},status:"completed"};if(!(await this.updatePullRequest(r,JSON.stringify(i),t)).body.status)throw new Error("Could not merge pull request")}async addPullRequestLabel(e,t={}){let{pullRequest:r,label:n}=e;if(!r.repository.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let o={name:n.name};if(!(await this.config.request({method:"POST",url:`${t.baseUrl||v}/${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(o),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:n}=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:`${t.baseUrl||v}/${encodeURIComponent(r.repository.owner.login)}/${encodeURIComponent(r.repository.project)}/_apis/git/repositories/${r.repository.name}/pullrequests/${r.id}/labels/${encodeURIComponent(n.name)}?api-version=6.0`,headers:{...P(this.config,t)}})}async setPullRequestLabels(e,t={}){let{pullRequest:r,labels:n}=e;if(!r.repository.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let o=r.labels;if(!o)throw new Error('Azure DevOps requires "labels" for this function.');for(let i of n)o.find(a=>a.id===i.id)||await this.addPullRequestLabel({pullRequest:r,label:i},t);for(let i of o)n.find(a=>i.id===a.id)||await this.removePullRequestLabel({pullRequest:r,label:i},t)}async setPullRequestAsDraft(e,t={}){let{pullRequest:r,isDraft:n}=e,o={isDraft:n};if(!(await this.updatePullRequest(r,JSON.stringify(o),t)).body.status)throw new Error("Could not set the pull request as draft")}async addPullRequestReviewer(e,t={}){let{pullRequest:r,reviewer:n,isRequired:o}=e,i={id:n.id,isRequired:o};if(!(await this.config.request({method:"PUT",url:`${t.baseUrl||v}/${encodeURIComponent(r.repository.owner.login)}/${encodeURIComponent(r.repository.project)}/_apis/git/repositories/${r.repository.name}/pullrequests/${r.id}/reviewers/${n.id}?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 reviewer")}async removePullRequestReviewer(e,t={}){let{pullRequest:r,reviewer:n}=e;await this.config.request({method:"DELETE",url:`${t.baseUrl||v}/${encodeURIComponent(r.repository.owner.login)}/${encodeURIComponent(r.repository.project)}/_apis/git/repositories/${r.repository.name}/pullrequests/${r.id}/reviewers/${n.id}?api-version=6.0`,headers:{...P(this.config,t),Accept:"application/json"}})}async setPullRequestReviewers(e,t={}){let{pullRequest:r,reviewers:n}=e;for(let o of n)r.assignees.find(i=>i.id===o.id)||await this.addPullRequestReviewer({pullRequest:r,reviewer:o,isRequired:!0},t);for(let o of r.assignees)n.find(i=>o.id===i.id)||await this.removePullRequestReviewer({pullRequest:r,reviewer:o},t)}async getIssuesForAzureProject(e,t={}){let{page:r,assigneeLogins:n,authorLogin:o,mentionLogin:i,statusByWorkItemIdByStatusId:a}=e||{},u=r||1,l=200,p=["[Microsoft.VSTS.Common.ClosedDate] = ''","[System.TeamProject] = @project","[Microsoft.VSTS.Common.ResolvedDate] = ''"];o&&p.push(`[System.CreatedBy] = '${o.replace("'","''")}'`),n&&n[0]&&p.push(`[System.AssignedTo] = '${n[0].replace("'","''")}'`),i&&p.push("[System.Id] IN (@recentMentions)");let d=`Select [Microsoft.VSTS.Common.ClosedDate], [Microsoft.VSTS.Common.ResolvedDate] From WorkItems Where ${p.join(" AND ")} order by [System.CreatedDate] desc`,c=await this.config.request({url:`${t.baseUrl||v}/${encodeURIComponent(e.namespace)}/${encodeURIComponent(e.project)}/_apis/wit/wiql?api-version=6.0`,body:JSON.stringify({query:d}),method:"POST",headers:{...P(this.config,t),"Content-Type":"application/json"}}),g=c.body.workItems.slice((u-1)*l,l*u).map(I=>I.id);if(g.length==0)return{pageInfo:{hasNextPage:!1,nextPage:null},data:[]};let m=await this.config.request({url:`${t.baseUrl||v}/${encodeURIComponent(e.namespace)}/${encodeURIComponent(e.project)}/_apis/wit/workitemsbatch?api-version=6.0`,body:JSON.stringify({ids:g,$expand:"Links"}),method:"POST",headers:{...P(this.config,t),"Content-Type":"application/json"}});return{pageInfo:{hasNextPage:c.body.workItems.length>l*u,nextPage:u+1},data:m.body.value.map(I=>$r(e.namespace,e.project,I,a||{}))}}async updateIssue(e,t,r={}){return await this.config.request({method:"PATCH",url:`${r.baseUrl||v}/${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={}){var a;let{issue:r,status:n}=e,o=[{op:"add",path:"/fields/System.State",value:n.name}];if(!((a=(await this.updateIssue(r,o,t)).body.fields)!=null&&a["System.State"]))throw new Error("Could not set issue status")}async setIssueAssignee(e,t={}){var a;let{issue:r,assignee:n}=e,o=[{op:"add",path:"/fields/System.AssignedTo",value:(n==null?void 0:n.name)??""}];if(!((a=(await this.updateIssue(r,o,t)).body.fields)!=null&&a["System.State"]))throw new Error("Could not set issue assignee")}async setIssueLabels(e,t={}){var u;let{issue:r,labels:n}=e,i=[{op:"replace",path:"/fields/System.Tags",value:n.map(l=>l.name).join(";")}];if(!((u=(await this.updateIssue(r,i,t)).body.fields)!=null&&u["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:n}=e;return{data:(await this.config.request({url:`${t.baseUrl||v}/${encodeURIComponent(r)}/${encodeURIComponent(n||"")}/_apis/wit/workitemtypes?api-version=6.0`,headers:{...P(this.config,t)}})).body.value}}async getLabelsForProject(e,t={}){let{namespace:r,project:n}=e;return{data:(await this.config.request({url:`${t.baseUrl||v}/${encodeURIComponent(r)}/${encodeURIComponent(n||"")}/_apis/wit/tags?api-version=6.0`,headers:{...P(this.config,t)}})).body.value.map(i=>({color:null,description:null,id:i.id,name:i.name,url:i.url}))}}};var A=(s,e={})=>f(e.token||s.token,e.isPAT||s.isPAT);var O="https://api.bitbucket.org/2.0",Gr={OPEN:"OPEN",MERGED:"MERGED",DECLINED:"CLOSED"},Xt=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}),Kt=s=>{var e,t;return{id:s.uuid,namespace:s.workspace.slug,name:s.slug,webUrl:s.links.html.href,httpsUrl:((e=s.links.clone.find(r=>r.name==="https"))==null?void 0:e.href)??null,sshUrl:((t=s.links.clone.find(r=>r.name==="ssh"))==null?void 0:t.href)??null,defaultBranch:{name:s.mainbranch.name},permission:null}},st=s=>{let e=s.id;return{id:e.toString(),title:s.title,number:e,state:Gr[s.state],isDraft:!1,commentCount:s.comment_count,upvoteCount:null,author:Xt(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:null},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:null,reviewDecision:null,additions:null,deletions:null,fileCount:null,commitCount:null,headRepository:null,mergeableState:"UNKNOWN",permissions:null}},te=class extends T{async refreshToken(e){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 ${e.base64ClientIDColonClientSecret}`},body:`grant_type=refresh_token&refresh_token=${e.refreshToken}`})).body}}async getCurrentUser(e={},t={}){let r=await this.config.request({url:`${O}/user`,headers:A(this.config,t)});return{data:Xt(r.body)}}async getUserForCommit(e,t={}){var i;let n=(await this.config.request({url:`${O}/repositories/${e.repo.namespace}/${e.repo.name}/commit/${e.oid}`,headers:A(this.config,t)})).body.author,o=n.raw.match(/([^<]+)<(.+)>/);return{data:{name:o?o[1].trim():null,email:o?o[2]:null,avatarUrl:((i=n.user)==null?void 0:i.links.avatar.href)||null}}}async getRepo(e,t={}){let r=await this.config.request({url:`${O}/repositories/${e.namespace}/${e.name}`,headers:A(this.config,t)});return{data:Kt(r.body)}}async getRepos(e,t={}){let r=[],n=[];return await Promise.all(e.map(async o=>{try{let i=await this.getRepo(o,t);r.push(i.data)}catch(i){n.push({input:o,error:i})}})),{data:r,errors:n}}async getReposForCurrentUser(e,t={}){let r=new URL(`${O}/repositories`);r.searchParams.set("role","member"),r.searchParams.set("pagelen",S.toString()),e.cursor&&r.searchParams.set("after",e.cursor);let n=await this.config.request({url:r.toString(),headers:A(this.config,t)}),o=!!n.body.next,i=null;return n.body.next&&(i=new URL(n.body.next).searchParams.get("after")),{pageInfo:{hasNextPage:o,endCursor:i},data:n.body.values.map(Kt)}}async getBranches(e,t={}){var i;let r=new URL(`${O}/repositories/${e.repo.namespace}/${e.repo.name}/refs/branches`);r.searchParams.set("page",((i=e.page)==null?void 0:i.toString())||"1"),r.searchParams.set("pagelen",S.toString());let n=await this.config.request({url:r.toString(),headers:A(this.config,t)}),o=!!n.body.next;return{pageInfo:{hasNextPage:o,nextPage:o?n.body.page+1:null},data:n.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 getTags(e,t={}){let r=new URL(`${O}/repositories/${e.repo.namespace}/${e.repo.name}/refs/tags`);r.searchParams.set("pagelen",S.toString()),e.cursor&&r.searchParams.set("page",e.cursor);let n=await this.config.request({url:r.toString(),headers:A(this.config,t)}),o=!!n.body.next,i=null;return n.body.next&&(i=new URL(n.body.next).searchParams.get("page")),{pageInfo:{hasNextPage:o,endCursor:i},data:n.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 getPullRequestsForUser(e,t={}){var i;let r=new URL(`${O}/pullrequests/${e.userId}`);r.searchParams.set("page",((i=e.page)==null?void 0:i.toString())||"1"),r.searchParams.set("pagelen","50");let n=await this.config.request({url:r.toString(),headers:A(this.config,t)}),o=!!n.body.next;return{pageInfo:{hasNextPage:o,nextPage:o?n.body.page+1:null},data:n.body.values.map(st)}}async getPullRequestsForRepoBase(e,t={}){var n;let r=new URL(`${O}/repositories/${encodeURI(e.repo.namespace)}/${encodeURI(e.repo.name)}/pullrequests?state=OPEN`);return r.searchParams.set("page",((n=e.page)==null?void 0:n.toString())||"1"),r.searchParams.set("pagelen","50"),await this.config.request({url:r.toString(),headers:A(this.config,t)})}async getPullRequestsForRepo(e,t={}){let r=[],n=await this.getPullRequestsForRepoBase(e,t);n.body.values.forEach(i=>{if(e.authorLogin&&i.author.uuid!==e.authorLogin)return null;r.push(st(i))});let o=!!n.body.next;return{pageInfo:{hasNextPage:o,nextPage:o?n.body.page+1:null},data:r}}async getPullRequestsForRepos(e,t={}){let r=[];return await Promise.all(e.repos.map(async n=>{try{(await this.getPullRequestsForRepoBase({repo:n,...e},t)).body.values.forEach(i=>{if(e.authorLogin&&i.author.uuid!==e.authorLogin)return null;r.push(st(i))})}catch(o){if(o.statusCode!==404&&o.statusCode!==401)throw o}})),{data:r}}async closePullRequest(e,t={}){let{pullRequest:r}=e;if(!(await this.config.request({method:"POST",url:`${O}/repositories/${r.repository.owner.login}/${r.repository.name}/pullrequests/${r.id}/decline`,headers:A(this.config,t)})).body.title)throw new Error("Could not close pull request")}async mergePullRequest(e,t={}){let{pullRequest:r,mergeStrategy:n}=e,o;switch(n){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:`${O}/repositories/${r.repository.owner.login}/${r.repository.name}/pullrequests/${r.id}/merge`,body:JSON.stringify(i),headers:{...A(this.config,t),"Content-Type":"application/json"}})).body.title)throw new Error("Could not merge pull request")}async setPullRequestReviewers(e,t={}){let{pullRequest:r,reviewers:n}=e,o={reviewers:n.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:`${O}/repositories/${r.repository.owner.login}/${r.repository.name}/pullrequests/${r.id}`,body:JSON.stringify(o),headers:{...A(this.config,t),"Content-Type":"application/json"}})).body.title)throw new Error("Could not set pull request reviewers")}};var nt=s=>({name:s.displayName,email:s.emailAddress,avatarUrl:s.avatarUrl??null,id:s.id.toString(),username:s.name,url:s.links.self[0].href}),re=s=>{var u,l,p,d,c,g;let e={OPEN:"OPEN",MERGED:"MERGED",DECLINED:"CLOSED"},t={UNAPPROVED:"REVIEW_REQUESTED",NEEDS_WORK:"CHANGES_REQUESTED",APPROVED:"APPROVED"},r=s.reviewers.map(m=>({reviewer:nt(m.user),state:t[m.status]})),n=((u=s.toRef.repository.links.clone.find(m=>m.name==="ssh"))==null?void 0:u.href)??null,o=((l=s.toRef.repository.links.clone.find(m=>m.name==="https"))==null?void 0:l.href)??null;o||(o=((p=s.toRef.repository.links.clone.find(m=>m.name==="http"))==null?void 0:p.href)??null);let i=((d=s.fromRef.repository.links.clone.find(m=>m.name==="ssh"))==null?void 0:d.href)??null,a=((c=s.fromRef.repository.links.clone.find(m=>m.name==="https"))==null?void 0:c.href)??null;return a||(a=((g=s.fromRef.repository.links.clone.find(m=>m.name==="http"))==null?void 0:g.href)??null),{id:s.id.toString(),number:s.id,title:s.title,url:s.links.self[0].href,state:e[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:nt(s.author.user),assignees:null,reviews:r,reviewDecision:z(r),repository:{id:s.toRef.repository.id.toString(),name:s.toRef.repository.name,owner:{login:s.toRef.repository.project.key},remoteInfo:o&&n?{cloneUrlHTTPS:o,cloneUrlSSH:n}: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:"UNKNOWN",permissions:null,version:s.version}},Yt=s=>{var e,t,r;return{id:s.id.toString(),namespace:s.project.key,name:s.slug,webUrl:((e=s.links.self[0])==null?void 0:e.href)??null,httpsUrl:((t=s.links.clone.find(n=>n.name==="https"))==null?void 0:t.href)??null,sshUrl:((r=s.links.clone.find(n=>n.name==="ssh"))==null?void 0:r.href)??null,defaultBranch:null,permission:null}},se=class extends N{getBaseUrl(e){let t=e.baseUrl||this.config.baseUrl;if(!t)throw new Error('Bitbucket Server requires "baseUrl"');return t}getRequestHeaders(e){return f(e.token||this.config.token)}async getCurrentUser(e={},t={}){let r=await this.config.request({url:`${this.getBaseUrl(t)}/users?limit=2`,headers:this.getRequestHeaders(t)}),{headers:{"x-auserid":n,"x-ausername":o}}=r,i=n?parseInt(n,10):null,a=decodeURIComponent(o),l=(await this.config.request({url:`${this.getBaseUrl(t)}/users?filter=${o}&avatarSize=64`,headers:this.getRequestHeaders(t)})).body.values.find(({emailAddress:p,id:d,name:c,slug:g})=>i?i===d:a===c||a===p||a===g);if(!l)throw new Error("Could not find current Bitbucket Server user");return{data:nt(l)}}async getRepo(e,t={}){let r=await this.config.request({url:`${this.getBaseUrl(t)}/projects/${e.namespace}/repos/${e.name}`,headers:this.getRequestHeaders(t)});return{data:Yt(r.body)}}async getRepos(e,t={}){let r=[],n=[];return await Promise.all(e.map(async o=>{try{let i=await this.getRepo(o,t);r.push(i.data)}catch(i){n.push({input:o,error:i})}})),{data:r,errors:n}}async getReposForCurrentUser(e,t={}){let r=e.page??0,n=await this.config.request({url:`${this.getBaseUrl(t)}/repos?start=${r}`,headers:this.getRequestHeaders(t)});return{pageInfo:{hasNextPage:!n.body.isLastPage,nextPage:n.body.nextPageStart},data:n.body.values.map(Yt)}}async getPullRequestsForRepoBase(e,t={}){var n;let r=new URL(`${this.getBaseUrl(t)}/projects/${encodeURI(e.repo.namespace)}/repos/${encodeURI(e.repo.name)}/pull-requests?state=OPEN`);return r.searchParams.set("start",((n=e.page)==null?void 0:n.toString())||"0"),r.searchParams.set("limit","50"),await this.config.request({url:r.toString(),headers:this.getRequestHeaders(t)})}async getPullRequestsForRepo(e,t={}){let r=[],n=await this.getPullRequestsForRepoBase(e,t);n.body.values.forEach(i=>{if(e.authorLogin&&i.author.user.name!==e.authorLogin)return null;r.push(re(i))});let o=n.body.values.length!==0;return{pageInfo:{hasNextPage:o,nextPage:o?n.body.start+n.body.values.length:null},data:r}}async getPullRequestsForRepos(e,t={}){let r=[];return await Promise.all(e.repos.map(async n=>{try{(await this.getPullRequestsForRepoBase({repo:n,...e},t)).body.values.forEach(i=>{if(e.authorLogin&&i.author.user.name!==e.authorLogin)return null;r.push(re(i))})}catch(o){if(o.statusCode!==404&&o.statusCode!==401)throw o}})),{data:r}}async getPullRequestsForCurrentUser(e,t={}){var i;let r=new URL(`${this.getBaseUrl(t)}/dashboard/pull-requests`);r.searchParams.set("state","OPEN"),r.searchParams.set("start",((i=e.page)==null?void 0:i.toString())||"0"),r.searchParams.set("limit","50");let n=await this.config.request({url:r.toString(),headers:this.getRequestHeaders(t)}),o=n.body.values.length!==0;return{pageInfo:{hasNextPage:o,nextPage:o?n.body.start+n.body.values.length:null},data:n.body.values.map(re)}}async closePullRequest(e,t={}){let{pullRequest:r}=e;if(r.version===void 0)throw new Error('Bitbucket Server requires "version" for this function.');if(!(await this.config.request({method:"POST",url:`${this.getBaseUrl(t)}/projects/${r.repository.owner.login}/repos/${r.repository.name}/pull-requests/${r.id}/decline`,body:JSON.stringify({version:r.version}),headers:{...this.getRequestHeaders(t),"Content-Type":"application/json"}})).body.title)throw new Error("Could not close pull request")}async mergePullRequest(e,t={}){let{pullRequest:r,mergeStrategyId:n}=e;if(e.mergeStrategy)throw new Error('Bitbucket Server uses "mergeStrategyId" instead of "mergeStrategy".');if(r.version===void 0)throw new Error('Bitbucket Server requires "version" for this function.');if(!(await this.config.request({method:"POST",url:`${this.getBaseUrl(t)}/projects/${r.repository.owner.login}/repos/${r.repository.name}/pull-requests/${r.id}/merge`,body:JSON.stringify({strategyId:n,version:r.version}),headers:{...this.getRequestHeaders(t),"Content-Type":"application/json"}})).body.title)throw new Error("Could not merge pull request")}async getMergeStrategies(e={}){let t=await this.config.request({url:`${this.getBaseUrl(e)}/admin/pull-requests/git`,headers:{...this.getRequestHeaders(e),"Content-Type":"application/json"}});return{data:{defaultStrategy:t.body.mergeConfig.defaultStrategy,strategies:t.body.mergeConfig.strategies}}}async setPullRequestReviewers(e,t={}){let{pullRequest:r,reviewers:n}=e;if(r.version===void 0)throw new Error('Bitbucket Server requires "version" for this function.');let o={reviewers:n.map(a=>{if(a.username)throw new Error('Bitbucket Server reviewer requires "username" for this function.');return{user:{name:a.username}}}),version:r.version};if(!(await this.config.request({method:"PUT",url:`${this.getBaseUrl(t)}/projects/${r.repository.owner.login}/repos/${r.repository.name}/pull-requests/${r.id}`,body:JSON.stringify(o),headers:{...this.getRequestHeaders(t),"Content-Type":"application/json"}})).body.title)throw new Error("Could not set pull request reviewers")}};var rr=require("js-base64");var me=(t=>(t.Open="OPEN",t.Closed="CLOSED",t))(me||{});var Tr={AS_CODE_OWNER:[3,0,0],CHECK_RUN:[3,0,0],LATEST_REVIEWS:[3,0,0],VIEWER_CAN_MERGE_AS_ADMIN:[3,5,0]},he=(s,e)=>{let t=Tr[e];for(let r=0;r<3;r++){if(s[r]>t[r])return!0;if(s[r]<t[r])return!1}return!0},Ie="https://api.github.com",Or=`${Ie}/graphql`,Re=`
1
+ "use strict";var qr=Object.create;var de=Object.defineProperty;var Sr=Object.getOwnPropertyDescriptor;var Cr=Object.getOwnPropertyNames;var Dr=Object.getPrototypeOf,Lr=Object.prototype.hasOwnProperty;var N=(s,e)=>{for(var t in e)de(s,t,{get:e[t],enumerable:!0})},Bt=(s,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of Cr(e))!Lr.call(s,n)&&n!==t&&de(s,n,{get:()=>e[n],enumerable:!(r=Sr(e,n))||r.enumerable});return s};var Ur=(s,e,t)=>(t=s!=null?qr(Dr(s)):{},Bt(e||!s||!s.__esModule?de(t,"default",{value:s,enumerable:!0}):t,s)),Ar=s=>Bt(de({},"__esModule",{value:!0}),s);var Hs={};N(Hs,{AzureDevOps:()=>te,AzureDevopsUtils:()=>Oe,Bitbucket:()=>re,BitbucketServer:()=>ne,BitbucketServerUtils:()=>ke,BitbucketUtils:()=>xe,EntityIdentifierProviderType:()=>A,EntityIdentifierUtils:()=>Ve,EntityType:()=>U,EntityVersion:()=>L,GitBuildStatusStage:()=>jt,GitBuildStatusState:()=>ee,GitDiffLineType:()=>tt,GitHub:()=>oe,GitHubIssueCloseReason:()=>vr,GitHubUtils:()=>Xe,GitIssueState:()=>he,GitLab:()=>ie,GitLabUtils:()=>Ye,GitMergeStrategy:()=>X,GitProviderUtils:()=>Ke,GitPullRequestMergeableState:()=>B,GitPullRequestReviewState:()=>Q,GitPullRequestState:()=>J,Jira:()=>ue,JiraServer:()=>le,JiraUtils:()=>Ze,PullRequestAsyncStatus:()=>Er,Trello:()=>pe,TrelloUtils:()=>et,Utils:()=>zs,default:()=>Ms,isFetch:()=>ce});module.exports=Ar(Hs);var jt=(n=>(n.Build="build",n.Production="production",n.Staging="staging",n.Test="test",n))(jt||{}),ee=(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))(ee||{}),X=(o=>(o.MergeCommit="MERGE_COMMIT",o.Rebase="REBASE",o.RebaseThenMergeCommit="REBASE_THEN_MERGE_COMMIT",o.FastForward="FAST_FORWARD",o.Squash="SQUASH",o))(X||{}),J=(r=>(r.Open="OPEN",r.Closed="CLOSED",r.Merged="MERGED",r))(J||{}),Q=(n=>(n.Approved="APPROVED",n.ChangesRequested="CHANGES_REQUESTED",n.Commented="COMMENTED",n.ReviewRequested="REVIEW_REQUESTED",n))(Q||{}),B=(a=>(a.Behind="BEHIND",a.Blocked="BLOCKED",a.Conflicts="CONFLICTS",a.Mergeable="MERGEABLE",a.Unknown="UNKNOWN",a.UnknownAndBlocked="UNKNOWN_AND_BLOCKED",a.Unstable="UNSTABLE",a))(B||{}),tt=(r=>(r.ADDED="ADDED",r.DELETED="DELETED",r.UNMODIFIED="UNMODIFIED",r))(tt||{});var Ft={APPROVED:0,COMMENTED:1,REVIEW_REQUESTED:2,CHANGES_REQUESTED:3},H=s=>!s||s.length===0?null:s.reduce((e,t)=>Ft[t.state]>Ft[e]?t.state:e,"APPROVED");var C=100;var Mt=Ur(require("node-fetch")),zt=globalThis.fetch||Mt.default;var $r=async s=>{let e=s.headers.get("content-type")||"",t=null;if(e.startsWith("application/json")){let n=await s.text();t=n.trim().length>0?JSON.parse(n):null}else if(e.startsWith("text/")||e==="")t=await s.text();else if(e.startsWith("application/vnd.github.raw+json"))t=await s.arrayBuffer();else throw new Error(`Unsupported content-type: ${e}`);let r={body:t,headers:Object.fromEntries(s.headers.entries()),status:s.status,statusText:s.statusText};if(!s.ok){let n=new Error(s.statusText);throw Object.assign(n,{response:r}),n}return r},rt=s=>async({url:e,...t})=>{let r=await s(e,t);return $r(r)};var ce=(s,e=!1)=>s.name==="fetch"||e;var O=class{constructor(e){let t=(e==null?void 0:e.request)||zt;this.config={...e,request:ce(t,e==null?void 0:e.forceIsFetch)?rt(t):t}}updateConfig(e){this.config={...this.config,...e,request:e.request&&ce(e.request,(e==null?void 0:e.forceIsFetch)??this.config.forceIsFetch)?rt(e.request):this.config.request}}},_=class extends O{};var I=(s,e)=>{let t={};return s&&(t.Authorization=`${e?"Basic":"Bearer"} ${s}`),t},Ht=s=>s?s.reduce((e,t)=>(e[t]=!0,e),{}):void 0,W=(s,e,t)=>!s||e.some(r=>s[r])?t:"",Wt=async s=>{var n,o,i;let e=[],t=!0,r;for(;t;){let a=await s(r);e=e.concat(a.data),t=!!((n=a==null?void 0:a.pageInfo)!=null&&n.hasNextPage),r=((o=a==null?void 0:a.pageInfo)==null?void 0:o.endCursor)||((i=a==null?void 0:a.pageInfo)==null?void 0:i.nextPage)}return e};var P=(s,e={})=>I(e.token||s.token,e.isPAT||s.isPAT),Jt=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/");var Vt="https://app.vssps.visualstudio.com/_apis",q="https://dev.azure.com",Gr={active:"OPEN",completed:"MERGED",abandoned:"CLOSED"},Tr={10:"APPROVED",5:"APPROVED",0:"REVIEW_REQUESTED",[-5]:"CHANGES_REQUESTED",[-10]:"CHANGES_REQUESTED"},st=s=>({id:s.id,name:s.displayName??null,username:(s.uniqueName||s.displayName)??null,email:null,avatarUrl:s.imageUrl??null,url:null}),me=s=>s.startsWith("refs/heads/")?s.replace("refs/heads/",""):s,ge=(s,e)=>{var n;let t=[],r=[];return e.reviewers.forEach(o=>{let i={reviewer:st(o),state:Tr[o.vote??0]||"REVIEW_REQUESTED"};o.isRequired&&t.push(i),r.push(i)}),{id:e.pullRequestId.toString(),title:e.title,number:e.codeReviewId,state:Gr[e.status],isDraft:e.isDraft,commentCount:null,upvoteCount:null,author:st(e.createdBy),createdDate:new Date(e.creationDate),updatedDate:new Date(e.closedDate||e.creationDate),closedDate:e.closedDate?new Date(e.closedDate):null,mergedDate:e.closedDate&&e.status==="completed"?new Date(e.closedDate):null,repository:{id:e.repository.id,name:e.repository.name,project:e.repository.project.name,owner:{login:s},remoteInfo:null},headCommit:{buildStatuses:null},baseRef:{name:me(e.targetRefName),oid:e.lastMergeTargetCommit.commitId},headRef:{name:me(e.sourceRefName),oid:e.lastMergeSourceCommit.commitId},url:Jt(e),assignees:e.reviewers.map(st),reviews:r,reviewDecision:H(t),additions:null,deletions:null,fileCount:null,commitCount:null,headRepository:null,mergeableState:"UNKNOWN",labels:((n=e.labels)==null?void 0:n.map(o=>({color:null,description:null,id:o.id,name:o.name})))??[],permissions:null}},Kt=(s,e)=>({id:e.id,name:e.name,namespace:s,project:e.project.name,webUrl:e.webUrl,httpsUrl:e.remoteUrl,sshUrl:e.sshUrl,defaultBranch:e.defaultBranch?{name:me(e.defaultBranch)}:null,permission:null}),Or=(s,e,t,r)=>{var l,p,d,c,g,m;let n=t.fields,o=n["System.AssignedTo"],i=n["System.State"],a=n["System.WorkItemType"],u;return i&&a&&(u=(l=r[a])==null?void 0:l[i]),{id:t.id.toString(),number:t.id.toString(),title:n["System.Title"],commentCount:n["System.CommentCount"],author:{avatarUrl:((d=(p=n["System.CreatedBy"]._links)==null?void 0:p.avatar)==null?void 0:d.href)??null,email:null,id:n["System.CreatedBy"].id,name:n["System.CreatedBy"].uniqueName??null,username:n["System.CreatedBy"].displayName??null,url:null},closedDate:n["Microsoft.VSTS.Common.ClosedDate"]?new Date(n["Microsoft.VSTS.Common.ClosedDate"]):null,createdDate:new Date(n["System.CreatedDate"]),updatedDate:new Date(n["System.ChangedDate"]),url:t._links.html.href,assignees:o?[{avatarUrl:((g=(c=o._links)==null?void 0:c.avatar)==null?void 0:g.href)??null,email:null,id:o.id,name:o.uniqueName??null,username:o.displayName??null,url:null}]:[],description:null,state:{name:(u==null?void 0:u.title)||i,color:null},type:n["System.WorkItemType"],repository:null,project:{namespace:s,name:e,resourceId:null,key:null,id:null},upvoteCount:0,labels:((m=t.fields["System.Tags"])==null?void 0:m.split(";").map(h=>({color:null,description:null,id:null,name:h.trim()})))??[]}},te=class extends O{async getCurrentUser(e={},t={}){if(t.isPAT||this.config.isPAT)throw new Error("Azure DevOps does not support PATs for this function.");let r=await this.config.request({url:`${Vt}/profile/profiles/me`,headers:P(this.config,t)});return{data:{id:r.body.id,name:r.body.displayName,username:r.body.displayName,email:r.body.emailAddress,avatarUrl:null,url:null}}}async getCurrentUserForInstance(e,t={}){let n=(await this.config.request({url:`${q}/${encodeURIComponent(e.namespace)}/_apis/ConnectionData`,headers:P(this.config,t)})).body.authorizedUser;if(n.providerDisplayName==="Anonymous")throw new Error("Current user not found.");return{data:{id:n.id,name:n.providerDisplayName,username:n.providerDisplayName,email:n.properties.Account.$value,avatarUrl:null}}}async getUserForCommit(e,t={}){if(!e.repo.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let n=(await this.config.request({url:`${q}/${encodeURIComponent(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:n.name,email:n.email,avatarUrl:n.imageUrl}}}async getOrgsForUser(e,t={}){return{data:(await this.config.request({url:`${Vt}/accounts?memberId=${e.userId}&api-version=6.0`,headers:P(this.config,t)})).body.value.map(n=>({id:n.accountId,name:n.accountName}))}}async getAzureProjects(e,t={}){let r=new URL(`${q}/${encodeURIComponent(e.namespace)}/_apis/projects`);r.searchParams.set("$top",C.toString()),e.cursor&&r.searchParams.set("$skip",e.cursor);let n=await this.config.request({url:r.toString(),headers:P(this.config,t)}),o=n.headers["x-ms-continuationtoken"];return{pageInfo:{hasNextPage:!!o,endCursor:o||null},data:n.body.value.map(i=>({id:i.id,name:i.name,namespace:e.namespace}))}}async getAzureProjectScopeDescriptor(e,t={}){let{namespace:r,projectId:n}=e;return{data:{scope:(await this.config.request({url:`https://vssps.dev.azure.com/${encodeURIComponent(r)}/_apis/graph/descriptors/${n}?api-version=6.0`,headers:P(this.config,t)})).body.value}}}async getAzureGraphAccountsForAzureProject(e,t={}){let{namespace:r,projectScopeDescriptor:n,cursor:o}=e,i=new URL(`https://vssps.dev.azure.com/${encodeURIComponent(r)}/_apis/graph/users`);n&&i.searchParams.set("scopeDescriptor",n),o&&i.searchParams.set("continuationToken",o);let a=await this.config.request({url:i.toString(),headers:P(this.config,t)}),u=a.headers["x-ms-continuationtoken"];return{pageInfo:{endCursor:u||null,hasNextPage:!!u},data:a.body.value.map(l=>{var p,d,c,g;return{avatarUrl:((d=(p=l._links)==null?void 0:p.avatar)==null?void 0:d.href)??null,descriptor:l.descriptor??null,email:l.mailAddress??null,name:l.displayName??null,storageKeyURL:((g=(c=l._links)==null?void 0:c.storageKey)==null?void 0:g.href)??null,username:l.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 n=await this.config.request({url:r.storageKeyURL,headers:P(this.config,t)});return{data:{avatarUrl:r.avatarUrl,email:r.email,id:n.body.value,name:r.name,username:r.username,url:null}}}async getAccountsFromAzureGraphAccounts(e,t={}){let r=[];for(let n of e.azureGraphAccounts){let o=await this.getAccountFromAzureGraphAccount({azureGraphAccount:n},t);r.push(o.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:`${q}/${encodeURIComponent(e.namespace)}/${encodeURIComponent(e.project)}/_apis/git/repositories/${encodeURIComponent(e.name)}`,headers:P(this.config,t)});return{data:Kt(e.namespace,r.body)}}async getRepos(e,t={}){let r=[],n=[];return await Promise.all(e.map(async o=>{try{let i=await this.getRepo(o,t);r.push(i.data)}catch(i){n.push({input:o,error:i})}})),{data:r,errors:n}}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:`${q}/${encodeURIComponent(e.namespace)}/${encodeURIComponent(e.project)}/_apis/git/repositories`,headers:P(this.config,t)})).body.value.map(n=>Kt(e.namespace,n))}}async getRefs(e,t,r={}){if(!t.repo.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let n=new URL(`${q}/${encodeURIComponent(t.repo.namespace)}/${encodeURIComponent(t.repo.project)}/_apis/git/repositories/${encodeURIComponent(t.repo.name)}/refs`);n.searchParams.set("filter",e),n.searchParams.set("$top",C.toString()),t.cursor&&n.searchParams.set("continuationToken",t.cursor);let o=await this.config.request({url:n.toString(),headers:P(this.config,r)}),i=o.headers["x-ms-continuationtoken"];return{pageInfo:{hasNextPage:!!i,endCursor:i||null},data:o.body.value.map(a=>({name:me(a.name),commit:{oid:a.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:n,repo:o,assigneeLogins:i,authorLogin:a}=e||{},u=n||1;if(!o.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let l="searchCriteria.status=1";return i&&i.length&&(l+=`&searchCriteria.reviewerId=${i[0]}`),a&&(l+=`&searchCriteria.creatorId=${a}`),await this.config.request({url:`${t.baseUrl||q}/${encodeURIComponent(o.namespace)}/${encodeURIComponent(o.project||"")}/_apis/git/repositories/${encodeURIComponent(o.name)}/pullRequests?${l}&%24top=${r}&%24skip=${(u-1)*r}`,headers:P(this.config,t)})}async getPullRequestsForRepo(e,t={}){let n=e.page||1,o=await this.getPullRequestsForRepoBase(e,t,100);return{pageInfo:{hasNextPage:o.body.value.length===100,nextPage:n+1},data:o.body.value.map(i=>ge(e.repo.namespace,i))}}async getPullRequestsForRepos(e,t={}){if(!e.repos.every(o=>o.project))throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let{repos:r}=e||{},n=[];return await Promise.all(r.map(async o=>{try{(await this.getPullRequestsForRepoBase({repo:o,...e},t)).body.value.forEach(a=>{n.push(ge(o.namespace,a))})}catch(i){if(i.statusCode!==404&&i.statusCode!==401)throw i}})),{data:n}}async getPullRequestsForProjectBase(e,t={},r=100){let{namespace:n,project:o,page:i,assigneeLogins:a,authorLogin:u}=e,l=i||1,p=new URL(`${t.baseUrl||q}/${encodeURIComponent(n)}/${encodeURIComponent(o)}/_apis/git/pullRequests`);return p.searchParams.set("searchCriteria.status","1"),p.searchParams.set("$top",r.toString()),p.searchParams.set("$skip",((l-1)*r).toString()),a&&a.length&&p.searchParams.set("searchCriteria.reviewerId",a[0]),u&&p.searchParams.set("searchCriteria.creatorId",u),await this.config.request({url:p.toString(),headers:P(this.config,t)})}async getPullRequestsForProject(e,t={}){let n=e.page||1,o=await this.getPullRequestsForProjectBase(e,t,100);return{pageInfo:{hasNextPage:o.body.value.length===100,nextPage:n+1},data:o.body.value.map(i=>ge(e.namespace,i))}}async getPullRequestsForProjects(e,t={}){let{projects:r}=e||{},n=[];return await Promise.all(r.map(async o=>{try{(await this.getPullRequestsForProjectBase({...o,...e},t)).body.value.forEach(a=>{n.push(ge(o.namespace,a))})}catch(i){if(i.statusCode!==404&&i.statusCode!==401)throw i}})),{data:n}}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:n,name:o},pullRequestId:i}=e,a=await this.config.request({url:`${t.baseUrl||q}/${encodeURIComponent(r)}/${encodeURIComponent(n||"")}/_apis/git/repositories/${o}/pullrequests/${i}?includeCommits=true?api-version=6.0`,headers:{...P(this.config,t)}});if(!a.body.mergeStatus)throw new Error("Could not fetch pull request");return{data:a.body.mergeStatus}}async updatePullRequest(e,t,r){return await this.config.request({method:"PATCH",url:`${r.baseUrl||q}/${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,n={status:"abandoned"};if(!(await this.updatePullRequest(r,JSON.stringify(n),t)).body.status)throw new Error("Could not close pull request")}async mergePullRequest(e,t={}){var u;let{pullRequest:r,mergeStrategy:n}=e,o;switch(n){case"MERGE_COMMIT":{o="noFastForward";break}case"REBASE":{o="rebase";break}case"REBASE_THEN_MERGE_COMMIT":{o="rebaseMerge";break}case"SQUASH":{o="squash";break}}let i={completionOptions:{mergeStrategy:o},lastMergeSourceCommit:{commitId:(u=r.headRef)==null?void 0:u.oid},status:"completed"};if(!(await this.updatePullRequest(r,JSON.stringify(i),t)).body.status)throw new Error("Could not merge pull request")}async addPullRequestLabel(e,t={}){let{pullRequest:r,label:n}=e;if(!r.repository.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let o={name:n.name};if(!(await this.config.request({method:"POST",url:`${t.baseUrl||q}/${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(o),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:n}=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:`${t.baseUrl||q}/${encodeURIComponent(r.repository.owner.login)}/${encodeURIComponent(r.repository.project)}/_apis/git/repositories/${r.repository.name}/pullrequests/${r.id}/labels/${encodeURIComponent(n.name)}?api-version=6.0`,headers:{...P(this.config,t)}})}async setPullRequestLabels(e,t={}){let{pullRequest:r,labels:n}=e;if(!r.repository.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let o=r.labels;if(!o)throw new Error('Azure DevOps requires "labels" for this function.');for(let i of n)o.find(a=>a.id===i.id)||await this.addPullRequestLabel({pullRequest:r,label:i},t);for(let i of o)n.find(a=>i.id===a.id)||await this.removePullRequestLabel({pullRequest:r,label:i},t)}async setPullRequestAsDraft(e,t={}){let{pullRequest:r,isDraft:n}=e,o={isDraft:n};if(!(await this.updatePullRequest(r,JSON.stringify(o),t)).body.status)throw new Error("Could not set the pull request as draft")}async addPullRequestReviewer(e,t={}){let{pullRequest:r,reviewer:n,isRequired:o}=e,i={id:n.id,isRequired:o};if(!(await this.config.request({method:"PUT",url:`${t.baseUrl||q}/${encodeURIComponent(r.repository.owner.login)}/${encodeURIComponent(r.repository.project)}/_apis/git/repositories/${r.repository.name}/pullrequests/${r.id}/reviewers/${n.id}?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 reviewer")}async removePullRequestReviewer(e,t={}){let{pullRequest:r,reviewer:n}=e;await this.config.request({method:"DELETE",url:`${t.baseUrl||q}/${encodeURIComponent(r.repository.owner.login)}/${encodeURIComponent(r.repository.project)}/_apis/git/repositories/${r.repository.name}/pullrequests/${r.id}/reviewers/${n.id}?api-version=6.0`,headers:{...P(this.config,t),Accept:"application/json"}})}async setPullRequestReviewers(e,t={}){let{pullRequest:r,reviewers:n}=e;for(let o of n)r.assignees.find(i=>i.id===o.id)||await this.addPullRequestReviewer({pullRequest:r,reviewer:o,isRequired:!0},t);for(let o of r.assignees)n.find(i=>o.id===i.id)||await this.removePullRequestReviewer({pullRequest:r,reviewer:o},t)}async getIssuesForAzureProject(e,t={}){let{page:r,assigneeLogins:n,authorLogin:o,mentionLogin:i,labelNames:a,statusByWorkItemIdByStatusId:u}=e||{},l=r||1,p=200,d=["[Microsoft.VSTS.Common.ClosedDate] = ''","[System.TeamProject] = @project","[Microsoft.VSTS.Common.ResolvedDate] = ''"];o&&d.push(`[System.CreatedBy] = '${o.replace("'","''")}'`),n&&n[0]&&d.push(`[System.AssignedTo] = '${n[0].replace("'","''")}'`),i&&d.push("[System.Id] IN (@recentMentions)"),a&&a.forEach(R=>d.push(`[System.Tags] Contains '${R}'`));let c=`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:`${t.baseUrl||q}/${encodeURIComponent(e.namespace)}/${encodeURIComponent(e.project)}/_apis/wit/wiql?api-version=6.0`,body:JSON.stringify({query:c}),method:"POST",headers:{...P(this.config,t),"Content-Type":"application/json"}}),m=g.body.workItems.slice((l-1)*p,p*l).map(R=>R.id);if(m.length==0)return{pageInfo:{hasNextPage:!1,nextPage:null},data:[]};let h=await this.config.request({url:`${t.baseUrl||q}/${encodeURIComponent(e.namespace)}/${encodeURIComponent(e.project)}/_apis/wit/workitemsbatch?api-version=6.0`,body:JSON.stringify({ids:m,$expand:"Links"}),method:"POST",headers:{...P(this.config,t),"Content-Type":"application/json"}});return{pageInfo:{hasNextPage:g.body.workItems.length>p*l,nextPage:l+1},data:h.body.value.map(R=>Or(e.namespace,e.project,R,u||{}))}}async updateIssue(e,t,r={}){return await this.config.request({method:"PATCH",url:`${r.baseUrl||q}/${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={}){var a;let{issue:r,status:n}=e,o=[{op:"add",path:"/fields/System.State",value:n.name}];if(!((a=(await this.updateIssue(r,o,t)).body.fields)!=null&&a["System.State"]))throw new Error("Could not set issue status")}async setIssueAssignee(e,t={}){var a;let{issue:r,assignee:n}=e,o=[{op:"add",path:"/fields/System.AssignedTo",value:(n==null?void 0:n.name)??""}];if(!((a=(await this.updateIssue(r,o,t)).body.fields)!=null&&a["System.State"]))throw new Error("Could not set issue assignee")}async setIssueLabels(e,t={}){var u;let{issue:r,labels:n}=e,i=[{op:"replace",path:"/fields/System.Tags",value:n.map(l=>l.name).join(";")}];if(!((u=(await this.updateIssue(r,i,t)).body.fields)!=null&&u["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:n}=e;return{data:(await this.config.request({url:`${t.baseUrl||q}/${encodeURIComponent(r)}/${encodeURIComponent(n||"")}/_apis/wit/workitemtypes?api-version=6.0`,headers:{...P(this.config,t)}})).body.value}}async getLabelsForProject(e,t={}){let{namespace:r,project:n}=e;return{data:(await this.config.request({url:`${t.baseUrl||q}/${encodeURIComponent(r)}/${encodeURIComponent(n||"")}/_apis/wit/tags?api-version=6.0`,headers:{...P(this.config,t)}})).body.value.map(i=>({color:null,description:null,id:i.id,name:i.name,url:i.url}))}}};var $=(s,e={})=>I(e.token||s.token,e.isPAT||s.isPAT);var x="https://api.bitbucket.org/2.0",xr={OPEN:"OPEN",MERGED:"MERGED",DECLINED:"CLOSED"},Yt=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}),Xt=s=>{var e,t;return{id:s.uuid,namespace:s.workspace.slug,name:s.slug,webUrl:s.links.html.href,httpsUrl:((e=s.links.clone.find(r=>r.name==="https"))==null?void 0:e.href)??null,sshUrl:((t=s.links.clone.find(r=>r.name==="ssh"))==null?void 0:t.href)??null,defaultBranch:{name:s.mainbranch.name},permission:null}},nt=s=>{let e=s.id;return{id:e.toString(),title:s.title,number:e,state:xr[s.state],isDraft:!1,commentCount:s.comment_count,upvoteCount:null,author:Yt(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:null},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:null,reviewDecision:null,additions:null,deletions:null,fileCount:null,commitCount:null,headRepository:null,mergeableState:"UNKNOWN",permissions:null}},re=class extends O{async refreshToken(e){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 ${e.base64ClientIDColonClientSecret}`},body:`grant_type=refresh_token&refresh_token=${e.refreshToken}`})).body}}async getCurrentUser(e={},t={}){let r=await this.config.request({url:`${x}/user`,headers:$(this.config,t)});return{data:Yt(r.body)}}async getUserForCommit(e,t={}){var i;let n=(await this.config.request({url:`${x}/repositories/${e.repo.namespace}/${e.repo.name}/commit/${e.oid}`,headers:$(this.config,t)})).body.author,o=n.raw.match(/([^<]+)<(.+)>/);return{data:{name:o?o[1].trim():null,email:o?o[2]:null,avatarUrl:((i=n.user)==null?void 0:i.links.avatar.href)||null}}}async getRepo(e,t={}){let r=await this.config.request({url:`${x}/repositories/${e.namespace}/${e.name}`,headers:$(this.config,t)});return{data:Xt(r.body)}}async getRepos(e,t={}){let r=[],n=[];return await Promise.all(e.map(async o=>{try{let i=await this.getRepo(o,t);r.push(i.data)}catch(i){n.push({input:o,error:i})}})),{data:r,errors:n}}async getReposForCurrentUser(e,t={}){let r=new URL(`${x}/repositories`);r.searchParams.set("role","member"),r.searchParams.set("pagelen",C.toString()),e.cursor&&r.searchParams.set("after",e.cursor);let n=await this.config.request({url:r.toString(),headers:$(this.config,t)}),o=!!n.body.next,i=null;return n.body.next&&(i=new URL(n.body.next).searchParams.get("after")),{pageInfo:{hasNextPage:o,endCursor:i},data:n.body.values.map(Xt)}}async getBranches(e,t={}){var i;let r=new URL(`${x}/repositories/${e.repo.namespace}/${e.repo.name}/refs/branches`);r.searchParams.set("page",((i=e.page)==null?void 0:i.toString())||"1"),r.searchParams.set("pagelen",C.toString());let n=await this.config.request({url:r.toString(),headers:$(this.config,t)}),o=!!n.body.next;return{pageInfo:{hasNextPage:o,nextPage:o?n.body.page+1:null},data:n.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 getTags(e,t={}){let r=new URL(`${x}/repositories/${e.repo.namespace}/${e.repo.name}/refs/tags`);r.searchParams.set("pagelen",C.toString()),e.cursor&&r.searchParams.set("page",e.cursor);let n=await this.config.request({url:r.toString(),headers:$(this.config,t)}),o=!!n.body.next,i=null;return n.body.next&&(i=new URL(n.body.next).searchParams.get("page")),{pageInfo:{hasNextPage:o,endCursor:i},data:n.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 getPullRequestsForUser(e,t={}){var i;let r=new URL(`${x}/pullrequests/${e.userId}`);r.searchParams.set("page",((i=e.page)==null?void 0:i.toString())||"1"),r.searchParams.set("pagelen","50");let n=await this.config.request({url:r.toString(),headers:$(this.config,t)}),o=!!n.body.next;return{pageInfo:{hasNextPage:o,nextPage:o?n.body.page+1:null},data:n.body.values.map(nt)}}async getPullRequestsForRepoBase(e,t={}){var n;let r=new URL(`${x}/repositories/${encodeURI(e.repo.namespace)}/${encodeURI(e.repo.name)}/pullrequests?state=OPEN`);return r.searchParams.set("page",((n=e.page)==null?void 0:n.toString())||"1"),r.searchParams.set("pagelen","50"),await this.config.request({url:r.toString(),headers:$(this.config,t)})}async getPullRequestsForRepo(e,t={}){let r=[],n=await this.getPullRequestsForRepoBase(e,t);n.body.values.forEach(i=>{if(e.authorLogin&&i.author.uuid!==e.authorLogin)return null;r.push(nt(i))});let o=!!n.body.next;return{pageInfo:{hasNextPage:o,nextPage:o?n.body.page+1:null},data:r}}async getPullRequestsForRepos(e,t={}){let r=[];return await Promise.all(e.repos.map(async n=>{try{(await this.getPullRequestsForRepoBase({repo:n,...e},t)).body.values.forEach(i=>{if(e.authorLogin&&i.author.uuid!==e.authorLogin)return null;r.push(nt(i))})}catch(o){if(o.statusCode!==404&&o.statusCode!==401)throw o}})),{data:r}}async closePullRequest(e,t={}){let{pullRequest:r}=e;if(!(await this.config.request({method:"POST",url:`${x}/repositories/${r.repository.owner.login}/${r.repository.name}/pullrequests/${r.id}/decline`,headers:$(this.config,t)})).body.title)throw new Error("Could not close pull request")}async mergePullRequest(e,t={}){let{pullRequest:r,mergeStrategy:n}=e,o;switch(n){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:`${x}/repositories/${r.repository.owner.login}/${r.repository.name}/pullrequests/${r.id}/merge`,body:JSON.stringify(i),headers:{...$(this.config,t),"Content-Type":"application/json"}})).body.title)throw new Error("Could not merge pull request")}async setPullRequestReviewers(e,t={}){let{pullRequest:r,reviewers:n}=e,o={reviewers:n.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:`${x}/repositories/${r.repository.owner.login}/${r.repository.name}/pullrequests/${r.id}`,body:JSON.stringify(o),headers:{...$(this.config,t),"Content-Type":"application/json"}})).body.title)throw new Error("Could not set pull request reviewers")}};var ot=s=>({name:s.displayName,email:s.emailAddress,avatarUrl:s.avatarUrl??null,id:s.id.toString(),username:s.name,url:s.links.self[0].href}),se=s=>{var u,l,p,d,c,g;let e={OPEN:"OPEN",MERGED:"MERGED",DECLINED:"CLOSED"},t={UNAPPROVED:"REVIEW_REQUESTED",NEEDS_WORK:"CHANGES_REQUESTED",APPROVED:"APPROVED"},r=s.reviewers.map(m=>({reviewer:ot(m.user),state:t[m.status]})),n=((u=s.toRef.repository.links.clone.find(m=>m.name==="ssh"))==null?void 0:u.href)??null,o=((l=s.toRef.repository.links.clone.find(m=>m.name==="https"))==null?void 0:l.href)??null;o||(o=((p=s.toRef.repository.links.clone.find(m=>m.name==="http"))==null?void 0:p.href)??null);let i=((d=s.fromRef.repository.links.clone.find(m=>m.name==="ssh"))==null?void 0:d.href)??null,a=((c=s.fromRef.repository.links.clone.find(m=>m.name==="https"))==null?void 0:c.href)??null;return a||(a=((g=s.fromRef.repository.links.clone.find(m=>m.name==="http"))==null?void 0:g.href)??null),{id:s.id.toString(),number:s.id,title:s.title,url:s.links.self[0].href,state:e[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:ot(s.author.user),assignees:null,reviews:r,reviewDecision:H(r),repository:{id:s.toRef.repository.id.toString(),name:s.toRef.repository.name,owner:{login:s.toRef.repository.project.key},remoteInfo:o&&n?{cloneUrlHTTPS:o,cloneUrlSSH:n}: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:"UNKNOWN",permissions:null,version:s.version}},Zt=s=>{var e,t,r;return{id:s.id.toString(),namespace:s.project.key,name:s.slug,webUrl:((e=s.links.self[0])==null?void 0:e.href)??null,httpsUrl:((t=s.links.clone.find(n=>n.name==="https"))==null?void 0:t.href)??null,sshUrl:((r=s.links.clone.find(n=>n.name==="ssh"))==null?void 0:r.href)??null,defaultBranch:null,permission:null}},ne=class extends _{getBaseUrl(e){let t=e.baseUrl||this.config.baseUrl;if(!t)throw new Error('Bitbucket Server requires "baseUrl"');return t}getRequestHeaders(e){return I(e.token||this.config.token)}async getCurrentUser(e={},t={}){let r=await this.config.request({url:`${this.getBaseUrl(t)}/users?limit=2`,headers:this.getRequestHeaders(t)}),{headers:{"x-auserid":n,"x-ausername":o}}=r,i=n?parseInt(n,10):null,a=decodeURIComponent(o),l=(await this.config.request({url:`${this.getBaseUrl(t)}/users?filter=${o}&avatarSize=64`,headers:this.getRequestHeaders(t)})).body.values.find(({emailAddress:p,id:d,name:c,slug:g})=>i?i===d:a===c||a===p||a===g);if(!l)throw new Error("Could not find current Bitbucket Server user");return{data:ot(l)}}async getRepo(e,t={}){let r=await this.config.request({url:`${this.getBaseUrl(t)}/projects/${e.namespace}/repos/${e.name}`,headers:this.getRequestHeaders(t)});return{data:Zt(r.body)}}async getRepos(e,t={}){let r=[],n=[];return await Promise.all(e.map(async o=>{try{let i=await this.getRepo(o,t);r.push(i.data)}catch(i){n.push({input:o,error:i})}})),{data:r,errors:n}}async getReposForCurrentUser(e,t={}){let r=e.page??0,n=await this.config.request({url:`${this.getBaseUrl(t)}/repos?start=${r}`,headers:this.getRequestHeaders(t)});return{pageInfo:{hasNextPage:!n.body.isLastPage,nextPage:n.body.nextPageStart},data:n.body.values.map(Zt)}}async getPullRequestsForRepoBase(e,t={}){var n;let r=new URL(`${this.getBaseUrl(t)}/projects/${encodeURI(e.repo.namespace)}/repos/${encodeURI(e.repo.name)}/pull-requests?state=OPEN`);return r.searchParams.set("start",((n=e.page)==null?void 0:n.toString())||"0"),r.searchParams.set("limit","50"),await this.config.request({url:r.toString(),headers:this.getRequestHeaders(t)})}async getPullRequestsForRepo(e,t={}){let r=[],n=await this.getPullRequestsForRepoBase(e,t);n.body.values.forEach(i=>{if(e.authorLogin&&i.author.user.name!==e.authorLogin)return null;r.push(se(i))});let o=n.body.values.length!==0;return{pageInfo:{hasNextPage:o,nextPage:o?n.body.start+n.body.values.length:null},data:r}}async getPullRequestsForRepos(e,t={}){let r=[];return await Promise.all(e.repos.map(async n=>{try{(await this.getPullRequestsForRepoBase({repo:n,...e},t)).body.values.forEach(i=>{if(e.authorLogin&&i.author.user.name!==e.authorLogin)return null;r.push(se(i))})}catch(o){if(o.statusCode!==404&&o.statusCode!==401)throw o}})),{data:r}}async getPullRequestsForCurrentUser(e,t={}){var i;let r=new URL(`${this.getBaseUrl(t)}/dashboard/pull-requests`);r.searchParams.set("state","OPEN"),r.searchParams.set("start",((i=e.page)==null?void 0:i.toString())||"0"),r.searchParams.set("limit","50");let n=await this.config.request({url:r.toString(),headers:this.getRequestHeaders(t)}),o=n.body.values.length!==0;return{pageInfo:{hasNextPage:o,nextPage:o?n.body.start+n.body.values.length:null},data:n.body.values.map(se)}}async closePullRequest(e,t={}){let{pullRequest:r}=e;if(r.version===void 0)throw new Error('Bitbucket Server requires "version" for this function.');if(!(await this.config.request({method:"POST",url:`${this.getBaseUrl(t)}/projects/${r.repository.owner.login}/repos/${r.repository.name}/pull-requests/${r.id}/decline`,body:JSON.stringify({version:r.version}),headers:{...this.getRequestHeaders(t),"Content-Type":"application/json"}})).body.title)throw new Error("Could not close pull request")}async mergePullRequest(e,t={}){let{pullRequest:r,mergeStrategyId:n}=e;if(e.mergeStrategy)throw new Error('Bitbucket Server uses "mergeStrategyId" instead of "mergeStrategy".');if(r.version===void 0)throw new Error('Bitbucket Server requires "version" for this function.');if(!(await this.config.request({method:"POST",url:`${this.getBaseUrl(t)}/projects/${r.repository.owner.login}/repos/${r.repository.name}/pull-requests/${r.id}/merge`,body:JSON.stringify({strategyId:n,version:r.version}),headers:{...this.getRequestHeaders(t),"Content-Type":"application/json"}})).body.title)throw new Error("Could not merge pull request")}async getMergeStrategies(e={}){let t=await this.config.request({url:`${this.getBaseUrl(e)}/admin/pull-requests/git`,headers:{...this.getRequestHeaders(e),"Content-Type":"application/json"}});return{data:{defaultStrategy:t.body.mergeConfig.defaultStrategy,strategies:t.body.mergeConfig.strategies}}}async setPullRequestReviewers(e,t={}){let{pullRequest:r,reviewers:n}=e;if(r.version===void 0)throw new Error('Bitbucket Server requires "version" for this function.');let o={reviewers:n.map(a=>{if(a.username)throw new Error('Bitbucket Server reviewer requires "username" for this function.');return{user:{name:a.username}}}),version:r.version};if(!(await this.config.request({method:"PUT",url:`${this.getBaseUrl(t)}/projects/${r.repository.owner.login}/repos/${r.repository.name}/pull-requests/${r.id}`,body:JSON.stringify(o),headers:{...this.getRequestHeaders(t),"Content-Type":"application/json"}})).body.title)throw new Error("Could not set pull request reviewers")}};var or=require("js-base64");var he=(t=>(t.Open="OPEN",t.Closed="CLOSED",t))(he||{});var kr={AS_CODE_OWNER:[3,0,0],CHECK_RUN:[3,0,0],LATEST_REVIEWS:[3,0,0],VIEWER_CAN_MERGE_AS_ADMIN:[3,5,0]},er=15,tr=100,D=s=>!!s,fe=(s,e)=>{let t=kr[e];for(let r=0;r<3;r++){if(s[r]>t[r])return!0;if(s[r]<t[r])return!1}return!0},Re="https://api.github.com",Nr=`${Re}/graphql`,ye=`
2
2
  description
3
3
  dueOn
4
4
  id
@@ -6,7 +6,7 @@ number
6
6
  state
7
7
  title
8
8
  url
9
- `,xr=`
9
+ `,_r=`
10
10
  ... on CheckRun {
11
11
  completedAt
12
12
  conclusion
@@ -15,39 +15,39 @@ url
15
15
  permalink
16
16
  startedAt
17
17
  }
18
- `,fe=/\/api\/v\d+$/,ye=`
18
+ `,Ie=/\/api\/v\d+$/,be=`
19
19
  color
20
20
  description
21
21
  id
22
22
  name
23
- `,Zt=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.")},kr=(s,e)=>{let t=e.baseUrl||s.baseUrl;return t?(t=t.replace(/\/$/,""),Zt(t),fe.test(t)&&(t=t.replace(fe,"")),`${t}/api/graphql`):Or},ot=(s,e)=>{let t=e.baseUrl||s.baseUrl;return t?(t=t.replace(/\/$/,""),Zt(t),fe.test(t)&&(t=t.replace(fe,"")),`${t}/api/v3`):Ie},R=(s,e,t)=>{let r=f(t.token||s.token);return r["X-Github-Next-Global-ID"]="1",r["Content-Type"]="application/json",r.Accept="application/vnd.github.merge-info-preview+json",s.request({url:kr(s,t),method:"POST",headers:r,body:JSON.stringify(e)})},Nr={user:!0,"user:email":!0,"read:user":!0},B=s=>s.some(e=>Nr[e]),$=(s=!1,e=!1,t)=>`
23
+ `,rr=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.")},Qr=(s,e)=>{let t=e.baseUrl||s.baseUrl;return t?(t=t.replace(/\/$/,""),rr(t),Ie.test(t)&&(t=t.replace(Ie,"")),`${t}/api/graphql`):Nr},it=(s,e)=>{let t=e.baseUrl||s.baseUrl;return t?(t=t.replace(/\/$/,""),rr(t),Ie.test(t)&&(t=t.replace(Ie,"")),`${t}/api/v3`):Re},y=(s,e,t)=>{let r=I(t.token||s.token);return r["X-Github-Next-Global-ID"]="1",r["Content-Type"]="application/json",r.Accept="application/vnd.github.merge-info-preview+json",s.request({url:Qr(s,t),method:"POST",headers:r,body:JSON.stringify(e)})},Br={user:!0,"user:email":!0,"read:user":!0},j=s=>s.some(e=>Br[e]),G=(s=!1,e=!1,t)=>`
24
24
  __typename
25
- ${H(t,["graphQLId"],"id")}
26
- ${H(t,["id"],"databaseId")}
27
- ${H(t,["name"],"name")}
28
- ${H(t,["name","username"],"login")}
29
- ${e?H(t,["email"],"email"):""}
30
- ${H(t,["avatarUrl"],`avatarUrl${s?"(size: $avatarSize)":""}`)}
31
- ${H(t,["url"],"url")}
32
- `,_r=(s=!1)=>`
25
+ ${W(t,["graphQLId"],"id")}
26
+ ${W(t,["id"],"databaseId")}
27
+ ${W(t,["name"],"name")}
28
+ ${W(t,["name","username"],"login")}
29
+ ${e?W(t,["email"],"email"):""}
30
+ ${W(t,["avatarUrl"],`avatarUrl${s?"(size: $avatarSize)":""}`)}
31
+ ${W(t,["url"],"url")}
32
+ `,jr=(s=!1)=>`
33
33
  latestReviews(first: 100) {
34
34
  nodes {
35
35
  author {
36
36
  ... on User {
37
- ${$(!1,s)}
37
+ ${G(!1,s)}
38
38
  }
39
39
  }
40
40
  state
41
41
  }
42
42
  }
43
- `,er=(s=!1)=>`
43
+ `,sr=(s=!1)=>`
44
44
  __typename
45
45
  id
46
46
  databaseId
47
47
  login
48
48
  avatarUrl${s?"(size: $avatarSize)":""}
49
49
  url
50
- `,be=(s,e=!1,t)=>`
50
+ `,we=(s,e=!1,t)=>`
51
51
  id
52
52
  databaseId
53
53
  number
@@ -55,10 +55,10 @@ title
55
55
  state
56
56
  author {
57
57
  ... on User {
58
- ${$(!1,e)}
58
+ ${G(!1,e)}
59
59
  }
60
60
  ... on Bot {
61
- ${er(!1)}
61
+ ${sr(!1)}
62
62
  }
63
63
  }
64
64
  commits(last: 1) {
@@ -71,7 +71,7 @@ commits(last: 1) {
71
71
  contexts(first: 100) {
72
72
  totalCount
73
73
  nodes {
74
- ${!t||he(t,"CHECK_RUN")?xr:""}
74
+ ${!t||fe(t,"CHECK_RUN")?_r:""}
75
75
  ... on StatusContext {
76
76
  context
77
77
  createdAt
@@ -133,44 +133,44 @@ closedAt
133
133
  mergedAt
134
134
  assignees(first: 100) {
135
135
  nodes {
136
- ${$(!1,e)}
136
+ ${G(!1,e)}
137
137
  }
138
138
  }
139
139
  reviewRequests(first: 100) {
140
140
  nodes {
141
- ${!t||he(t,"AS_CODE_OWNER")?"asCodeOwner":""}
141
+ ${!t||fe(t,"AS_CODE_OWNER")?"asCodeOwner":""}
142
142
  requestedReviewer {
143
143
  ... on User {
144
- ${$(!1,e)}
144
+ ${G(!1,e)}
145
145
  }
146
146
  }
147
147
  }
148
148
  }
149
- ${!t||he(t,"LATEST_REVIEWS")?_r(e):""}
149
+ ${!t||fe(t,"LATEST_REVIEWS")?jr(e):""}
150
150
  additions
151
151
  deletions
152
152
  changedFiles
153
153
  mergeable
154
154
  mergeStateStatus
155
155
  milestone {
156
- ${Re}
156
+ ${ye}
157
157
  }
158
158
  labels(first: 100) {
159
159
  nodes {
160
- ${ye}
160
+ ${be}
161
161
  }
162
162
  }
163
- ${!t||he(t,"VIEWER_CAN_MERGE_AS_ADMIN")?"viewerCanMergeAsAdmin":""}
164
- `,Qr=(s=!1)=>`
163
+ ${!t||fe(t,"VIEWER_CAN_MERGE_AS_ADMIN")?"viewerCanMergeAsAdmin":""}
164
+ `,Fr=(s=!1)=>`
165
165
  id
166
166
  databaseId
167
167
  title
168
168
  author {
169
169
  ... on User {
170
- ${$(!1,s)}
170
+ ${G(!1,s)}
171
171
  }
172
172
  ... on Bot {
173
- ${er(!1)}
173
+ ${sr(!1)}
174
174
  }
175
175
  }
176
176
  closedAt
@@ -194,39 +194,39 @@ comments {
194
194
  }
195
195
  assignees(first: 100) {
196
196
  nodes {
197
- ${$(!1,s)}
197
+ ${G(!1,s)}
198
198
  }
199
199
  }
200
200
  state
201
201
  milestone {
202
- ${Re}
202
+ ${ye}
203
203
  }
204
204
  labels(first: 100) {
205
205
  nodes {
206
- ${ye}
206
+ ${be}
207
207
  }
208
208
  }
209
- `,Br={"-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"},jr=new RegExp('(([^\\s]+:)?\\"(?:[^\\"\\\\]|\\\\.)*\\"?)|([^\\"\\s]+)',"g"),it=s=>{let e=[];return(s.match(jr)??[]).forEach(r=>{if(r.includes(":")&&r!="is:closed"){let n=r.split(":")[0];Br[n]&&e.push(r)}}),e},at=(s,e,t,r)=>{let n=s==="issue";return{query:`
209
+ `,Mr={"-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"},zr=new RegExp('(([^\\s]+:)?\\"(?:[^\\"\\\\]|\\\\.)*\\"?)|([^\\"\\s]+)',"g"),at=s=>{let e=[];return(s.match(zr)??[]).forEach(r=>{if(r.includes(":")&&r!="is:closed"){let n=r.split(":")[0];Mr[n]&&e.push(r)}}),e},ut=(s,e,t,r)=>{let n=s==="issue";return{query:`
210
210
  query SearchIssuesOrPullRequests($query: String! $after: String) {
211
- search(type:ISSUE query:$query first:100 after:$after) {
211
+ search(type:ISSUE query:$query first: ${r.maxPageSize} after:$after) {
212
212
  pageInfo {
213
213
  hasNextPage
214
214
  endCursor
215
215
  }
216
216
  nodes {
217
217
  ... on ${n?"Issue":"PullRequest"} {
218
- ${n?Qr(r.supportsEmail):be(r.supportsDrafts??!1,r.supportsEmail,r.enterpriseVersion??null)}
218
+ ${n?Fr(r.supportsEmail):we(r.supportsDrafts??!1,r.supportsEmail,r.enterpriseVersion??null)}
219
219
  }
220
220
  }
221
221
  }
222
- }`,variables:{query:`is:${s} is:open ${r.includeFromArchivedRepos?"":"archived:false"} ${e}`,after:t}}},Fr="Field 'isDraft' doesn't exist on type 'PullRequest'",we=(s=[])=>s.some(e=>(e==null?void 0:e.message)===Fr),Mr=/@@ -(\d+)(?:,\d+ | )\+(\d+)(?:,\d+ | )@@(?:\\n)?/,zr=`
222
+ }`,variables:{query:`is:${s} is:open ${r.includeFromArchivedRepos?"":"archived:false"} ${e}`,after:t}}},Hr="Field 'isDraft' doesn't exist on type 'PullRequest'",Pe=(s=[])=>s.some(e=>(e==null?void 0:e.message)===Hr),Wr=/@@ -(\d+)(?:,\d+ | )\+(\d+)(?:,\d+ | )@@(?:\\n)?/,Jr=`
223
223
  \
224
- +`,tr=(s,e,t,r)=>{let n=Mr.exec(s);if(!n||!n[0]||!n[1])return[];let o=parseInt(n[1],10),i=parseInt(n[2],10),a=s.replace(zr,`
224
+ +`,nr=(s,e,t,r)=>{let n=Wr.exec(s);if(!n||!n[0]||!n[1])return[];let o=parseInt(n[1],10),i=parseInt(n[2],10),a=s.replace(Jr,`
225
225
  +`).split(`
226
- `).slice(1),u=o-1,l=i-1,p=a.map(g=>{let m,I;switch(g[0]){case"-":{m="DELETED",u+=1,I=`${g.slice(1)}
227
- `;break}case"+":{m="ADDED",l+=1,I=`${g.slice(1)}
228
- `;break}default:m="UNMODIFIED",l+=1,u+=1,I=`${g}
229
- `}return{line:I,oldLineNumber:m!=="ADDED"?u:null,newLineNumber:m!=="DELETED"?l:null,type:m}}),d=t,c=e;if(d!==null&&c!==null&&r!==null&&d<c){let g=0,m=p.length,I=r==="LEFT"?"oldLineNumber":"newLineNumber";for(let w=0;w<p.length;w++){let y=p[w][I];y===d?g=w:y===c&&(m=w)}p=p.slice(g,m+1)}return p};var ut=`
226
+ `).slice(1),u=o-1,l=i-1,p=a.map(g=>{let m,h;switch(g[0]){case"-":{m="DELETED",u+=1,h=`${g.slice(1)}
227
+ `;break}case"+":{m="ADDED",l+=1,h=`${g.slice(1)}
228
+ `;break}default:m="UNMODIFIED",l+=1,u+=1,h=`${g}
229
+ `}return{line:h,oldLineNumber:m!=="ADDED"?u:null,newLineNumber:m!=="DELETED"?l:null,type:m}}),d=t,c=e;if(d!==null&&c!==null&&r!==null&&d<c){let g=0,m=p.length,h=r==="LEFT"?"oldLineNumber":"newLineNumber";for(let R=0;R<p.length;R++){let f=p[R][h];f===d?g=R:f===c&&(m=R)}p=p.slice(g,m+1)}return p};var lt=`
230
230
  id
231
231
  databaseId
232
232
  owner {
@@ -239,18 +239,18 @@ defaultBranchRef {
239
239
  name
240
240
  }
241
241
  viewerPermission
242
- `,dt={__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"},Hr={APPROVED:"APPROVED",CHANGES_REQUESTED:"CHANGES_REQUESTED",COMMENTED:"COMMENTED",REVIEW_REQUESTED:"REVIEW_REQUESTED"},Wr={MERGEABLE:"MERGEABLE",CONFLICTING:"CONFLICTS",UNKNOWN:"UNKNOWN"},Jr={BEHIND:"BEHIND",BLOCKED:"BLOCKED",UNKNOWN:"UNKNOWN_AND_BLOCKED",UNSTABLE:"UNSTABLE",CLEAN:null,DIRTY:null,DRAFT:null,HAS_HOOKS:null},Vr={OPEN:"OPEN",CLOSED:"CLOSED"},Kr=["ADMIN","MAINTAIN","TRIAGE","WRITE"],ct=s=>({color:s.color,description:s.description,graphQLId:s.id,id:null,name:s.name}),lt=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,permission:s.viewerPermission}),Xr={OPEN:"OPEN",CLOSED:"CLOSED",MERGED:"MERGED"},Yr={id:!0,graphQLId:!0,name:!0,username:!0,email:!0,avatarUrl:!0,url:!0},x=(s,e=Yr)=>{let t={};return e.id&&(t.id=s.databaseId.toString()),e.graphQLId&&(t.graphQLId=s.id),e.name&&(t.name=s.name??s.login),e.username&&(t.username=s.login),e.email&&(t.email=s.email??null),e.avatarUrl&&(t.avatarUrl=s.avatarUrl),e.url&&(t.url=s.url),t},Zr=(s,e)=>{let t={IN_PROGRESS:"RUNNING",PENDING:"PENDING",QUEUED:"PENDING",REQUESTED:"PENDING",WAITING:"PENDING"};return s!=="COMPLETED"?t[s]:{ACTION_REQUIRED:"ACTION_REQUIRED",CANCELLED:"CANCELLED",FAILURE:"FAILED",NEUTRAL:null,SKIPPED:"SKIPPED",STALE:"FAILED",STARTUP_FAILURE:"FAILED",SUCCESS:"SUCCESS",TIMED_OUT:"ERROR"}[e]},es=s=>({ERROR:"ERROR",EXPECTED:"PENDING",FAILURE:"FAILED",PENDING:"PENDING",SUCCESS:"SUCCESS"})[s],pt=s=>{var i,a,u,l,p,d,c,g,m,I,w;let e=null;s.author?e=(s.author.__typename==="Bot",s.author):e=dt;let t=(((i=s.reviewRequests)==null?void 0:i.nodes)||[]).filter(h=>!h.asCodeOwner),r=(a=s.headRepository)==null?void 0:a.url;r&&!r.endsWith(".git")&&(r=`${r}.git`);let n=(u=s.repository)==null?void 0:u.url;n&&!n.endsWith(".git")&&(n=`${n}.git`);let o=t.filter(h=>h.requestedReviewer&&"__typename"in h.requestedReviewer).map(h=>({reviewer:x(h.requestedReviewer),state:"REVIEW_REQUESTED"})).concat((((l=s.latestReviews)==null?void 0:l.nodes)||[]).map(h=>{let y=dt;return h.author&&Object.keys(h.author).length>0&&(y=h.author),{reviewer:x(y),state:Hr[h.state]}}));return{id:s.databaseId.toString(),graphQLId:s.id,title:s.title,number:s.number,state:Xr[s.state],commentCount:s.comments.totalCount,upvoteCount:s.reactions.totalCount,author:e?x(e):null,createdDate:new Date(s.createdAt),isDraft:s.isDraft,repository:{id:s.repository.databaseId,graphQLId:s.repository.id,name:s.repository.name,owner:{login:s.repository.owner.login},remoteInfo:{cloneUrlHTTPS:n,cloneUrlSSH:s.repository.sshUrl}},headRepository:s.headRepository?{id:s.headRepository.databaseId,graphQLId:s.headRepository.id,name:s.headRepository.name,owner:{login:s.headRepository.owner.login},remoteInfo:{cloneUrlHTTPS:r,cloneUrlSSH:s.headRepository.sshUrl}}:null,headCommit:{buildStatuses:((c=(d=(p=s.commits.nodes)==null?void 0:p[0].commit.statusCheckRollup)==null?void 0:d.contexts.nodes)==null?void 0:c.map(h=>"context"in h?{completedAt:null,description:h.description,name:h.context,state:es(h.state),startedAt:new Date(h.createdAt),stage:null,url:h.targetUrl}:{completedAt:h.completedAt?new Date(h.completedAt):null,description:null,name:h.name,state:Zr(h.status,h.conclusion),startedAt:h.startedAt?new Date(h.startedAt):null,stage:null,url:h.permalink}))??[]},headRef:s.headRef?{name:s.headRef.name,oid:((g=s.headRef.target)==null?void 0:g.oid)??null}:null,baseRef:s.baseRef?{name:s.baseRef.name,oid:((m=s.baseRef.target)==null?void 0:m.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.map(h=>x(h)):null,reviews:o,reviewDecision:z(o),additions:s.additions,deletions:s.deletions,fileCount:s.changedFiles,commitCount:s.commits.totalCount,mergeableState:Jr[s.mergeStateStatus]??Wr[s.mergeable],milestone:s.milestone?gt(s.milestone):null,labels:((w=(I=s.labels)==null?void 0:I.nodes)==null?void 0:w.map(ct))??[],permissions:{canMerge:Kr.includes(s.repository.viewerPermission),canMergeAndBypassProtections:s.viewerCanMergeAsAdmin??!1}}},ts=s=>{let{comments:e,isOutdated:t,isResolved:r,originalLine:n,originalStartLine:o,startDiffSide:i}=s,{author:a,body:u,databaseId:l,id:p,path:d,publishedAt:c,url:g}=e.nodes[0];return{author:a?{avatarUrl:a.avatarUrl,email:null,name:a.login}:null,body:u,createdAt:c?new Date(c):null,diffLines:tr(e.nodes[0].diffHunk,n,o,i),id:l,isOutdated:t,isResolved:r,graphQLId:p,filename:d,replies:e.nodes.slice(1).map(rs),url:g}},rs=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.databaseId,url:s.url}),ss=s=>{var t,r;let e=null;return s.author?e=(s.author.__typename==="Bot",s.author):e=dt,{id:s.databaseId.toString(),graphQLId:s.id,number:s.number,title:s.title,author:x(e),commentCount:s.comments.totalCount,closedDate:s.closedAt?new Date(s.closedAt):null,createdDate:new Date(s.createdAt),description:null,state:{name:Vr[s.state],color:null},type:null,repository:{id:s.repository.databaseId,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?s.assignees.nodes.map(n=>x(n)):[],upvoteCount:s.reactions.totalCount,milestone:s.milestone?gt(s.milestone):null,labels:((r=(t=s.labels)==null?void 0:t.nodes)==null?void 0:r.map(ct))??[]}},gt=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}),ne=class extends N{constructor(){super(...arguments);this._scopesCache={};this._enterpriseVersionsCache={}}async getScopes(t){let r=t.token||this.config.token;if(!r)return[];let n=this._scopesCache[r];if(!n){let i=(await R(this.config,{query:"query { rateLimit(dryRun: true) { __typename } }"},t)).headers["x-oauth-scopes"];n=i?i.split(", "):[],this._scopesCache[r]=n}return n}async getEnterpriseVersion(t){let r=t.baseUrl||this.config.baseUrl;if(!r)return null;let n=this._enterpriseVersionsCache[r];if(!n){let o=await this.config.request({url:`${ot(this.config,t)}/meta`,headers:f(t.token||this.config.token)});if(!o.body.installed_version)return null;n=o.body.installed_version.split(".").slice(0,3).map(i=>parseInt(i,10)),this._enterpriseVersionsCache[r]=n}return n}getEnterpriseAvatarUrlIfNeeded(t,r,n){let o=n.baseUrl||this.config.baseUrl;return!o||o.startsWith(Ie)?t:r?`https://avatars.githubusercontent.com/u/e?email=${encodeURIComponent(r)}`:""}async getCurrentUser(t={},r={}){var u;if(t.fields&&!t.fields.length)throw new Error('"fields" must contain at least one field or be omitted');let n=zt(t.fields),o=await this.getScopes(r),a=(u=(await R(this.config,{query:`
242
+ `,ct={__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"},Vr={APPROVED:"APPROVED",CHANGES_REQUESTED:"CHANGES_REQUESTED",COMMENTED:"COMMENTED",REVIEW_REQUESTED:"REVIEW_REQUESTED"},Kr={MERGEABLE:"MERGEABLE",CONFLICTING:"CONFLICTS",UNKNOWN:"UNKNOWN"},Xr={BEHIND:"BEHIND",BLOCKED:"BLOCKED",UNKNOWN:"UNKNOWN_AND_BLOCKED",UNSTABLE:"UNSTABLE",CLEAN:null,DIRTY:null,DRAFT:null,HAS_HOOKS:null},Yr={OPEN:"OPEN",CLOSED:"CLOSED"},Zr=["ADMIN","MAINTAIN","TRIAGE","WRITE"],gt=s=>({color:`#${s.color}`,description:s.description,graphQLId:s.id,id:null,name:s.name}),pt=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,permission:s.viewerPermission}),es={OPEN:"OPEN",CLOSED:"CLOSED",MERGED:"MERGED"},ts={id:!0,graphQLId:!0,name:!0,username:!0,email:!0,avatarUrl:!0,url:!0},k=(s,e=ts)=>{let t={};return e.id&&(t.id=s.databaseId.toString()),e.graphQLId&&(t.graphQLId=s.id),e.name&&(t.name=s.name??s.login),e.username&&(t.username=s.login),e.email&&(t.email=s.email??null),e.avatarUrl&&(t.avatarUrl=s.avatarUrl),e.url&&(t.url=s.url),t},rs=(s,e)=>{let t={IN_PROGRESS:"RUNNING",PENDING:"PENDING",QUEUED:"PENDING",REQUESTED:"PENDING",WAITING:"PENDING"};return s!=="COMPLETED"?t[s]:{ACTION_REQUIRED:"ACTION_REQUIRED",CANCELLED:"CANCELLED",FAILURE:"FAILED",NEUTRAL:null,SKIPPED:"SKIPPED",STALE:"FAILED",STARTUP_FAILURE:"FAILED",SUCCESS:"SUCCESS",TIMED_OUT:"ERROR"}[e]},ss=s=>({ERROR:"ERROR",EXPECTED:"PENDING",FAILURE:"FAILED",PENDING:"PENDING",SUCCESS:"SUCCESS"})[s],dt=s=>{var i,a,u,l,p,d,c,g,m,h,R,w;let e=null;s.author?e=(s.author.__typename==="Bot",s.author):e=ct;let t=(((i=s.reviewRequests)==null?void 0:i.nodes)||[]).filter(D).filter(f=>!f.asCodeOwner),r=(a=s.headRepository)==null?void 0:a.url;r&&!r.endsWith(".git")&&(r=`${r}.git`);let n=(u=s.repository)==null?void 0:u.url;n&&!n.endsWith(".git")&&(n=`${n}.git`);let o=t.filter(f=>f.requestedReviewer&&"__typename"in f.requestedReviewer).map(f=>({reviewer:k(f.requestedReviewer),state:"REVIEW_REQUESTED"})).concat((((l=s.latestReviews)==null?void 0:l.nodes)||[]).filter(D).map(f=>{let E=ct;return f.author&&Object.keys(f.author).length>0&&(E=f.author),{reviewer:k(E),state:Vr[f.state]}}));return{id:s.databaseId.toString(),graphQLId:s.id,title:s.title,number:s.number,state:es[s.state],commentCount:s.comments.totalCount,upvoteCount:s.reactions.totalCount,author:e?k(e):null,createdDate:new Date(s.createdAt),isDraft:s.isDraft,repository:{id:s.repository.databaseId,graphQLId:s.repository.id,name:s.repository.name,owner:{login:s.repository.owner.login},remoteInfo:{cloneUrlHTTPS:n,cloneUrlSSH:s.repository.sshUrl}},headRepository:s.headRepository?{id:s.headRepository.databaseId,graphQLId:s.headRepository.id,name:s.headRepository.name,owner:{login:s.headRepository.owner.login},remoteInfo:{cloneUrlHTTPS:r,cloneUrlSSH:s.headRepository.sshUrl}}:null,headCommit:{buildStatuses:((g=(c=(d=(p=s.commits.nodes)==null?void 0:p.filter(D)[0])==null?void 0:d.commit.statusCheckRollup)==null?void 0:c.contexts.nodes)==null?void 0:g.filter(D).map(f=>"context"in f?{completedAt:null,description:f.description,name:f.context,state:ss(f.state),startedAt:new Date(f.createdAt),stage:null,url:f.targetUrl}:{completedAt:f.completedAt?new Date(f.completedAt):null,description:null,name:f.name,state:rs(f.status,f.conclusion),startedAt:f.startedAt?new Date(f.startedAt):null,stage:null,url:f.permalink}))??[]},headRef:s.headRef?{name:s.headRef.name,oid:((m=s.headRef.target)==null?void 0:m.oid)??null}:null,baseRef:s.baseRef?{name:s.baseRef.name,oid:((h=s.baseRef.target)==null?void 0:h.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(D).map(f=>k(f)):null,reviews:o,reviewDecision:H(o),additions:s.additions,deletions:s.deletions,fileCount:s.changedFiles,commitCount:s.commits.totalCount,mergeableState:Xr[s.mergeStateStatus]??Kr[s.mergeable],milestone:s.milestone?mt(s.milestone):null,labels:((w=(R=s.labels)==null?void 0:R.nodes)==null?void 0:w.filter(D).map(gt))??[],permissions:{canMerge:Zr.includes(s.repository.viewerPermission),canMergeAndBypassProtections:s.viewerCanMergeAsAdmin??!1}}},ns=s=>{var h,R;let{comments:e,isOutdated:t,isResolved:r,originalLine:n,originalStartLine:o,startDiffSide:i}=s,a=(h=e.nodes)==null?void 0:h[0];if(!a)return null;let{author:u,body:l,databaseId:p,id:d,path:c,publishedAt:g,url:m}=a;return{author:u?{avatarUrl:u.avatarUrl,email:null,name:u.login}:null,body:l,createdAt:g?new Date(g):null,diffLines:nr(a.diffHunk,n,o,i),id:p,isOutdated:t,isResolved:r,graphQLId:d,filename:c,replies:((R=e.nodes)==null?void 0:R.filter(D).slice(1).map(os))??[],url:m}},os=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.databaseId,url:s.url}),is=s=>{var t,r,n;let e=null;return s.author?e=(s.author.__typename==="Bot",s.author):e=ct,{id:s.databaseId.toString(),graphQLId:s.id,number:s.number,title:s.title,author:k(e),commentCount:s.comments.totalCount,closedDate:s.closedAt?new Date(s.closedAt):null,createdDate:new Date(s.createdAt),description:null,state:{name:Yr[s.state],color:null},type:null,repository:{id:s.repository.databaseId,graphQLId:s.repository.id,name:s.repository.name,owner:{login:s.repository.owner.login}},url:s.url,updatedDate:new Date(s.updatedAt),assignees:((t=s.assignees.nodes)==null?void 0:t.filter(D).map(o=>k(o)))??[],upvoteCount:s.reactions.totalCount,milestone:s.milestone?mt(s.milestone):null,labels:((n=(r=s.labels)==null?void 0:r.nodes)==null?void 0:n.filter(D).map(gt))??[]}},mt=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}),oe=class extends _{constructor(){super(...arguments);this._scopesCache={};this._enterpriseVersionsCache={}}async getScopes(t){let r=t.token||this.config.token;if(!r)return[];let n=this._scopesCache[r];if(!n){let i=(await y(this.config,{query:"query { rateLimit(dryRun: true) { __typename } }"},t)).headers["x-oauth-scopes"];n=i?i.split(", "):[],this._scopesCache[r]=n}return n}async getEnterpriseVersion(t){let r=t.baseUrl||this.config.baseUrl;if(!r)return null;let n=this._enterpriseVersionsCache[r];if(!n){let o=await this.config.request({url:`${it(this.config,t)}/meta`,headers:I(t.token||this.config.token)});if(!o.body.installed_version)return null;n=o.body.installed_version.split(".").slice(0,3).map(i=>parseInt(i,10)),this._enterpriseVersionsCache[r]=n}return n}getEnterpriseAvatarUrlIfNeeded(t,r,n){let o=n.baseUrl||this.config.baseUrl;return!o||o.startsWith(Re)?t:r?`https://avatars.githubusercontent.com/u/e?email=${encodeURIComponent(r)}`:""}async getCurrentUser(t={},r={}){var u;if(t.fields&&!t.fields.length)throw new Error('"fields" must contain at least one field or be omitted');let n=Ht(t.fields),o=await this.getScopes(r),a=(u=(await y(this.config,{query:`
243
243
  query getCurrentUser {
244
244
  viewer {
245
- ${$(!1,B(o),n)}
245
+ ${G(!1,j(o),n)}
246
246
  }
247
247
  }
248
- `},r)).body.data)==null?void 0:u.viewer;if(!a)throw new Error("Current user not found.");return{data:x(a,n)}}async getAccountsForRepo(t,r={}){var l,p,d,c,g,m;let n=await this.getScopes(r),{repo:{namespace:o,name:i},cursor:a}=t,u=await R(this.config,{query:`
248
+ `},r)).body.data)==null?void 0:u.viewer;if(!a)throw new Error("Current user not found.");return{data:k(a,n)}}async getAccountsForRepo(t,r={}){var l,p,d,c,g,m;let n=await this.getScopes(r),{repo:{namespace:o,name:i},cursor:a}=t,u=await y(this.config,{query:`
249
249
  query getAccountsForRepo($owner: String!, $name: String! $cursor: String, $first: Int!) {
250
250
  repository(owner: $owner, name: $name) {
251
251
  assignableUsers(first: $first, after: $cursor) {
252
252
  nodes {
253
- ${$(!1,B(n))}
253
+ ${G(!1,j(n))}
254
254
  }
255
255
  pageInfo {
256
256
  endCursor
@@ -259,7 +259,7 @@ query getAccountsForRepo($owner: String!, $name: String! $cursor: String, $first
259
259
  }
260
260
  }
261
261
  }
262
- `,variables:{owner:o,name:i,cursor:a,first:S}},r);if(!u.body.data)throw new Error(((l=u.body.errors)==null?void 0:l[0].message)||u.statusText||"Unknown error");return{pageInfo:((d=(p=u.body.data.repository)==null?void 0:p.assignableUsers)==null?void 0:d.pageInfo)??{endCursor:null,hasNextPage:!1},data:((m=(g=(c=u.body.data.repository)==null?void 0:c.assignableUsers)==null?void 0:g.nodes)==null?void 0:m.map(I=>x(I)))??[]}}async getUserForCommit(t,r={}){var a,u;let o=(a=(await R(this.config,{query:`
262
+ `,variables:{owner:o,name:i,cursor:a,first:C}},r);if(!u.body.data)throw new Error(((l=u.body.errors)==null?void 0:l[0].message)||u.statusText||"Unknown error");return{pageInfo:((d=(p=u.body.data.repository)==null?void 0:p.assignableUsers)==null?void 0:d.pageInfo)??{endCursor:null,hasNextPage:!1},data:((m=(g=(c=u.body.data.repository)==null?void 0:c.assignableUsers)==null?void 0:g.nodes)==null?void 0:m.map(h=>k(h)))??[]}}async getUserForCommit(t,r={}){var a,u;let o=(a=(await y(this.config,{query:`
263
263
  query getUserForCommit(
264
264
  $owner: String!
265
265
  $name: String!
@@ -278,7 +278,7 @@ query getUserForCommit(
278
278
  }
279
279
  }
280
280
  }
281
- `,variables:{owner:t.repo.namespace,name:t.repo.name,oid:t.oid,avatarSize:t.avatarSize}},r)).body.data)==null?void 0:a.repository;if(!o)throw new Error("Repository not found.");let i=(u=o.object)==null?void 0:u.author;if(!i)throw new Error("Commit not found.");return{data:{name:i.name,email:i.email,avatarUrl:this.getEnterpriseAvatarUrlIfNeeded(i.avatarUrl,i.email,r)}}}async createCommit(t,r={}){var p;let{commitMessage:n,deletedFiles:o,newOrModifiedFiles:i,repo:a,target:u}=t,l=await R(this.config,{query:`
281
+ `,variables:{owner:t.repo.namespace,name:t.repo.name,oid:t.oid,avatarSize:t.avatarSize}},r)).body.data)==null?void 0:a.repository;if(!o)throw new Error("Repository not found.");let i=(u=o.object)==null?void 0:u.author;if(!i)throw new Error("Commit not found.");return{data:{name:i.name,email:i.email,avatarUrl:this.getEnterpriseAvatarUrlIfNeeded(i.avatarUrl,i.email,r)}}}async createCommit(t,r={}){var p;let{commitMessage:n,deletedFiles:o,newOrModifiedFiles:i,repo:a,target:u}=t,l=await y(this.config,{query:`
282
282
  mutation createCommitOnBranch(
283
283
  $branchName: String!,
284
284
  $expectedHeadOid: GitObjectID!,
@@ -305,23 +305,23 @@ mutation createCommitOnBranch(
305
305
  }
306
306
  }
307
307
  }
308
- `,variables:{branchName:u.name,expectedHeadOid:u.oid,fileChanges:{additions:Object.entries(i).map(([d,c])=>({contents:rr.Base64.encode(c),path:d})),deletions:o.map(d=>({path:d}))},message:{body:n.description,headline:n.summary},repositoryNameWithOwner:`${a.namespace}/${a.name}`}},r);if((p=l.body.errors)!=null&&p[0])throw new Error(l.body.errors[0].message);if(!l.body.data)throw new Error("Could not create commit");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(t,r={}){var a,u,l;let n=await this.getScopes(r),i=(l=(u=(a=(await R(this.config,{query:`
308
+ `,variables:{branchName:u.name,expectedHeadOid:u.oid,fileChanges:{additions:Object.entries(i).map(([d,c])=>({contents:or.Base64.encode(c),path:d})),deletions:o.map(d=>({path:d}))},message:{body:n.description,headline:n.summary},repositoryNameWithOwner:`${a.namespace}/${a.name}`}},r);if((p=l.body.errors)!=null&&p[0])throw new Error(l.body.errors[0].message);if(!l.body.data)throw new Error("Could not create commit");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(t,r={}){var a,u,l;let n=await this.getScopes(r),i=(l=(u=(a=(await y(this.config,{query:`
309
309
  query getAccountForEmail($query: String! $avatarSize: Int) {
310
310
  search(query: $query, type: USER, first: 1) {
311
311
  nodes {
312
312
  ... on User {
313
- ${$(!0,B(n))}
313
+ ${G(!0,j(n))}
314
314
  }
315
315
  }
316
316
  }
317
317
  }
318
- `,variables:{query:`in:email ${t.email}`,avatarSize:t.avatarSize}},r)).body.data)==null?void 0:a.search)==null?void 0:u.nodes)==null?void 0:l[0];if(!i)throw new Error("User not found.");return{data:x({...i,avatarUrl:this.getEnterpriseAvatarUrlIfNeeded(i.avatarUrl,i.email,r)})}}async getAccountForUsername(t,r={}){var a;let n=await this.getScopes(r),i=(a=(await R(this.config,{query:`
318
+ `,variables:{query:`in:email ${t.email}`,avatarSize:t.avatarSize}},r)).body.data)==null?void 0:a.search)==null?void 0:u.nodes)==null?void 0:l[0];if(!i)throw new Error("User not found.");return{data:k({...i,avatarUrl:this.getEnterpriseAvatarUrlIfNeeded(i.avatarUrl,i.email,r)})}}async getAccountForUsername(t,r={}){var a;let n=await this.getScopes(r),i=(a=(await y(this.config,{query:`
319
319
  query getUserForUsername($login: String! $avatarSize: Int) {
320
320
  user(login: $login) {
321
- ${$(!0,B(n))}
321
+ ${G(!0,j(n))}
322
322
  }
323
323
  }
324
- `,variables:{login:t.username,avatarSize:t.avatarSize}},r)).body.data)==null?void 0:a.user;if(!i)throw new Error("User not found.");return{data:x({...i,avatarUrl:this.getEnterpriseAvatarUrlIfNeeded(i.avatarUrl,i.email,r)})}}async getOrgsForCurrentUser(t={},r={}){var i;let n=await R(this.config,{query:`
324
+ `,variables:{login:t.username,avatarSize:t.avatarSize}},r)).body.data)==null?void 0:a.user;if(!i)throw new Error("User not found.");return{data:k({...i,avatarUrl:this.getEnterpriseAvatarUrlIfNeeded(i.avatarUrl,i.email,r)})}}async getOrgsForCurrentUser(t={},r={}){var i;let n=await y(this.config,{query:`
325
325
  query getOrgsForCurrentUser($cursor: String, $first: Int!) {
326
326
  viewer {
327
327
  organizations(first: $first after: $cursor) {
@@ -340,7 +340,7 @@ query getOrgsForCurrentUser($cursor: String, $first: Int!) {
340
340
  }
341
341
  }
342
342
  }
343
- `,variables:{cursor:t.cursor,first:S}},r);if(!n.body.data)throw new Error(((i=n.body.errors)==null?void 0:i[0].message)||n.statusText||"Unknown error");let o=n.body.data.viewer.organizations.nodes||[];return{pageInfo:n.body.data.viewer.organizations.pageInfo,data:o.map(a=>({id:a.databaseId.toString(),graphQLId:a.id,username:a.login,name:a.name||null,email:a.email||null,avatarUrl:a.avatarUrl}))}}async getOrgMembers(t,r={}){var i,a,u;let n=await R(this.config,{query:`
343
+ `,variables:{cursor:t.cursor,first:C}},r);if(!n.body.data)throw new Error(((i=n.body.errors)==null?void 0:i[0].message)||n.statusText||"Unknown error");let o=n.body.data.viewer.organizations.nodes||[];return{pageInfo:n.body.data.viewer.organizations.pageInfo,data:o.map(a=>({id:a.databaseId.toString(),graphQLId:a.id,username:a.login,name:a.name||null,email:a.email||null,avatarUrl:a.avatarUrl}))}}async getOrgMembers(t,r={}){var i,a,u;let n=await y(this.config,{query:`
344
344
  query getOrgMember($cursor: String, $first: Int!, $login: String!) {
345
345
  viewer {
346
346
  organization(login: $login) {
@@ -350,28 +350,28 @@ query getOrgMember($cursor: String, $first: Int!, $login: String!) {
350
350
  hasNextPage
351
351
  }
352
352
  nodes {
353
- ${$(!1,!0)}
353
+ ${G(!1,!0)}
354
354
  }
355
355
  }
356
356
  }
357
357
  }
358
358
  }
359
- `,variables:{cursor:t.cursor,first:S,login:t.org}},r);if(!n.body.data)throw new Error(((i=n.body.errors)==null?void 0:i[0].message)||n.statusText||"Unknown error");if(!((u=(a=n.body.data)==null?void 0:a.viewer.organization)!=null&&u.membersWithRole))throw new Error("Could not read the members of the organization");let o=n.body.data.viewer.organization.membersWithRole.nodes||[];return{pageInfo:n.body.data.viewer.organization.membersWithRole.pageInfo,data:o.map(l=>x({...l,avatarUrl:this.getEnterpriseAvatarUrlIfNeeded(l.avatarUrl,l.email,r)}))}}async getRepo(t,r={}){var o;let n=await R(this.config,{query:`
359
+ `,variables:{cursor:t.cursor,first:C,login:t.org}},r);if(!n.body.data)throw new Error(((i=n.body.errors)==null?void 0:i[0].message)||n.statusText||"Unknown error");if(!((u=(a=n.body.data)==null?void 0:a.viewer.organization)!=null&&u.membersWithRole))throw new Error("Could not read the members of the organization");let o=n.body.data.viewer.organization.membersWithRole.nodes||[];return{pageInfo:n.body.data.viewer.organization.membersWithRole.pageInfo,data:o.map(l=>k({...l,avatarUrl:this.getEnterpriseAvatarUrlIfNeeded(l.avatarUrl,l.email,r)}))}}async getRepo(t,r={}){var o;let n=await y(this.config,{query:`
360
360
  query getRepo($owner: String!, $name: String!) {
361
361
  repository(owner: $owner, name: $name) {
362
- ${ut}
362
+ ${lt}
363
363
  }
364
364
  }
365
- `,variables:{owner:t.namespace,name:t.name}},r);if(!((o=n.body.data)!=null&&o.repository))throw new Error(`Repository ${t.namespace}/${t.name} not found`);return{data:lt(n.body.data.repository)}}async getRepos(t,r={}){let n=t.map(({namespace:u,name:l},p)=>`
365
+ `,variables:{owner:t.namespace,name:t.name}},r);if(!((o=n.body.data)!=null&&o.repository))throw new Error(`Repository ${t.namespace}/${t.name} not found`);return{data:pt(n.body.data.repository)}}async getRepos(t,r={}){let n=t.map(({namespace:u,name:l},p)=>`
366
366
  getRepo_${p}: repository(owner: "${u}", name: "${l}") {
367
- ${ut}
367
+ ${lt}
368
368
  }
369
369
  `).join(`
370
- `),o=await R(this.config,{query:`
370
+ `),o=await y(this.config,{query:`
371
371
  query batchGetRepos {
372
372
  ${n}
373
373
  }
374
- `},r);if(!o.body.data)throw new Error(o.statusText||"Unknown error");let i=[],a=[];return t.forEach((u,l)=>{let p=o.body.data[`getRepo_${l}`];p?i.push(lt(p)):a.push({input:u})}),{data:i,errors:a}}async getReposForUsernames(t,r={}){var i;if(!t.usernames.length)return{pageInfo:{endCursor:null,hasNextPage:!1},data:[]};let n=await R(this.config,{query:`
374
+ `},r);if(!o.body.data)throw new Error(o.statusText||"Unknown error");let i=[],a=[];return t.forEach((u,l)=>{let p=o.body.data[`getRepo_${l}`];p?i.push(pt(p)):a.push({input:u})}),{data:i,errors:a}}async getReposForUsernames(t,r={}){var i;if(!t.usernames.length)return{pageInfo:{endCursor:null,hasNextPage:!1},data:[]};let n=await y(this.config,{query:`
375
375
  query getReposForUsernames($query: String!, $cursor: String, $first: Int!) {
376
376
  search(query: $query, type: REPOSITORY, first: $first, after: $cursor) {
377
377
  pageInfo {
@@ -380,12 +380,12 @@ query getReposForUsernames($query: String!, $cursor: String, $first: Int!) {
380
380
  }
381
381
  nodes {
382
382
  ... on Repository {
383
- ${ut}
383
+ ${lt}
384
384
  }
385
385
  }
386
386
  }
387
387
  }
388
- `,variables:{query:`fork:true ${t.usernames.map(a=>`user:${a}`).join(" ")}`,cursor:t.cursor,first:S}},r);if(!n.body.data)throw new Error(((i=n.body.errors)==null?void 0:i[0].message)||n.statusText||"Unknown error");let o=n.body.data.search.nodes||[];return{pageInfo:n.body.data.search.pageInfo,data:o.map(lt)}}async getReposForOwners(t,r={}){return this.getReposForUsernames({usernames:t.owners.filter(n=>n.username).map(n=>n.username),cursor:t.cursor},r)}async getRefs(t,r,n={}){var u;let i=(u=(await R(this.config,{query:`
388
+ `,variables:{query:`fork:true ${t.usernames.map(a=>`user:${a}`).join(" ")}`,cursor:t.cursor,first:C}},r);if(!n.body.data)throw new Error(((i=n.body.errors)==null?void 0:i[0].message)||n.statusText||"Unknown error");let o=n.body.data.search.nodes||[];return{pageInfo:n.body.data.search.pageInfo,data:o.map(pt)}}async getReposForOwners(t,r={}){return this.getReposForUsernames({usernames:t.owners.filter(n=>n.username).map(n=>n.username),cursor:t.cursor},r)}async getRefs(t,r,n={}){var u;let i=(u=(await y(this.config,{query:`
389
389
  query getRefs($owner: String!, $name: String!, $refPrefix: String!, $cursor: String, $first: Int!) {
390
390
  repository(owner: $owner, name: $name) {
391
391
  refs(refPrefix: $refPrefix first: $first after: $cursor) {
@@ -406,7 +406,7 @@ query getRefs($owner: String!, $name: String!, $refPrefix: String!, $cursor: Str
406
406
  }
407
407
  }
408
408
  }
409
- `,variables:{owner:r.repo.namespace,name:r.repo.name,refPrefix:t,cursor:r.cursor,first:S}},n)).body.data)==null?void 0:u.repository;if(!i)throw new Error("Repository not found.");let a=i.refs;return a?{pageInfo:a.pageInfo,data:(a.nodes||[]).map(l=>{var d;let p=(d=l.target)!=null&&d.oid?l.target:null;return{name:l.name,commit:p?{oid:p.oid,authoredDate:new Date(p.authoredDate),committedDate:new Date(p.committedDate)}:null}})}:{pageInfo:{endCursor:null,hasNextPage:!1},data:[]}}async getBranches(t,r={}){return this.getRefs("refs/heads/",t,r)}async getTags(t,r={}){return this.getRefs("refs/tags/",t,r)}async getBlame(t,r={}){var a;let o=(a=(await R(this.config,{query:`
409
+ `,variables:{owner:r.repo.namespace,name:r.repo.name,refPrefix:t,cursor:r.cursor,first:C}},n)).body.data)==null?void 0:u.repository;if(!i)throw new Error("Repository not found.");let a=i.refs;return a?{pageInfo:a.pageInfo,data:(a.nodes||[]).map(l=>{var d;let p=(d=l.target)!=null&&d.oid?l.target:null;return{name:l.name,commit:p?{oid:p.oid,authoredDate:new Date(p.authoredDate),committedDate:new Date(p.committedDate)}:null}})}:{pageInfo:{endCursor:null,hasNextPage:!1},data:[]}}async getBranches(t,r={}){return this.getRefs("refs/heads/",t,r)}async getTags(t,r={}){return this.getRefs("refs/tags/",t,r)}async getBlame(t,r={}){var a;let o=(a=(await y(this.config,{query:`
410
410
  query getBlame($owner: String!, $name: String!, $ref: String!, $path: String!) {
411
411
  repository(owner: $owner, name: $name) {
412
412
  object(expression: $ref) {
@@ -445,7 +445,7 @@ query getBlame($owner: String!, $name: String!, $ref: String!, $path: String!) {
445
445
  }
446
446
  }
447
447
  }
448
- `,variables:{owner:t.repo.namespace,name:t.repo.name,ref:t.ref,path:t.path}},r)).body.data)==null?void 0:a.repository;if(!o)throw new Error("Repository not found.");let i=o.object;if(!i||!("blame"in i))throw new Error("Ref not found.");if(i.blame.ranges.length===0)throw new Error("File not found.");return{data:{ranges:i.blame.ranges.map(u=>{var l;return{startingLine:u.startingLine,endingLine:u.endingLine,commit:{oid:u.commit.oid,parentOids:((l=u.commit.parents.nodes)==null?void 0:l.map(p=>p.oid))||[],authoredDate:new Date(u.commit.authoredDate),author:u.commit.author?{name:u.commit.author.name,email:u.commit.author.email,avatarUrl:u.commit.author.avatarUrl}:null,committedDate:new Date(u.commit.committedDate),committer:u.commit.committer?{name:u.commit.committer.name,email:u.commit.committer.email,avatarUrl:u.commit.committer.avatarUrl}:null,message:u.commit.message,fileCount:u.commit.changedFilesIfAvailable,additions:u.commit.additions,deletions:u.commit.deletions}}})}}}async getFileContents(t,r={}){let n=await this.config.request({url:`${ot(this.config,r)}/repos/${t.repo.namespace}/${t.repo.name}/contents/${encodeURIComponent(t.path)}?ref=${t.ref}`,headers:{...f(r.token||this.config.token),Accept:"application/vnd.github.raw+json"}});if(n.headers["content-type"].startsWith("application/json"))throw new Error(`GitHub: got directory when fetching "${t.path}", getFileContents does not support fetching directories`);if(!n.headers["content-type"].startsWith("application/vnd.github.raw+json"))throw new Error(`GitHub: unsupported content type "${n.headers["content-type"]}" when fetching "${t.path}"`);return{data:new Blob([n.body])}}async searchPullRequests(t,r={}){var p,d;let n=await this.getEnterpriseVersion(r),o=await this.getScopes(r),i=B(o),a=c=>{let g=c&&typeof t.isDraft=="boolean"?`${t.query} draft:${t.isDraft}`:t.query;return at("pr",g,t.cursor,{supportsEmail:i,supportsDrafts:c,enterpriseVersion:n,includeFromArchivedRepos:t.includeFromArchivedRepos})},u=await R(this.config,a(!0),r);u.body.errors&&we(u.body.errors)&&(this.config.baseUrl||r.baseUrl)&&(u=await R(this.config,a(!1),r));let{data:l}=u.body;if(!l)throw new Error(((p=u.body.errors)==null?void 0:p[0].message)||u.statusText||"Unknown error");return{pageInfo:{hasNextPage:l.search.pageInfo.hasNextPage,endCursor:l.search.pageInfo.endCursor},data:((d=l.search.nodes)==null?void 0:d.map(pt))||[]}}async searchIssues(t,r={}){var u,l;let n=await this.getScopes(r),o=B(n),i=await R(this.config,at("issue",t.query,t.cursor,{supportsEmail:o,includeFromArchivedRepos:t.includeFromArchivedRepos}),r),{data:a}=i.body;if(!a)throw new Error(((u=i.body.errors)==null?void 0:u[0].message)||i.statusText||"Unknown error");return{pageInfo:{hasNextPage:a.search.pageInfo.hasNextPage,endCursor:a.search.pageInfo.endCursor},data:((l=a.search.nodes)==null?void 0:l.map(ss))||[]}}async getPullRequestsAssociatedWithUser(t,r={}){return this.searchPullRequests({query:`involves:${t.username}`,cursor:t.cursor,includeFromArchivedRepos:t.includeFromArchivedRepos},r)}async getPullRequestsForRepos(t,r={}){let{assigneeLogins:n,updatedBefore:o,authorLogin:i,repos:a,reviewRequestedLogin:u,startQuery:l,mentionLogin:p}=t,d=it(l||"");return a.forEach(c=>{d.push(`repo:${c.namespace}/${c.name}`)}),n&&n.forEach(c=>{d.push(`assignee:${c}`)}),o&&d.push(`updated:<${o}`),i&&d.push(`author:${i}`),u&&d.push(`review-requested:${u}`),p&&d.push(`mentions:${p}`),this.searchPullRequests({query:`sort:updated ${d.join(" ")}`,isDraft:t.isDraft,cursor:t.cursor,includeFromArchivedRepos:t.includeFromArchivedRepos},r)}async getPullRequestForRepo(t,r={}){var d,c;let n=await this.getEnterpriseVersion(r),o=await this.getScopes(r),i=B(o),a=g=>({query:`query getPullRequest(
448
+ `,variables:{owner:t.repo.namespace,name:t.repo.name,ref:t.ref,path:t.path}},r)).body.data)==null?void 0:a.repository;if(!o)throw new Error("Repository not found.");let i=o.object;if(!i||!("blame"in i))throw new Error("Ref not found.");if(i.blame.ranges.length===0)throw new Error("File not found.");return{data:{ranges:i.blame.ranges.map(u=>{var l;return{startingLine:u.startingLine,endingLine:u.endingLine,commit:{oid:u.commit.oid,parentOids:((l=u.commit.parents.nodes)==null?void 0:l.map(p=>p.oid))||[],authoredDate:new Date(u.commit.authoredDate),author:u.commit.author?{name:u.commit.author.name,email:u.commit.author.email,avatarUrl:u.commit.author.avatarUrl}:null,committedDate:new Date(u.commit.committedDate),committer:u.commit.committer?{name:u.commit.committer.name,email:u.commit.committer.email,avatarUrl:u.commit.committer.avatarUrl}:null,message:u.commit.message,fileCount:u.commit.changedFilesIfAvailable,additions:u.commit.additions,deletions:u.commit.deletions}}})}}}async getFileContents(t,r={}){let n=await this.config.request({url:`${it(this.config,r)}/repos/${t.repo.namespace}/${t.repo.name}/contents/${encodeURIComponent(t.path)}?ref=${t.ref}`,headers:{...I(r.token||this.config.token),Accept:"application/vnd.github.raw+json"}});if(n.headers["content-type"].startsWith("application/json"))throw new Error(`GitHub: got directory when fetching "${t.path}", getFileContents does not support fetching directories`);if(!n.headers["content-type"].startsWith("application/vnd.github.raw+json"))throw new Error(`GitHub: unsupported content type "${n.headers["content-type"]}" when fetching "${t.path}"`);return{data:new Blob([n.body])}}async searchPullRequests(t,r={}){var p,d;let n=await this.getEnterpriseVersion(r),o=await this.getScopes(r),i=j(o),a=c=>{let g=c&&typeof t.isDraft=="boolean"?`${t.query} draft:${t.isDraft}`:t.query;return ut("pr",g,t.cursor,{maxPageSize:t.maxPageSize??er,supportsEmail:i,supportsDrafts:c,enterpriseVersion:n,includeFromArchivedRepos:t.includeFromArchivedRepos})},u=await y(this.config,a(!0),r);u.body.errors&&Pe(u.body.errors)&&(this.config.baseUrl||r.baseUrl)&&(u=await y(this.config,a(!1),r));let{data:l}=u.body;if(!l)throw new Error(((p=u.body.errors)==null?void 0:p[0].message)||u.statusText||"Unknown error");return{pageInfo:{hasNextPage:l.search.pageInfo.hasNextPage,endCursor:l.search.pageInfo.endCursor},data:((d=l.search.nodes)==null?void 0:d.filter(D).map(dt))||[]}}async searchIssues(t,r={}){var u,l;let n=await this.getScopes(r),o=j(n),i=await y(this.config,ut("issue",t.query,t.cursor,{supportsEmail:o,includeFromArchivedRepos:t.includeFromArchivedRepos,maxPageSize:t.maxPageSize??tr}),r),{data:a}=i.body;if(!a)throw new Error(((u=i.body.errors)==null?void 0:u[0].message)||i.statusText||"Unknown error");return{pageInfo:{hasNextPage:a.search.pageInfo.hasNextPage,endCursor:a.search.pageInfo.endCursor},data:((l=a.search.nodes)==null?void 0:l.map(is))||[]}}async getPullRequestsAssociatedWithUser(t,r={}){let n=[`involves:${t.username}`];return t.labelNames&&t.labelNames.forEach(o=>{n.push(`label:"${o}"`)}),this.searchPullRequests({query:n.join(" "),cursor:t.cursor,includeFromArchivedRepos:t.includeFromArchivedRepos,maxPageSize:t.maxPageSize},r)}async getPullRequestsForRepos(t,r={}){let{assigneeLogins:n,updatedBefore:o,authorLogin:i,repos:a,reviewRequestedLogin:u,startQuery:l,mentionLogin:p,labelNames:d,maxPageSize:c}=t,g=at(l||"");return a.forEach(m=>{g.push(`repo:${m.namespace}/${m.name}`)}),n&&n.forEach(m=>{g.push(`assignee:${m}`)}),o&&g.push(`updated:<${o}`),i&&g.push(`author:${i}`),u&&g.push(`review-requested:${u}`),p&&g.push(`mentions:${p}`),d&&d.forEach(m=>{g.push(`label:"${m}"`)}),this.searchPullRequests({query:`sort:updated ${g.join(" ")}`,isDraft:t.isDraft,cursor:t.cursor,includeFromArchivedRepos:t.includeFromArchivedRepos,maxPageSize:c},r)}async getPullRequestForRepo(t,r={}){var d,c;let n=await this.getEnterpriseVersion(r),o=await this.getScopes(r),i=j(o),a=g=>({query:`query getPullRequest(
449
449
  $owner: String!
450
450
  $name: String!
451
451
  $number: Int!
@@ -455,24 +455,24 @@ query getBlame($owner: String!, $name: String!, $ref: String!, $path: String!) {
455
455
  name: $name
456
456
  ) {
457
457
  pullRequest(number: $number) {
458
- ${be(g,i,n)}
458
+ ${we(g,i,n)}
459
459
  }
460
460
  }
461
- }`,variables:{owner:t.repo.namespace,name:t.repo.name,number:t.number}}),u=await R(this.config,a(!0),r);u.body.errors&&we(u.body.errors)&&(this.config.baseUrl||r.baseUrl)&&(u=await R(this.config,a(!1),r));let{data:l}=u.body;if(!l)throw new Error(((d=u.body.errors)==null?void 0:d[0].message)||u.statusText||"Unknown error");let p=(c=u.body.data)==null?void 0:c.repository.pullRequest;return{data:p?pt(p):null}}async getPullRequestByGraphQLId(t,r={}){var d,c;let n=await this.getEnterpriseVersion(r),o=await this.getScopes(r),i=B(o),a=g=>({query:`query getPullRequest(
461
+ }`,variables:{owner:t.repo.namespace,name:t.repo.name,number:t.number}}),u=await y(this.config,a(!0),r);u.body.errors&&Pe(u.body.errors)&&(this.config.baseUrl||r.baseUrl)&&(u=await y(this.config,a(!1),r));let{data:l}=u.body;if(!l)throw new Error(((d=u.body.errors)==null?void 0:d[0].message)||u.statusText||"Unknown error");let p=(c=u.body.data)==null?void 0:c.repository.pullRequest;return{data:p?dt(p):null}}async getPullRequestByGraphQLId(t,r={}){var d,c;let n=await this.getEnterpriseVersion(r),o=await this.getScopes(r),i=j(o),a=g=>({query:`query getPullRequest(
462
462
  $graphQLId: ID!
463
463
  ) {
464
464
  node(id: $graphQLId) {
465
465
  ... on PullRequest {
466
- ${be(g,i,n)}
466
+ ${we(g,i,n)}
467
467
  }
468
468
  }
469
- }`,variables:{graphQLId:t.graphQLId}}),u=await R(this.config,a(!0),r);u.body.errors&&we(u.body.errors)&&(this.config.baseUrl||r.baseUrl)&&(u=await R(this.config,a(!1),r));let{data:l}=u.body;if(!l)throw new Error(((d=u.body.errors)==null?void 0:d[0].message)||u.statusText||"Unknown error");let p=(c=u.body.data)==null?void 0:c.node;return{data:p?pt(p):null}}async closePullRequest(t,r={}){var a,u,l;let{pullRequest:{graphQLId:n}}=t;if(!n)throw new Error('GitHub requires "graphQLId" for this function.');let o=`mutation ClosePullRequest($pullRequestGraphQLId: ID!) {
469
+ }`,variables:{graphQLId:t.graphQLId}}),u=await y(this.config,a(!0),r);u.body.errors&&Pe(u.body.errors)&&(this.config.baseUrl||r.baseUrl)&&(u=await y(this.config,a(!1),r));let{data:l}=u.body;if(!l)throw new Error(((d=u.body.errors)==null?void 0:d[0].message)||u.statusText||"Unknown error");let p=(c=u.body.data)==null?void 0:c.node;return{data:p?dt(p):null}}async closePullRequest(t,r={}){var a,u,l;let{pullRequest:{graphQLId:n}}=t;if(!n)throw new Error('GitHub requires "graphQLId" for this function.');let o=`mutation ClosePullRequest($pullRequestGraphQLId: ID!) {
470
470
  closePullRequest(input: { pullRequestId: $pullRequestGraphQLId }) {
471
471
  pullRequest {
472
472
  id
473
473
  }
474
474
  }
475
- }`;if(!((l=(u=(a=(await R(this.config,{query:`${o}`,variables:{pullRequestGraphQLId:n}},r)).body.data)==null?void 0:a.closePullRequest)==null?void 0:u.pullRequest)!=null&&l.id))throw new Error("Could not close pull request")}async mergePullRequest(t,r={}){var l,p,d,c;let{pullRequest:n,mergeStrategy:o}=t;if(!n.graphQLId)throw new Error('GitHub requires "graphQLId" for this function.');if(!((l=n.headRef)!=null&&l.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(
475
+ }`;if(!((l=(u=(a=(await y(this.config,{query:`${o}`,variables:{pullRequestGraphQLId:n}},r)).body.data)==null?void 0:a.closePullRequest)==null?void 0:u.pullRequest)!=null&&l.id))throw new Error("Could not close pull request")}async mergePullRequest(t,r={}){var l,p,d,c;let{pullRequest:n,mergeStrategy:o}=t;if(!n.graphQLId)throw new Error('GitHub requires "graphQLId" for this function.');if(!((l=n.headRef)!=null&&l.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(
476
476
  $pullRequestGraphQLId: ID!,
477
477
  $expectedSourceSha: GitObjectID!,
478
478
  $mergeStrategy: PullRequestMergeMethod,
@@ -486,43 +486,43 @@ query getBlame($owner: String!, $name: String!, $ref: String!, $path: String!) {
486
486
  id
487
487
  }
488
488
  }
489
- }`;if(!((c=(d=(p=(await R(this.config,{query:`${a}`,variables:{pullRequestGraphQLId:n.graphQLId,expectedSourceSha:n.headRef.oid,mergeStrategy:i}},r)).body.data)==null?void 0:p.mergePullRequest)==null?void 0:d.pullRequest)!=null&&c.id))throw new Error("Could not merge pull request")}async setPullRequestMilestone(t,r={}){var u,l,p;let{pullRequest:n,milestone:o}=t;if(!n.graphQLId)throw new Error('GitHub requires "graphQLId" for this function.');let i=`mutation SetPullRequestMilestone($pullRequestGraphQLId: ID!, $milestoneGraphQLId: ID) {
489
+ }`;if(!((c=(d=(p=(await y(this.config,{query:`${a}`,variables:{pullRequestGraphQLId:n.graphQLId,expectedSourceSha:n.headRef.oid,mergeStrategy:i}},r)).body.data)==null?void 0:p.mergePullRequest)==null?void 0:d.pullRequest)!=null&&c.id))throw new Error("Could not merge pull request")}async setPullRequestMilestone(t,r={}){var u,l,p;let{pullRequest:n,milestone:o}=t;if(!n.graphQLId)throw new Error('GitHub requires "graphQLId" for this function.');let i=`mutation SetPullRequestMilestone($pullRequestGraphQLId: ID!, $milestoneGraphQLId: ID) {
490
490
  updatePullRequest(input: { pullRequestId: $pullRequestGraphQLId, milestoneId: $milestoneGraphQLId }) {
491
491
  pullRequest {
492
492
  id
493
493
  }
494
494
  }
495
- }`;if(!((p=(l=(u=(await R(this.config,{query:`${i}`,variables:{pullRequestGraphQLId:n.graphQLId,milestoneGraphQLId:(o==null?void 0:o.graphQLId)??null}},r)).body.data)==null?void 0:u.updatePullRequest)==null?void 0:l.pullRequest)!=null&&p.id))throw new Error("Could not set milestone of pull request")}async markPullRequestReadyForReview(t,r){var i,a,u;let n=`mutation MarkReadyToReview($pullRequestGraphQLId: ID!) {
495
+ }`;if(!((p=(l=(u=(await y(this.config,{query:`${i}`,variables:{pullRequestGraphQLId:n.graphQLId,milestoneGraphQLId:(o==null?void 0:o.graphQLId)??null}},r)).body.data)==null?void 0:u.updatePullRequest)==null?void 0:l.pullRequest)!=null&&p.id))throw new Error("Could not set milestone of pull request")}async markPullRequestReadyForReview(t,r){var i,a,u;let n=`mutation MarkReadyToReview($pullRequestGraphQLId: ID!) {
496
496
  markPullRequestReadyForReview(input: { pullRequestId: $pullRequestGraphQLId }) {
497
497
  pullRequest {
498
498
  id
499
499
  }
500
500
  }
501
- }`;if(!((u=(a=(i=(await R(this.config,{query:n,variables:{pullRequestGraphQLId:t}},r)).body.data)==null?void 0:i.markPullRequestReadyForReview)==null?void 0:a.pullRequest)!=null&&u.id))throw new Error("Could not mark pull request ready to review")}async convertPullRequestToDraft(t,r){var i,a,u;let n=`mutation ConvertToDraft($pullRequestGraphQLId: ID!) {
501
+ }`;if(!((u=(a=(i=(await y(this.config,{query:n,variables:{pullRequestGraphQLId:t}},r)).body.data)==null?void 0:i.markPullRequestReadyForReview)==null?void 0:a.pullRequest)!=null&&u.id))throw new Error("Could not mark pull request ready to review")}async convertPullRequestToDraft(t,r){var i,a,u;let n=`mutation ConvertToDraft($pullRequestGraphQLId: ID!) {
502
502
  convertPullRequestToDraft(input: { pullRequestId: $pullRequestGraphQLId }) {
503
503
  pullRequest {
504
504
  id
505
505
  }
506
506
  }
507
- }`;if(!((u=(a=(i=(await R(this.config,{query:n,variables:{pullRequestGraphQLId:t}},r)).body.data)==null?void 0:i.convertPullRequestToDraft)==null?void 0:a.pullRequest)!=null&&u.id))throw new Error("Could not convert pull request to draft")}async setPullRequestAsDraft(t,r={}){let{pullRequest:{graphQLId:n},isDraft:o}=t;if(!n)throw new Error('GitHub requires "graphQLId" for this function.');if(o){await this.convertPullRequestToDraft(n,r);return}await this.markPullRequestReadyForReview(n,r)}async setPullRequestReviewers(t,r={}){var d,c,g;let{pullRequest:{reviews:n,graphQLId:o},reviewers:i}=t;if(!n)throw new Error('GitHub requires "reviews" for this function');if(!o)throw new Error('GitHub requires "graphQLId" for this function.');let a=n.filter(m=>m.state!=="REVIEW_REQUESTED").map(m=>{if(!m.reviewer.graphQLId)throw new Error('GitHub requires reviewer "graphQLId" for this function.');return m.reviewer.graphQLId}),u=i.map(m=>{if(!m.graphQLId)throw new Error('GitHub requires reviewer "graphQLId" for this function.');return m.graphQLId}).filter(m=>a.indexOf(m)===-1),l=`mutation SetPullRequestReviewers($pullRequestGraphQLId: ID!, $reviewerGraphQLIds: [ID!]!) {
507
+ }`;if(!((u=(a=(i=(await y(this.config,{query:n,variables:{pullRequestGraphQLId:t}},r)).body.data)==null?void 0:i.convertPullRequestToDraft)==null?void 0:a.pullRequest)!=null&&u.id))throw new Error("Could not convert pull request to draft")}async setPullRequestAsDraft(t,r={}){let{pullRequest:{graphQLId:n},isDraft:o}=t;if(!n)throw new Error('GitHub requires "graphQLId" for this function.');if(o){await this.convertPullRequestToDraft(n,r);return}await this.markPullRequestReadyForReview(n,r)}async setPullRequestReviewers(t,r={}){var d,c,g;let{pullRequest:{reviews:n,graphQLId:o},reviewers:i}=t;if(!n)throw new Error('GitHub requires "reviews" for this function');if(!o)throw new Error('GitHub requires "graphQLId" for this function.');let a=n.filter(m=>m.state!=="REVIEW_REQUESTED").map(m=>{if(!m.reviewer.graphQLId)throw new Error('GitHub requires reviewer "graphQLId" for this function.');return m.reviewer.graphQLId}),u=i.map(m=>{if(!m.graphQLId)throw new Error('GitHub requires reviewer "graphQLId" for this function.');return m.graphQLId}).filter(m=>a.indexOf(m)===-1),l=`mutation SetPullRequestReviewers($pullRequestGraphQLId: ID!, $reviewerGraphQLIds: [ID!]!) {
508
508
  requestReviews(input: { pullRequestId: $pullRequestGraphQLId, userIds: $reviewerGraphQLIds }) {
509
509
  pullRequest {
510
510
  id
511
511
  }
512
512
  }
513
- }`;if(!((g=(c=(d=(await R(this.config,{query:l,variables:{pullRequestGraphQLId:o,reviewerGraphQLIds:u}},r)).body.data)==null?void 0:d.requestReviews)==null?void 0:c.pullRequest)!=null&&g.id))throw new Error("Could not set pull request reviewers")}async reRequestPullRequestReviews(t,r={}){var p,d,c;let{pullRequest:{reviews:n,graphQLId:o},reviewers:i}=t;if(!o)throw new Error('GitHub requires "graphQLId" for this function.');if(!n)throw new Error('GitHub requires "reviews" for this function.');let a=[];for(let g of i){if(!g.graphQLId)throw new Error('GitHub requires reviwer "graphQLId" for this function.');if(!n.find(m=>m.reviewer.graphQLId===g.graphQLId))throw new Error("Can only re-request review from existing reviewer.");a.push(g.graphQLId)}let u=`mutation SetPullRequestReviewers($pullRequestGraphQLId: ID!, $reviewerGraphQLIds: [ID!]!) {
513
+ }`;if(!((g=(c=(d=(await y(this.config,{query:l,variables:{pullRequestGraphQLId:o,reviewerGraphQLIds:u}},r)).body.data)==null?void 0:d.requestReviews)==null?void 0:c.pullRequest)!=null&&g.id))throw new Error("Could not set pull request reviewers")}async reRequestPullRequestReviews(t,r={}){var p,d,c;let{pullRequest:{reviews:n,graphQLId:o},reviewers:i}=t;if(!o)throw new Error('GitHub requires "graphQLId" for this function.');if(!n)throw new Error('GitHub requires "reviews" for this function.');let a=[];for(let g of i){if(!g.graphQLId)throw new Error('GitHub requires reviwer "graphQLId" for this function.');if(!n.find(m=>m.reviewer.graphQLId===g.graphQLId))throw new Error("Can only re-request review from existing reviewer.");a.push(g.graphQLId)}let u=`mutation SetPullRequestReviewers($pullRequestGraphQLId: ID!, $reviewerGraphQLIds: [ID!]!) {
514
514
  requestReviews(input: { pullRequestId: $pullRequestGraphQLId, userIds: $reviewerGraphQLIds, union: true }) {
515
515
  pullRequest {
516
516
  id
517
517
  }
518
518
  }
519
- }`;if(!((c=(d=(p=(await R(this.config,{query:u,variables:{pullRequestGraphQLId:o,reviewerGraphQLIds:a}},r)).body.data)==null?void 0:p.requestReviews)==null?void 0:d.pullRequest)!=null&&c.id))throw new Error("Could not re-request pull request reviews")}async setPullRequestAssignees(t,r={}){var l,p,d;let{pullRequest:n,assignees:o}=t;if(!n.graphQLId)throw new Error('GitHub requires "graphQLId" for this function.');let i=o.map(c=>{if(!c.graphQLId)throw new Error('GitHub requires assignee "graphQLId" for this function.');return c.graphQLId}),a=`mutation SetPullRequestAssignees($pullRequestGraphQLId: ID!, $assigneeGraphQLIds: [ID!]!) {
519
+ }`;if(!((c=(d=(p=(await y(this.config,{query:u,variables:{pullRequestGraphQLId:o,reviewerGraphQLIds:a}},r)).body.data)==null?void 0:p.requestReviews)==null?void 0:d.pullRequest)!=null&&c.id))throw new Error("Could not re-request pull request reviews")}async setPullRequestAssignees(t,r={}){var l,p,d;let{pullRequest:n,assignees:o}=t;if(!n.graphQLId)throw new Error('GitHub requires "graphQLId" for this function.');let i=o.map(c=>{if(!c.graphQLId)throw new Error('GitHub requires assignee "graphQLId" for this function.');return c.graphQLId}),a=`mutation SetPullRequestAssignees($pullRequestGraphQLId: ID!, $assigneeGraphQLIds: [ID!]!) {
520
520
  updatePullRequest(input: { pullRequestId: $pullRequestGraphQLId, assigneeIds: $assigneeGraphQLIds }) {
521
521
  pullRequest {
522
522
  id
523
523
  }
524
524
  }
525
- }`;if(!((d=(p=(l=(await R(this.config,{query:a,variables:{pullRequestGraphQLId:n.graphQLId,assigneeGraphQLIds:i}},r)).body.data)==null?void 0:l.updatePullRequest)==null?void 0:p.pullRequest)!=null&&d.id))throw new Error("Could not set pull request assignees")}async getReviewsForPullRequest(t,r={}){var d,c;let{repo:{namespace:n,name:o},pullRequestId:i}=t,a=`query getPullRequests(
525
+ }`;if(!((d=(p=(l=(await y(this.config,{query:a,variables:{pullRequestGraphQLId:n.graphQLId,assigneeGraphQLIds:i}},r)).body.data)==null?void 0:l.updatePullRequest)==null?void 0:p.pullRequest)!=null&&d.id))throw new Error("Could not set pull request assignees")}async getReviewsForPullRequest(t,r={}){var d,c,g,m;let{repo:{namespace:n,name:o},pullRequestId:i}=t,a=`query getPullRequests(
526
526
  $namespace: String!
527
527
  $name: String!
528
528
  $pullRequestId: Int!
@@ -574,54 +574,54 @@ query getBlame($owner: String!, $name: String!, $ref: String!, $path: String!) {
574
574
  }
575
575
  }
576
576
  }
577
- }`,u=await R(this.config,{query:a,variables:{namespace:n,name:o,pullRequestId:i}},r),l=((d=u.body.data)==null?void 0:d.repository.pullRequest.reviewThreads.nodes.reduce((g,m)=>{let I=m.comments.nodes[0].pullRequestReview;return I&&(g[I.id]||(g[I.id]=[]),g[I.id].push(ts(m))),g},{}))??{};return{data:((c=u.body.data)==null?void 0:c.repository.pullRequest.reviews.nodes.filter(g=>l[g.id]).map(g=>({author:g.author?{avatarUrl:g.author.avatarUrl,email:null,name:g.author.login}:null,body:g.body,createdAt:g.publishedAt?new Date(g.publishedAt):null,id:g.databaseId,graphQLId:g.id,reviewComments:l[g.id],url:g.url})))??[]}}async getIssuesAssociatedWithUser(t,r={}){var d;let[n,o]=((d=t.cursor)==null?void 0:d.split(";"))||[void 0,void 0],[i,a]=await Promise.all([n==="null"?null:this.searchIssues({query:`author:${t.username}`,cursor:n,includeFromArchivedRepos:t.includeFromArchivedRepos},r),o==="null"?null:this.searchIssues({query:`assignee:${t.username}`,cursor:o,includeFromArchivedRepos:t.includeFromArchivedRepos},r)]),u={},l=[],p=c=>{u[c.id]||(u[c.id]=!0,l.push(c))};return i==null||i.data.forEach(p),a==null||a.data.forEach(p),{pageInfo:{hasNextPage:(i==null?void 0:i.pageInfo.hasNextPage)||(a==null?void 0:a.pageInfo.hasNextPage)||!1,endCursor:`${(i==null?void 0:i.pageInfo.hasNextPage)&&(i==null?void 0:i.pageInfo.endCursor)||"null"};${(a==null?void 0:a.pageInfo.hasNextPage)&&(a==null?void 0:a.pageInfo.endCursor)||"null"}`},data:l}}async setPullRequestLabels(t,r={}){var u,l,p;let{pullRequest:n,labels:o}=t;if(!n.graphQLId)throw new Error('GitHub requires "graphQLId" for this function.');let i=`mutation SetPullRequestLabels($pullRequestGraphQLId: ID!, $labelGraphQLIds: [ID!]) {
577
+ }`,u=await y(this.config,{query:a,variables:{namespace:n,name:o,pullRequestId:i}},r),l=((c=(d=u.body.data)==null?void 0:d.repository.pullRequest.reviewThreads.nodes)==null?void 0:c.filter(D).reduce((h,R)=>{var E,S;if(!((S=(E=R.comments.nodes)==null?void 0:E[0])!=null&&S.pullRequestReview))return h;let w=R.comments.nodes[0].pullRequestReview,f=ns(R);return f&&(h[w.id]||(h[w.id]=[]),h[w.id].push(f)),h},{}))??{};return{data:((m=(g=u.body.data)==null?void 0:g.repository.pullRequest.reviews.nodes)==null?void 0:m.filter(D).filter(h=>l[h.id]).map(h=>({author:h.author?{avatarUrl:h.author.avatarUrl,email:null,name:h.author.login}:null,body:h.body,createdAt:h.publishedAt?new Date(h.publishedAt):null,id:h.databaseId,graphQLId:h.id,reviewComments:l[h.id],url:h.url})))??[]}}async getIssuesAssociatedWithUser(t,r={}){var c;let[n,o]=((c=t.cursor)==null?void 0:c.split(";"))||[void 0,void 0],i=[];t.labelNames&&t.labelNames.forEach(g=>{i.push(`label:"${g}"`)});let[a,u]=await Promise.all([n==="null"?null:this.searchIssues({query:`author:${t.username} ${i.join(" ")}`,cursor:n,includeFromArchivedRepos:t.includeFromArchivedRepos,maxPageSize:t.maxPageSize},r),o==="null"?null:this.searchIssues({query:`assignee:${t.username} ${i.join(" ")}`,cursor:o,includeFromArchivedRepos:t.includeFromArchivedRepos,maxPageSize:t.maxPageSize},r)]),l={},p=[],d=g=>{l[g.id]||(l[g.id]=!0,p.push(g))};return a==null||a.data.forEach(d),u==null||u.data.forEach(d),{pageInfo:{hasNextPage:(a==null?void 0:a.pageInfo.hasNextPage)||(u==null?void 0:u.pageInfo.hasNextPage)||!1,endCursor:`${(a==null?void 0:a.pageInfo.hasNextPage)&&(a==null?void 0:a.pageInfo.endCursor)||"null"};${(u==null?void 0:u.pageInfo.hasNextPage)&&(u==null?void 0:u.pageInfo.endCursor)||"null"}`},data:p}}async setPullRequestLabels(t,r={}){var u,l,p;let{pullRequest:n,labels:o}=t;if(!n.graphQLId)throw new Error('GitHub requires "graphQLId" for this function.');let i=`mutation SetPullRequestLabels($pullRequestGraphQLId: ID!, $labelGraphQLIds: [ID!]) {
578
578
  updatePullRequest(input: { pullRequestId: $pullRequestGraphQLId, labelIds: $labelGraphQLIds }) {
579
579
  pullRequest {
580
580
  id
581
581
  }
582
582
  }
583
- }`;if(!((p=(l=(u=(await R(this.config,{query:i,variables:{pullRequestGraphQLId:n.graphQLId,labelGraphQLIds:o.map(d=>{if(!d.graphQLId)throw new Error('GitHub requires label "graphQLId" for this function.');return d.graphQLId})}},r)).body.data)==null?void 0:u.updatePullRequest)==null?void 0:l.pullRequest)!=null&&p.id))throw new Error("Could not set pull request labels")}async getIssuesForRepos(t,r={}){let n=it(t.startQuery||""),{cursor:o,assigneeLogins:i,updatedBefore:a,authorLogin:u,mentionLogin:l}=t;return t.repos.forEach(p=>{n.push(`repo:${p.namespace}/${p.name}`)}),i&&i.forEach(p=>{n.push(`assignee:${p}`)}),a&&n.push(`updated:<${a}`),u&&n.push(`author:${u}`),l&&n.push(`mentions:${l}`),this.searchIssues({query:`sort:updated ${n.join(" ")}`,cursor:o,includeFromArchivedRepos:t.includeFromArchivedRepos},r)}async closeIssueWithReason(t,r={}){var u,l,p;let{issue:n,reason:o}=t;if(!n.graphQLId)throw new Error('GitHub requires "graphQLId" for this function.');let i=`mutation CloseIssueWithReason($issueGraphQLId: ID!, $reason: IssueClosedStateReason!) {
583
+ }`;if(!((p=(l=(u=(await y(this.config,{query:i,variables:{pullRequestGraphQLId:n.graphQLId,labelGraphQLIds:o.map(d=>{if(!d.graphQLId)throw new Error('GitHub requires label "graphQLId" for this function.');return d.graphQLId})}},r)).body.data)==null?void 0:u.updatePullRequest)==null?void 0:l.pullRequest)!=null&&p.id))throw new Error("Could not set pull request labels")}async getIssuesForRepos(t,r={}){let n=at(t.startQuery||""),{cursor:o,assigneeLogins:i,updatedBefore:a,authorLogin:u,mentionLogin:l,labelNames:p}=t;return t.repos.forEach(d=>{n.push(`repo:${d.namespace}/${d.name}`)}),i&&i.forEach(d=>{n.push(`assignee:${d}`)}),a&&n.push(`updated:<${a}`),u&&n.push(`author:${u}`),l&&n.push(`mentions:${l}`),p&&p.forEach(d=>{n.push(`label:"${d}"`)}),this.searchIssues({query:`sort:updated ${n.join(" ")}`,cursor:o,includeFromArchivedRepos:t.includeFromArchivedRepos,maxPageSize:t.maxPageSize},r)}async closeIssueWithReason(t,r={}){var u,l,p;let{issue:n,reason:o}=t;if(!n.graphQLId)throw new Error('GitHub requires "graphQLId" for this function.');let i=`mutation CloseIssueWithReason($issueGraphQLId: ID!, $reason: IssueClosedStateReason!) {
584
584
  closeIssue(input: { issueId: $issueGraphQLId, stateReason: $reason }) {
585
585
  issue {
586
586
  id
587
587
  }
588
588
  }
589
- }`;if(!((p=(l=(u=(await R(this.config,{query:i,variables:{issueGraphQLId:n.graphQLId,reason:o}},r)).body.data)==null?void 0:u.closeIssue)==null?void 0:l.issue)!=null&&p.id))throw new Error("Could not close issue with reason")}async closeIssue(t,r={}){var a,u,l;let{issue:n}=t;if(!n.graphQLId)throw new Error('GitHub requires "graphQLId" for this function.');let o=`mutation SetIssueState($issueGraphQLId: ID!) {
589
+ }`;if(!((p=(l=(u=(await y(this.config,{query:i,variables:{issueGraphQLId:n.graphQLId,reason:o}},r)).body.data)==null?void 0:u.closeIssue)==null?void 0:l.issue)!=null&&p.id))throw new Error("Could not close issue with reason")}async closeIssue(t,r={}){var a,u,l;let{issue:n}=t;if(!n.graphQLId)throw new Error('GitHub requires "graphQLId" for this function.');let o=`mutation SetIssueState($issueGraphQLId: ID!) {
590
590
  updateIssue(input: { id: $issueGraphQLId, state: CLOSED }) {
591
591
  issue {
592
592
  id
593
593
  }
594
594
  }
595
- }`;if(!((l=(u=(a=(await R(this.config,{query:o,variables:{issueGraphQLId:n.graphQLId}},r)).body.data)==null?void 0:a.updateIssue)==null?void 0:u.issue)!=null&&l.id))throw new Error("Could not close issue")}async reOpenIssue(t,r={}){var a,u,l;let{issue:n}=t;if(!n.graphQLId)throw new Error('GitHub requires "graphQLId" for this function.');let o=`mutation ReOpenIssue($issueGraphQLId: ID!) {
595
+ }`;if(!((l=(u=(a=(await y(this.config,{query:o,variables:{issueGraphQLId:n.graphQLId}},r)).body.data)==null?void 0:a.updateIssue)==null?void 0:u.issue)!=null&&l.id))throw new Error("Could not close issue")}async reOpenIssue(t,r={}){var a,u,l;let{issue:n}=t;if(!n.graphQLId)throw new Error('GitHub requires "graphQLId" for this function.');let o=`mutation ReOpenIssue($issueGraphQLId: ID!) {
596
596
  reopenIssue(input: { issueId: $issueGraphQLId }) {
597
597
  issue {
598
598
  id
599
599
  }
600
600
  }
601
- }`;if(!((l=(u=(a=(await R(this.config,{query:o,variables:{issueGraphQLId:n.graphQLId}},r)).body.data)==null?void 0:a.reopenIssue)==null?void 0:u.issue)!=null&&l.id))throw new Error("Could not reopen issue")}async setIssueLabels(t,r={}){var l,p,d;let{issue:n,labels:o}=t;if(!n.graphQLId)throw new Error('GitHub requires "graphQLId" for this function.');let i=o.map(c=>c.graphQLId),a=`mutation SetIssueLabels($issueGraphQLId: ID!, $labelGraphQLIds: [ID!]) {
601
+ }`;if(!((l=(u=(a=(await y(this.config,{query:o,variables:{issueGraphQLId:n.graphQLId}},r)).body.data)==null?void 0:a.reopenIssue)==null?void 0:u.issue)!=null&&l.id))throw new Error("Could not reopen issue")}async setIssueLabels(t,r={}){var l,p,d;let{issue:n,labels:o}=t;if(!n.graphQLId)throw new Error('GitHub requires "graphQLId" for this function.');let i=o.map(c=>c.graphQLId),a=`mutation SetIssueLabels($issueGraphQLId: ID!, $labelGraphQLIds: [ID!]) {
602
602
  updateIssue(input: { id: $issueGraphQLId, labelIds: $labelGraphQLIds }) {
603
603
  issue {
604
604
  id
605
605
  }
606
606
  }
607
- }`;if(!((d=(p=(l=(await R(this.config,{query:a,variables:{issueGraphQLId:n.graphQLId,labelGraphQLIds:i}},r)).body.data)==null?void 0:l.updateIssue)==null?void 0:p.issue)!=null&&d.id))throw new Error("Could not set issue labels")}async setIssueMilestone(t,r={}){var u,l,p;let{issue:n,milestone:o}=t;if(!n.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) {
607
+ }`;if(!((d=(p=(l=(await y(this.config,{query:a,variables:{issueGraphQLId:n.graphQLId,labelGraphQLIds:i}},r)).body.data)==null?void 0:l.updateIssue)==null?void 0:p.issue)!=null&&d.id))throw new Error("Could not set issue labels")}async setIssueMilestone(t,r={}){var u,l,p;let{issue:n,milestone:o}=t;if(!n.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) {
608
608
  updateIssue(input: { id: $issueGraphQLId, milestoneId: $milestoneGraphQLId }) {
609
609
  issue {
610
610
  id
611
611
  }
612
612
  }
613
- }`;if(!((p=(l=(u=(await R(this.config,{query:`${i}`,variables:{issueGraphQLId:n.graphQLId,milestoneGraphQLId:(o==null?void 0:o.graphQLId)??null}},r)).body.data)==null?void 0:u.updateIssue)==null?void 0:l.issue)!=null&&p.id))throw new Error("Could not set milestone of issue")}async setIssueAssignees(t,r={}){var l,p,d;let{issue:n,assignees:o}=t;if(!n.graphQLId)throw new Error('GitHub requires "graphQLId" for this function.');let i=o.map(c=>{if(!c.graphQLId)throw new Error('GitHub requires assignee "graphQLId" for this function.');return c.graphQLId}),a=`mutation SetIssueAssignees($issueGraphQLId: ID!, $assigneeGraphQLIds: [ID!]!) {
613
+ }`;if(!((p=(l=(u=(await y(this.config,{query:`${i}`,variables:{issueGraphQLId:n.graphQLId,milestoneGraphQLId:(o==null?void 0:o.graphQLId)??null}},r)).body.data)==null?void 0:u.updateIssue)==null?void 0:l.issue)!=null&&p.id))throw new Error("Could not set milestone of issue")}async setIssueAssignees(t,r={}){var l,p,d;let{issue:n,assignees:o}=t;if(!n.graphQLId)throw new Error('GitHub requires "graphQLId" for this function.');let i=o.map(c=>{if(!c.graphQLId)throw new Error('GitHub requires assignee "graphQLId" for this function.');return c.graphQLId}),a=`mutation SetIssueAssignees($issueGraphQLId: ID!, $assigneeGraphQLIds: [ID!]!) {
614
614
  updateIssue(input: { id: $issueGraphQLId, assigneeIds: $assigneeGraphQLIds }) {
615
615
  issue {
616
616
  id
617
617
  }
618
618
  }
619
- }`;if(!((d=(p=(l=(await R(this.config,{query:a,variables:{issueGraphQLId:n.graphQLId,assigneeGraphQLIds:i}},r)).body.data)==null?void 0:l.updateIssue)==null?void 0:p.issue)!=null&&d.id))throw new Error("Could not set issue assignees")}async getMilestonesForRepo(t,r={}){var u,l,p,d;let{repo:{namespace:n,name:o},cursor:i}=t,a=await R(this.config,{query:`
619
+ }`;if(!((d=(p=(l=(await y(this.config,{query:a,variables:{issueGraphQLId:n.graphQLId,assigneeGraphQLIds:i}},r)).body.data)==null?void 0:l.updateIssue)==null?void 0:p.issue)!=null&&d.id))throw new Error("Could not set issue assignees")}async getMilestonesForRepo(t,r={}){var u,l,p,d;let{repo:{namespace:n,name:o},cursor:i}=t,a=await y(this.config,{query:`
620
620
  query getLabelsForRepo($owner: String!, $name: String! $cursor: String, $first: Int!) {
621
621
  repository(owner: $owner, name: $name) {
622
622
  milestones(first: $first, after: $cursor) {
623
623
  nodes {
624
- ${Re}
624
+ ${ye}
625
625
  }
626
626
  pageInfo {
627
627
  endCursor
@@ -630,12 +630,12 @@ query getLabelsForRepo($owner: String!, $name: String! $cursor: String, $first:
630
630
  }
631
631
  }
632
632
  }
633
- `,variables:{owner:n,name:o,cursor:i,first:S}},r);if(!a.body.data)throw new Error(((u=a.body.errors)==null?void 0:u[0].message)||a.statusText||"Unknown error");return{pageInfo:((l=a.body.data.repository.milestones)==null?void 0:l.pageInfo)??{endCursor:null,hasNextPage:!1},data:((d=(p=a.body.data.repository.milestones)==null?void 0:p.nodes)==null?void 0:d.map(gt))??[]}}async getLabelsForRepo(t,r={}){var u,l,p,d;let{repo:{namespace:n,name:o},cursor:i}=t,a=await R(this.config,{query:`
633
+ `,variables:{owner:n,name:o,cursor:i,first:C}},r);if(!a.body.data)throw new Error(((u=a.body.errors)==null?void 0:u[0].message)||a.statusText||"Unknown error");return{pageInfo:((l=a.body.data.repository.milestones)==null?void 0:l.pageInfo)??{endCursor:null,hasNextPage:!1},data:((d=(p=a.body.data.repository.milestones)==null?void 0:p.nodes)==null?void 0:d.map(mt))??[]}}async getLabelsForRepo(t,r={}){var u,l,p,d;let{repo:{namespace:n,name:o},cursor:i}=t,a=await y(this.config,{query:`
634
634
  query getLabelsForRepo($owner: String!, $name: String! $cursor: String, $first: Int!) {
635
635
  repository(owner: $owner, name: $name) {
636
636
  labels(first: $first, after: $cursor) {
637
637
  nodes {
638
- ${ye}
638
+ ${be}
639
639
  }
640
640
  pageInfo {
641
641
  endCursor
@@ -644,7 +644,7 @@ query getLabelsForRepo($owner: String!, $name: String! $cursor: String, $first:
644
644
  }
645
645
  }
646
646
  }
647
- `,variables:{owner:n,name:o,cursor:i,first:S}},r);if(!a.body.data)throw new Error(((u=a.body.errors)==null?void 0:u[0].message)||a.statusText||"Unknown error");return{pageInfo:((l=a.body.data.repository.labels)==null?void 0:l.pageInfo)??{endCursor:null,hasNextPage:!1},data:((d=(p=a.body.data.repository.labels)==null?void 0:p.nodes)==null?void 0:d.map(ct))??[]}}};var ns="https://gitlab.com/api/v4",os="https://gitlab.com/api/graphql",sr=/\/api\/v\d+$/,nr=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.")},mt=(s,e)=>{let t=e.baseUrl||s.baseUrl;return t?(t=t.replace(/\/$/,""),nr(t),t):ns},is=(s,e)=>{let t=e.baseUrl||s.baseUrl;return t?(t=t.replace(/\/$/,""),nr(t),sr.test(t)&&(t=t.replace(sr,"")),`${t}/api/graphql`):os},b=(s,e,t)=>{let r=f(t.token||s.token);return s.request({url:is(s,t),method:"POST",headers:{...r,"Content-Type":"application/json"},body:JSON.stringify(e)})},Pe=s=>s==null?void 0:s.map(e=>`"${e.message}"`).join(", ");var yt=s=>s.split("/").slice(0,-1).join("/"),bt=s=>s.split("/").at(-1)??"",Ee=s=>({id:s.id.replace(X,""),graphQLId:s.id,namespace:yt(s.fullPath),name:bt(s.fullPath),webUrl:s.webUrl}),or=s=>({id:s.id.replace(X,""),graphQLId:s.id,httpsUrl:s.httpUrlToRepo,namespace:yt(s.fullPath),name:bt(s.fullPath),sshUrl:s.sshUrlToRepo,webUrl:s.webUrl}),as={assigned:"assignedMergeRequests",authored:"authoredMergeRequests",reviewRequested:"reviewRequestedMergeRequests"},us={CAN_BE_MERGED:"MERGEABLE",CANNOT_BE_MERGED:"CONFLICTS",CANNOT_BE_MERGED_RECHECK:"UNKNOWN",UNCHECKED:"UNKNOWN",CHECKING:"UNKNOWN"};var ls="gid://gitlab/User/",X="gid://gitlab/Project/",ps="gid://gitlab/MergeRequest/",ds="gid://gitlab/Issue/",cs="gid://gitlab/ProjectLabel/",gs="gid://gitlab/Milestone/",ms="gid://gitlab/Ci::Build/",wt=`
647
+ `,variables:{owner:n,name:o,cursor:i,first:C}},r);if(!a.body.data)throw new Error(((u=a.body.errors)==null?void 0:u[0].message)||a.statusText||"Unknown error");return{pageInfo:((l=a.body.data.repository.labels)==null?void 0:l.pageInfo)??{endCursor:null,hasNextPage:!1},data:((d=(p=a.body.data.repository.labels)==null?void 0:p.nodes)==null?void 0:d.map(gt))??[]}}};var as="https://gitlab.com/api/v4",us="https://gitlab.com/api/graphql",ir=/\/api\/v\d+$/,ar=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.")},ht=(s,e)=>{let t=e.baseUrl||s.baseUrl;return t?(t=t.replace(/\/$/,""),ar(t),t):as},ls=(s,e)=>{let t=e.baseUrl||s.baseUrl;return t?(t=t.replace(/\/$/,""),ar(t),ir.test(t)&&(t=t.replace(ir,"")),`${t}/api/graphql`):us},b=(s,e,t)=>{let r=I(t.token||s.token);return s.request({url:ls(s,t),method:"POST",headers:{...r,"Content-Type":"application/json"},body:JSON.stringify(e)})},Ee=s=>s==null?void 0:s.map(e=>`"${e.message}"`).join(", ");var bt=s=>s.split("/").slice(0,-1).join("/"),wt=s=>s.split("/").at(-1)??"",ve=s=>({id:s.id.replace(Y,""),graphQLId:s.id,namespace:bt(s.fullPath),name:wt(s.fullPath),webUrl:s.webUrl}),ur=s=>({id:s.id.replace(Y,""),graphQLId:s.id,httpsUrl:s.httpUrlToRepo,namespace:bt(s.fullPath),name:wt(s.fullPath),sshUrl:s.sshUrlToRepo,webUrl:s.webUrl}),ps={assigned:"assignedMergeRequests",authored:"authoredMergeRequests",reviewRequested:"reviewRequestedMergeRequests"},ds={CAN_BE_MERGED:"MERGEABLE",CANNOT_BE_MERGED:"CONFLICTS",CANNOT_BE_MERGED_RECHECK:"UNKNOWN",UNCHECKED:"UNKNOWN",CHECKING:"UNKNOWN"};var cs="gid://gitlab/User/",Y="gid://gitlab/Project/",gs="gid://gitlab/MergeRequest/",ms="gid://gitlab/Issue/",hs="gid://gitlab/ProjectLabel/",fs="gid://gitlab/Milestone/",Is="gid://gitlab/Ci::Build/",Pt=`
648
648
  description
649
649
  dueDate
650
650
  id
@@ -653,7 +653,7 @@ startDate
653
653
  state
654
654
  title
655
655
  webPath
656
- `,ht=`
656
+ `,ft=`
657
657
  id
658
658
  fullPath
659
659
  webUrl
@@ -662,25 +662,25 @@ sshUrlToRepo
662
662
  repository {
663
663
  rootRef
664
664
  }
665
- `,j=`
665
+ `,F=`
666
666
  id
667
667
  name
668
668
  username
669
669
  publicEmail
670
670
  avatarUrl
671
671
  webUrl
672
- `,Pt=`
672
+ `,Et=`
673
673
  color
674
674
  description
675
675
  id
676
676
  title
677
- `,ft=`
677
+ `,It=`
678
678
  author {
679
- ${j}
679
+ ${F}
680
680
  }
681
681
  assignees {
682
682
  nodes {
683
- ${j}
683
+ ${F}
684
684
  }
685
685
  }
686
686
  closedAt
@@ -691,7 +691,7 @@ id
691
691
  iid
692
692
  labels {
693
693
  nodes {
694
- ${Pt}
694
+ ${Et}
695
695
  }
696
696
  }
697
697
  state
@@ -702,9 +702,9 @@ upvotes
702
702
  userNotesCount
703
703
  webUrl
704
704
  milestone {
705
- ${wt}
705
+ ${Pt}
706
706
  }
707
- `,hs=`
707
+ `,Rs=`
708
708
  stages {
709
709
  nodes {
710
710
  jobs {
@@ -720,12 +720,12 @@ stages {
720
720
  name
721
721
  }
722
722
  }
723
- `,ir=(s,e,t)=>`
723
+ `,lr=(s,e,t)=>`
724
724
  id
725
725
  state
726
726
  approved
727
727
  author {
728
- ${j}
728
+ ${F}
729
729
  }
730
730
  diffRefs {
731
731
  baseSha
@@ -750,12 +750,12 @@ targetBranch
750
750
  sourceBranch
751
751
  assignees {
752
752
  nodes {
753
- ${j}
753
+ ${F}
754
754
  }
755
755
  }
756
756
  reviewers {
757
757
  nodes {
758
- ${j}
758
+ ${F}
759
759
  mergeRequestInteraction {
760
760
  approved
761
761
  reviewState
@@ -765,19 +765,19 @@ reviewers {
765
765
  mergeStatusEnum
766
766
  labels {
767
767
  nodes {
768
- ${Pt}
768
+ ${Et}
769
769
  }
770
770
  }
771
771
  ${s?"project { id httpUrlToRepo fullPath sshUrlToRepo webUrl archived } sourceProject { id httpUrlToRepo fullPath sshUrlToRepo webUrl }":""}
772
- ${e?`milestone { ${wt} }`:""}
773
- ${t?`headPipeline { ${hs} }`:""}
774
- `,J=s=>`${s.namespace}/${s.name}`,fs=s=>`${s.namespace}/${s.name}`,It=s=>{var e;return{id:s.id.replace(X,""),graphQLId:s.id,namespace:yt(s.fullPath),name:bt(s.fullPath),webUrl:s.webUrl,httpsUrl:s.httpUrlToRepo,sshUrl:s.sshUrlToRepo,defaultBranch:(e=s.repository)!=null&&e.rootRef?{name:s.repository.rootRef}:null,permission:null}},Is={opened:"OPEN",merged:"MERGED",closed:"CLOSED"},F=(s,e)=>{let t=s.avatarUrl;return!e&&(t!=null&&t.startsWith("/"))&&(t=`https://gitlab.com${t}`),{id:s.id.replace(ls,""),graphQLId:s.id,name:s.name,username:s.username,email:s.publicEmail??null,avatarUrl:t,url:s.webUrl}},Et=s=>({color:s.color,description:s.description,id:s.id.replace(cs,""),graphQLId:s.id,name:s.title}),Rs=(s,e)=>s?s==="FAILED"&&e?"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,ys=(s,e)=>{var r;let t={APPROVED:"APPROVED",REQUESTED_CHANGES:"CHANGES_REQUESTED",REVIEWED:"COMMENTED",UNAPPROVED:"REVIEW_REQUESTED",UNREVIEWED:"REVIEW_REQUESTED"};return{reviewer:F(s,e),state:(r=s.mergeRequestInteraction)!=null&&r.reviewState?t[s.mergeRequestInteraction.reviewState]:"REVIEW_REQUESTED"}},ar=(s,e,t,r)=>{var o,i,a,u,l,p,d,c,g,m,I,w;let n=(o=s.reviewers)!=null&&o.nodes?s.reviewers.nodes.map(h=>ys(h,r)):null;return{id:s.id.replace(ps,""),graphQLId:s.id,title:s.title,number:parseInt(s.iid,10),state:Is[s.state],commentCount:s.userNotesCount||0,upvoteCount:s.upvotes,author:s.author?F(s.author,r):null,createdDate:new Date(s.createdAt),isDraft:s.draft,repository:{id:e.id,graphQLId:e.graphQLId,name:e.name,owner:{login:e.namespace},remoteInfo:e.httpsUrl&&e.sshUrl?{cloneUrlHTTPS:e.httpsUrl,cloneUrlSSH:e.sshUrl}:null},headRepository:t?{id:t.id,graphQLId:t.graphQLId,name:t.name,owner:{login:t.namespace},remoteInfo:{cloneUrlHTTPS:t.httpsUrl,cloneUrlSSH:t.sshUrl}}:null,headCommit:{buildStatuses:((u=(a=(i=s.headPipeline)==null?void 0:i.stages)==null?void 0:a.nodes)==null?void 0:u.flatMap(h=>{var y,q;return((q=(y=h.jobs)==null?void 0:y.nodes)==null?void 0:q.map(C=>({completedAt:C.finishedAt?new Date(C.finishedAt):null,description:null,name:C.name??null,state:Rs(C.status,C.allowFailure),stage:h.name??null,startedAt:new Date(C.createdAt),url:`${e.webUrl}/-/jobs/${C.id.replace(ms,"")}`})))??[]}))??[]},baseRef:{name:s.targetBranch,oid:((l=s.diffRefs)==null?void 0:l.baseSha)??null},headRef:{name:s.sourceBranch,oid:((p=s.diffRefs)==null?void 0:p.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:(d=s.assignees)!=null&&d.nodes?s.assignees.nodes.map(h=>F(h,r)):null,reviews:n,reviewDecision:s.approved?"APPROVED":z(n),additions:((c=s.diffStatsSummary)==null?void 0:c.additions)||0,deletions:((g=s.diffStatsSummary)==null?void 0:g.deletions)||0,fileCount:((m=s.diffStatsSummary)==null?void 0:m.fileCount)||0,commitCount:s.commitCount||0,mergeableState:us[s.mergeStatusEnum],milestone:s.milestone?vt(s.milestone,e.webUrl):null,labels:((w=(I=s.labels)==null?void 0:I.nodes)==null?void 0:w.map(Et))??[],permissions:null}},Rt=(s,e,t)=>{var r,n;return{author:F(s.author,t),assignees:s.assignees.nodes.map(o=>F(o,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(ds,""),labels:((n=(r=s.labels)==null?void 0:r.nodes)==null?void 0:n.map(Et))??[],number:s.iid,repository:{id:e.id.replace(X,""),graphQLId:e.id,name:e.name,owner:{login:e.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?vt(s.milestone,e.webUrl):null}},vt=(s,e)=>({id:s.id.replace(gs,""),graphQLId:s.id,number:parseInt(s.iid,10),title:s.title,description:s.description,isOpen:s.state==="active",url:`${e}/-/${s.webPath.replace(/.+?\/-\//,"")}`,startDate:s.startDate?new Date(s.startDate):null,dueDate:s.dueDate?new Date(s.dueDate):null}),oe=class extends N{getIsSelfHosted(e){return!!e.baseUrl||!!this.config.baseUrl}async getCurrentUser(e={},t={}){var o;let n=(o=(await b(this.config,{query:`
772
+ ${e?`milestone { ${Pt} }`:""}
773
+ ${t?`headPipeline { ${Rs} }`:""}
774
+ `,V=s=>`${s.namespace}/${s.name}`,ys=s=>`${s.namespace}/${s.name}`,Rt=s=>{var e;return{id:s.id.replace(Y,""),graphQLId:s.id,namespace:bt(s.fullPath),name:wt(s.fullPath),webUrl:s.webUrl,httpsUrl:s.httpUrlToRepo,sshUrl:s.sshUrlToRepo,defaultBranch:(e=s.repository)!=null&&e.rootRef?{name:s.repository.rootRef}:null,permission:null}},bs={opened:"OPEN",merged:"MERGED",closed:"CLOSED"},M=(s,e)=>{let t=s.avatarUrl;return!e&&(t!=null&&t.startsWith("/"))&&(t=`https://gitlab.com${t}`),{id:s.id.replace(cs,""),graphQLId:s.id,name:s.name,username:s.username,email:s.publicEmail??null,avatarUrl:t,url:s.webUrl}},vt=s=>({color:s.color,description:s.description,id:s.id.replace(hs,""),graphQLId:s.id,name:s.title}),ws=(s,e)=>s?s==="FAILED"&&e?"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,Ps=(s,e)=>{var r;let t={APPROVED:"APPROVED",REQUESTED_CHANGES:"CHANGES_REQUESTED",REVIEWED:"COMMENTED",UNAPPROVED:"REVIEW_REQUESTED",UNREVIEWED:"REVIEW_REQUESTED"};return{reviewer:M(s,e),state:(r=s.mergeRequestInteraction)!=null&&r.reviewState?t[s.mergeRequestInteraction.reviewState]:"REVIEW_REQUESTED"}},pr=(s,e,t,r)=>{var o,i,a,u,l,p,d,c,g,m,h,R;let n=(o=s.reviewers)!=null&&o.nodes?s.reviewers.nodes.map(w=>Ps(w,r)):null;return{id:s.id.replace(gs,""),graphQLId:s.id,title:s.title,number:parseInt(s.iid,10),state:bs[s.state],commentCount:s.userNotesCount||0,upvoteCount:s.upvotes,author:s.author?M(s.author,r):null,createdDate:new Date(s.createdAt),isDraft:s.draft,repository:{id:e.id,graphQLId:e.graphQLId,name:e.name,owner:{login:e.namespace},remoteInfo:e.httpsUrl&&e.sshUrl?{cloneUrlHTTPS:e.httpsUrl,cloneUrlSSH:e.sshUrl}:null},headRepository:t?{id:t.id,graphQLId:t.graphQLId,name:t.name,owner:{login:t.namespace},remoteInfo:{cloneUrlHTTPS:t.httpsUrl,cloneUrlSSH:t.sshUrl}}:null,headCommit:{buildStatuses:((u=(a=(i=s.headPipeline)==null?void 0:i.stages)==null?void 0:a.nodes)==null?void 0:u.flatMap(w=>{var f,E;return((E=(f=w.jobs)==null?void 0:f.nodes)==null?void 0:E.map(S=>({completedAt:S.finishedAt?new Date(S.finishedAt):null,description:null,name:S.name??null,state:ws(S.status,S.allowFailure),stage:w.name??null,startedAt:new Date(S.createdAt),url:`${e.webUrl}/-/jobs/${S.id.replace(Is,"")}`})))??[]}))??[]},baseRef:{name:s.targetBranch,oid:((l=s.diffRefs)==null?void 0:l.baseSha)??null},headRef:{name:s.sourceBranch,oid:((p=s.diffRefs)==null?void 0:p.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:(d=s.assignees)!=null&&d.nodes?s.assignees.nodes.map(w=>M(w,r)):null,reviews:n,reviewDecision:s.approved?"APPROVED":H(n),additions:((c=s.diffStatsSummary)==null?void 0:c.additions)||0,deletions:((g=s.diffStatsSummary)==null?void 0:g.deletions)||0,fileCount:((m=s.diffStatsSummary)==null?void 0:m.fileCount)||0,commitCount:s.commitCount||0,mergeableState:ds[s.mergeStatusEnum],milestone:s.milestone?qt(s.milestone,e.webUrl):null,labels:((R=(h=s.labels)==null?void 0:h.nodes)==null?void 0:R.map(vt))??[],permissions:null}},yt=(s,e,t)=>{var r,n;return{author:M(s.author,t),assignees:s.assignees.nodes.map(o=>M(o,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(ms,""),labels:((n=(r=s.labels)==null?void 0:r.nodes)==null?void 0:n.map(vt))??[],number:s.iid,repository:{id:e.id.replace(Y,""),graphQLId:e.id,name:e.name,owner:{login:e.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?qt(s.milestone,e.webUrl):null}},qt=(s,e)=>({id:s.id.replace(fs,""),graphQLId:s.id,number:parseInt(s.iid,10),title:s.title,description:s.description,isOpen:s.state==="active",url:`${e}/-/${s.webPath.replace(/.+?\/-\//,"")}`,startDate:s.startDate?new Date(s.startDate):null,dueDate:s.dueDate?new Date(s.dueDate):null}),ie=class extends _{getIsSelfHosted(e){return!!e.baseUrl||!!this.config.baseUrl}async getCurrentUser(e={},t={}){var o;let n=(o=(await b(this.config,{query:`
775
775
  query getCurrentUser {
776
776
  currentUser {
777
- ${j}
777
+ ${F}
778
778
  }
779
779
  }
780
- `},t)).body.data)==null?void 0:o.currentUser;if(!n)throw new Error("Current user not found.");return{data:F(n,this.getIsSelfHosted(t))}}async getUserForCommit(e,t={}){var i,a,u,l;let r=J(e.repo),o=(l=(u=(a=(i=(await b(this.config,{query:`
780
+ `},t)).body.data)==null?void 0:o.currentUser;if(!n)throw new Error("Current user not found.");return{data:M(n,this.getIsSelfHosted(t))}}async getUserForCommit(e,t={}){var i,a,u,l;let r=V(e.repo),o=(l=(u=(a=(i=(await b(this.config,{query:`
781
781
  query getUserForCommit($fullPath: ID!, $oid: String!) {
782
782
  project(fullPath: $fullPath) {
783
783
  repository {
@@ -795,17 +795,17 @@ query getUserForCommit($fullPath: ID!, $oid: String!) {
795
795
  query getAccountForEmail($email: String!) {
796
796
  users(search: $email) {
797
797
  nodes {
798
- ${j}
798
+ ${F}
799
799
  }
800
800
  }
801
801
  }
802
- `,variables:{email:e.email}},t)).body.data)==null?void 0:o.users)==null?void 0:i.nodes)==null?void 0:a[0];if(!n)throw new Error("User not found.");return{data:F(n,this.getIsSelfHosted(t))}}async getAccountForUsername(e,t={}){var o;let n=(o=(await b(this.config,{query:`
802
+ `,variables:{email:e.email}},t)).body.data)==null?void 0:o.users)==null?void 0:i.nodes)==null?void 0:a[0];if(!n)throw new Error("User not found.");return{data:M(n,this.getIsSelfHosted(t))}}async getAccountForUsername(e,t={}){var o;let n=(o=(await b(this.config,{query:`
803
803
  query getAccountForUsername($username: String!) {
804
804
  user(username: $username) {
805
- ${j}
805
+ ${F}
806
806
  }
807
807
  }
808
- `,variables:{username:e.username}},t)).body.data)==null?void 0:o.user;if(!n)throw new Error("User not found.");return{data:F(n,this.getIsSelfHosted(t))}}async getAccountsForRepo(e,t={}){var u,l,p,d,c,g,m;let{repo:{namespace:r,name:n},cursor:o}=e,i=await b(this.config,{query:`
808
+ `,variables:{username:e.username}},t)).body.data)==null?void 0:o.user;if(!n)throw new Error("User not found.");return{data:M(n,this.getIsSelfHosted(t))}}async getAccountsForRepo(e,t={}){var u,l,p,d,c,g,m;let{repo:{namespace:r,name:n},cursor:o}=e,i=await b(this.config,{query:`
809
809
  query getAccountsForRepo(
810
810
  $fullPath: ID!
811
811
  $after: String
@@ -816,7 +816,7 @@ query getAccountsForRepo(
816
816
  projectMembers(after: $after) {
817
817
  nodes {
818
818
  user {
819
- ${j}
819
+ ${F}
820
820
  }
821
821
  }
822
822
  pageInfo {
@@ -826,22 +826,22 @@ query getAccountsForRepo(
826
826
  }
827
827
  }
828
828
  }
829
- `,variables:{fullPath:`${r}/${n}`,after:o}},t),a=(d=(p=(l=(u=i.body.data)==null?void 0:u.project)==null?void 0:l.projectMembers)==null?void 0:p.nodes)==null?void 0:d.map(I=>I.user).filter(I=>I!==null);return{pageInfo:((m=(g=(c=i.body.data)==null?void 0:c.project)==null?void 0:g.projectMembers)==null?void 0:m.pageInfo)??{endCursor:null,hasNextPage:!1},data:(a==null?void 0:a.map(I=>F(I,this.getIsSelfHosted(t))))??[]}}async getRepo(e,t={}){var o;let r=J(e),n=await b(this.config,{query:`
829
+ `,variables:{fullPath:`${r}/${n}`,after:o}},t),a=(d=(p=(l=(u=i.body.data)==null?void 0:u.project)==null?void 0:l.projectMembers)==null?void 0:p.nodes)==null?void 0:d.map(h=>h.user).filter(h=>h!==null);return{pageInfo:((m=(g=(c=i.body.data)==null?void 0:c.project)==null?void 0:g.projectMembers)==null?void 0:m.pageInfo)??{endCursor:null,hasNextPage:!1},data:(a==null?void 0:a.map(h=>M(h,this.getIsSelfHosted(t))))??[]}}async getRepo(e,t={}){var o;let r=V(e),n=await b(this.config,{query:`
830
830
  query getRepo($fullPath: ID!) {
831
831
  project(fullPath: $fullPath) {
832
- ${ht}
832
+ ${ft}
833
833
  }
834
834
  }
835
- `,variables:{fullPath:r}},t);if(!((o=n.body.data)!=null&&o.project))throw new Error(`Repository ${r} not found`);return{data:It(n.body.data.project)}}async getReposBase(e,t={}){let n=e.map(J).map((u,l)=>`
835
+ `,variables:{fullPath:r}},t);if(!((o=n.body.data)!=null&&o.project))throw new Error(`Repository ${r} not found`);return{data:Rt(n.body.data.project)}}async getReposBase(e,t={}){let n=e.map(V).map((u,l)=>`
836
836
  getRepo_${l}: project(fullPath: "${u}") {
837
- ${ht}
837
+ ${ft}
838
838
  }
839
839
  `).join(`
840
840
  `),o=await b(this.config,{query:`
841
841
  query batchGetRepos {
842
842
  ${n}
843
843
  }
844
- `},t);if(!o.body.data)throw new Error(Pe(o.body.errors)||o.statusText||"Unknown error");let i=[],a=[];return e.forEach((u,l)=>{let p=o.body.data[`getRepo_${l}`];p?i.push(It(p)):a.push({input:u})}),{data:i,errors:a}}async getRepos(e,t={}){let r=[];for(let i=0;i<e.length;i+=20)r.push(e.slice(i,i+20));return(await Promise.all(r.map(i=>this.getReposBase(i,t)))).reduce((i,a)=>({data:[...i.data,...a.data],errors:[...i.errors,...a.errors]}),{data:[],errors:[]})}async getReposForCurrentUser(e,t={}){var o,i,a,u,l;let r=await b(this.config,{query:`
844
+ `},t);if(!o.body.data)throw new Error(Ee(o.body.errors)||o.statusText||"Unknown error");let i=[],a=[];return e.forEach((u,l)=>{let p=o.body.data[`getRepo_${l}`];p?i.push(Rt(p)):a.push({input:u})}),{data:i,errors:a}}async getRepos(e,t={}){let r=[];for(let i=0;i<e.length;i+=20)r.push(e.slice(i,i+20));return(await Promise.all(r.map(i=>this.getReposBase(i,t)))).reduce((i,a)=>({data:[...i.data,...a.data],errors:[...i.errors,...a.errors]}),{data:[],errors:[]})}async getReposForCurrentUser(e,t={}){var o,i,a,u,l;let r=await b(this.config,{query:`
845
845
  query getReposForCurrentUser($after: String) {
846
846
  projects(membership: true first: 100 after: $after) {
847
847
  pageInfo {
@@ -849,25 +849,25 @@ query getReposForCurrentUser($after: String) {
849
849
  hasNextPage
850
850
  }
851
851
  nodes {
852
- ${ht}
852
+ ${ft}
853
853
  }
854
854
  }
855
855
  }
856
- `,variables:{after:e.cursor}},t);if(!((o=r.body.data)!=null&&o.projects))throw new Error(Pe(r.body.errors)||r.statusText||"Unknown error");let n=((a=(i=r.body.data)==null?void 0:i.projects)==null?void 0:a.nodes)||[];return{pageInfo:(l=(u=r.body.data)==null?void 0:u.projects)==null?void 0:l.pageInfo,data:n.map(It)}}async getRefs(e,t,r={}){var u;let n=J(t.repo),o=new URL(`${mt(this.config,r)}/projects/${encodeURIComponent(n)}/repository/${e}`);o.searchParams.set("page",((u=t.page)==null?void 0:u.toString())||"1"),o.searchParams.set("per_page",S.toString());let i=await this.config.request({url:o.toString(),headers:f(r.token||this.config.token)}),a=i.headers["x-next-page"];return{pageInfo:{hasNextPage:!!a,nextPage:a?parseInt(a,10):null},data:i.body.map(l=>({name:l.name,commit:{oid:l.commit.id,authoredDate:new Date(l.commit.authored_date),committedDate:new Date(l.commit.committed_date)}}))}}async getBranches(e,t={}){return this.getRefs("branches",e,t)}async getTags(e,t={}){return this.getRefs("tags",e,t)}async getBlame(e,t={}){let r=J(e.repo),n=new URL(`${mt(this.config,t)}/projects/${encodeURIComponent(r)}/repository/files/${encodeURIComponent(e.path)}/blame`);n.searchParams.set("ref",e.ref);let o=await this.config.request({url:n.toString(),headers:f(t.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(e,t={}){var i;let r=as[e.association],n=await b(this.config,{query:`
857
- query getPullRequestsForUser($username: String! $cursor: String) {
856
+ `,variables:{after:e.cursor}},t);if(!((o=r.body.data)!=null&&o.projects))throw new Error(Ee(r.body.errors)||r.statusText||"Unknown error");let n=((a=(i=r.body.data)==null?void 0:i.projects)==null?void 0:a.nodes)||[];return{pageInfo:(l=(u=r.body.data)==null?void 0:u.projects)==null?void 0:l.pageInfo,data:n.map(Rt)}}async getRefs(e,t,r={}){var u;let n=V(t.repo),o=new URL(`${ht(this.config,r)}/projects/${encodeURIComponent(n)}/repository/${e}`);o.searchParams.set("page",((u=t.page)==null?void 0:u.toString())||"1"),o.searchParams.set("per_page",C.toString());let i=await this.config.request({url:o.toString(),headers:I(r.token||this.config.token)}),a=i.headers["x-next-page"];return{pageInfo:{hasNextPage:!!a,nextPage:a?parseInt(a,10):null},data:i.body.map(l=>({name:l.name,commit:{oid:l.commit.id,authoredDate:new Date(l.commit.authored_date),committedDate:new Date(l.commit.committed_date)}}))}}async getBranches(e,t={}){return this.getRefs("branches",e,t)}async getTags(e,t={}){return this.getRefs("tags",e,t)}async getBlame(e,t={}){let r=V(e.repo),n=new URL(`${ht(this.config,t)}/projects/${encodeURIComponent(r)}/repository/files/${encodeURIComponent(e.path)}/blame`);n.searchParams.set("ref",e.ref);let o=await this.config.request({url:n.toString(),headers:I(t.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(e,t={}){var i;let r=ps[e.association],n=await b(this.config,{query:`
857
+ query getPullRequestsForUser($username: String! $cursor: String $labelNames: [String]) {
858
858
  user(username: $username) {
859
- ${r}(state:opened first:100 after:$cursor) {
859
+ ${r}(state:opened first:100 after:$cursor labelName: $labelNames) {
860
860
  pageInfo {
861
861
  endCursor
862
862
  hasNextPage
863
863
  }
864
864
  nodes {
865
- ${ir(!0,!0,!0)}
865
+ ${lr(!0,!0,!0)}
866
866
  }
867
867
  }
868
868
  }
869
869
  }
870
- `,variables:{username:e.username,cursor:e.cursor}},t);if(!n.body.data)throw new Error(Pe(n.body.errors)||n.statusText||"Unknown error");if(!n.body.data.user)throw new Error("User not found");let o=n.body.data.user[r];if(!o)throw new Error("Unexpected response");return{pageInfo:o.pageInfo,data:((i=o.nodes)==null?void 0:i.filter(a=>e.includeFromArchivedRepos||!a.project.archived).map(a=>ar(a,or(a.project),or(a.sourceProject),this.getIsSelfHosted(t))))||[]}}async getPullRequestsAssociatedWithUser(e,t={}){var c;let[r,n,o]=((c=e.cursor)==null?void 0:c.split(";"))||[void 0,void 0,void 0],[i,a,u]=await Promise.all([r==="null"?null:this.getPullRequestsForUser({username:e.username,association:"authored",cursor:r,includeFromArchivedRepos:e.includeFromArchivedRepos},t),n==="null"?null:this.getPullRequestsForUser({username:e.username,association:"assigned",cursor:n,includeFromArchivedRepos:e.includeFromArchivedRepos},t),o==="null"?null:this.getPullRequestsForUser({username:e.username,association:"reviewRequested",cursor:o,includeFromArchivedRepos:e.includeFromArchivedRepos},t)]),l={},p=[],d=g=>{l[g.id]||(l[g.id]=!0,p.push(g))};return i==null||i.data.forEach(d),a==null||a.data.forEach(d),u==null||u.data.forEach(d),{pageInfo:{hasNextPage:(i==null?void 0:i.pageInfo.hasNextPage)||(a==null?void 0:a.pageInfo.hasNextPage)||(u==null?void 0:u.pageInfo.hasNextPage)||!1,endCursor:`${(i==null?void 0:i.pageInfo.hasNextPage)&&(i==null?void 0:i.pageInfo.endCursor)||"null"};${(a==null?void 0:a.pageInfo.hasNextPage)&&(a==null?void 0:a.pageInfo.endCursor)||"null"};${(u==null?void 0:u.pageInfo.hasNextPage)&&(u==null?void 0:u.pageInfo.endCursor)||"null"}`},data:p}}getVariablesForPullRequests(e){let{updatedBefore:t,isDraft:r,authorLogin:n,assigneeLogins:o,reviewRequestedLogin:i}=e||{},a={},u=[],l=[],p=(d,c,g)=>{u.push(`$${d}: ${g}`),l.push(`${d}: $${d}`),a[d]=c};return t&&p("updatedBefore",t,"Time"),n&&p("authorUsername",n,"String"),o&&p("assigneeUsername",o[0],"String"),r!=null&&p("draft",r,"Boolean"),i&&p("reviewerUsername",i,"String"),{variables:a,variableTypes:u,mergeRequestArguments:l}}async getPullRequestsForRepoBase(e,t={},r){var w,h,y;let{cursor:n,repo:o}=e||{},i=J(o),{variables:a,variableTypes:u,mergeRequestArguments:l}=this.getVariablesForPullRequests(e),p={fullPath:i,...a},d=await b(this.config,{query:`
870
+ `,variables:{username:e.username,cursor:e.cursor,labelNames:e.labelNames}},t);if(!n.body.data)throw new Error(Ee(n.body.errors)||n.statusText||"Unknown error");if(!n.body.data.user)throw new Error("User not found");let o=n.body.data.user[r];if(!o)throw new Error("Unexpected response");return{pageInfo:o.pageInfo,data:((i=o.nodes)==null?void 0:i.filter(a=>e.includeFromArchivedRepos||!a.project.archived).map(a=>pr(a,ur(a.project),ur(a.sourceProject),this.getIsSelfHosted(t))))||[]}}async getPullRequestsAssociatedWithUser(e,t={}){var c;let[r,n,o]=((c=e.cursor)==null?void 0:c.split(";"))||[void 0,void 0,void 0],[i,a,u]=await Promise.all([r==="null"?null:this.getPullRequestsForUser({username:e.username,association:"authored",cursor:r,includeFromArchivedRepos:e.includeFromArchivedRepos,labelNames:e.labelNames},t),n==="null"?null:this.getPullRequestsForUser({username:e.username,association:"assigned",cursor:n,includeFromArchivedRepos:e.includeFromArchivedRepos,labelNames:e.labelNames},t),o==="null"?null:this.getPullRequestsForUser({username:e.username,association:"reviewRequested",cursor:o,includeFromArchivedRepos:e.includeFromArchivedRepos,labelNames:e.labelNames},t)]),l={},p=[],d=g=>{l[g.id]||(l[g.id]=!0,p.push(g))};return i==null||i.data.forEach(d),a==null||a.data.forEach(d),u==null||u.data.forEach(d),{pageInfo:{hasNextPage:(i==null?void 0:i.pageInfo.hasNextPage)||(a==null?void 0:a.pageInfo.hasNextPage)||(u==null?void 0:u.pageInfo.hasNextPage)||!1,endCursor:`${(i==null?void 0:i.pageInfo.hasNextPage)&&(i==null?void 0:i.pageInfo.endCursor)||"null"};${(a==null?void 0:a.pageInfo.hasNextPage)&&(a==null?void 0:a.pageInfo.endCursor)||"null"};${(u==null?void 0:u.pageInfo.hasNextPage)&&(u==null?void 0:u.pageInfo.endCursor)||"null"}`},data:p}}getVariablesForPullRequests(e){let{updatedBefore:t,isDraft:r,authorLogin:n,assigneeLogins:o,labelNames:i,reviewRequestedLogin:a}=e||{},u={},l=[],p=[],d=(c,g,m)=>{l.push(`$${c}: ${m}`),p.push(`${c}: $${c}`),u[c]=g};return t&&d("updatedBefore",t,"Time"),n&&d("authorUsername",n,"String"),o&&d("assigneeUsername",o[0],"String"),i&&d("labelName",i,"[String]"),r!=null&&d("draft",r,"Boolean"),a&&d("reviewerUsername",a,"String"),{variables:u,variableTypes:l,mergeRequestArguments:p}}async getPullRequestsForRepoBase(e,t={},r){var R,w,f;let{cursor:n,repo:o}=e||{},i=V(o),{variables:a,variableTypes:u,mergeRequestArguments:l}=this.getVariablesForPullRequests(e),p={fullPath:i,...a},d=await b(this.config,{query:`
871
871
  query getPullRequestsForRepo(
872
872
  $fullPath: ID!
873
873
  $after: String
@@ -892,12 +892,12 @@ query getPullRequestsForRepo(
892
892
  hasNextPage
893
893
  }
894
894
  nodes {
895
- ${ir(!1,!0,!0)}
895
+ ${lr(!1,!0,!0)}
896
896
  }
897
897
  }
898
898
  }
899
899
  }
900
- `,variables:{...p,after:n}},t),c=[],g=(w=d.body.data)==null?void 0:w.project;if(!r&&(g!=null&&g.archived))return{pageInfo:null,data:[]};let m=Ee(g||{id:"",fullPath:"",webUrl:""});return(((h=g==null?void 0:g.mergeRequests)==null?void 0:h.nodes)||[]).forEach(q=>{c.push(ar(q,m,null,this.getIsSelfHosted(t)))}),{pageInfo:(y=g==null?void 0:g.mergeRequests)==null?void 0:y.pageInfo,data:c}}async getPullRequestsForRepo(e,t={}){return this.getPullRequestsForRepoBase(e,t,!1)}async getPullRequestsForRepos(e,t={}){let{repos:r,assigneeLogins:n,updatedBefore:o,authorLogin:i,isDraft:a,reviewRequestedLogin:u}=e;return{data:(await Promise.all(r.map(p=>this.getPullRequestsForRepoBase({repo:p,assigneeLogins:n,updatedBefore:o,authorLogin:i,isDraft:a,reviewRequestedLogin:u},t,e.includeFromArchivedRepos??!1)))).flatMap(p=>p.data)}}async closePullRequest(e,t={}){var a,u,l;let{pullRequest:r}=e,n=`mutation ClosePullRequest($fullPath: ID!, $pullRequestId: String!) {
900
+ `,variables:{...p,after:n}},t),c=[],g=(R=d.body.data)==null?void 0:R.project;if(!r&&(g!=null&&g.archived))return{pageInfo:null,data:[]};let m=ve(g||{id:"",fullPath:"",webUrl:""});return(((w=g==null?void 0:g.mergeRequests)==null?void 0:w.nodes)||[]).forEach(E=>{c.push(pr(E,m,null,this.getIsSelfHosted(t)))}),{pageInfo:(f=g==null?void 0:g.mergeRequests)==null?void 0:f.pageInfo,data:c}}async getPullRequestsForRepo(e,t={}){return this.getPullRequestsForRepoBase(e,t,!1)}async getPullRequestsForRepos(e,t={}){let{repos:r,assigneeLogins:n,updatedBefore:o,authorLogin:i,labelNames:a,isDraft:u,reviewRequestedLogin:l}=e;return{data:(await Promise.all(r.map(d=>this.getPullRequestsForRepoBase({repo:d,assigneeLogins:n,updatedBefore:o,authorLogin:i,labelNames:a,isDraft:u,reviewRequestedLogin:l},t,e.includeFromArchivedRepos??!1)))).flatMap(d=>d.data)}}async closePullRequest(e,t={}){var a,u,l;let{pullRequest:r}=e,n=`mutation ClosePullRequest($fullPath: ID!, $pullRequestId: String!) {
901
901
  mergeRequestUpdate(input: { projectPath: $fullPath, iid: $pullRequestId, state: CLOSED }) {
902
902
  errors,
903
903
  mergeRequest {
@@ -962,18 +962,18 @@ query getPullRequestsForRepo(
962
962
  id
963
963
  }
964
964
  }
965
- }`;if(!((p=(l=(u=(await b(this.config,{query:i,variables:{fullPath:`${r.repository.owner.login}/${r.repository.name}`,pullRequestId:r.number.toString(),labelGraphQLIds:o}},t)).body.data)==null?void 0:u.mergeRequestSetLabels)==null?void 0:l.mergeRequest)!=null&&p.id))throw new Error("Could not set pull request labels")}async getIssue(e,t={}){var o,i,a;let r=fs(e),n=await b(this.config,{query:`
965
+ }`;if(!((p=(l=(u=(await b(this.config,{query:i,variables:{fullPath:`${r.repository.owner.login}/${r.repository.name}`,pullRequestId:r.number.toString(),labelGraphQLIds:o}},t)).body.data)==null?void 0:u.mergeRequestSetLabels)==null?void 0:l.mergeRequest)!=null&&p.id))throw new Error("Could not set pull request labels")}async getIssue(e,t={}){var o,i,a;let r=ys(e),n=await b(this.config,{query:`
966
966
  query GetSingleIssue($projectId: ID!, $issueNumber: String!) {
967
967
  project(fullPath: $projectId) {
968
968
  id
969
969
  fullPath
970
970
  webUrl
971
971
  issue(iid: $issueNumber) {
972
- ${ft}
972
+ ${It}
973
973
  }
974
974
  }
975
975
  }
976
- `,variables:{issueNumber:e.number,projectId:r}},t);if(!((o=n.body.data)!=null&&o.project))throw new Error(`Repository ${r} not found`);if(!((a=(i=n.body.data)==null?void 0:i.project)!=null&&a.issue))throw new Error(`Issue ${e.number} not found`);return{data:Rt(n.body.data.project.issue,Ee(n.body.data.project),this.getIsSelfHosted(t))}}getVariablesForIssues(e){let{updatedBefore:t,authorLogin:r,assigneeLogins:n}=e||{},o={},i=[],a=[],u=(l,p,d)=>{i.push(`$${l}: ${d}`),a.push(`${l}: $${l}`),o[l]=p};return t&&u("updatedBefore",t,"Time"),r&&u("authorUsername",r,"String"),n&&u("assigneeUsername",n[0],"String"),{variables:o,variableTypes:i,issueArguments:a}}async getIssuesForRepo(e,t={}){var w,h,y;let{cursor:r,repo:n}=e||{},o=J(n),{variables:i,variableTypes:a,issueArguments:u}=this.getVariablesForIssues(e),l={fullPath:o,...i},p=`
976
+ `,variables:{issueNumber:e.number,projectId:r}},t);if(!((o=n.body.data)!=null&&o.project))throw new Error(`Repository ${r} not found`);if(!((a=(i=n.body.data)==null?void 0:i.project)!=null&&a.issue))throw new Error(`Issue ${e.number} not found`);return{data:yt(n.body.data.project.issue,ve(n.body.data.project),this.getIsSelfHosted(t))}}getVariablesForIssues(e){let{updatedBefore:t,authorLogin:r,assigneeLogins:n,labelNames:o}=e||{},i={},a=[],u=[],l=(p,d,c)=>{a.push(`$${p}: ${c}`),u.push(`${p}: $${p}`),i[p]=d};return t&&l("updatedBefore",t,"Time"),r&&l("authorUsername",r,"String"),n&&l("assigneeUsername",n[0],"String"),o&&l("labelName",o,"[String]"),{variables:i,variableTypes:a,issueArguments:u}}async getIssuesForRepo(e,t={}){var R,w,f;let{cursor:r,repo:n}=e||{},o=V(n),{variables:i,variableTypes:a,issueArguments:u}=this.getVariablesForIssues(e),l={fullPath:o,...i},p=`
977
977
  query GetIssuesFromProject(
978
978
  $fullPath: ID!
979
979
  $after: String
@@ -993,7 +993,7 @@ query GetSingleIssue($projectId: ID!, $issueNumber: String!) {
993
993
  ${u.length?u.join(" "):""}
994
994
  ) {
995
995
  nodes {
996
- ${ft}
996
+ ${It}
997
997
  }
998
998
  pageInfo {
999
999
  endCursor
@@ -1001,7 +1001,7 @@ query GetSingleIssue($projectId: ID!, $issueNumber: String!) {
1001
1001
  }
1002
1002
  }
1003
1003
  }
1004
- }`,d=await b(this.config,{query:p,variables:{...l,after:r}},t),c=[],g=(w=d.body.data)==null?void 0:w.project,m=Ee(g||{id:"",fullPath:"",webUrl:""});return(((h=g==null?void 0:g.issues)==null?void 0:h.nodes)||[]).forEach(q=>{c.push(Rt(q,m,this.getIsSelfHosted(t)))}),{pageInfo:((y=g==null?void 0:g.issues)==null?void 0:y.pageInfo)??{endCursor:null,hasNextPage:!1},data:c.sort((q,C)=>(q.updatedDate||q.createdDate).getTime()-(C.updatedDate||C.createdDate).getTime())}}async getIssuesForRepos(e,t={}){var g,m,I,w,h;let{cursor:r}=e||{},n=e.repoIds.map(y=>y.toString().startsWith(X)?y:`${X}${y}`),{variables:o,variableTypes:i,mergeRequestArguments:a}=this.getVariablesForPullRequests(e),u={projectIds:n,...o},l=`
1004
+ }`,d=await b(this.config,{query:p,variables:{...l,after:r}},t),c=[],g=(R=d.body.data)==null?void 0:R.project,m=ve(g||{id:"",fullPath:"",webUrl:""});return(((w=g==null?void 0:g.issues)==null?void 0:w.nodes)||[]).forEach(E=>{c.push(yt(E,m,this.getIsSelfHosted(t)))}),{pageInfo:((f=g==null?void 0:g.issues)==null?void 0:f.pageInfo)??{endCursor:null,hasNextPage:!1},data:c.sort((E,S)=>(E.updatedDate||E.createdDate).getTime()-(S.updatedDate||S.createdDate).getTime())}}async getIssuesForRepos(e,t={}){var g,m,h,R,w;let{cursor:r}=e||{},n=e.repoIds.map(f=>f.toString().startsWith(Y)?f:`${Y}${f}`),{variables:o,variableTypes:i,mergeRequestArguments:a}=this.getVariablesForPullRequests(e),u={projectIds:n,...o},l=`
1005
1005
  query GetIssuesFromProject(
1006
1006
  $projectIds: [ID!]
1007
1007
  $after: String
@@ -1027,12 +1027,12 @@ query GetSingleIssue($projectId: ID!, $issueNumber: String!) {
1027
1027
  ${a.length?a.join(" "):""}
1028
1028
  ) {
1029
1029
  nodes {
1030
- ${ft}
1030
+ ${It}
1031
1031
  }
1032
1032
  }
1033
1033
  }
1034
1034
  }
1035
- }`,p=await b(this.config,{query:l,variables:{...u,after:r}},t),d=[];return(((m=(g=p.body.data)==null?void 0:g.projects)==null?void 0:m.nodes)||[]).forEach(y=>{var Y;if(!e.includeFromArchivedRepos&&y.archived)return;let q=Ee(y);(((Y=y.issues)==null?void 0:Y.nodes)||[]).forEach(E=>d.push(Rt(E,q,this.getIsSelfHosted(t))))}),{pageInfo:((h=(w=(I=p.body)==null?void 0:I.data)==null?void 0:w.projects)==null?void 0:h.pageInfo)??{endCursor:null,hasNextPage:!1},data:d.sort((y,q)=>(y.updatedDate||y.createdDate).getTime()-(q.updatedDate||q.createdDate).getTime())}}async setIssueState(e,t={}){var a,u,l;let{issue:r,state:n}=e;if(!r.repository)throw new Error('GitLab requires "repository" for this function.');let o=`mutation SetIssueState($fullPath: ID!, $issueId: String!, $status: IssueStateEvent!) {
1035
+ }`,p=await b(this.config,{query:l,variables:{...u,after:r}},t),d=[];return(((m=(g=p.body.data)==null?void 0:g.projects)==null?void 0:m.nodes)||[]).forEach(f=>{var Z;if(!e.includeFromArchivedRepos&&f.archived)return;let E=ve(f);(((Z=f.issues)==null?void 0:Z.nodes)||[]).forEach(v=>d.push(yt(v,E,this.getIsSelfHosted(t))))}),{pageInfo:((w=(R=(h=p.body)==null?void 0:h.data)==null?void 0:R.projects)==null?void 0:w.pageInfo)??{endCursor:null,hasNextPage:!1},data:d.sort((f,E)=>(f.updatedDate||f.createdDate).getTime()-(E.updatedDate||E.createdDate).getTime())}}async setIssueState(e,t={}){var a,u,l;let{issue:r,state:n}=e;if(!r.repository)throw new Error('GitLab requires "repository" for this function.');let o=`mutation SetIssueState($fullPath: ID!, $issueId: String!, $status: IssueStateEvent!) {
1036
1036
  updateIssue(input: { projectPath: $fullPath, iid: $issueId, stateEvent: $status }) {
1037
1037
  issue {
1038
1038
  id
@@ -1072,7 +1072,7 @@ query getLabelsForRepo(
1072
1072
  webUrl
1073
1073
  milestones(after: $after) {
1074
1074
  nodes {
1075
- ${wt}
1075
+ ${Pt}
1076
1076
  }
1077
1077
  pageInfo {
1078
1078
  endCursor
@@ -1081,7 +1081,7 @@ query getLabelsForRepo(
1081
1081
  }
1082
1082
  }
1083
1083
  }
1084
- `,variables:{fullPath:`${r}/${n}`,after:o}},t);return{pageInfo:((l=(u=(a=i.body.data)==null?void 0:a.project)==null?void 0:u.milestones)==null?void 0:l.pageInfo)??{endCursor:null,hasNextPage:!1},data:((g=(c=(d=(p=i.body.data)==null?void 0:p.project)==null?void 0:d.milestones)==null?void 0:c.nodes)==null?void 0:g.map(m=>{var I,w;return vt(m,((w=(I=i.body.data)==null?void 0:I.project)==null?void 0:w.webUrl)||"")}))??[]}}async getLabelsForRepo(e,t={}){var a,u,l,p,d,c,g;let{repo:{namespace:r,name:n},cursor:o}=e,i=await b(this.config,{query:`
1084
+ `,variables:{fullPath:`${r}/${n}`,after:o}},t);return{pageInfo:((l=(u=(a=i.body.data)==null?void 0:a.project)==null?void 0:u.milestones)==null?void 0:l.pageInfo)??{endCursor:null,hasNextPage:!1},data:((g=(c=(d=(p=i.body.data)==null?void 0:p.project)==null?void 0:d.milestones)==null?void 0:c.nodes)==null?void 0:g.map(m=>{var h,R;return qt(m,((R=(h=i.body.data)==null?void 0:h.project)==null?void 0:R.webUrl)||"")}))??[]}}async getLabelsForRepo(e,t={}){var a,u,l,p,d,c,g;let{repo:{namespace:r,name:n},cursor:o}=e,i=await b(this.config,{query:`
1085
1085
  query getLabelsForRepo(
1086
1086
  $fullPath: ID!
1087
1087
  $after: String
@@ -1091,7 +1091,7 @@ query getLabelsForRepo(
1091
1091
  ) {
1092
1092
  labels(after: $after) {
1093
1093
  nodes {
1094
- ${Pt}
1094
+ ${Et}
1095
1095
  }
1096
1096
  pageInfo {
1097
1097
  endCursor
@@ -1100,5 +1100,5 @@ query getLabelsForRepo(
1100
1100
  }
1101
1101
  }
1102
1102
  }
1103
- `,variables:{fullPath:`${r}/${n}`,after:o}},t);return{pageInfo:((l=(u=(a=i.body.data)==null?void 0:a.project)==null?void 0:u.labels)==null?void 0:l.pageInfo)??{endCursor:null,hasNextPage:!1},data:((g=(c=(d=(p=i.body.data)==null?void 0:p.project)==null?void 0:d.labels)==null?void 0:c.nodes)==null?void 0:g.map(Et))??[]}}};var bs="https://api.atlassian.com/ex/jira",ve=10,qt=["assignee","comment","summary","created","creator","updated","votes","issuetype","status","labels","components","project"],St=(s,e,t)=>{var o,i,a,u;let r=s.fields.assignee,n=!t;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:qe(s.fields.creator,e,n),updatedDate:new Date(s.fields.updated),assignees:r?[qe(r,e,n)]:[],description:null,repository:null,project:{name:s.fields.project.name,resourceId:t??null,key:s.fields.project.key,namespace:null,id:s.fields.project.id},state:vs(s.fields.status),statusTransitions:((o=s.transitions)==null?void 0:o.map(ws))??[],components:((i=s.fields.components)==null?void 0:i.map(Ps))??[],type:s.fields.issuetype.name,upvoteCount:((a=s.fields.votes)==null?void 0:a.votes)||0,labels:((u=s.fields.labels)==null?void 0:u.map(l=>({color:null,description:null,id:null,name:l})))??[]}},ws=s=>{let e;switch(s.to.statusCategory.name){case"To Do":e="TO_DO";break;case"In Progress":e="IN_PROGRESS";break;default:e="DONE";break}return{name:s.name,id:s.id,to:{id:s.to.id,name:s.to.name,color:s.to.statusCategory.colorName,category:e}}},Ps=s=>({description:s.description??null,id:s.id,name:s.name}),Es=(s,e,t)=>t&&s.name?`${e}/secure/ViewProfile.jspa?name=${encodeURIComponent(s.name)}`:`${e}/jira/people/${s.accountId}`,qe=(s,e,t)=>({id:(t?s.key:s.accountId)??"",name:s.displayName,email:s.emailAddress,avatarUrl:s.avatarUrls["48x48"],username:s.displayName,url:Es(s,e,t)}),vs=s=>{let e;switch(s.statusCategory.name){case"To Do":e="TO_DO";break;case"In Progress":e="IN_PROGRESS";break;default:e="DONE";break}return{id:s.id,name:s.name,color:s.statusCategory.colorName,category:e}},V=(s,e,t)=>t?`${e.baseUrl||bs}/${t}`:`${(e==null?void 0:e.baseUrl)||s.baseUrl}`,Se=async(s,e,t,r={})=>{let{number:n,resourceId:o}=e||{},i=await s.request({url:`${V(s,r,o)}/rest/api/2/issue/${n}?fields=${qt.join(",")}&expand=transitions`,headers:f(r.token||s.token)});return{data:St(i.body,t,o)}},Ce=async(s,e,t,r={})=>{let{page:n,resourceId:o}=e||{},i=n??0,a=`statusCategory != Done AND (creator = currentUser() OR assignee = currentUser()
1104
- OR comment ~ currentUser() OR summary ~ currentUser() OR description ~ currentUser())`,l=(await s.request({url:`${V(s,r,o)}/rest/api/2/search?jql=${a}&startAt=${i}&maxResults=${ve}&fields=${qt.join(",")}&expand=transitions`,headers:f(r.token||s.token)})).body.issues.map(d=>St(d,t,o)),p=l.length==ve;return{data:l,pageInfo:{hasNextPage:p,nextPage:p?i+l.length:null}}},ur=async(s,e,t,r={})=>{let{page:n,resourceId:o,jql:i}=e||{},a=n??0,l=(await s.request({url:`${V(s,r,o)}/rest/api/2/search?jql=${i.join(" AND ")}&startAt=${a}&maxResults=${ve}&fields=${qt.join(",")}&expand=transitions`,headers:f(r.token||s.token)})).body.issues.map(d=>St(d,t,o)),p=l.length==ve;return{data:l,pageInfo:{hasNextPage:p,nextPage:p?a+l.length:null}}},De=async(s,e,t,r={})=>{let{assigneeLogins:n,authorLogin:o,mentionLogin:i,page:a,projectKey:u,resourceId:l}=e||{},p=a??0,d=[`project = "${u}"`,"statusCategory != Done"];return o&&d.push(`creator in ("${o}")`),n&&n.length!==0&&d.push(`assignee in ("${n.join('", "')}")`),i&&d.push(`comment ~ "${i}"`),ur(s,{resourceId:l,jql:d,page:p},t,r)},Le=async(s,e,t,r={})=>{let{assigneeLogins:n,authorLogin:o,mentionLogin:i,page:a,projectKeys:u,resourceId:l}=e||{},p=a??0,c=["("+u.map(g=>`project = "${g}"`).join(" OR ")+")","statusCategory != Done"];return o&&c.push(`creator in ("${o}")`),n&&n.length!==0&&c.push(`assignee in ("${n.join('", "')}")`),i&&c.push(`comment ~ "${i}"`),ur(s,{resourceId:l,jql:c,page:p},t,r)},Ue=async(s,e,t={})=>{let{issue:r,labels:n}=e;if(!r.project)throw new Error('Jira requires a "project" for this function.');let o={fields:{labels:n.map(i=>i.name)}};await s.request({method:"PUT",url:`${V(s,t,r.project.resourceId??void 0)}/rest/api/2/issue/${r.id}`,body:JSON.stringify(o),headers:{...f(t.token||s.token),"Content-Type":"application/json"}})},Ae=async(s,e,t={})=>{let{issue:r,components:n}=e;if(!r.project)throw new Error('Jira requires a "project" for this function.');let o={fields:{components:n.map(i=>({id:i.id}))}};await s.request({method:"PUT",url:`${V(s,t,r.project.resourceId??void 0)}/rest/api/2/issue/${r.id}`,body:JSON.stringify(o),headers:{...f(t.token||s.token),"Content-Type":"application/json"}})},$e=async(s,e,t={})=>{let{issue:r,status:n}=e;if(!r.project)throw new Error('Jira requires a "project" for this function.');if(!n.id)throw new Error('Jira requires a status "id" for this function.');let o={transition:{id:n.id}};await s.request({method:"POST",url:`${V(s,t,r.project.resourceId??void 0)}/rest/api/2/issue/${r.id}/transitions`,body:JSON.stringify(o),headers:{...f(t.token||s.token),"Content-Type":"application/json"}})},Ge=async(s,e,t={})=>{let{resourceId:r,projectIdOrKey:n}=e,o=new URL(`${V(s,t,r)}/rest/api/2/project/${n}/components`);return{data:(await s.request({url:o.toString(),headers:f(t.token||s.token)})).body}};var ie="https://api.atlassian.com/ex/jira",Ct=100,ae=class extends T{constructor(){super(...arguments);this._resourceUrlCache={}}async getResourceUrl(t,r={}){var i;let n=r.token||this.config.token;if(!n)return null;let o=this._resourceUrlCache[n];return o?o[t.resourceId]??null:(await this.getJiraResourcesForCurrentUser(r),((i=this._resourceUrlCache[n])==null?void 0:i[t.resourceId])??null)}async getCurrentUserForResource(t,r={}){let n=await this.getResourceUrl({resourceId:t.resourceId},r),o=await this.config.request({url:`${r.baseUrl||ie}/${t.resourceId}/rest/api/2/myself`,headers:f(r.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:n?`${n}/jira/people/${o.body.accountId}`:null}}}async getJiraResourcesForCurrentUser(t={}){let r=await this.config.request({url:`${t.baseUrl||"https://api.atlassian.com/"}/oauth/token/accessible-resources`,headers:f(t.token||this.config.token)}),n=t.token||this.config.token,o=n?this._resourceUrlCache[n]||{}:void 0,i=r.body.map(a=>(o&&(o[a.id]=a.url),{avatarUrl:a.avatarUrl,id:a.id,name:a.name,url:a.url}));return n&&(this._resourceUrlCache[n]=o),{data:i}}async getJiraProjectsForResource(t,r={}){let n=new URL(`${r.baseUrl||ie}/${t.resourceId}/rest/api/2/project/search`);n.searchParams.set("maxResults",Ct.toString()),t.cursor&&n.searchParams.set("startAt",t.cursor);let o=await this.config.request({url:n.toString(),headers:f(r.token||this.config.token)});return{pageInfo:{hasNextPage:o.body.values.length!==0,endCursor:(o.body.startAt+o.body.values.length).toString()},data:o.body.values.map(i=>({id:i.id,key:i.key,name:i.name,resourceId:t.resourceId}))}}async getJiraProjectsForResources(t,r={}){let n=[];return await Promise.all(t.resourceIds.map(async o=>{try{return await Ht(i=>this.getJiraProjectsForResource({resourceId:o,cursor:i},r))}catch{return[]}})).then((...o)=>{o.forEach(i=>{n=n.concat(...i)})}),{data:n}}async getAccountsForJiraProject(t,r={}){let{resourceId:n,projectKey:o,cursor:i}=t,a=await this.getResourceUrl({resourceId:n},r),u=new URL(`${r.baseUrl||ie}/${n}/rest/api/2/user/assignable/search`);u.searchParams.set("maxResults",Ct.toString()),i&&u.searchParams.set("startAt",i),u.searchParams.set("project",o);let l=await this.config.request({url:u.toString(),headers:f(r.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=>qe(p,a,!1))}}async getComponentsForJiraProject(t,r={}){return await Ge(this.config,t,r)}async getIssue(t,r={}){let n=await this.getResourceUrl({resourceId:t.resourceId},r);return await Se(this.config,t,n,r)}async getIssuesForProject(t,r={}){let n=await this.getResourceUrl({resourceId:t.resourceId},r);return await De(this.config,t,n,r)}async getIssuesForProjects(t,r={}){let n=await this.getResourceUrl({resourceId:t.resourceId},r);return await Le(this.config,t,n,r)}async getIssuesForResourceForCurrentUser(t,r={}){let n=await this.getResourceUrl({resourceId:t.resourceId},r);return await Ce(this.config,t,n,r)}async setIssueStatus(t,r={}){await $e(this.config,t,r)}async setIssueAssignee(t,r={}){let{issue:n,assignee:o}=t;if(!n.project)throw new Error('Jira Cloud requires a "project" for this function.');if(!n.project.resourceId)throw new Error('Jira Cloud requires a project "resourceId" for this function.');let i={accountId:o==null?void 0:o.id};await this.config.request({method:"PUT",url:`${r.baseUrl||ie}/${n.project.resourceId}/rest/api/2/issue/${n.id}/assignee`,body:JSON.stringify(i),headers:{...f(r.token||this.config.token),"Content-Type":"application/json"}})}async setIssueComponents(t,r={}){await Ae(this.config,t,r)}async setIssueLabels(t,r={}){await Ue(this.config,t,r)}async getLabelsForResource(t,r={}){let{resourceId:n,cursor:o}=t,i=new URL(`${r.baseUrl||ie}/${n}/rest/api/2/label`);i.searchParams.set("maxResults",Ct.toString()),o&&i.searchParams.set("startAt",o);let a=await this.config.request({url:i.toString(),headers:f(r.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 ue=class extends N{async getCurrentUser(e={}){let t=await this.config.request({url:`${(e==null?void 0:e.baseUrl)||this.config.baseUrl}/rest/api/2/myself`,headers:f((e==null?void 0: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==null?void 0:e.baseUrl)||this.config.baseUrl}/rest/api/2/project`,headers:f((e==null?void 0:e.token)||this.config.token)})).body.map(r=>({id:r.id,name:r.name}))}}async getIssue(e,t={}){if(!t.baseUrl)throw new Error('Jira Server requires a "baseUrl" for this function.');return await Se(this.config,e,t.baseUrl,t)}async getIssuesForProject(e,t={}){if(!t.baseUrl)throw new Error('Jira Server requires a "baseUrl" for this function.');return await De(this.config,e,t.baseUrl,t)}async getIssuesForProjects(e,t={}){if(!t.baseUrl)throw new Error('Jira Server requires a "baseUrl" for this function.');return await Le(this.config,e,t.baseUrl,t)}async getIssuesForResourceForCurrentUser(e,t={}){if(!t.baseUrl)throw new Error('Jira Server requires a "baseUrl" for this function.');return await Ce(this.config,e,t.baseUrl,t)}async setIssueStatus(e,t={}){await $e(this.config,e,t)}async setIssueLabels(e,t={}){await Ue(this.config,e,t)}async setIssueComponents(e,t={}){await Ae(this.config,e,t)}async getLabels(e={}){return{data:(await this.config.request({url:`${(e==null?void 0:e.baseUrl)||this.config.baseUrl}/rest/api/2/jql/autocompletedata/suggestions?fieldName=labels`,headers:f(e.token||this.config.token)})).body.results.map(({displayName:r})=>({color:null,description:null,id:null,name:r}))}}async getComponentsForJiraProject(e,t={}){return await Ge(this.config,e,t)}};var M="https://api.trello.com",qs=1e3,Ss=(s,e)=>{let t=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(t.toISOString()),author:null,updatedDate:new Date(s.dateLastActivity),assignees:s.idMembers.map(r=>({id:r,username:null,name:null,email:null,avatarUrl:null,url:null})),description:null,state:e[s.idList??""]?{id:s.idList,name:e[s.idList].name,color:null}:null,type:null,repository:null,upvoteCount:s.badges.votes,labels:s.labels.map(r=>({color:r.color,description:null,id:r.id,name:r.name}))}},le=class extends T{async getCurrentUser(e,t={}){let r=await this.config.request({url:`${t.baseUrl||M}/1/members/me?key=${e.appKey}&token=${t.token||this.config.token}`,headers:f(t.token||this.config.token)});return{data:{name:r.body.fullName,email:r.body.email,avatarUrl:r.body.avatarHash?`https://trello-members.s3.amazonaws.com/${r.body.id}/${r.body.avatarHash}/50.png`:null,id:r.body.id,username:r.body.username,url:r.body.url}}}async getBoardsForCurrentUser(e,t={}){return{data:(await this.config.request({url:`${t.baseUrl||M}/1/members/me/boards?fields=name&key=${e.appKey}&token=${t.token||this.config.token}&filter=open`,headers:f(t.token||this.config.token)})).body.map(n=>({id:n.id,name:n.name}))}}async getListsForTrelloBoard(e,t={}){let{appKey:r,boardId:n}=e;return{data:(await this.config.request({url:`${t.baseUrl||M}/1/boards/${n}/lists?key=${r}&token=${t.token||this.config.token}`,headers:f(t.token||this.config.token)})).body}}async getAccountsForTrelloBoard(e,t={}){let{appKey:r,boardId:n}=e;return{data:(await this.config.request({url:`${t.baseUrl||M}/1/boards/${n}/members?key=${r}&token=${t.token||this.config.token}`,headers:f(t.token||this.config.token)})).body.map(i=>({id:i.id,name:i.fullName,username:i.username,email:null,avatarUrl:null,url:null}))}}async getIssuesForBoard(e,t={}){let r=["-is:archived","sort:edited"],{appKey:n,boardId:o,filterText:i,assigneeLogins:a,trelloBoardListsById:u}=e||{};a&&r.push("@me");let l=`${i?`${i}`:""}${r.join(" ")} board:${o}`;return{data:(await this.config.request({url:`${t.baseUrl||M}/1/search?key=${n}&query=${l}&cards_limit=${qs}&token=${t.token||this.config.token}`,headers:f(t.token||this.config.token)})).body.cards.map(d=>Ss(d,u||{}))}}async updateIssue(e,t,r,n){return await this.config.request({method:"PUT",url:`${n.baseUrl||M}/1/cards/${t.id}?key=${e}&token=${n.token||this.config.token}&${r}`,headers:f(n.token||this.config.token)})}async setIssueStatus(e,t={}){let{appKey:r,issue:n,status:o}=e;if(!o.id)throw new Error('Trello requires a status "id" for this function.');let i=`idList=${o.id}`;if(!(await this.updateIssue(r,n,i,t)).body.id)throw new Error("Could not set issue status")}async setIssueAssignees(e,t={}){let{appKey:r,issue:n,assignees:o}=e,i=o.map(l=>l.id),a=`idMembers=${encodeURIComponent(i.join(","))}`;if(!(await this.updateIssue(r,n,a,t)).body.id)throw new Error("Could not set issue status")}async setIssueLabels(e,t={}){let{appKey:r,issue:n,labels:o}=e,i=o.map(u=>u.id).join(",");if(!(await this.config.request({method:"PUT",url:`${t.baseUrl||M}/1/cards/${n.id}?key=${r}&token=${t.token||this.config.token}&idLabels=${encodeURIComponent(i)}`,headers:f(t.token||this.config.token)})).body.id)throw new Error("Could not set issue status")}async setIssueArchived(e,t={}){let{appKey:r,issue:n,archived:o}=e;if(!(await this.config.request({method:"PUT",url:`${t.baseUrl||M}/1/cards/${n.id}?key=${r}&token=${t.token||this.config.token}&closed=${o}`,headers:f(t.token||this.config.token)})).body.id)throw new Error("Could not update issue archived status")}async archiveIssue(e,t={}){await this.setIssueArchived({...e,archived:!0},t)}async unArchiveIssue(e,t={}){await this.setIssueArchived({...e,archived:!1},t)}async getLabelsForBoard(e,t={}){let{appKey:r,boardId:n}=e;return{data:(await this.config.request({url:`${t.baseUrl||M}/1/boards/${n}/labels?key=${r}&token=${t.token||this.config.token}`,headers:f(t.token||this.config.token)})).body.map(i=>({color:i.color,description:null,id:i.id,name:i.name}))}}};var Te={};k(Te,{default:()=>Cs});var Cs={};var Oe={};k(Oe,{default:()=>Ds});var Ds={};var xe={};k(xe,{restApiPullRequestToCommonPullRequest:()=>Ls});var Ls=s=>re(s);var Je={};k(Je,{decode:()=>Gs,decodeV0:()=>Ts,encode:()=>$s,validate:()=>As});var D=(t=>(t.Zero="0",t.One="1",t))(D||{}),L=(t=>(t.PullRequest="pr",t.Issue="issue",t))(L||{}),U=(p=>(p.Azure="azure",p.Github="github",p.GithubEnterprise="githubEnterprise",p.Gitlab="gitlab",p.GitlabSelfHosted="gitlabSelfHosted",p.Bitbucket="bitbucket",p.BitbucketServer="bitbucketServer",p.Jira="jira",p.JiraServer="jiraServer",p.Trello="trello",p))(U||{});var ke=class{constructor(){}validate(e){if(!e.organizationName)throw new Error("organizationName is required");if(!e.projectId)throw new Error("projectId is required");if(!e.entityId)throw new Error("issueId is required")}encode(e){if(this.validate(e),!e.organizationName||!e.projectId||!e.entityId)throw new Error("Missing required fields for Azure DevOps issue uniqueId");let t=[];return t.push("azure"),t.push("issue"),t.push("1"),t.push(e.domain||""),t.push(e.organizationName),t.push(e.projectId),t.push(e.entityId),JSON.stringify(t)}decode(e){if(e.length<7)throw new Error("Invalid Azure DevOps issue uniqueId, check version");return{provider:e[0],entityType:e[1],version:e[2],domain:e[3]==""?null:e[3],resourceId:null,accountOrOrgId:null,organizationName:e[4],projectId:e[5],repoId:null,entityId:e[6]}}};var Ne=class{constructor(){}validate(e){if(!e.organizationName)throw new Error("organizationName is required");if(!e.projectId)throw new Error("projectId is required");if(!e.repoId)throw new Error("repoId is required");if(!e.entityId)throw new Error("entityId is required")}encode(e){if(this.validate(e),!e.organizationName||!e.projectId||!e.repoId||!e.entityId)throw new Error("Missing required fields for Azure DevOps pull request uniqueId");let t=[];return t.push("azure"),t.push("pr"),t.push("1"),t.push(e.domain||""),t.push(e.organizationName),t.push(e.projectId),t.push(e.repoId),t.push(e.entityId),JSON.stringify(t)}decode(e){if(e.length<8)throw new Error("Invalid Azure DevOps pull request uniqueId, check version");return{provider:e[0],entityType:e[1],version:e[2],domain:e[3]==""?null:e[3],resourceId:null,accountOrOrgId:null,organizationName:e[4],projectId:e[5],repoId:e[6],entityId:e[7]}}};var _e=class{constructor(){}validate(e){if(e.domain&&e.provider=="bitbucket")throw new Error("domain is only supported for BitbucketServer");if(!e.repoId)throw new Error("repoId is required");if(!e.entityId)throw new Error("issueId is required")}encode(e){if(this.validate(e),!e.repoId||!e.entityId)throw new Error("Missing required fields for Bitbucket DevOps issue uniqueId");let t=[];return t.push(e.domain?"bitbucketServer":"bitbucket"),t.push("issue"),t.push("1"),t.push(e.domain||""),t.push(e.repoId),t.push(e.entityId),JSON.stringify(t)}decode(e){if(e.length<6)throw new Error("Invalid Bitbucket DevOps issue uniqueId, check version");return{provider:e[0],entityType:e[1],version:e[2],domain:e[3]==""?null:e[3],resourceId:null,accountOrOrgId:null,organizationName:null,projectId:null,repoId:e[4],entityId:e[5]}}};var Qe=class{constructor(){}validate(e){if(e.domain&&e.provider=="bitbucket")throw new Error("domain is only supported for BitbucketServer");if(!e.repoId)throw new Error("repoId is required");if(!e.entityId)throw new Error("entityId is required")}encode(e){if(this.validate(e),!e.repoId||!e.entityId)throw new Error("Missing required fields for Bitbucket DevOps pull request uniqueId");let t=[];return t.push(e.domain?"bitbucketServer":"bitbucket"),t.push("pr"),t.push("1"),t.push(e.domain||""),t.push(e.repoId),t.push(e.entityId),JSON.stringify(t)}decode(e){if(e.length<6)throw new Error("Invalid Bitbucket DevOps pull request uniqueId, check version");return{provider:e[0],entityType:e[1],version:e[2],domain:e[3]==""?null:e[3],resourceId:null,accountOrOrgId:null,organizationName:null,projectId:null,repoId:e[4],entityId:e[5]}}};var Be=class{constructor(){}validate(e){if(e.domain&&e.provider=="github")throw new Error("domain is only supported for GithubEnterprise");if(!e.entityId)throw new Error("entityId is required")}encode(e){if(this.validate(e),!e.entityId)throw new Error("Missing required fields for Github issue uniqueId");let t=[];return t.push(e.domain?"githubEnterprise":"github"),t.push("issue"),t.push("1"),t.push(e.domain||""),t.push(e.entityId),JSON.stringify(t)}decode(e){if(e.length<5)throw new Error("Invalid Github issue uniqueId, check version");return{provider:e[0],entityType:e[1],version:e[2],domain:e[3]==""?null:e[3],resourceId:null,accountOrOrgId:null,organizationName:null,projectId:null,repoId:null,entityId:e[4]}}};var je=class{constructor(){}validate(e){if(e.domain&&e.provider=="github")throw new Error("domain is only supported for GithubEnterprise");if(!e.entityId)throw new Error("entityId is required")}encode(e){if(this.validate(e),!e.entityId)throw new Error("Missing required fields for Github pull request uniqueId");let t=[];return t.push(e.domain?"githubEnterprise":"github"),t.push("pr"),t.push("1"),t.push(e.domain||""),t.push(e.entityId),JSON.stringify(t)}decode(e){if(e.length<5)throw new Error("Invalid Github pull request uniqueId, check version");return{provider:e[0],entityType:e[1],version:e[2],domain:e[3]==""?null:e[3],resourceId:null,accountOrOrgId:null,organizationName:null,projectId:null,repoId:null,entityId:e[4]}}};var Fe=class{constructor(){}validate(e){if(e.domain&&e.provider=="gitlab")throw new Error("domain is only supported for GitlabSelfHosted");if(!e.entityId)throw new Error("entityId is required")}encode(e){if(this.validate(e),!e.entityId)throw new Error("Missing required fields for Gitlab issue uniqueId");let t=[];return t.push(e.domain?"gitlabSelfHosted":"gitlab"),t.push("issue"),t.push("1"),t.push(e.domain||""),t.push(e.entityId),JSON.stringify(t)}decode(e){if(e.length<5)throw new Error("Invalid Gitlab issue uniqueId, check version");return{provider:e[0],entityType:e[1],version:e[2],domain:e[3]==""?null:e[3],resourceId:null,accountOrOrgId:null,organizationName:null,projectId:null,repoId:null,entityId:e[4]}}};var Me=class{constructor(){}validate(e){if(e.domain&&e.provider=="gitlab")throw new Error("domain is only supported for GitlabSelfHosted");if(!e.entityId)throw new Error("entityId is required")}encode(e){if(this.validate(e),!e.entityId)throw new Error("Missing required fields for Gitlab pull request uniqueId");let t=[];return t.push(e.domain?"gitlabSelfHosted":"gitlab"),t.push("pr"),t.push("1"),t.push(e.domain||""),t.push(e.entityId),JSON.stringify(t)}decode(e){if(e.length<5)throw new Error("Invalid Gitlab pull request uniqueId, check version");return{provider:e[0],entityType:e[1],version:e[2],domain:e[3]==""?null:e[3],resourceId:null,accountOrOrgId:null,organizationName:null,projectId:null,repoId:null,entityId:e[4]}}};var ze=class{constructor(){}validate(e){if(e.domain&&e.provider=="jira")throw new Error("domain is only supported for JiraServer");if(e.resourceId&&e.provider=="jiraServer")throw new Error("resourceId is only supported for Jira Cloud");if(!e.resourceId&&e.provider=="jira")throw new Error("resourceId is required");if(!e.projectId)throw new Error("projectId is required");if(!e.entityId)throw new Error("entityId is required")}encode(e){if(this.validate(e),!e.projectId||!e.entityId)throw new Error("Missing required fields for Jira issue uniqueId");let t=[];return t.push(e.domain?"jiraServer":"jira"),t.push("issue"),t.push("1"),t.push(e.domain||""),t.push(e.resourceId||""),t.push(e.projectId),t.push(e.entityId),JSON.stringify(t)}decode(e){if(e.length<7)throw new Error("Invalid Jira issue uniqueId, check version");return{provider:e[0],entityType:e[1],version:e[2],domain:e[3]==""?null:e[3],resourceId:e[4]==""?null:e[4],accountOrOrgId:null,organizationName:null,projectId:e[5],repoId:null,entityId:e[6]}}};var He=class{constructor(){}validate(e){if(!e.accountOrOrgId)throw new Error("accountOrOrgId is required");if(!e.projectId)throw new Error("projectId is required");if(!e.entityId)throw new Error("entityId is required")}encode(e){if(this.validate(e),!e.accountOrOrgId||!e.projectId||!e.entityId)throw new Error("Missing required fields for Trello issue uniqueId");let t=[];return t.push("trello"),t.push("issue"),t.push("1"),t.push(""),t.push(e.accountOrOrgId),t.push(e.projectId),t.push(e.entityId),JSON.stringify(t)}decode(e){if(e.length<7)throw new Error("Invalid Trello issue uniqueId, check version");return{provider:e[0],entityType:e[1],version:e[2],domain:e[3]==""?null:e[3],resourceId:null,accountOrOrgId:e[4],organizationName:null,projectId:e[5],repoId:null,entityId:e[6]}}};var We=(s,e)=>{if(!e)throw new Error("entityType is required");if(!s)throw new Error("provider is required");switch(s){case"azure":return e==="pr"?new Ne:new ke;case"bitbucket":case"bitbucketServer":return e==="pr"?new Qe:new _e;case"github":case"githubEnterprise":return e==="pr"?new je:new Be;case"gitlab":case"gitlabSelfHosted":return e==="pr"?new Me:new Fe;case"jira":case"jiraServer":if(e==="pr")throw new Error("EntityType PullRequest is not valid for Jira");return new ze;case"trello":if(e==="pr")throw new Error("EntityType PullRequest is not valid for Jira");return new He;default:throw new Error("unknown provider")}},Us=s=>{if(!s.entityType)throw new Error("entityType is required");if(!s.provider)throw new Error("provider is required");if(!s.entityId)throw new Error("entityID is required")},As=s=>{if(s.version==="0"){Us(s);return}We(s.provider,s.entityType).validate(s)},$s=s=>We(s.provider,s.entityType).encode(s),Gs=s=>{let e=JSON.parse(s);if(!e||!e.length)throw new Error("invalid issue unique id");return We(e[0],e[1]).decode(e)},Ts=(s,e,t)=>{if(!t)throw new Error("entityID is required");try{let r=JSON.parse(t);if(!r||!r.length)throw new Error("Invalid pull request uniqueId");let n=[s,e,"0",...r];return We(s,e).decode(n)}catch{return{provider:s,entityType:e,version:"0",domain:"",resourceId:null,accountOrOrgId:null,organizationName:null,projectId:null,repoId:null,entityId:t}}};var Ve={};k(Ve,{CHANGES_REQUESTED_ACTION_CATEGORY:()=>mr,CHANGES_REQUESTED_BUCKET_ID:()=>Tt,CONFLICTS_ACTION_CATEGORY:()=>cr,CONFLICTS_BUCKET_ID:()=>$t,DRAFT_ACTION_CATEGORY:()=>Ir,DRAFT_BUCKET_ID:()=>kt,FAILING_CI_ACTION_CATEGORY:()=>dr,FAILING_CI_BUCKET_ID:()=>At,NEEDS_MY_REVIEW_ACTION_CATEGORY:()=>gr,NEEDS_MY_REVIEW_BUCKET_ID:()=>Gt,OTHER_ACTION_CATEGORY:()=>Rr,OTHER_BUCKET_ID:()=>Nt,PINNED_BUCKET_ID:()=>Dt,READY_TO_MERGE_ACTION_CATEGORY:()=>lr,READY_TO_MERGE_BUCKET_ID:()=>Lt,REVIEWER_COMMENTED_ACTION_CATEGORY:()=>hr,REVIEWER_COMMENTED_BUCKET_ID:()=>Ot,SNOOZED_BUCKET_ID:()=>_t,UNASSIGNED_REVIEWERS_ACTION_CATEGORY:()=>pr,UNASSIGNED_REVIEWERS_BUCKET_ID:()=>Ut,WAITING_FOR_REVIEW_ACTION_CATEGORY:()=>fr,WAITING_FOR_REVIEW_BUCKET_ID:()=>xt,getActionablePullRequests:()=>yr,groupPullRequestsIntoBuckets:()=>Os});var G=(s,e,t,r)=>({id:s,faIconName:t,name:e,priority:r,pullRequests:[]}),Dt="pinned",Lt="readyToMerge",Ut="unassignedReviewers",At="failingCI",$t="conflicts",Gt="needsMyReview",Tt="changesRequested",Ot="reviewerCommented",xt="waitingForReview",kt="draft",Nt="other",_t="snoozed",lr="readyToMerge",pr="unassignedReviewers",dr="failingCI",cr="conflicts",gr="needsMyReview",mr="changesRequested",hr="reviewerCommented",fr="waitingForReview",Ir="draft",Rr="other",yr=(s,e,t)=>s.map(r=>{var u,l,p,d,c,g,m,I,w,h,y,q,C,Y;let o={...r,...{suggestedActionCategory:Rr,priority:1e3,viewer:{canMerge:!1,isAuthor:!1,isAssignee:!1,isReviewer:!1,shouldMerge:!1,shouldAssignReviewer:!1,waitingOnReviews:!1,shouldReview:!1},failingCI:!1,hasConflicts:!1,changeRequestReviewCount:0,codeSuggestionsCount:0,commentReviewCount:0,approvalReviewCount:0}};e&&(o.viewer.isAuthor=((u=r.author)==null?void 0:u.id)===e.id,o.viewer.isAssignee=((l=r.assignees)==null?void 0:l.some(E=>E.id===e.id))??!1,o.viewer.isReviewer=((p=r.reviews)==null?void 0:p.some(E=>E.reviewer.id===e.id))??!1),o.viewer.canMerge=((d=r.permissions)==null?void 0:d.canMerge)??!0,o.hasConflicts=r.mergeableState==="CONFLICTS",o.failingCI=((g=(c=r.headCommit)==null?void 0:c.buildStatuses)==null?void 0:g.some(E=>E.state==="ERROR"||E.state==="FAILED"))??!1,o.commentReviewCount=((m=r.reviews)==null?void 0:m.filter(E=>E.state==="COMMENTED").length)??0,o.approvalReviewCount=((I=r.reviews)==null?void 0:I.filter(E=>E.state==="APPROVED").length)??0,o.changeRequestReviewCount=((w=r.reviews)==null?void 0:w.filter(E=>E.state==="CHANGES_REQUESTED").length)??0;let i=(h=t==null?void 0:t.enrichedItemsByUniqueId)==null?void 0:h[r.uuid];i!=null&&(o.viewer.enrichedItems=i,i.some(E=>E.type==="pin")&&(o.viewer.pinned=!0,o.priority-=800),i.some(E=>E.type==="snooze")&&(o.viewer.snoozed=!0));let a=((q=(y=t==null?void 0:t.codeSuggestionsCountByPrUuid)==null?void 0:y[r.uuid])==null?void 0:q.count)||0;return a&&(o.codeSuggestionsCount=a),(!e||o.viewer.isAuthor||o.viewer.isAssignee&&!o.viewer.isReviewer)&&o.viewer.canMerge&&!o.isDraft&&!o.failingCI&&r.mergeableState==="MERGEABLE"&&(!r.reviewDecision||r.reviewDecision==="APPROVED")&&(o.viewer.shouldMerge=!0,o.suggestedActionCategory=lr),(!e||o.viewer.isAuthor)&&r.isDraft&&(o.suggestedActionCategory=Ir),(!e||o.viewer.isAuthor)&&r.reviewDecision==="REVIEW_REQUESTED"&&(o.suggestedActionCategory=fr,o.viewer.waitingOnReviews=!0),(!e||o.viewer.isAuthor)&&r.reviewDecision==="COMMENTED"&&(o.suggestedActionCategory=hr),(!e||o.viewer.isAuthor)&&o.failingCI&&(o.suggestedActionCategory=dr),(!e||o.viewer.isAuthor)&&o.hasConflicts&&(o.suggestedActionCategory=cr),(!e||o.viewer.isAuthor)&&(r.reviewDecision==="CHANGES_REQUESTED"||o.codeSuggestionsCount>0)&&(o.suggestedActionCategory=mr),(!e||o.viewer.isAuthor)&&!((C=r.reviews)!=null&&C.length)&&(o.suggestedActionCategory=pr,o.viewer.shouldAssignReviewer=!0),e&&((Y=r.reviews)!=null&&Y.some(E=>E.reviewer.id===e.id&&E.state==="REVIEW_REQUESTED"))&&(o.suggestedActionCategory=gr,o.viewer.shouldReview=!0),o}),Os=(s,e,t)=>{let r={pinned:G(Dt,"Pinned","thumbtack",-1),readyToMerge:G(Lt,"Ready to Merge","code-merge",0),unassignedReviewers:G(Ut,"Unassigned Reviewers","user-plus",1),failingCI:G(At,"Failing CI","circle-x",2),conflicts:G($t,"Resolve Conflicts","triangle-exclamation",3),needsMyReview:G(Gt,"Needs My Review","eye",4),changesRequested:G(Tt,"Suggested Changes","file-plus",5),reviewerCommented:G(Ot,"Reviewer Commented","comment",6),waitingForReview:G(xt,"Waiting for Review","circle-pause",7),draft:G(kt,"Draft","compass-drafting",8),other:G(Nt,"Other","ellipsis",9),snoozed:G(_t,"Snoozed","snooze",10)},o=yr(s,e,t).reduce((i,a)=>(i[a.uuid]=a,i),{});return s.forEach(i=>{let a=o[i.uuid],u=!0;if(a.viewer.snoozed){r[_t].pullRequests.push(i);return}a.viewer.pinned&&r[Dt].pullRequests.push(i),(!e||a.viewer.isAuthor||a.viewer.isAssignee&&!a.viewer.isReviewer)&&!a.isDraft&&a.viewer.canMerge&&a.mergeableState==="MERGEABLE"&&(!i.reviewDecision||i.reviewDecision==="APPROVED")&&(r[Lt].pullRequests.push(i),u=!1),a.viewer.shouldAssignReviewer&&(r[Ut].pullRequests.push(i),u=!1),(!e||a.viewer.isAuthor)&&a.failingCI&&(r[At].pullRequests.push(i),u=!1),(!e||a.viewer.isAuthor)&&a.hasConflicts&&(r[$t].pullRequests.push(i),u=!1),a.viewer.shouldReview&&(r[Gt].pullRequests.push(i),u=!1),(!e||a.viewer.isAuthor)&&(a.reviewDecision==="CHANGES_REQUESTED"||a.codeSuggestionsCount>0)&&(r[Tt].pullRequests.push(i),u=!1),(!e||a.viewer.isAuthor)&&a.reviewDecision==="COMMENTED"&&(r[Ot].pullRequests.push(i),u=!1),(!e||a.viewer.isAuthor)&&a.reviewDecision==="REVIEW_REQUESTED"&&(r[xt].pullRequests.push(i),u=!1),a.isDraft&&(r[kt].pullRequests.push(i),u=!1),u&&r[Nt].pullRequests.push(i)}),Object.values(r).forEach(i=>{i.pullRequests.sort((a,u)=>o[a.uuid].priority-o[u.uuid].priority)}),r};var Ke={};k(Ke,{getPullRequestRank:()=>xs});var xs=(s,e,t)=>{var i,a,u;let r=0,n,o;return(i=s.reviews)==null||i.forEach(l=>{l.reviewer.id===e&&(n=l.state),l.state==="CHANGES_REQUESTED"?o="CHANGES_REQUESTED":l.state==="APPROVED"&&o!=="CHANGES_REQUESTED"&&(o="APPROVED")}),o||(o="REVIEW_REQUESTED"),((a=s.author)==null?void 0:a.id)===e?r+=1e3:(u=s.assignees)!=null&&u.find(l=>l.id===e)?r+=900:n==="REVIEW_REQUESTED"?r+=800:t&&(r+=700),o==="APPROVED"?s.mergeableState==="MERGEABLE"?r+=100:s.mergeableState==="CONFLICTS"?r+=90:r+=80:o=="CHANGES_REQUESTED"&&(r+=70),r};var Xe={};k(Xe,{default:()=>ks});var ks={};var Ye={};k(Ye,{default:()=>Ns});var Ns={};var Ze={};k(Ze,{default:()=>_s});var _s={};var br=(i=>(i.Conflicts="conflicts",i.Failure="failure",i.NotSet="notSet",i.Queued="queued",i.RejectedByPolicy="rejectedByPolicy",i.Succeeded="succeeded",i))(br||{});var wr=(t=>(t.Completed="COMPLETED",t.NotPlanned="NOT_PLANNED",t))(wr||{});var Qs=s=>{let e={request:s==null?void 0:s.request};return{azureDevOps:new ee({...e,...s==null?void 0:s.azureDevOps}),bitbucket:new te({...e,...s==null?void 0:s.bitbucket}),bitbucketServer:new se({...e,...s==null?void 0:s.bitbucketServer}),github:new ne({...e,...s==null?void 0:s.github}),gitlab:new oe({...e,...s==null?void 0:s.gitlab}),jira:new ae({...e,...s==null?void 0:s.jira}),jiraServer:new ue({...e,...s==null?void 0:s.jiraServer}),trello:new le({...e,...s==null?void 0:s.trello})}},Bs=Qs;var js={azureDevOps:Te,bitbucket:Oe,bitbucketServer:xe,github:Ke,gitlab:Xe,gitProvider:Ve,jira:Ye,trello:Ze,entityIdentifier:Je};
1103
+ `,variables:{fullPath:`${r}/${n}`,after:o}},t);return{pageInfo:((l=(u=(a=i.body.data)==null?void 0:a.project)==null?void 0:u.labels)==null?void 0:l.pageInfo)??{endCursor:null,hasNextPage:!1},data:((g=(c=(d=(p=i.body.data)==null?void 0:p.project)==null?void 0:d.labels)==null?void 0:c.nodes)==null?void 0:g.map(vt))??[]}}};var Es="https://api.atlassian.com/ex/jira",qe=10,St=["assignee","comment","summary","created","creator","updated","votes","issuetype","status","labels","components","project"],Ct=(s,e,t)=>{var o,i,a,u;let r=s.fields.assignee,n=!t;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:Se(s.fields.creator,e,n),updatedDate:new Date(s.fields.updated),assignees:r?[Se(r,e,n)]:[],description:null,repository:null,project:{name:s.fields.project.name,resourceId:t??null,key:s.fields.project.key,namespace:null,id:s.fields.project.id},state:Cs(s.fields.status),statusTransitions:((o=s.transitions)==null?void 0:o.map(vs))??[],components:((i=s.fields.components)==null?void 0:i.map(qs))??[],type:s.fields.issuetype.name,upvoteCount:((a=s.fields.votes)==null?void 0:a.votes)||0,labels:((u=s.fields.labels)==null?void 0:u.map(l=>({color:null,description:null,id:null,name:l})))??[]}},vs=s=>{let e;switch(s.to.statusCategory.name){case"To Do":e="TO_DO";break;case"In Progress":e="IN_PROGRESS";break;default:e="DONE";break}return{name:s.name,id:s.id,to:{id:s.to.id,name:s.to.name,color:s.to.statusCategory.colorName,category:e}}},qs=s=>({description:s.description??null,id:s.id,name:s.name}),Ss=(s,e,t)=>t&&s.name?`${e}/secure/ViewProfile.jspa?name=${encodeURIComponent(s.name)}`:`${e}/jira/people/${s.accountId}`,Se=(s,e,t)=>({id:(t?s.key:s.accountId)??"",name:s.displayName,email:s.emailAddress,avatarUrl:s.avatarUrls["48x48"],username:s.displayName,url:Ss(s,e,t)}),Cs=s=>{let e;switch(s.statusCategory.name){case"To Do":e="TO_DO";break;case"In Progress":e="IN_PROGRESS";break;default:e="DONE";break}return{id:s.id,name:s.name,color:s.statusCategory.colorName,category:e}},K=(s,e,t)=>t?`${e.baseUrl||Es}/${t}`:`${(e==null?void 0:e.baseUrl)||s.baseUrl}`,Ce=async(s,e,t,r={})=>{let{number:n,resourceId:o}=e||{},i=await s.request({url:`${K(s,r,o)}/rest/api/2/issue/${n}?fields=${St.join(",")}&expand=transitions`,headers:I(r.token||s.token)});return{data:Ct(i.body,t,o)}},De=async(s,e,t,r={})=>{let{page:n,resourceId:o,labelNames:i}=e||{},a=n??0,u=["statusCategory != Done",`(creator = currentUser() OR assignee = currentUser()
1104
+ OR comment ~ currentUser() OR summary ~ currentUser() OR description ~ currentUser())`];i&&i.forEach(c=>u.push(`labels = "${c}"`));let p=(await s.request({url:`${K(s,r,o)}/rest/api/2/search?jql=${u.join(" AND ")}&startAt=${a}&maxResults=${qe}&fields=${St.join(",")}&expand=transitions`,headers:I(r.token||s.token)})).body.issues.map(c=>Ct(c,t,o)),d=p.length==qe;return{data:p,pageInfo:{hasNextPage:d,nextPage:d?a+p.length:null}}},dr=async(s,e,t,r={})=>{let{page:n,resourceId:o,jql:i}=e||{},a=n??0,l=(await s.request({url:`${K(s,r,o)}/rest/api/2/search?jql=${i.join(" AND ")}&startAt=${a}&maxResults=${qe}&fields=${St.join(",")}&expand=transitions`,headers:I(r.token||s.token)})).body.issues.map(d=>Ct(d,t,o)),p=l.length==qe;return{data:l,pageInfo:{hasNextPage:p,nextPage:p?a+l.length:null}}},Le=async(s,e,t,r={})=>{let{assigneeLogins:n,authorLogin:o,mentionLogin:i,labelNames:a,page:u,projectKey:l,resourceId:p}=e||{},d=u??0,c=[`project = "${l}"`,"statusCategory != Done"];return o&&c.push(`creator in ("${o}")`),n&&n.length!==0&&c.push(`assignee in ("${n.join('", "')}")`),i&&c.push(`comment ~ "${i}"`),a&&a.forEach(g=>c.push(`labels = "${g}"`)),dr(s,{resourceId:p,jql:c,page:d},t,r)},Ue=async(s,e,t,r={})=>{let{assigneeLogins:n,authorLogin:o,mentionLogin:i,labelNames:a,page:u,projectKeys:l,resourceId:p}=e||{},d=u??0,g=["("+l.map(m=>`project = "${m}"`).join(" OR ")+")","statusCategory != Done"];return o&&g.push(`creator in ("${o}")`),n&&n.length!==0&&g.push(`assignee in ("${n.join('", "')}")`),i&&g.push(`comment ~ "${i}"`),a&&a.forEach(m=>g.push(`labels = "${m}"`)),dr(s,{resourceId:p,jql:g,page:d},t,r)},Ae=async(s,e,t={})=>{let{issue:r,labels:n}=e;if(!r.project)throw new Error('Jira requires a "project" for this function.');let o={fields:{labels:n.map(i=>i.name)}};await s.request({method:"PUT",url:`${K(s,t,r.project.resourceId??void 0)}/rest/api/2/issue/${r.id}`,body:JSON.stringify(o),headers:{...I(t.token||s.token),"Content-Type":"application/json"}})},$e=async(s,e,t={})=>{let{issue:r,components:n}=e;if(!r.project)throw new Error('Jira requires a "project" for this function.');let o={fields:{components:n.map(i=>({id:i.id}))}};await s.request({method:"PUT",url:`${K(s,t,r.project.resourceId??void 0)}/rest/api/2/issue/${r.id}`,body:JSON.stringify(o),headers:{...I(t.token||s.token),"Content-Type":"application/json"}})},Ge=async(s,e,t={})=>{let{issue:r,status:n}=e;if(!r.project)throw new Error('Jira requires a "project" for this function.');if(!n.id)throw new Error('Jira requires a status "id" for this function.');let o={transition:{id:n.id}};await s.request({method:"POST",url:`${K(s,t,r.project.resourceId??void 0)}/rest/api/2/issue/${r.id}/transitions`,body:JSON.stringify(o),headers:{...I(t.token||s.token),"Content-Type":"application/json"}})},Te=async(s,e,t={})=>{let{resourceId:r,projectIdOrKey:n}=e,o=new URL(`${K(s,t,r)}/rest/api/2/project/${n}/components`);return{data:(await s.request({url:o.toString(),headers:I(t.token||s.token)})).body}};var ae="https://api.atlassian.com/ex/jira",Dt=100,ue=class extends O{constructor(){super(...arguments);this._resourceUrlCache={}}async getResourceUrl(t,r={}){var i;let n=r.token||this.config.token;if(!n)return null;let o=this._resourceUrlCache[n];return o?o[t.resourceId]??null:(await this.getJiraResourcesForCurrentUser(r),((i=this._resourceUrlCache[n])==null?void 0:i[t.resourceId])??null)}async getCurrentUserForResource(t,r={}){let n=await this.getResourceUrl({resourceId:t.resourceId},r),o=await this.config.request({url:`${r.baseUrl||ae}/${t.resourceId}/rest/api/2/myself`,headers:I(r.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:n?`${n}/jira/people/${o.body.accountId}`:null}}}async getJiraResourcesForCurrentUser(t={}){let r=await this.config.request({url:`${t.baseUrl||"https://api.atlassian.com/"}/oauth/token/accessible-resources`,headers:I(t.token||this.config.token)}),n=t.token||this.config.token,o=n?this._resourceUrlCache[n]||{}:void 0,i=r.body.map(a=>(o&&(o[a.id]=a.url),{avatarUrl:a.avatarUrl,id:a.id,name:a.name,url:a.url}));return n&&(this._resourceUrlCache[n]=o),{data:i}}async getJiraProjectsForResource(t,r={}){let n=new URL(`${r.baseUrl||ae}/${t.resourceId}/rest/api/2/project/search`);n.searchParams.set("maxResults",Dt.toString()),t.cursor&&n.searchParams.set("startAt",t.cursor);let o=await this.config.request({url:n.toString(),headers:I(r.token||this.config.token)});return{pageInfo:{hasNextPage:o.body.values.length!==0,endCursor:(o.body.startAt+o.body.values.length).toString()},data:o.body.values.map(i=>({id:i.id,key:i.key,name:i.name,resourceId:t.resourceId}))}}async getJiraProjectsForResources(t,r={}){let n=[];return await Promise.all(t.resourceIds.map(async o=>{try{return await Wt(i=>this.getJiraProjectsForResource({resourceId:o,cursor:i},r))}catch{return[]}})).then((...o)=>{o.forEach(i=>{n=n.concat(...i)})}),{data:n}}async getAccountsForJiraProject(t,r={}){let{resourceId:n,projectKey:o,cursor:i}=t,a=await this.getResourceUrl({resourceId:n},r),u=new URL(`${r.baseUrl||ae}/${n}/rest/api/2/user/assignable/search`);u.searchParams.set("maxResults",Dt.toString()),i&&u.searchParams.set("startAt",i),u.searchParams.set("project",o);let l=await this.config.request({url:u.toString(),headers:I(r.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=>Se(p,a,!1))}}async getComponentsForJiraProject(t,r={}){return await Te(this.config,t,r)}async getIssue(t,r={}){let n=await this.getResourceUrl({resourceId:t.resourceId},r);return await Ce(this.config,t,n,r)}async getIssuesForProject(t,r={}){let n=await this.getResourceUrl({resourceId:t.resourceId},r);return await Le(this.config,t,n,r)}async getIssuesForProjects(t,r={}){let n=await this.getResourceUrl({resourceId:t.resourceId},r);return await Ue(this.config,t,n,r)}async getIssuesForResourceForCurrentUser(t,r={}){let n=await this.getResourceUrl({resourceId:t.resourceId},r);return await De(this.config,t,n,r)}async setIssueStatus(t,r={}){await Ge(this.config,t,r)}async setIssueAssignee(t,r={}){let{issue:n,assignee:o}=t;if(!n.project)throw new Error('Jira Cloud requires a "project" for this function.');if(!n.project.resourceId)throw new Error('Jira Cloud requires a project "resourceId" for this function.');let i={accountId:o==null?void 0:o.id};await this.config.request({method:"PUT",url:`${r.baseUrl||ae}/${n.project.resourceId}/rest/api/2/issue/${n.id}/assignee`,body:JSON.stringify(i),headers:{...I(r.token||this.config.token),"Content-Type":"application/json"}})}async setIssueComponents(t,r={}){await $e(this.config,t,r)}async setIssueLabels(t,r={}){await Ae(this.config,t,r)}async getLabelsForResource(t,r={}){let{resourceId:n,cursor:o}=t,i=new URL(`${r.baseUrl||ae}/${n}/rest/api/2/label`);i.searchParams.set("maxResults",Dt.toString()),o&&i.searchParams.set("startAt",o);let a=await this.config.request({url:i.toString(),headers:I(r.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 le=class extends _{async getCurrentUser(e={}){let t=await this.config.request({url:`${(e==null?void 0:e.baseUrl)||this.config.baseUrl}/rest/api/2/myself`,headers:I((e==null?void 0: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==null?void 0:e.baseUrl)||this.config.baseUrl}/rest/api/2/project`,headers:I((e==null?void 0:e.token)||this.config.token)})).body.map(r=>({id:r.id,name:r.name}))}}async getIssue(e,t={}){if(!t.baseUrl)throw new Error('Jira Server requires a "baseUrl" for this function.');return await Ce(this.config,e,t.baseUrl,t)}async getIssuesForProject(e,t={}){if(!t.baseUrl)throw new Error('Jira Server requires a "baseUrl" for this function.');return await Le(this.config,e,t.baseUrl,t)}async getIssuesForProjects(e,t={}){if(!t.baseUrl)throw new Error('Jira Server requires a "baseUrl" for this function.');return await Ue(this.config,e,t.baseUrl,t)}async getIssuesForResourceForCurrentUser(e,t={}){if(!t.baseUrl)throw new Error('Jira Server requires a "baseUrl" for this function.');return await De(this.config,e,t.baseUrl,t)}async setIssueStatus(e,t={}){await Ge(this.config,e,t)}async setIssueLabels(e,t={}){await Ae(this.config,e,t)}async setIssueComponents(e,t={}){await $e(this.config,e,t)}async getLabels(e={}){return{data:(await this.config.request({url:`${(e==null?void 0:e.baseUrl)||this.config.baseUrl}/rest/api/2/jql/autocompletedata/suggestions?fieldName=labels`,headers:I(e.token||this.config.token)})).body.results.map(({displayName:r})=>({color:null,description:null,id:null,name:r}))}}async getComponentsForJiraProject(e,t={}){return await Te(this.config,e,t)}};var z="https://api.trello.com",Ds=1e3,Ls=(s,e)=>{let t=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(t.toISOString()),author:null,updatedDate:new Date(s.dateLastActivity),assignees:s.idMembers.map(r=>({id:r,username:null,name:null,email:null,avatarUrl:null,url:null})),description:null,state:e[s.idList??""]?{id:s.idList,name:e[s.idList].name,color:null}:null,type:null,repository:null,upvoteCount:s.badges.votes,labels:s.labels.map(r=>({color:r.color,description:null,id:r.id,name:r.name}))}},pe=class extends O{async getCurrentUser(e,t={}){let r=await this.config.request({url:`${t.baseUrl||z}/1/members/me?key=${e.appKey}&token=${t.token||this.config.token}`,headers:I(t.token||this.config.token)});return{data:{name:r.body.fullName,email:r.body.email,avatarUrl:r.body.avatarHash?`https://trello-members.s3.amazonaws.com/${r.body.id}/${r.body.avatarHash}/50.png`:null,id:r.body.id,username:r.body.username,url:r.body.url}}}async getBoardsForCurrentUser(e,t={}){return{data:(await this.config.request({url:`${t.baseUrl||z}/1/members/me/boards?fields=name&key=${e.appKey}&token=${t.token||this.config.token}&filter=open`,headers:I(t.token||this.config.token)})).body.map(n=>({id:n.id,name:n.name}))}}async getListsForTrelloBoard(e,t={}){let{appKey:r,boardId:n}=e;return{data:(await this.config.request({url:`${t.baseUrl||z}/1/boards/${n}/lists?key=${r}&token=${t.token||this.config.token}`,headers:I(t.token||this.config.token)})).body}}async getAccountsForTrelloBoard(e,t={}){let{appKey:r,boardId:n}=e;return{data:(await this.config.request({url:`${t.baseUrl||z}/1/boards/${n}/members?key=${r}&token=${t.token||this.config.token}`,headers:I(t.token||this.config.token)})).body.map(i=>({id:i.id,name:i.fullName,username:i.username,email:null,avatarUrl:null,url:null}))}}async getIssuesForBoard(e,t={}){let r=["-is:archived","sort:edited"],{appKey:n,boardId:o,filterText:i,assigneeLogins:a,labelNamesOrColors:u,trelloBoardListsById:l}=e||{};a&&r.push("@me"),u&&u.forEach(c=>r.push(`label:"${c}"`));let p=`${i?`${i}`:""}${r.join(" ")} board:${o}`;return{data:(await this.config.request({url:`${t.baseUrl||z}/1/search?key=${n}&query=${p}&cards_limit=${Ds}&token=${t.token||this.config.token}`,headers:I(t.token||this.config.token)})).body.cards.map(c=>Ls(c,l||{}))}}async updateIssue(e,t,r,n){return await this.config.request({method:"PUT",url:`${n.baseUrl||z}/1/cards/${t.id}?key=${e}&token=${n.token||this.config.token}&${r}`,headers:I(n.token||this.config.token)})}async setIssueStatus(e,t={}){let{appKey:r,issue:n,status:o}=e;if(!o.id)throw new Error('Trello requires a status "id" for this function.');let i=`idList=${o.id}`;if(!(await this.updateIssue(r,n,i,t)).body.id)throw new Error("Could not set issue status")}async setIssueAssignees(e,t={}){let{appKey:r,issue:n,assignees:o}=e,i=o.map(l=>l.id),a=`idMembers=${encodeURIComponent(i.join(","))}`;if(!(await this.updateIssue(r,n,a,t)).body.id)throw new Error("Could not set issue status")}async setIssueLabels(e,t={}){let{appKey:r,issue:n,labels:o}=e,i=o.map(u=>u.id).join(",");if(!(await this.config.request({method:"PUT",url:`${t.baseUrl||z}/1/cards/${n.id}?key=${r}&token=${t.token||this.config.token}&idLabels=${encodeURIComponent(i)}`,headers:I(t.token||this.config.token)})).body.id)throw new Error("Could not set issue status")}async setIssueArchived(e,t={}){let{appKey:r,issue:n,archived:o}=e;if(!(await this.config.request({method:"PUT",url:`${t.baseUrl||z}/1/cards/${n.id}?key=${r}&token=${t.token||this.config.token}&closed=${o}`,headers:I(t.token||this.config.token)})).body.id)throw new Error("Could not update issue archived status")}async archiveIssue(e,t={}){await this.setIssueArchived({...e,archived:!0},t)}async unArchiveIssue(e,t={}){await this.setIssueArchived({...e,archived:!1},t)}async getLabelsForBoard(e,t={}){let{appKey:r,boardId:n}=e;return{data:(await this.config.request({url:`${t.baseUrl||z}/1/boards/${n}/labels?key=${r}&token=${t.token||this.config.token}`,headers:I(t.token||this.config.token)})).body.map(i=>({color:i.color,description:null,id:i.id,name:i.name}))}}};var Oe={};N(Oe,{default:()=>Us});var Us={};var xe={};N(xe,{default:()=>As});var As={};var ke={};N(ke,{restApiPullRequestToCommonPullRequest:()=>$s});var $s=s=>se(s);var Ve={};N(Ve,{decode:()=>xs,decodeV0:()=>ks,encode:()=>Os,validate:()=>Ts});var L=(t=>(t.Zero="0",t.One="1",t))(L||{}),U=(t=>(t.PullRequest="pr",t.Issue="issue",t))(U||{}),A=(p=>(p.Azure="azure",p.Github="github",p.GithubEnterprise="githubEnterprise",p.Gitlab="gitlab",p.GitlabSelfHosted="gitlabSelfHosted",p.Bitbucket="bitbucket",p.BitbucketServer="bitbucketServer",p.Jira="jira",p.JiraServer="jiraServer",p.Trello="trello",p))(A||{});var Ne=class{constructor(){}validate(e){if(!e.organizationName)throw new Error("organizationName is required");if(!e.projectId)throw new Error("projectId is required");if(!e.entityId)throw new Error("issueId is required")}encode(e){if(this.validate(e),!e.organizationName||!e.projectId||!e.entityId)throw new Error("Missing required fields for Azure DevOps issue uniqueId");let t=[];return t.push("azure"),t.push("issue"),t.push("1"),t.push(e.domain||""),t.push(e.organizationName),t.push(e.projectId),t.push(e.entityId),JSON.stringify(t)}decode(e){if(e.length<7)throw new Error("Invalid Azure DevOps issue uniqueId, check version");return{provider:e[0],entityType:e[1],version:e[2],domain:e[3]==""?null:e[3],resourceId:null,accountOrOrgId:null,organizationName:e[4],projectId:e[5],repoId:null,entityId:e[6]}}};var _e=class{constructor(){}validate(e){if(!e.organizationName)throw new Error("organizationName is required");if(!e.projectId)throw new Error("projectId is required");if(!e.repoId)throw new Error("repoId is required");if(!e.entityId)throw new Error("entityId is required")}encode(e){if(this.validate(e),!e.organizationName||!e.projectId||!e.repoId||!e.entityId)throw new Error("Missing required fields for Azure DevOps pull request uniqueId");let t=[];return t.push("azure"),t.push("pr"),t.push("1"),t.push(e.domain||""),t.push(e.organizationName),t.push(e.projectId),t.push(e.repoId),t.push(e.entityId),JSON.stringify(t)}decode(e){if(e.length<8)throw new Error("Invalid Azure DevOps pull request uniqueId, check version");return{provider:e[0],entityType:e[1],version:e[2],domain:e[3]==""?null:e[3],resourceId:null,accountOrOrgId:null,organizationName:e[4],projectId:e[5],repoId:e[6],entityId:e[7]}}};var Qe=class{constructor(){}validate(e){if(!e.repoId)throw new Error("repoId is required");if(!e.entityId)throw new Error("issueId is required")}encode(e){if(this.validate(e),!e.repoId||!e.entityId)throw new Error("Missing required fields for Bitbucket DevOps issue uniqueId");let t=[];return t.push(e.provider),t.push("issue"),t.push("1"),e.provider==="bitbucketServer"?t.push(e.domain):t.push(""),t.push(e.repoId),t.push(e.entityId),JSON.stringify(t)}decode(e){if(e.length<6)throw new Error("Invalid Bitbucket DevOps issue uniqueId, check version");return{provider:e[0],entityType:e[1],version:e[2],domain:e[3]==""?null:e[3],resourceId:null,accountOrOrgId:null,organizationName:null,projectId:null,repoId:e[4],entityId:e[5]}}};var Be=class{constructor(){}validate(e){if(!e.repoId)throw new Error("repoId is required");if(!e.entityId)throw new Error("entityId is required")}encode(e){if(this.validate(e),!e.repoId||!e.entityId)throw new Error("Missing required fields for Bitbucket DevOps pull request uniqueId");let t=[];return t.push(e.provider),t.push("pr"),t.push("1"),e.provider==="bitbucketServer"?t.push(e.domain):t.push(""),t.push(e.repoId),t.push(e.entityId),JSON.stringify(t)}decode(e){if(e.length<6)throw new Error("Invalid Bitbucket DevOps pull request uniqueId, check version");return{provider:e[0],entityType:e[1],version:e[2],domain:e[3]==""?null:e[3],resourceId:null,accountOrOrgId:null,organizationName:null,projectId:null,repoId:e[4],entityId:e[5]}}};var je=class{constructor(){}validate(e){if(!e.entityId)throw new Error("entityId is required")}encode(e){if(this.validate(e),!e.entityId)throw new Error("Missing required fields for Github issue uniqueId");let t=[];return t.push(e.provider),t.push("issue"),t.push("1"),e.provider==="githubEnterprise"?t.push(e.domain):t.push(""),t.push(e.entityId),JSON.stringify(t)}decode(e){if(e.length<5)throw new Error("Invalid Github issue uniqueId, check version");return{provider:e[0],entityType:e[1],version:e[2],domain:e[3]==""?null:e[3],resourceId:null,accountOrOrgId:null,organizationName:null,projectId:null,repoId:null,entityId:e[4]}}};var Fe=class{constructor(){}validate(e){if(!e.entityId)throw new Error("entityId is required")}encode(e){if(this.validate(e),!e.entityId)throw new Error("Missing required fields for Github pull request uniqueId");let t=[];return t.push(e.provider),t.push("pr"),t.push("1"),e.provider==="githubEnterprise"?t.push(e.domain):t.push(""),t.push(e.entityId),JSON.stringify(t)}decode(e){if(e.length<5)throw new Error("Invalid Github pull request uniqueId, check version");return{provider:e[0],entityType:e[1],version:e[2],domain:e[3]==""?null:e[3],resourceId:null,accountOrOrgId:null,organizationName:null,projectId:null,repoId:null,entityId:e[4]}}};var Me=class{constructor(){}validate(e){if(!e.entityId)throw new Error("entityId is required")}encode(e){if(this.validate(e),!e.entityId)throw new Error("Missing required fields for Gitlab issue uniqueId");let t=[];return t.push(e.provider),t.push("issue"),t.push("1"),e.provider==="gitlabSelfHosted"?t.push(e.domain):t.push(""),t.push(e.entityId),JSON.stringify(t)}decode(e){if(e.length<5)throw new Error("Invalid Gitlab issue uniqueId, check version");return{provider:e[0],entityType:e[1],version:e[2],domain:e[3]==""?null:e[3],resourceId:null,accountOrOrgId:null,organizationName:null,projectId:null,repoId:null,entityId:e[4]}}};var ze=class{constructor(){}validate(e){if(!e.entityId)throw new Error("entityId is required")}encode(e){if(this.validate(e),!e.entityId)throw new Error("Missing required fields for Gitlab pull request uniqueId");let t=[];return t.push(e.provider),t.push("pr"),t.push("1"),e.provider==="gitlabSelfHosted"?t.push(e.domain):t.push(""),t.push(e.entityId),JSON.stringify(t)}decode(e){if(e.length<5)throw new Error("Invalid Gitlab pull request uniqueId, check version");return{provider:e[0],entityType:e[1],version:e[2],domain:e[3]==""?null:e[3],resourceId:null,accountOrOrgId:null,organizationName:null,projectId:null,repoId:null,entityId:e[4]}}};var He=class{constructor(){}validate(e){if(!e.projectId)throw new Error("projectId is required");if(!e.entityId)throw new Error("entityId is required")}encode(e){if(this.validate(e),!e.projectId||!e.entityId)throw new Error("Missing required fields for Jira issue uniqueId");let t=[];return t.push(e.provider),t.push("issue"),t.push("1"),e.provider=="jira"?(t.push(""),t.push(e.resourceId)):(t.push(e.domain),t.push("")),t.push(e.projectId),t.push(e.entityId),JSON.stringify(t)}decode(e){if(e.length<7)throw new Error("Invalid Jira issue uniqueId, check version");return{provider:e[0],entityType:e[1],version:e[2],domain:e[3]==""?null:e[3],resourceId:e[4]==""?null:e[4],accountOrOrgId:null,organizationName:null,projectId:e[5],repoId:null,entityId:e[6]}}};var We=class{constructor(){}validate(e){if(!e.accountOrOrgId)throw new Error("accountOrOrgId is required");if(!e.projectId)throw new Error("projectId is required");if(!e.entityId)throw new Error("entityId is required")}encode(e){if(this.validate(e),!e.accountOrOrgId||!e.projectId||!e.entityId)throw new Error("Missing required fields for Trello issue uniqueId");let t=[];return t.push("trello"),t.push("issue"),t.push("1"),t.push(""),t.push(e.accountOrOrgId),t.push(e.projectId),t.push(e.entityId),JSON.stringify(t)}decode(e){if(e.length<7)throw new Error("Invalid Trello issue uniqueId, check version");return{provider:e[0],entityType:e[1],version:e[2],domain:e[3]==""?null:e[3],resourceId:null,accountOrOrgId:e[4],organizationName:null,projectId:e[5],repoId:null,entityId:e[6]}}};var Je=(s,e)=>{if(e!=="issue"&&e!=="pr")throw new Error("unknown entityType");switch(s){case"azure":return e==="pr"?new _e:new Ne;case"bitbucket":case"bitbucketServer":return e==="pr"?new Be:new Qe;case"github":case"githubEnterprise":return e==="pr"?new Fe:new je;case"gitlab":case"gitlabSelfHosted":return e==="pr"?new ze:new Me;case"jira":case"jiraServer":if(e==="pr")throw new Error("EntityType PullRequest is not valid for Jira");return new He;case"trello":if(e==="pr")throw new Error("EntityType PullRequest is not valid for Jira");return new We;default:throw new Error("unknown provider")}},Gs=s=>{if(!s.entityType)throw new Error("entityType is required");if(!s.provider)throw new Error("provider is required");if(!s.entityId)throw new Error("entityID is required")},Ts=s=>{if(s.version==="0"){Gs(s);return}Je(s.provider,s.entityType).validate(s)},Os=s=>Je(s.provider,s.entityType).encode(s),xs=s=>{let e=JSON.parse(s);if(!e||!e.length)throw new Error("invalid issue unique id");return Je(e[0],e[1]).decode(e)},ks=(s,e,t)=>{if(!t)throw new Error("entityID is required");try{let r=JSON.parse(t);if(!r||!r.length)throw new Error("Invalid pull request uniqueId");let n=[s,e,"0",...r];return Je(s,e).decode(n)}catch{return{provider:s,entityType:e,version:"0",domain:"",resourceId:null,accountOrOrgId:null,organizationName:null,projectId:null,repoId:null,entityId:t}}};var Ke={};N(Ke,{CHANGES_REQUESTED_ACTION_CATEGORY:()=>Ir,CHANGES_REQUESTED_BUCKET_ID:()=>Ot,CONFLICTS_ACTION_CATEGORY:()=>hr,CONFLICTS_BUCKET_ID:()=>Gt,DRAFT_ACTION_CATEGORY:()=>br,DRAFT_BUCKET_ID:()=>Nt,FAILING_CI_ACTION_CATEGORY:()=>mr,FAILING_CI_BUCKET_ID:()=>$t,NEEDS_MY_REVIEW_ACTION_CATEGORY:()=>fr,NEEDS_MY_REVIEW_BUCKET_ID:()=>Tt,OTHER_ACTION_CATEGORY:()=>wr,OTHER_BUCKET_ID:()=>_t,PINNED_BUCKET_ID:()=>Lt,READY_TO_MERGE_ACTION_CATEGORY:()=>cr,READY_TO_MERGE_BUCKET_ID:()=>Ut,REVIEWER_COMMENTED_ACTION_CATEGORY:()=>Rr,REVIEWER_COMMENTED_BUCKET_ID:()=>xt,SNOOZED_BUCKET_ID:()=>Qt,UNASSIGNED_REVIEWERS_ACTION_CATEGORY:()=>gr,UNASSIGNED_REVIEWERS_BUCKET_ID:()=>At,WAITING_FOR_REVIEW_ACTION_CATEGORY:()=>yr,WAITING_FOR_REVIEW_BUCKET_ID:()=>kt,getActionablePullRequests:()=>Pr,groupPullRequestsIntoBuckets:()=>Ns});var T=(s,e,t,r)=>({id:s,faIconName:t,name:e,priority:r,pullRequests:[]}),Lt="pinned",Ut="readyToMerge",At="unassignedReviewers",$t="failingCI",Gt="conflicts",Tt="needsMyReview",Ot="changesRequested",xt="reviewerCommented",kt="waitingForReview",Nt="draft",_t="other",Qt="snoozed",cr="readyToMerge",gr="unassignedReviewers",mr="failingCI",hr="conflicts",fr="needsMyReview",Ir="changesRequested",Rr="reviewerCommented",yr="waitingForReview",br="draft",wr="other",Pr=(s,e,t)=>s.map(r=>{var u,l,p,d,c,g,m,h,R,w,f,E,S,Z;let o={...r,...{suggestedActionCategory:wr,priority:1e3,viewer:{canMerge:!1,isAuthor:!1,isAssignee:!1,isReviewer:!1,shouldMerge:!1,shouldAssignReviewer:!1,waitingOnReviews:!1,shouldReview:!1},failingCI:!1,hasConflicts:!1,changeRequestReviewCount:0,codeSuggestionsCount:0,commentReviewCount:0,approvalReviewCount:0}};e&&(o.viewer.isAuthor=((u=r.author)==null?void 0:u.id)===e.id,o.viewer.isAssignee=((l=r.assignees)==null?void 0:l.some(v=>v.id===e.id))??!1,o.viewer.isReviewer=((p=r.reviews)==null?void 0:p.some(v=>v.reviewer.id===e.id))??!1),o.viewer.canMerge=((d=r.permissions)==null?void 0:d.canMerge)??!0,o.hasConflicts=r.mergeableState==="CONFLICTS",o.failingCI=((g=(c=r.headCommit)==null?void 0:c.buildStatuses)==null?void 0:g.some(v=>v.state==="ERROR"||v.state==="FAILED"))??!1,o.commentReviewCount=((m=r.reviews)==null?void 0:m.filter(v=>v.state==="COMMENTED").length)??0,o.approvalReviewCount=((h=r.reviews)==null?void 0:h.filter(v=>v.state==="APPROVED").length)??0,o.changeRequestReviewCount=((R=r.reviews)==null?void 0:R.filter(v=>v.state==="CHANGES_REQUESTED").length)??0;let i=(w=t==null?void 0:t.enrichedItemsByUniqueId)==null?void 0:w[r.uuid];i!=null&&(o.viewer.enrichedItems=i,i.some(v=>v.type==="pin")&&(o.viewer.pinned=!0,o.priority-=800),i.some(v=>v.type==="snooze")&&(o.viewer.snoozed=!0));let a=((E=(f=t==null?void 0:t.codeSuggestionsCountByPrUuid)==null?void 0:f[r.uuid])==null?void 0:E.count)||0;return a&&(o.codeSuggestionsCount=a),(!e||o.viewer.isAuthor||o.viewer.isAssignee&&!o.viewer.isReviewer)&&o.viewer.canMerge&&!o.isDraft&&!o.failingCI&&r.mergeableState==="MERGEABLE"&&(!r.reviewDecision||r.reviewDecision==="APPROVED")&&(o.viewer.shouldMerge=!0,o.suggestedActionCategory=cr),(!e||o.viewer.isAuthor)&&r.isDraft&&(o.suggestedActionCategory=br),(!e||o.viewer.isAuthor)&&r.reviewDecision==="REVIEW_REQUESTED"&&(o.suggestedActionCategory=yr,o.viewer.waitingOnReviews=!0),(!e||o.viewer.isAuthor)&&r.reviewDecision==="COMMENTED"&&(o.suggestedActionCategory=Rr),(!e||o.viewer.isAuthor)&&o.failingCI&&(o.suggestedActionCategory=mr),(!e||o.viewer.isAuthor)&&o.hasConflicts&&(o.suggestedActionCategory=hr),(!e||o.viewer.isAuthor)&&(r.reviewDecision==="CHANGES_REQUESTED"||o.codeSuggestionsCount>0)&&(o.suggestedActionCategory=Ir),(!e||o.viewer.isAuthor)&&!((S=r.reviews)!=null&&S.length)&&(o.suggestedActionCategory=gr,o.viewer.shouldAssignReviewer=!0),e&&((Z=r.reviews)!=null&&Z.some(v=>v.reviewer.id===e.id&&v.state==="REVIEW_REQUESTED"))&&(o.suggestedActionCategory=fr,o.viewer.shouldReview=!0),o}),Ns=(s,e,t)=>{let r={pinned:T(Lt,"Pinned","thumbtack",-1),readyToMerge:T(Ut,"Ready to Merge","code-merge",0),unassignedReviewers:T(At,"Unassigned Reviewers","user-plus",1),failingCI:T($t,"Failing CI","circle-x",2),conflicts:T(Gt,"Resolve Conflicts","triangle-exclamation",3),needsMyReview:T(Tt,"Needs My Review","eye",4),changesRequested:T(Ot,"Suggested Changes","file-plus",5),reviewerCommented:T(xt,"Reviewer Commented","comment",6),waitingForReview:T(kt,"Waiting for Review","circle-pause",7),draft:T(Nt,"Draft","compass-drafting",8),other:T(_t,"Other","ellipsis",9),snoozed:T(Qt,"Snoozed","snooze",10)},o=Pr(s,e,t).reduce((i,a)=>(i[a.uuid]=a,i),{});return s.forEach(i=>{let a=o[i.uuid],u=!0;if(a.viewer.snoozed){r[Qt].pullRequests.push(i);return}a.viewer.pinned&&r[Lt].pullRequests.push(i),(!e||a.viewer.isAuthor||a.viewer.isAssignee&&!a.viewer.isReviewer)&&!a.isDraft&&a.viewer.canMerge&&a.mergeableState==="MERGEABLE"&&(!i.reviewDecision||i.reviewDecision==="APPROVED")&&(r[Ut].pullRequests.push(i),u=!1),a.viewer.shouldAssignReviewer&&(r[At].pullRequests.push(i),u=!1),(!e||a.viewer.isAuthor)&&a.failingCI&&(r[$t].pullRequests.push(i),u=!1),(!e||a.viewer.isAuthor)&&a.hasConflicts&&(r[Gt].pullRequests.push(i),u=!1),a.viewer.shouldReview&&(r[Tt].pullRequests.push(i),u=!1),(!e||a.viewer.isAuthor)&&(a.reviewDecision==="CHANGES_REQUESTED"||a.codeSuggestionsCount>0)&&(r[Ot].pullRequests.push(i),u=!1),(!e||a.viewer.isAuthor)&&a.reviewDecision==="COMMENTED"&&(r[xt].pullRequests.push(i),u=!1),(!e||a.viewer.isAuthor)&&a.reviewDecision==="REVIEW_REQUESTED"&&(r[kt].pullRequests.push(i),u=!1),a.isDraft&&(r[Nt].pullRequests.push(i),u=!1),u&&r[_t].pullRequests.push(i)}),Object.values(r).forEach(i=>{i.pullRequests.sort((a,u)=>o[a.uuid].priority-o[u.uuid].priority)}),r};var Xe={};N(Xe,{getPullRequestRank:()=>_s});var _s=(s,e,t)=>{var i,a,u;let r=0,n,o;return(i=s.reviews)==null||i.forEach(l=>{l.reviewer.id===e&&(n=l.state),l.state==="CHANGES_REQUESTED"?o="CHANGES_REQUESTED":l.state==="APPROVED"&&o!=="CHANGES_REQUESTED"&&(o="APPROVED")}),o||(o="REVIEW_REQUESTED"),((a=s.author)==null?void 0:a.id)===e?r+=1e3:(u=s.assignees)!=null&&u.find(l=>l.id===e)?r+=900:n==="REVIEW_REQUESTED"?r+=800:t&&(r+=700),o==="APPROVED"?s.mergeableState==="MERGEABLE"?r+=100:s.mergeableState==="CONFLICTS"?r+=90:r+=80:o=="CHANGES_REQUESTED"&&(r+=70),r};var Ye={};N(Ye,{default:()=>Qs});var Qs={};var Ze={};N(Ze,{default:()=>Bs});var Bs={};var et={};N(et,{default:()=>js});var js={};var Er=(i=>(i.Conflicts="conflicts",i.Failure="failure",i.NotSet="notSet",i.Queued="queued",i.RejectedByPolicy="rejectedByPolicy",i.Succeeded="succeeded",i))(Er||{});var vr=(t=>(t.Completed="COMPLETED",t.NotPlanned="NOT_PLANNED",t))(vr||{});var Fs=s=>{let e={request:s==null?void 0:s.request};return{azureDevOps:new te({...e,...s==null?void 0:s.azureDevOps}),bitbucket:new re({...e,...s==null?void 0:s.bitbucket}),bitbucketServer:new ne({...e,...s==null?void 0:s.bitbucketServer}),github:new oe({...e,...s==null?void 0:s.github}),gitlab:new ie({...e,...s==null?void 0:s.gitlab}),jira:new ue({...e,...s==null?void 0:s.jira}),jiraServer:new le({...e,...s==null?void 0:s.jiraServer}),trello:new pe({...e,...s==null?void 0:s.trello})}},Ms=Fs;var zs={azureDevOps:Oe,bitbucket:xe,bitbucketServer:ke,github:Xe,gitlab:Ye,gitProvider:Ke,jira:Ze,trello:et,entityIdentifier:Ve};