@gitkraken/provider-apis 0.25.8 → 0.25.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- "use strict";var kt=Object.create;var ne=Object.defineProperty;var Nt=Object.getOwnPropertyDescriptor;var Ft=Object.getOwnPropertyNames;var Qt=Object.getPrototypeOf,_t=Object.prototype.hasOwnProperty;var Bt=(r,s)=>{for(var e in s)ne(r,e,{get:s[e],enumerable:!0})},nt=(r,s,e,t)=>{if(s&&typeof s=="object"||typeof s=="function")for(let n of Ft(s))!_t.call(r,n)&&n!==e&&ne(r,n,{get:()=>s[n],enumerable:!(t=Nt(s,n))||t.enumerable});return r};var jt=(r,s,e)=>(e=r!=null?kt(Qt(r)):{},nt(s||!r||!r.__esModule?ne(e,"default",{value:r,enumerable:!0}):e,r)),Mt=r=>nt(ne({},"__esModule",{value:!0}),r);var Wr={};Bt(Wr,{AzureDevOps:()=>W,Bitbucket:()=>J,BitbucketServer:()=>K,EntityIdentifierProviderType:()=>Tt,EntityType:()=>Gt,EntityVersion:()=>At,GitBuildStatusStage:()=>ot,GitBuildStatusState:()=>oe,GitDiffLineType:()=>Le,GitHub:()=>V,GitHubIssueCloseReason:()=>Ot,GitIssueState:()=>le,GitLab:()=>Z,GitMergeStrategy:()=>H,GitPullRequestMergeableState:()=>M,GitPullRequestReviewState:()=>j,GitPullRequestState:()=>B,Jira:()=>Y,JiraServer:()=>ee,PullRequestAsyncStatus:()=>$t,Trello:()=>te,default:()=>Hr,isFetch:()=>ae});module.exports=Mt(Wr);var ot=(n=>(n.Build="build",n.Production="production",n.Staging="staging",n.Test="test",n))(ot||{}),oe=(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))(oe||{}),H=(o=>(o.MergeCommit="MERGE_COMMIT",o.Rebase="REBASE",o.RebaseThenMergeCommit="REBASE_THEN_MERGE_COMMIT",o.FastForward="FAST_FORWARD",o.Squash="SQUASH",o))(H||{}),B=(t=>(t.Open="OPEN",t.Closed="CLOSED",t.Merged="MERGED",t))(B||{}),j=(n=>(n.Approved="APPROVED",n.ChangesRequested="CHANGES_REQUESTED",n.Commented="COMMENTED",n.ReviewRequested="REVIEW_REQUESTED",n))(j||{}),M=(i=>(i.Behind="BEHIND",i.Blocked="BLOCKED",i.Conflicts="CONFLICTS",i.Mergeable="MERGEABLE",i.Unknown="UNKNOWN",i.UnknownAndBlocked="UNKNOWN_AND_BLOCKED",i.Unstable="UNSTABLE",i))(M||{}),Le=(t=>(t.ADDED="ADDED",t.DELETED="DELETED",t.UNMODIFIED="UNMODIFIED",t))(Le||{});var at={APPROVED:0,COMMENTED:1,REVIEW_REQUESTED:2,CHANGES_REQUESTED:3},F=r=>!r||r.length===0?null:r.reduce((s,e)=>at[e.state]>at[s]?e.state:s,"APPROVED");var q=100;var it=jt(require("node-fetch")),ut=globalThis.fetch||it.default;var zt=async r=>{let s=r.headers.get("content-type")||"",e=null;if(s.startsWith("application/json")){let n=await r.text();e=n.trim().length>0?JSON.parse(n):null}else if(s.startsWith("text/")||s==="")e=await r.text();else if(s.startsWith("application/vnd.github.raw+json"))e=await r.arrayBuffer();else throw new Error(`Unsupported content-type: ${s}`);let t={body:e,headers:Object.fromEntries(r.headers.entries()),status:r.status,statusText:r.statusText};if(!r.ok){let n=new Error(r.statusText);throw Object.assign(n,{response:t}),n}return t},$e=r=>async({url:s,...e})=>{let t=await r(s,e);return zt(t)};var ae=(r,s=!1)=>r.name==="fetch"||s;var D=class{constructor(s){let e=(s==null?void 0:s.request)||ut;this.config={...s,request:ae(e,s==null?void 0:s.forceIsFetch)?$e(e):e}}updateConfig(s){this.config={...this.config,...s,request:s.request&&ae(s.request,(s==null?void 0:s.forceIsFetch)??this.config.forceIsFetch)?$e(s.request):this.config.request}}},G=class extends D{};var I=(r,s)=>{let e={};return r&&(e.Authorization=`${s?"Basic":"Bearer"} ${r}`),e},lt=r=>r?r.reduce((s,e)=>(s[e]=!0,s),{}):void 0,Q=(r,s,e)=>!r||s.some(t=>r[t])?e:"",pt=async r=>{var n,o,a;let s=[],e=!0,t;for(;e;){let i=await r(t);s=s.concat(i.data),e=!!((n=i==null?void 0:i.pageInfo)!=null&&n.hasNextPage),t=((o=i==null?void 0:i.pageInfo)==null?void 0:o.endCursor)||((a=i==null?void 0:i.pageInfo)==null?void 0:a.nextPage)}return s};var w=(r,s={})=>I(s.token||r.token,s.isPAT||r.isPAT),dt=r=>r.url.replace("/_apis/git/repositories/","/_git/").replace(`/${r.repository.project.id}/`,`/${encodeURIComponent(r.repository.project.name)}/`).replace(`/${r.repository.id}/`,`/${encodeURIComponent(r.repository.name)}/`).replace("/pullRequests/","/pullrequest/");var ct="https://app.vssps.visualstudio.com/_apis",v="https://dev.azure.com",Ht={active:"OPEN",completed:"MERGED",abandoned:"CLOSED"},Wt={10:"APPROVED",5:"APPROVED",0:"REVIEW_REQUESTED",[-5]:"CHANGES_REQUESTED",[-10]:"CHANGES_REQUESTED"},Ae=r=>({id:r.id,name:r.displayName??null,username:(r.uniqueName||r.displayName)??null,email:null,avatarUrl:r.imageUrl??null,url:null}),ue=r=>r.startsWith("refs/heads/")?r.replace("refs/heads/",""):r,ie=(r,s)=>{var n;let e=[],t=[];return s.reviewers.forEach(o=>{let a={reviewer:Ae(o),state:Wt[o.vote??0]||"REVIEW_REQUESTED"};o.isRequired&&e.push(a),t.push(a)}),{id:s.pullRequestId.toString(),title:s.title,number:s.codeReviewId,state:Ht[s.status],isDraft:s.isDraft,commentCount:null,upvoteCount:null,author:Ae(s.createdBy),createdDate:new Date(s.creationDate),updatedDate:new Date(s.closedDate||s.creationDate),closedDate:s.closedDate?new Date(s.closedDate):null,mergedDate:s.closedDate&&s.status==="completed"?new Date(s.closedDate):null,repository:{id:s.repository.id,name:s.repository.name,project:s.repository.project.name,owner:{login:r},remoteInfo:null},headCommit:{buildStatuses:null},baseRef:{name:ue(s.targetRefName),oid:s.lastMergeTargetCommit.commitId},headRef:{name:ue(s.sourceRefName),oid:s.lastMergeSourceCommit.commitId},url:dt(s),assignees:s.reviewers.map(Ae),reviews:t,reviewDecision:F(e),additions:null,deletions:null,fileCount:null,commitCount:null,headRepository:null,mergeableState:"UNKNOWN",labels:((n=s.labels)==null?void 0:n.map(o=>({color:null,description:null,id:o.id,name:o.name})))??[],permissions:null}},gt=(r,s)=>({id:s.id,name:s.name,namespace:r,project:s.project.name,webUrl:s.webUrl,httpsUrl:s.remoteUrl,sshUrl:s.sshUrl,defaultBranch:s.defaultBranch?{name:ue(s.defaultBranch)}:null,permission:null}),Jt=(r,s,e,t)=>{var l,p,d,c,g,m;let n=e.fields,o=n["System.AssignedTo"],a=n["System.State"],i=n["System.WorkItemType"],u;return a&&i&&(u=(l=t[i])==null?void 0:l[a]),{id:e.id.toString(),number:e.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:e._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)||a,color:null},type:n["System.WorkItemType"],repository:null,project:{namespace:r,name:s,resourceId:null,key:null,id:null},upvoteCount:0,labels:((m=e.fields["System.Tags"])==null?void 0:m.split(";").map(h=>({color:null,description:null,id:null,name:h.trim()})))??[]}},W=class extends D{async getCurrentUser(s={},e={}){if(e.isPAT||this.config.isPAT)throw new Error("Azure DevOps does not support PATs for this function.");let t=await this.config.request({url:`${ct}/profile/profiles/me`,headers:w(this.config,e)});return{data:{id:t.body.id,name:t.body.displayName,username:t.body.displayName,email:t.body.emailAddress,avatarUrl:null,url:null}}}async getCurrentUserForInstance(s,e={}){let n=(await this.config.request({url:`${v}/${encodeURIComponent(s.namespace)}/_apis/ConnectionData`,headers:w(this.config,e)})).body.authorizedUser;if(n.providerDisplayName==="Anonymous")throw new Error("Current user not found.");return{data:{id:n.id,name:n.providerDisplayName,username:n.providerDisplayName,email:n.properties.Account.$value,avatarUrl:null}}}async getUserForCommit(s,e={}){if(!s.repo.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let n=(await this.config.request({url:`${v}/${encodeURIComponent(s.repo.namespace)}/${encodeURIComponent(s.repo.project)}/_apis/git/repositories/${encodeURIComponent(s.repo.name)}/commits/${s.oid}`,headers:w(this.config,e)})).body.author;return{data:{name:n.name,email:n.email,avatarUrl:n.imageUrl}}}async getOrgsForUser(s,e={}){return{data:(await this.config.request({url:`${ct}/accounts?memberId=${s.userId}&api-version=6.0`,headers:w(this.config,e)})).body.value.map(n=>({id:n.accountId,name:n.accountName}))}}async getAzureProjects(s,e={}){let t=new URL(`${v}/${encodeURIComponent(s.namespace)}/_apis/projects`);t.searchParams.set("$top",q.toString()),s.cursor&&t.searchParams.set("$skip",s.cursor);let n=await this.config.request({url:t.toString(),headers:w(this.config,e)}),o=n.headers["x-ms-continuationtoken"];return{pageInfo:{hasNextPage:!!o,endCursor:o||null},data:n.body.value.map(a=>({id:a.id,name:a.name,namespace:s.namespace}))}}async getAzureProjectScopeDescriptor(s,e={}){let{namespace:t,projectId:n}=s;return{data:{scope:(await this.config.request({url:`https://vssps.dev.azure.com/${encodeURIComponent(t)}/_apis/graph/descriptors/${n}?api-version=6.0`,headers:w(this.config,e)})).body.value}}}async getAzureGraphAccountsForAzureProject(s,e={}){let{namespace:t,projectScopeDescriptor:n,cursor:o}=s,a=new URL(`https://vssps.dev.azure.com/${encodeURIComponent(t)}/_apis/graph/users`);n&&a.searchParams.set("scopeDescriptor",n),o&&a.searchParams.set("continuationToken",o);let i=await this.config.request({url:a.toString(),headers:w(this.config,e)}),u=i.headers["x-ms-continuationtoken"];return{pageInfo:{endCursor:u||null,hasNextPage:!!u},data:i.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(s,e={}){let{azureGraphAccount:t}=s;if(!t.storageKeyURL)throw new Error("Expected 'storageKeyURL' to not be null for 'azureGraphAccount'");let n=await this.config.request({url:t.storageKeyURL,headers:w(this.config,e)});return{data:{avatarUrl:t.avatarUrl,email:t.email,id:n.body.value,name:t.name,username:t.username,url:null}}}async getAccountsFromAzureGraphAccounts(s,e={}){let t=[];for(let n of s.azureGraphAccounts){let o=await this.getAccountFromAzureGraphAccount({azureGraphAccount:n},e);t.push(o.data)}return{data:t}}async getRepo(s,e={}){if(!s.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let t=await this.config.request({url:`${v}/${encodeURIComponent(s.namespace)}/${encodeURIComponent(s.project)}/_apis/git/repositories/${encodeURIComponent(s.name)}`,headers:w(this.config,e)});return{data:gt(s.namespace,t.body)}}async getRepos(s,e={}){let t=[],n=[];return await Promise.all(s.map(async o=>{try{let a=await this.getRepo(o,e);t.push(a.data)}catch(a){n.push({input:o,error:a})}})),{data:t,errors:n}}async getReposForAzureProject(s,e={}){if(!s.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');return{data:(await this.config.request({url:`${v}/${encodeURIComponent(s.namespace)}/${encodeURIComponent(s.project)}/_apis/git/repositories`,headers:w(this.config,e)})).body.value.map(n=>gt(s.namespace,n))}}async getRefs(s,e,t={}){if(!e.repo.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let n=new URL(`${v}/${encodeURIComponent(e.repo.namespace)}/${encodeURIComponent(e.repo.project)}/_apis/git/repositories/${encodeURIComponent(e.repo.name)}/refs`);n.searchParams.set("filter",s),n.searchParams.set("$top",q.toString()),e.cursor&&n.searchParams.set("continuationToken",e.cursor);let o=await this.config.request({url:n.toString(),headers:w(this.config,t)}),a=o.headers["x-ms-continuationtoken"];return{pageInfo:{hasNextPage:!!a,endCursor:a||null},data:o.body.value.map(i=>({name:ue(i.name),commit:{oid:i.objectId,authoredDate:null,committedDate:null}}))}}async getBranches(s,e={}){return this.getRefs("heads",s,e)}async getTags(s,e={}){return this.getRefs("tags",s,e)}async getPullRequestsForRepoBase(s,e={},t=100){let{page:n,repo:o,assigneeLogins:a,authorLogin:i}=s||{},u=n||1;if(!o.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let l="searchCriteria.status=1";return a&&a.length&&(l+=`&searchCriteria.reviewerId=${a[0]}`),i&&(l+=`&searchCriteria.creatorId=${i}`),await this.config.request({url:`${e.baseUrl||v}/${encodeURIComponent(o.namespace)}/${encodeURIComponent(o.project||"")}/_apis/git/repositories/${encodeURIComponent(o.name)}/pullRequests?${l}&%24top=${t}&%24skip=${(u-1)*t}`,headers:w(this.config,e)})}async getPullRequestsForRepo(s,e={}){let n=s.page||1,o=await this.getPullRequestsForRepoBase(s,e,100);return{pageInfo:{hasNextPage:o.body.value.length===100,nextPage:n+1},data:o.body.value.map(a=>ie(s.repo.namespace,a))}}async getPullRequestsForRepos(s,e={}){if(!s.repos.every(o=>o.project))throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let{repos:t}=s||{},n=[];return await Promise.all(t.map(async o=>{try{(await this.getPullRequestsForRepoBase({repo:o,...s},e)).body.value.forEach(i=>{n.push(ie(o.namespace,i))})}catch(a){if(a.statusCode!==404&&a.statusCode!==401)throw a}})),{data:n}}async getPullRequestsForProjectBase(s,e={},t=100){let{namespace:n,project:o,page:a,assigneeLogins:i,authorLogin:u}=s,l=a||1,p=new URL(`${e.baseUrl||v}/${encodeURIComponent(n)}/${encodeURIComponent(o)}/_apis/git/pullRequests`);return p.searchParams.set("searchCriteria.status","1"),p.searchParams.set("$top",t.toString()),p.searchParams.set("$skip",((l-1)*t).toString()),i&&i.length&&p.searchParams.set("searchCriteria.reviewerId",i[0]),u&&p.searchParams.set("searchCriteria.creatorId",u),await this.config.request({url:p.toString(),headers:w(this.config,e)})}async getPullRequestsForProject(s,e={}){let n=s.page||1,o=await this.getPullRequestsForProjectBase(s,e,100);return{pageInfo:{hasNextPage:o.body.value.length===100,nextPage:n+1},data:o.body.value.map(a=>ie(s.namespace,a))}}async getPullRequestsForProjects(s,e={}){let{projects:t}=s||{},n=[];return await Promise.all(t.map(async o=>{try{(await this.getPullRequestsForProjectBase({...o,...s},e)).body.value.forEach(i=>{n.push(ie(o.namespace,i))})}catch(a){if(a.statusCode!==404&&a.statusCode!==401)throw a}})),{data:n}}async getAzurePullRequestLastMergeStatus(s,e={}){if(!s.repo.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let{repo:{namespace:t,project:n,name:o},pullRequestId:a}=s,i=await this.config.request({url:`${e.baseUrl||v}/${encodeURIComponent(t)}/${encodeURIComponent(n||"")}/_apis/git/repositories/${o}/pullrequests/${a}?includeCommits=true?api-version=6.0`,headers:{...w(this.config,e)}});if(!i.body.mergeStatus)throw new Error("Could not fetch pull request");return{data:i.body.mergeStatus}}async updatePullRequest(s,e,t){return await this.config.request({method:"PATCH",url:`${t.baseUrl||v}/${encodeURIComponent(s.repository.owner.login)}/${encodeURIComponent(s.repository.project)}/_apis/git/repositories/${s.repository.name}/pullrequests/${s.id}?api-version=6.0`,body:e,headers:{...w(this.config,t),"Content-Type":"application/json"}})}async closePullRequest(s,e={}){let{pullRequest:t}=s,n={status:"abandoned"};if(!(await this.updatePullRequest(t,JSON.stringify(n),e)).body.status)throw new Error("Could not close pull request")}async mergePullRequest(s,e={}){var u;let{pullRequest:t,mergeStrategy:n}=s,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 a={completionOptions:{mergeStrategy:o},lastMergeSourceCommit:{commitId:(u=t.headRef)==null?void 0:u.oid},status:"completed"};if(!(await this.updatePullRequest(t,JSON.stringify(a),e)).body.status)throw new Error("Could not merge pull request")}async addPullRequestLabel(s,e={}){let{pullRequest:t,label:n}=s;if(!t.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:`${e.baseUrl||v}/${encodeURIComponent(t.repository.owner.login)}/${encodeURIComponent(t.repository.project)}/_apis/git/repositories/${t.repository.name}/pullrequests/${t.id}/labels?api-version=6.0`,body:JSON.stringify(o),headers:{...w(this.config,e),"Content-Type":"application/json"}})).body.id)throw new Error("Could not add pull request label")}async removePullRequestLabel(s,e={}){let{pullRequest:t,label:n}=s;if(!t.repository.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');await this.config.request({method:"DELETE",url:`${e.baseUrl||v}/${encodeURIComponent(t.repository.owner.login)}/${encodeURIComponent(t.repository.project)}/_apis/git/repositories/${t.repository.name}/pullrequests/${t.id}/labels/${encodeURIComponent(n.name)}?api-version=6.0`,headers:{...w(this.config,e)}})}async setPullRequestLabels(s,e={}){let{pullRequest:t,labels:n}=s;if(!t.repository.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let o=t.labels;if(!o)throw new Error('Azure DevOps requires "labels" for this function.');for(let a of n)o.find(i=>i.id===a.id)||await this.addPullRequestLabel({pullRequest:t,label:a},e);for(let a of o)n.find(i=>a.id===i.id)||await this.removePullRequestLabel({pullRequest:t,label:a},e)}async setPullRequestAsDraft(s,e={}){let{pullRequest:t,isDraft:n}=s,o={isDraft:n};if(!(await this.updatePullRequest(t,JSON.stringify(o),e)).body.status)throw new Error("Could not set the pull request as draft")}async addPullRequestReviewer(s,e={}){let{pullRequest:t,reviewer:n,isRequired:o}=s,a={id:n.id,isRequired:o};if(!(await this.config.request({method:"PUT",url:`${e.baseUrl||v}/${encodeURIComponent(t.repository.owner.login)}/${encodeURIComponent(t.repository.project)}/_apis/git/repositories/${t.repository.name}/pullrequests/${t.id}/reviewers/${n.id}?api-version=6.0`,body:JSON.stringify(a),headers:{...w(this.config,e),"Content-Type":"application/json"}})).body.id)throw new Error("Could not add pull request reviewer")}async removePullRequestReviewer(s,e={}){let{pullRequest:t,reviewer:n}=s;await this.config.request({method:"DELETE",url:`${e.baseUrl||v}/${encodeURIComponent(t.repository.owner.login)}/${encodeURIComponent(t.repository.project)}/_apis/git/repositories/${t.repository.name}/pullrequests/${t.id}/reviewers/${n.id}?api-version=6.0`,headers:{...w(this.config,e),Accept:"application/json"}})}async setPullRequestReviewers(s,e={}){let{pullRequest:t,reviewers:n}=s;for(let o of n)t.assignees.find(a=>a.id===o.id)||await this.addPullRequestReviewer({pullRequest:t,reviewer:o,isRequired:!0},e);for(let o of t.assignees)n.find(a=>o.id===a.id)||await this.removePullRequestReviewer({pullRequest:t,reviewer:o},e)}async getIssuesForAzureProject(s,e={}){let{page:t,assigneeLogins:n,authorLogin:o,mentionLogin:a,labelNames:i,statusByWorkItemIdByStatusId:u}=s||{},l=t||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("'","''")}'`),a&&d.push("[System.Id] IN (@recentMentions)"),i&&i.forEach(b=>d.push(`[System.Tags] Contains '${b}'`));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:`${e.baseUrl||v}/${encodeURIComponent(s.namespace)}/${encodeURIComponent(s.project)}/_apis/wit/wiql?api-version=6.0`,body:JSON.stringify({query:c}),method:"POST",headers:{...w(this.config,e),"Content-Type":"application/json"}}),m=g.body.workItems.slice((l-1)*p,p*l).map(b=>b.id);if(m.length==0)return{pageInfo:{hasNextPage:!1,nextPage:null},data:[]};let h=await this.config.request({url:`${e.baseUrl||v}/${encodeURIComponent(s.namespace)}/${encodeURIComponent(s.project)}/_apis/wit/workitemsbatch?api-version=6.0`,body:JSON.stringify({ids:m,$expand:"Links"}),method:"POST",headers:{...w(this.config,e),"Content-Type":"application/json"}});return{pageInfo:{hasNextPage:g.body.workItems.length>p*l,nextPage:l+1},data:h.body.value.map(b=>Jt(s.namespace,s.project,b,u||{}))}}async updateIssue(s,e,t={}){return await this.config.request({method:"PATCH",url:`${t.baseUrl||v}/${encodeURIComponent(s.project.namespace)}/${encodeURIComponent(s.project.name)}/_apis/wit/workitems/${s.id}?api-version=6.0`,body:JSON.stringify(e),headers:{...w(this.config,t),"Content-Type":"application/json-patch+json"}})}async setIssueStatus(s,e={}){var i;let{issue:t,status:n}=s,o=[{op:"add",path:"/fields/System.State",value:n.name}];if(!((i=(await this.updateIssue(t,o,e)).body.fields)!=null&&i["System.State"]))throw new Error("Could not set issue status")}async setIssueAssignee(s,e={}){var i;let{issue:t,assignee:n}=s,o=[{op:"add",path:"/fields/System.AssignedTo",value:(n==null?void 0:n.name)??""}];if(!((i=(await this.updateIssue(t,o,e)).body.fields)!=null&&i["System.State"]))throw new Error("Could not set issue assignee")}async setIssueLabels(s,e={}){var u;let{issue:t,labels:n}=s,a=[{op:"replace",path:"/fields/System.Tags",value:n.map(l=>l.name).join(";")}];if(!((u=(await this.updateIssue(t,a,e)).body.fields)!=null&&u["System.Tags"]))throw new Error("Could not set issue tags")}async getIssueTypesForAzureProject(s,e={}){if(!s.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let{namespace:t,project:n}=s;return{data:(await this.config.request({url:`${e.baseUrl||v}/${encodeURIComponent(t)}/${encodeURIComponent(n||"")}/_apis/wit/workitemtypes?api-version=6.0`,headers:{...w(this.config,e)}})).body.value}}async getLabelsForProject(s,e={}){let{namespace:t,project:n}=s;return{data:(await this.config.request({url:`${e.baseUrl||v}/${encodeURIComponent(t)}/${encodeURIComponent(n||"")}/_apis/wit/tags?api-version=6.0`,headers:{...w(this.config,e)}})).body.value.map(a=>({color:null,description:null,id:a.id,name:a.name,url:a.url}))}}};var C=(r,s={})=>I(s.token||r.token,s.isPAT||r.isPAT);var L="https://api.bitbucket.org/2.0",Kt={OPEN:"OPEN",MERGED:"MERGED",DECLINED:"CLOSED"},ht=r=>({id:r.uuid,name:r.display_name||r.nickname,username:r.nickname||r.display_name,email:null,avatarUrl:r.links.avatar.href,url:r.links.html.href}),mt=r=>{var s,e;return{id:r.uuid,namespace:r.workspace.slug,name:r.slug,webUrl:r.links.html.href,httpsUrl:((s=r.links.clone.find(t=>t.name==="https"))==null?void 0:s.href)??null,sshUrl:((e=r.links.clone.find(t=>t.name==="ssh"))==null?void 0:e.href)??null,defaultBranch:{name:r.mainbranch.name},permission:null}},Ge=r=>{let s=r.id;return{id:s.toString(),title:r.title,number:s,state:Kt[r.state],isDraft:!1,commentCount:r.comment_count,upvoteCount:null,author:ht(r.author),createdDate:new Date(r.created_on),updatedDate:new Date(r.updated_on),closedDate:null,mergedDate:null,repository:{id:r.destination.repository.uuid,name:r.destination.repository.name,owner:{login:r.destination.repository.full_name.split("/")[0]},remoteInfo:null},headCommit:{buildStatuses:null},baseRef:{name:r.destination.branch.name,oid:r.destination.commit.hash},headRef:{name:r.source.branch.name,oid:r.source.commit.hash},url:r.links.html.href,assignees:null,reviews:null,reviewDecision:null,additions:null,deletions:null,fileCount:null,commitCount:null,headRepository:null,mergeableState:"UNKNOWN",permissions:null}},J=class extends D{async refreshToken(s){return{data:(await this.config.request({url:"https://bitbucket.org/site/oauth2/access_token",method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded",Authorization:`Basic ${s.base64ClientIDColonClientSecret}`},body:`grant_type=refresh_token&refresh_token=${s.refreshToken}`})).body}}async getCurrentUser(s={},e={}){let t=await this.config.request({url:`${L}/user`,headers:C(this.config,e)});return{data:ht(t.body)}}async getUserForCommit(s,e={}){var a;let n=(await this.config.request({url:`${L}/repositories/${s.repo.namespace}/${s.repo.name}/commit/${s.oid}`,headers:C(this.config,e)})).body.author,o=n.raw.match(/([^<]+)<(.+)>/);return{data:{name:o?o[1].trim():null,email:o?o[2]:null,avatarUrl:((a=n.user)==null?void 0:a.links.avatar.href)||null}}}async getRepo(s,e={}){let t=await this.config.request({url:`${L}/repositories/${s.namespace}/${s.name}`,headers:C(this.config,e)});return{data:mt(t.body)}}async getRepos(s,e={}){let t=[],n=[];return await Promise.all(s.map(async o=>{try{let a=await this.getRepo(o,e);t.push(a.data)}catch(a){n.push({input:o,error:a})}})),{data:t,errors:n}}async getReposForCurrentUser(s,e={}){let t=new URL(`${L}/repositories`);t.searchParams.set("role","member"),t.searchParams.set("pagelen",q.toString()),s.cursor&&t.searchParams.set("after",s.cursor);let n=await this.config.request({url:t.toString(),headers:C(this.config,e)}),o=!!n.body.next,a=null;return n.body.next&&(a=new URL(n.body.next).searchParams.get("after")),{pageInfo:{hasNextPage:o,endCursor:a},data:n.body.values.map(mt)}}async getBranches(s,e={}){var a;let t=new URL(`${L}/repositories/${s.repo.namespace}/${s.repo.name}/refs/branches`);t.searchParams.set("page",((a=s.page)==null?void 0:a.toString())||"1"),t.searchParams.set("pagelen",q.toString());let n=await this.config.request({url:t.toString(),headers:C(this.config,e)}),o=!!n.body.next;return{pageInfo:{hasNextPage:o,nextPage:o?n.body.page+1:null},data:n.body.values.map(i=>{let u=new Date(i.target.date);return{name:i.name,commit:{oid:i.target.hash,authoredDate:u,committedDate:u}}})}}async getTags(s,e={}){let t=new URL(`${L}/repositories/${s.repo.namespace}/${s.repo.name}/refs/tags`);t.searchParams.set("pagelen",q.toString()),s.cursor&&t.searchParams.set("page",s.cursor);let n=await this.config.request({url:t.toString(),headers:C(this.config,e)}),o=!!n.body.next,a=null;return n.body.next&&(a=new URL(n.body.next).searchParams.get("page")),{pageInfo:{hasNextPage:o,endCursor:a},data:n.body.values.map(i=>{let u=new Date(i.target.date);return{name:i.name,commit:{oid:i.target.hash,authoredDate:u,committedDate:u}}})}}async getPullRequestsForUser(s,e={}){var a;let t=new URL(`${L}/pullrequests/${s.userId}`);t.searchParams.set("page",((a=s.page)==null?void 0:a.toString())||"1"),t.searchParams.set("pagelen","50");let n=await this.config.request({url:t.toString(),headers:C(this.config,e)}),o=!!n.body.next;return{pageInfo:{hasNextPage:o,nextPage:o?n.body.page+1:null},data:n.body.values.map(Ge)}}async getPullRequestsForRepoBase(s,e={}){var n;let t=new URL(`${L}/repositories/${encodeURI(s.repo.namespace)}/${encodeURI(s.repo.name)}/pullrequests?state=OPEN`);return t.searchParams.set("page",((n=s.page)==null?void 0:n.toString())||"1"),t.searchParams.set("pagelen","50"),await this.config.request({url:t.toString(),headers:C(this.config,e)})}async getPullRequestsForRepo(s,e={}){let t=[],n=await this.getPullRequestsForRepoBase(s,e);n.body.values.forEach(a=>{if(s.authorLogin&&a.author.uuid!==s.authorLogin)return null;t.push(Ge(a))});let o=!!n.body.next;return{pageInfo:{hasNextPage:o,nextPage:o?n.body.page+1:null},data:t}}async getPullRequestsForRepos(s,e={}){let t=[];return await Promise.all(s.repos.map(async n=>{try{(await this.getPullRequestsForRepoBase({repo:n,...s},e)).body.values.forEach(a=>{if(s.authorLogin&&a.author.uuid!==s.authorLogin)return null;t.push(Ge(a))})}catch(o){if(o.statusCode!==404&&o.statusCode!==401)throw o}})),{data:t}}async closePullRequest(s,e={}){let{pullRequest:t}=s;if(!(await this.config.request({method:"POST",url:`${L}/repositories/${t.repository.owner.login}/${t.repository.name}/pullrequests/${t.id}/decline`,headers:C(this.config,e)})).body.title)throw new Error("Could not close pull request")}async mergePullRequest(s,e={}){let{pullRequest:t,mergeStrategy:n}=s,o;switch(n){case"MERGE_COMMIT":{o="merge_commit";break}case"FAST_FORWARD":{o="fast_forward";break}case"SQUASH":{o="squash";break}}let a={merge_strategy:o,type:"pullrequest"};if(!(await this.config.request({method:"POST",url:`${L}/repositories/${t.repository.owner.login}/${t.repository.name}/pullrequests/${t.id}/merge`,body:JSON.stringify(a),headers:{...C(this.config,e),"Content-Type":"application/json"}})).body.title)throw new Error("Could not merge pull request")}async setPullRequestReviewers(s,e={}){let{pullRequest:t,reviewers:n}=s,o={reviewers:n.map(i=>{if(i.username)throw new Error('Bitbucket reviewer requires "username" for this function.');return{username:i.username}})};if(!(await this.config.request({method:"PUT",url:`${L}/repositories/${t.repository.owner.login}/${t.repository.name}/pullrequests/${t.id}`,body:JSON.stringify(o),headers:{...C(this.config,e),"Content-Type":"application/json"}})).body.title)throw new Error("Could not set pull request reviewers")}};var Oe=r=>({name:r.displayName,email:r.emailAddress,avatarUrl:r.avatarUrl??null,id:r.id.toString(),username:r.name,url:r.links.self[0].href}),Te=r=>{var u,l,p,d,c,g;let s={OPEN:"OPEN",MERGED:"MERGED",DECLINED:"CLOSED"},e={UNAPPROVED:"REVIEW_REQUESTED",NEEDS_WORK:"CHANGES_REQUESTED",APPROVED:"APPROVED"},t=r.reviewers.map(m=>({reviewer:Oe(m.user),state:e[m.status]})),n=((u=r.toRef.repository.links.clone.find(m=>m.name==="ssh"))==null?void 0:u.href)??null,o=((l=r.toRef.repository.links.clone.find(m=>m.name==="https"))==null?void 0:l.href)??null;o||(o=((p=r.toRef.repository.links.clone.find(m=>m.name==="http"))==null?void 0:p.href)??null);let a=((d=r.fromRef.repository.links.clone.find(m=>m.name==="ssh"))==null?void 0:d.href)??null,i=((c=r.fromRef.repository.links.clone.find(m=>m.name==="https"))==null?void 0:c.href)??null;return i||(i=((g=r.fromRef.repository.links.clone.find(m=>m.name==="http"))==null?void 0:g.href)??null),{id:r.id.toString(),number:r.id,title:r.title,url:r.links.self[0].href,state:s[r.state],isDraft:!1,createdDate:new Date(r.createdDate),updatedDate:new Date(r.updatedDate),closedDate:r.closedDate?new Date(r.closedDate):null,mergedDate:r.state=="MERGED"&&r.closedDate?new Date(r.closedDate):null,baseRef:{name:r.toRef.displayId,oid:r.toRef.latestCommit},headRef:{name:r.fromRef.displayId,oid:r.fromRef.latestCommit},commentCount:r.properties.commentCount,upvoteCount:null,commitCount:null,fileCount:null,additions:null,deletions:null,author:Oe(r.author.user),assignees:null,reviews:t,reviewDecision:F(t),repository:{id:r.toRef.repository.id.toString(),name:r.toRef.repository.name,owner:{login:r.toRef.repository.project.key},remoteInfo:o&&n?{cloneUrlHTTPS:o,cloneUrlSSH:n}:null},headRepository:{id:r.fromRef.repository.id.toString(),name:r.fromRef.repository.name,owner:{login:r.fromRef.repository.project.key},remoteInfo:i&&a?{cloneUrlHTTPS:i,cloneUrlSSH:a}:null},headCommit:null,mergeableState:"UNKNOWN",permissions:null,version:r.version}},ft=r=>{var s,e,t;return{id:r.id.toString(),namespace:r.project.key,name:r.slug,webUrl:((s=r.links.self[0])==null?void 0:s.href)??null,httpsUrl:((e=r.links.clone.find(n=>n.name==="https"||n.name==="http"))==null?void 0:e.href)??null,sshUrl:((t=r.links.clone.find(n=>n.name==="ssh"))==null?void 0:t.href)??null,defaultBranch:null,permission:null}},K=class extends G{getBaseUrl(s){let e=s.baseUrl||this.config.baseUrl;if(!e)throw new Error('Bitbucket Server requires "baseUrl"');return e}getRequestHeaders(s){return I(s.token||this.config.token)}async getCurrentUser(s={},e={}){let t=await this.config.request({url:`${this.getBaseUrl(e)}/users?limit=2`,headers:this.getRequestHeaders(e)}),{headers:{"x-auserid":n,"x-ausername":o}}=t,a=n?parseInt(n,10):null,i=decodeURIComponent(o),l=(await this.config.request({url:`${this.getBaseUrl(e)}/users?filter=${o}&avatarSize=64`,headers:this.getRequestHeaders(e)})).body.values.find(({emailAddress:p,id:d,name:c,slug:g})=>a?a===d:i===c||i===p||i===g);if(!l)throw new Error("Could not find current Bitbucket Server user");return{data:Oe(l)}}async getRepo(s,e={}){let t=await this.config.request({url:`${this.getBaseUrl(e)}/projects/${s.namespace}/repos/${s.name}`,headers:this.getRequestHeaders(e)});return{data:ft(t.body)}}async getRepos(s,e={}){let t=[],n=[];return await Promise.all(s.map(async o=>{try{let a=await this.getRepo(o,e);t.push(a.data)}catch(a){n.push({input:o,error:a})}})),{data:t,errors:n}}async getReposForCurrentUser(s,e={}){let t=s.page??0,n=await this.config.request({url:`${this.getBaseUrl(e)}/repos?start=${t}`,headers:this.getRequestHeaders(e)});return{pageInfo:{hasNextPage:!n.body.isLastPage,nextPage:n.body.nextPageStart},data:n.body.values.map(ft)}}async getPullRequestsForRepoBase(s,e={}){var n;let t=new URL(`${this.getBaseUrl(e)}/projects/${encodeURI(s.repo.namespace)}/repos/${encodeURI(s.repo.name)}/pull-requests?state=OPEN`);return t.searchParams.set("start",((n=s.page)==null?void 0:n.toString())||"0"),t.searchParams.set("limit","50"),await this.config.request({url:t.toString(),headers:this.getRequestHeaders(e)})}async getPullRequestsForRepo(s,e={}){let t=[],n=await this.getPullRequestsForRepoBase(s,e);n.body.values.forEach(a=>{if(s.authorLogin&&a.author.user.name!==s.authorLogin)return null;t.push(Te(a))});let o=n.body.values.length!==0;return{pageInfo:{hasNextPage:o,nextPage:o?n.body.start+n.body.values.length:null},data:t}}async getPullRequestsForRepos(s,e={}){let t=[];return await Promise.all(s.repos.map(async n=>{try{(await this.getPullRequestsForRepoBase({repo:n,...s},e)).body.values.forEach(a=>{if(s.authorLogin&&a.author.user.name!==s.authorLogin)return null;t.push(Te(a))})}catch(o){if(o.statusCode!==404&&o.statusCode!==401)throw o}})),{data:t}}async getPullRequestsForCurrentUser(s,e={}){var a;let t=new URL(`${this.getBaseUrl(e)}/dashboard/pull-requests`);t.searchParams.set("state","OPEN"),t.searchParams.set("start",((a=s.page)==null?void 0:a.toString())||"0"),t.searchParams.set("limit","50");let n=await this.config.request({url:t.toString(),headers:this.getRequestHeaders(e)}),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(Te)}}async closePullRequest(s,e={}){let{pullRequest:t}=s;if(t.version===void 0)throw new Error('Bitbucket Server requires "version" for this function.');if(!(await this.config.request({method:"POST",url:`${this.getBaseUrl(e)}/projects/${t.repository.owner.login}/repos/${t.repository.name}/pull-requests/${t.id}/decline`,body:JSON.stringify({version:t.version}),headers:{...this.getRequestHeaders(e),"Content-Type":"application/json"}})).body.title)throw new Error("Could not close pull request")}async mergePullRequest(s,e={}){let{pullRequest:t,mergeStrategyId:n}=s;if(s.mergeStrategy)throw new Error('Bitbucket Server uses "mergeStrategyId" instead of "mergeStrategy".');if(t.version===void 0)throw new Error('Bitbucket Server requires "version" for this function.');if(!(await this.config.request({method:"POST",url:`${this.getBaseUrl(e)}/projects/${t.repository.owner.login}/repos/${t.repository.name}/pull-requests/${t.id}/merge`,body:JSON.stringify({strategyId:n,version:t.version}),headers:{...this.getRequestHeaders(e),"Content-Type":"application/json"}})).body.title)throw new Error("Could not merge pull request")}async getMergeStrategies(s={}){let e=await this.config.request({url:`${this.getBaseUrl(s)}/admin/pull-requests/git`,headers:{...this.getRequestHeaders(s),"Content-Type":"application/json"}});return{data:{defaultStrategy:e.body.mergeConfig.defaultStrategy,strategies:e.body.mergeConfig.strategies}}}async setPullRequestReviewers(s,e={}){let{pullRequest:t,reviewers:n}=s;if(t.version===void 0)throw new Error('Bitbucket Server requires "version" for this function.');let o={reviewers:n.map(i=>{if(i.username)throw new Error('Bitbucket Server reviewer requires "username" for this function.');return{user:{name:i.username}}}),version:t.version};if(!(await this.config.request({method:"PUT",url:`${this.getBaseUrl(e)}/projects/${t.repository.owner.login}/repos/${t.repository.name}/pull-requests/${t.id}`,body:JSON.stringify(o),headers:{...this.getRequestHeaders(e),"Content-Type":"application/json"}})).body.title)throw new Error("Could not set pull request reviewers")}};var St=require("js-base64");var le=(e=>(e.Open="OPEN",e.Closed="CLOSED",e))(le||{});var Vt={AS_CODE_OWNER:[3,0,0],CHECK_RUN:[3,0,0],LATEST_REVIEWS:[3,0,0],VIEWER_CAN_MERGE_AS_ADMIN:[3,5,0]},It=15,Rt=100,E=r=>!!r,pe=(r,s)=>{let e=Vt[s];for(let t=0;t<3;t++){if(r[t]>e[t])return!0;if(r[t]<e[t])return!1}return!0},ce="https://api.github.com",Xt=`${ce}/graphql`,ge=`
1
+ "use strict";var Nt=Object.create;var oe=Object.defineProperty;var Ft=Object.getOwnPropertyDescriptor;var Qt=Object.getOwnPropertyNames;var _t=Object.getPrototypeOf,Bt=Object.prototype.hasOwnProperty;var jt=(r,n)=>{for(var e in n)oe(r,e,{get:n[e],enumerable:!0})},ot=(r,n,e,t)=>{if(n&&typeof n=="object"||typeof n=="function")for(let s of Qt(n))!Bt.call(r,s)&&s!==e&&oe(r,s,{get:()=>n[s],enumerable:!(t=Ft(n,s))||t.enumerable});return r};var Mt=(r,n,e)=>(e=r!=null?Nt(_t(r)):{},ot(n||!r||!r.__esModule?oe(e,"default",{value:r,enumerable:!0}):e,r)),zt=r=>ot(oe({},"__esModule",{value:!0}),r);var Jr={};jt(Jr,{AzureDevOps:()=>J,Bitbucket:()=>K,BitbucketServer:()=>V,EntityIdentifierProviderType:()=>Ot,EntityType:()=>Tt,EntityVersion:()=>Gt,GitBuildStatusStage:()=>at,GitBuildStatusState:()=>ae,GitDiffLineType:()=>$e,GitHub:()=>X,GitHubIssueCloseReason:()=>xt,GitIssueState:()=>pe,GitLab:()=>Y,GitMergeStrategy:()=>W,GitPullRequestMergeableState:()=>z,GitPullRequestReviewState:()=>M,GitPullRequestState:()=>j,GraphQLErrors:()=>R,Jira:()=>ee,JiraServer:()=>te,PullRequestAsyncStatus:()=>At,Trello:()=>re,default:()=>Wr,isFetch:()=>ie});module.exports=zt(Jr);var at=(s=>(s.Build="build",s.Production="production",s.Staging="staging",s.Test="test",s))(at||{}),ae=(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))(ae||{}),W=(o=>(o.MergeCommit="MERGE_COMMIT",o.Rebase="REBASE",o.RebaseThenMergeCommit="REBASE_THEN_MERGE_COMMIT",o.FastForward="FAST_FORWARD",o.Squash="SQUASH",o))(W||{}),j=(t=>(t.Open="OPEN",t.Closed="CLOSED",t.Merged="MERGED",t))(j||{}),M=(s=>(s.Approved="APPROVED",s.ChangesRequested="CHANGES_REQUESTED",s.Commented="COMMENTED",s.ReviewRequested="REVIEW_REQUESTED",s))(M||{}),z=(i=>(i.Behind="BEHIND",i.Blocked="BLOCKED",i.Conflicts="CONFLICTS",i.Mergeable="MERGEABLE",i.Unknown="UNKNOWN",i.UnknownAndBlocked="UNKNOWN_AND_BLOCKED",i.Unstable="UNSTABLE",i))(z||{}),$e=(t=>(t.ADDED="ADDED",t.DELETED="DELETED",t.UNMODIFIED="UNMODIFIED",t))($e||{});var it={APPROVED:0,COMMENTED:1,REVIEW_REQUESTED:2,CHANGES_REQUESTED:3},Q=r=>!r||r.length===0?null:r.reduce((n,e)=>it[e.state]>it[n]?e.state:n,"APPROVED");var E=100;var ut=Mt(require("node-fetch")),lt=globalThis.fetch||ut.default;var Ht=async r=>{let n=r.headers.get("content-type")||"",e=null;if(n.startsWith("application/json")){let s=await r.text();e=s.trim().length>0?JSON.parse(s):null}else if(n.startsWith("text/")||n==="")e=await r.text();else if(n.startsWith("application/vnd.github.raw+json"))e=await r.arrayBuffer();else throw new Error(`Unsupported content-type: ${n}`);let t={body:e,headers:Object.fromEntries(r.headers.entries()),status:r.status,statusText:r.statusText};if(!r.ok){let s=new Error(r.statusText);throw Object.assign(s,{response:t}),s}return t},Ae=r=>async({url:n,...e})=>{let t=await r(n,e);return Ht(t)};var ie=(r,n=!1)=>r.name==="fetch"||n;var U=class{constructor(n){let e=(n==null?void 0:n.request)||lt;this.config={...n,request:ie(e,n==null?void 0:n.forceIsFetch)?Ae(e):e}}updateConfig(n){this.config={...this.config,...n,request:n.request&&ie(n.request,(n==null?void 0:n.forceIsFetch)??this.config.forceIsFetch)?Ae(n.request):this.config.request}}},T=class extends U{};var I=(r,n)=>{let e={};return r&&(e.Authorization=`${n?"Basic":"Bearer"} ${r}`),e},pt=r=>r?r.reduce((n,e)=>(n[e]=!0,n),{}):void 0,_=(r,n,e)=>!r||n.some(t=>r[t])?e:"",dt=async r=>{var s,o,a;let n=[],e=!0,t;for(;e;){let i=await r(t);n=n.concat(i.data),e=!!((s=i==null?void 0:i.pageInfo)!=null&&s.hasNextPage),t=((o=i==null?void 0:i.pageInfo)==null?void 0:o.endCursor)||((a=i==null?void 0:i.pageInfo)==null?void 0:a.nextPage)}return n};var w=(r,n={})=>I(n.token||r.token,n.isPAT||r.isPAT),ct=r=>r.url.replace("/_apis/git/repositories/","/_git/").replace(`/${r.repository.project.id}/`,`/${encodeURIComponent(r.repository.project.name)}/`).replace(`/${r.repository.id}/`,`/${encodeURIComponent(r.repository.name)}/`).replace("/pullRequests/","/pullrequest/");var gt="https://app.vssps.visualstudio.com/_apis",q="https://dev.azure.com",Wt={active:"OPEN",completed:"MERGED",abandoned:"CLOSED"},Jt={10:"APPROVED",5:"APPROVED",0:"REVIEW_REQUESTED",[-5]:"CHANGES_REQUESTED",[-10]:"CHANGES_REQUESTED"},Ge=r=>({id:r.id,name:r.displayName??null,username:(r.uniqueName||r.displayName)??null,email:null,avatarUrl:r.imageUrl??null,url:null}),le=r=>r.startsWith("refs/heads/")?r.replace("refs/heads/",""):r,ue=(r,n)=>{var s;let e=[],t=[];return n.reviewers.forEach(o=>{let a={reviewer:Ge(o),state:Jt[o.vote??0]||"REVIEW_REQUESTED"};o.isRequired&&e.push(a),t.push(a)}),{id:n.pullRequestId.toString(),title:n.title,number:n.codeReviewId,state:Wt[n.status],isDraft:n.isDraft,commentCount:null,upvoteCount:null,author:Ge(n.createdBy),createdDate:new Date(n.creationDate),updatedDate:new Date(n.closedDate||n.creationDate),closedDate:n.closedDate?new Date(n.closedDate):null,mergedDate:n.closedDate&&n.status==="completed"?new Date(n.closedDate):null,repository:{id:n.repository.id,name:n.repository.name,project:n.repository.project.name,owner:{login:r},remoteInfo:null},headCommit:{buildStatuses:null},baseRef:{name:le(n.targetRefName),oid:n.lastMergeTargetCommit.commitId},headRef:{name:le(n.sourceRefName),oid:n.lastMergeSourceCommit.commitId},url:ct(n),assignees:n.reviewers.map(Ge),reviews:t,reviewDecision:Q(e),additions:null,deletions:null,fileCount:null,commitCount:null,headRepository:null,mergeableState:"UNKNOWN",labels:((s=n.labels)==null?void 0:s.map(o=>({color:null,description:null,id:o.id,name:o.name})))??[],permissions:null}},mt=(r,n)=>({id:n.id,name:n.name,namespace:r,project:n.project.name,webUrl:n.webUrl,httpsUrl:n.remoteUrl,sshUrl:n.sshUrl,defaultBranch:n.defaultBranch?{name:le(n.defaultBranch)}:null,permission:null}),Kt=(r,n,e,t)=>{var l,p,d,c,g,m;let s=e.fields,o=s["System.AssignedTo"],a=s["System.State"],i=s["System.WorkItemType"],u;return a&&i&&(u=(l=t[i])==null?void 0:l[a]),{id:e.id.toString(),number:e.id.toString(),title:s["System.Title"],commentCount:s["System.CommentCount"],author:{avatarUrl:((d=(p=s["System.CreatedBy"]._links)==null?void 0:p.avatar)==null?void 0:d.href)??null,email:null,id:s["System.CreatedBy"].id,name:s["System.CreatedBy"].uniqueName??null,username:s["System.CreatedBy"].displayName??null,url:null},closedDate:s["Microsoft.VSTS.Common.ClosedDate"]?new Date(s["Microsoft.VSTS.Common.ClosedDate"]):null,createdDate:new Date(s["System.CreatedDate"]),updatedDate:new Date(s["System.ChangedDate"]),url:e._links.html.href,assignees:o?[{avatarUrl:((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)||a,color:null},type:s["System.WorkItemType"],repository:null,project:{namespace:r,name:n,resourceId:null,key:null,id:null},upvoteCount:0,labels:((m=e.fields["System.Tags"])==null?void 0:m.split(";").map(h=>({color:null,description:null,id:null,name:h.trim()})))??[]}},J=class extends U{async getCurrentUser(n={},e={}){if(e.isPAT||this.config.isPAT)throw new Error("Azure DevOps does not support PATs for this function.");let t=await this.config.request({url:`${gt}/profile/profiles/me`,headers:w(this.config,e)});return{data:{id:t.body.id,name:t.body.displayName,username:t.body.displayName,email:t.body.emailAddress,avatarUrl:null,url:null}}}async getCurrentUserForInstance(n,e={}){let s=(await this.config.request({url:`${q}/${encodeURIComponent(n.namespace)}/_apis/ConnectionData`,headers:w(this.config,e)})).body.authorizedUser;if(s.providerDisplayName==="Anonymous")throw new Error("Current user not found.");return{data:{id:s.id,name:s.providerDisplayName,username:s.providerDisplayName,email:s.properties.Account.$value,avatarUrl:null}}}async getUserForCommit(n,e={}){if(!n.repo.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let s=(await this.config.request({url:`${q}/${encodeURIComponent(n.repo.namespace)}/${encodeURIComponent(n.repo.project)}/_apis/git/repositories/${encodeURIComponent(n.repo.name)}/commits/${n.oid}`,headers:w(this.config,e)})).body.author;return{data:{name:s.name,email:s.email,avatarUrl:s.imageUrl}}}async getOrgsForUser(n,e={}){return{data:(await this.config.request({url:`${gt}/accounts?memberId=${n.userId}&api-version=6.0`,headers:w(this.config,e)})).body.value.map(s=>({id:s.accountId,name:s.accountName}))}}async getAzureProjects(n,e={}){let t=new URL(`${q}/${encodeURIComponent(n.namespace)}/_apis/projects`);t.searchParams.set("$top",E.toString()),n.cursor&&t.searchParams.set("$skip",n.cursor);let s=await this.config.request({url:t.toString(),headers:w(this.config,e)}),o=s.headers["x-ms-continuationtoken"];return{pageInfo:{hasNextPage:!!o,endCursor:o||null},data:s.body.value.map(a=>({id:a.id,name:a.name,namespace:n.namespace}))}}async getAzureProjectScopeDescriptor(n,e={}){let{namespace:t,projectId:s}=n;return{data:{scope:(await this.config.request({url:`https://vssps.dev.azure.com/${encodeURIComponent(t)}/_apis/graph/descriptors/${s}?api-version=6.0`,headers:w(this.config,e)})).body.value}}}async getAzureGraphAccountsForAzureProject(n,e={}){let{namespace:t,projectScopeDescriptor:s,cursor:o}=n,a=new URL(`https://vssps.dev.azure.com/${encodeURIComponent(t)}/_apis/graph/users`);s&&a.searchParams.set("scopeDescriptor",s),o&&a.searchParams.set("continuationToken",o);let i=await this.config.request({url:a.toString(),headers:w(this.config,e)}),u=i.headers["x-ms-continuationtoken"];return{pageInfo:{endCursor:u||null,hasNextPage:!!u},data:i.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(n,e={}){let{azureGraphAccount:t}=n;if(!t.storageKeyURL)throw new Error("Expected 'storageKeyURL' to not be null for 'azureGraphAccount'");let s=await this.config.request({url:t.storageKeyURL,headers:w(this.config,e)});return{data:{avatarUrl:t.avatarUrl,email:t.email,id:s.body.value,name:t.name,username:t.username,url:null}}}async getAccountsFromAzureGraphAccounts(n,e={}){let t=[];for(let s of n.azureGraphAccounts){let o=await this.getAccountFromAzureGraphAccount({azureGraphAccount:s},e);t.push(o.data)}return{data:t}}async getRepo(n,e={}){if(!n.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let t=await this.config.request({url:`${q}/${encodeURIComponent(n.namespace)}/${encodeURIComponent(n.project)}/_apis/git/repositories/${encodeURIComponent(n.name)}`,headers:w(this.config,e)});return{data:mt(n.namespace,t.body)}}async getRepos(n,e={}){let t=[],s=[];return await Promise.all(n.map(async o=>{try{let a=await this.getRepo(o,e);t.push(a.data)}catch(a){s.push({input:o,error:a})}})),{data:t,errors:s}}async getReposForAzureProject(n,e={}){if(!n.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');return{data:(await this.config.request({url:`${q}/${encodeURIComponent(n.namespace)}/${encodeURIComponent(n.project)}/_apis/git/repositories`,headers:w(this.config,e)})).body.value.map(s=>mt(n.namespace,s))}}async getRefs(n,e,t={}){if(!e.repo.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let s=new URL(`${q}/${encodeURIComponent(e.repo.namespace)}/${encodeURIComponent(e.repo.project)}/_apis/git/repositories/${encodeURIComponent(e.repo.name)}/refs`);s.searchParams.set("filter",n),s.searchParams.set("$top",E.toString()),e.cursor&&s.searchParams.set("continuationToken",e.cursor);let o=await this.config.request({url:s.toString(),headers:w(this.config,t)}),a=o.headers["x-ms-continuationtoken"];return{pageInfo:{hasNextPage:!!a,endCursor:a||null},data:o.body.value.map(i=>({name:le(i.name),commit:{oid:i.objectId,authoredDate:null,committedDate:null}}))}}async getBranches(n,e={}){return this.getRefs("heads",n,e)}async getTags(n,e={}){return this.getRefs("tags",n,e)}async getPullRequestsForRepoBase(n,e={},t=100){let{page:s,repo:o,assigneeLogins:a,authorLogin:i}=n||{},u=s||1;if(!o.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let l="searchCriteria.status=1";return a&&a.length&&(l+=`&searchCriteria.reviewerId=${a[0]}`),i&&(l+=`&searchCriteria.creatorId=${i}`),await this.config.request({url:`${e.baseUrl||q}/${encodeURIComponent(o.namespace)}/${encodeURIComponent(o.project||"")}/_apis/git/repositories/${encodeURIComponent(o.name)}/pullRequests?${l}&%24top=${t}&%24skip=${(u-1)*t}`,headers:w(this.config,e)})}async getPullRequestsForRepo(n,e={}){let s=n.page||1,o=await this.getPullRequestsForRepoBase(n,e,100);return{pageInfo:{hasNextPage:o.body.value.length===100,nextPage:s+1},data:o.body.value.map(a=>ue(n.repo.namespace,a))}}async getPullRequestsForRepos(n,e={}){if(!n.repos.every(o=>o.project))throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let{repos:t}=n||{},s=[];return await Promise.all(t.map(async o=>{try{(await this.getPullRequestsForRepoBase({repo:o,...n},e)).body.value.forEach(i=>{s.push(ue(o.namespace,i))})}catch(a){if(a.statusCode!==404&&a.statusCode!==401)throw a}})),{data:s}}async getPullRequestsForProjectBase(n,e={},t=100){let{namespace:s,project:o,page:a,assigneeLogins:i,authorLogin:u}=n,l=a||1,p=new URL(`${e.baseUrl||q}/${encodeURIComponent(s)}/${encodeURIComponent(o)}/_apis/git/pullRequests`);return p.searchParams.set("searchCriteria.status","1"),p.searchParams.set("$top",t.toString()),p.searchParams.set("$skip",((l-1)*t).toString()),i&&i.length&&p.searchParams.set("searchCriteria.reviewerId",i[0]),u&&p.searchParams.set("searchCriteria.creatorId",u),await this.config.request({url:p.toString(),headers:w(this.config,e)})}async getPullRequestsForProject(n,e={}){let s=n.page||1,o=await this.getPullRequestsForProjectBase(n,e,100);return{pageInfo:{hasNextPage:o.body.value.length===100,nextPage:s+1},data:o.body.value.map(a=>ue(n.namespace,a))}}async getPullRequestsForProjects(n,e={}){let{projects:t}=n||{},s=[];return await Promise.all(t.map(async o=>{try{(await this.getPullRequestsForProjectBase({...o,...n},e)).body.value.forEach(i=>{s.push(ue(o.namespace,i))})}catch(a){if(a.statusCode!==404&&a.statusCode!==401)throw a}})),{data:s}}async getAzurePullRequestLastMergeStatus(n,e={}){if(!n.repo.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let{repo:{namespace:t,project:s,name:o},pullRequestId:a}=n,i=await this.config.request({url:`${e.baseUrl||q}/${encodeURIComponent(t)}/${encodeURIComponent(s||"")}/_apis/git/repositories/${o}/pullrequests/${a}?includeCommits=true?api-version=6.0`,headers:{...w(this.config,e)}});if(!i.body.mergeStatus)throw new Error("Could not fetch pull request");return{data:i.body.mergeStatus}}async updatePullRequest(n,e,t){return await this.config.request({method:"PATCH",url:`${t.baseUrl||q}/${encodeURIComponent(n.repository.owner.login)}/${encodeURIComponent(n.repository.project)}/_apis/git/repositories/${n.repository.name}/pullrequests/${n.id}?api-version=6.0`,body:e,headers:{...w(this.config,t),"Content-Type":"application/json"}})}async closePullRequest(n,e={}){let{pullRequest:t}=n,s={status:"abandoned"};if(!(await this.updatePullRequest(t,JSON.stringify(s),e)).body.status)throw new Error("Could not close pull request")}async mergePullRequest(n,e={}){var u;let{pullRequest:t,mergeStrategy:s}=n,o;switch(s){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 a={completionOptions:{mergeStrategy:o},lastMergeSourceCommit:{commitId:(u=t.headRef)==null?void 0:u.oid},status:"completed"};if(!(await this.updatePullRequest(t,JSON.stringify(a),e)).body.status)throw new Error("Could not merge pull request")}async addPullRequestLabel(n,e={}){let{pullRequest:t,label:s}=n;if(!t.repository.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let o={name:s.name};if(!(await this.config.request({method:"POST",url:`${e.baseUrl||q}/${encodeURIComponent(t.repository.owner.login)}/${encodeURIComponent(t.repository.project)}/_apis/git/repositories/${t.repository.name}/pullrequests/${t.id}/labels?api-version=6.0`,body:JSON.stringify(o),headers:{...w(this.config,e),"Content-Type":"application/json"}})).body.id)throw new Error("Could not add pull request label")}async removePullRequestLabel(n,e={}){let{pullRequest:t,label:s}=n;if(!t.repository.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');await this.config.request({method:"DELETE",url:`${e.baseUrl||q}/${encodeURIComponent(t.repository.owner.login)}/${encodeURIComponent(t.repository.project)}/_apis/git/repositories/${t.repository.name}/pullrequests/${t.id}/labels/${encodeURIComponent(s.name)}?api-version=6.0`,headers:{...w(this.config,e)}})}async setPullRequestLabels(n,e={}){let{pullRequest:t,labels:s}=n;if(!t.repository.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let o=t.labels;if(!o)throw new Error('Azure DevOps requires "labels" for this function.');for(let a of s)o.find(i=>i.id===a.id)||await this.addPullRequestLabel({pullRequest:t,label:a},e);for(let a of o)s.find(i=>a.id===i.id)||await this.removePullRequestLabel({pullRequest:t,label:a},e)}async setPullRequestAsDraft(n,e={}){let{pullRequest:t,isDraft:s}=n,o={isDraft:s};if(!(await this.updatePullRequest(t,JSON.stringify(o),e)).body.status)throw new Error("Could not set the pull request as draft")}async addPullRequestReviewer(n,e={}){let{pullRequest:t,reviewer:s,isRequired:o}=n,a={id:s.id,isRequired:o};if(!(await this.config.request({method:"PUT",url:`${e.baseUrl||q}/${encodeURIComponent(t.repository.owner.login)}/${encodeURIComponent(t.repository.project)}/_apis/git/repositories/${t.repository.name}/pullrequests/${t.id}/reviewers/${s.id}?api-version=6.0`,body:JSON.stringify(a),headers:{...w(this.config,e),"Content-Type":"application/json"}})).body.id)throw new Error("Could not add pull request reviewer")}async removePullRequestReviewer(n,e={}){let{pullRequest:t,reviewer:s}=n;await this.config.request({method:"DELETE",url:`${e.baseUrl||q}/${encodeURIComponent(t.repository.owner.login)}/${encodeURIComponent(t.repository.project)}/_apis/git/repositories/${t.repository.name}/pullrequests/${t.id}/reviewers/${s.id}?api-version=6.0`,headers:{...w(this.config,e),Accept:"application/json"}})}async setPullRequestReviewers(n,e={}){let{pullRequest:t,reviewers:s}=n;for(let o of s)t.assignees.find(a=>a.id===o.id)||await this.addPullRequestReviewer({pullRequest:t,reviewer:o,isRequired:!0},e);for(let o of t.assignees)s.find(a=>o.id===a.id)||await this.removePullRequestReviewer({pullRequest:t,reviewer:o},e)}async getIssuesForAzureProject(n,e={}){let{page:t,assigneeLogins:s,authorLogin:o,mentionLogin:a,labelNames:i,statusByWorkItemIdByStatusId:u}=n||{},l=t||1,p=200,d=["[Microsoft.VSTS.Common.ClosedDate] = ''","[System.TeamProject] = @project","[Microsoft.VSTS.Common.ResolvedDate] = ''"];o&&d.push(`[System.CreatedBy] = '${o.replace("'","''")}'`),s&&s[0]&&d.push(`[System.AssignedTo] = '${s[0].replace("'","''")}'`),a&&d.push("[System.Id] IN (@recentMentions)"),i&&i.forEach(y=>d.push(`[System.Tags] Contains '${y}'`));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:`${e.baseUrl||q}/${encodeURIComponent(n.namespace)}/${encodeURIComponent(n.project)}/_apis/wit/wiql?api-version=6.0`,body:JSON.stringify({query:c}),method:"POST",headers:{...w(this.config,e),"Content-Type":"application/json"}}),m=g.body.workItems.slice((l-1)*p,p*l).map(y=>y.id);if(m.length==0)return{pageInfo:{hasNextPage:!1,nextPage:null},data:[]};let h=await this.config.request({url:`${e.baseUrl||q}/${encodeURIComponent(n.namespace)}/${encodeURIComponent(n.project)}/_apis/wit/workitemsbatch?api-version=6.0`,body:JSON.stringify({ids:m,$expand:"Links"}),method:"POST",headers:{...w(this.config,e),"Content-Type":"application/json"}});return{pageInfo:{hasNextPage:g.body.workItems.length>p*l,nextPage:l+1},data:h.body.value.map(y=>Kt(n.namespace,n.project,y,u||{}))}}async updateIssue(n,e,t={}){return await this.config.request({method:"PATCH",url:`${t.baseUrl||q}/${encodeURIComponent(n.project.namespace)}/${encodeURIComponent(n.project.name)}/_apis/wit/workitems/${n.id}?api-version=6.0`,body:JSON.stringify(e),headers:{...w(this.config,t),"Content-Type":"application/json-patch+json"}})}async setIssueStatus(n,e={}){var i;let{issue:t,status:s}=n,o=[{op:"add",path:"/fields/System.State",value:s.name}];if(!((i=(await this.updateIssue(t,o,e)).body.fields)!=null&&i["System.State"]))throw new Error("Could not set issue status")}async setIssueAssignee(n,e={}){var i;let{issue:t,assignee:s}=n,o=[{op:"add",path:"/fields/System.AssignedTo",value:(s==null?void 0:s.name)??""}];if(!((i=(await this.updateIssue(t,o,e)).body.fields)!=null&&i["System.State"]))throw new Error("Could not set issue assignee")}async setIssueLabels(n,e={}){var u;let{issue:t,labels:s}=n,a=[{op:"replace",path:"/fields/System.Tags",value:s.map(l=>l.name).join(";")}];if(!((u=(await this.updateIssue(t,a,e)).body.fields)!=null&&u["System.Tags"]))throw new Error("Could not set issue tags")}async getIssueTypesForAzureProject(n,e={}){if(!n.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let{namespace:t,project:s}=n;return{data:(await this.config.request({url:`${e.baseUrl||q}/${encodeURIComponent(t)}/${encodeURIComponent(s||"")}/_apis/wit/workitemtypes?api-version=6.0`,headers:{...w(this.config,e)}})).body.value}}async getLabelsForProject(n,e={}){let{namespace:t,project:s}=n;return{data:(await this.config.request({url:`${e.baseUrl||q}/${encodeURIComponent(t)}/${encodeURIComponent(s||"")}/_apis/wit/tags?api-version=6.0`,headers:{...w(this.config,e)}})).body.value.map(a=>({color:null,description:null,id:a.id,name:a.name,url:a.url}))}}};var D=(r,n={})=>I(n.token||r.token,n.isPAT||r.isPAT);var $="https://api.bitbucket.org/2.0",Vt={OPEN:"OPEN",MERGED:"MERGED",DECLINED:"CLOSED"},ft=r=>({id:r.uuid,name:r.display_name||r.nickname,username:r.nickname||r.display_name,email:null,avatarUrl:r.links.avatar.href,url:r.links.html.href}),ht=r=>{var n,e;return{id:r.uuid,namespace:r.workspace.slug,name:r.slug,webUrl:r.links.html.href,httpsUrl:((n=r.links.clone.find(t=>t.name==="https"))==null?void 0:n.href)??null,sshUrl:((e=r.links.clone.find(t=>t.name==="ssh"))==null?void 0:e.href)??null,defaultBranch:{name:r.mainbranch.name},permission:null}},Te=r=>{let n=r.id;return{id:n.toString(),title:r.title,number:n,state:Vt[r.state],isDraft:!1,commentCount:r.comment_count,upvoteCount:null,author:ft(r.author),createdDate:new Date(r.created_on),updatedDate:new Date(r.updated_on),closedDate:null,mergedDate:null,repository:{id:r.destination.repository.uuid,name:r.destination.repository.name,owner:{login:r.destination.repository.full_name.split("/")[0]},remoteInfo:null},headCommit:{buildStatuses:null},baseRef:{name:r.destination.branch.name,oid:r.destination.commit.hash},headRef:{name:r.source.branch.name,oid:r.source.commit.hash},url:r.links.html.href,assignees:null,reviews:null,reviewDecision:null,additions:null,deletions:null,fileCount:null,commitCount:null,headRepository:null,mergeableState:"UNKNOWN",permissions:null}},K=class extends U{async refreshToken(n){return{data:(await this.config.request({url:"https://bitbucket.org/site/oauth2/access_token",method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded",Authorization:`Basic ${n.base64ClientIDColonClientSecret}`},body:`grant_type=refresh_token&refresh_token=${n.refreshToken}`})).body}}async getCurrentUser(n={},e={}){let t=await this.config.request({url:`${$}/user`,headers:D(this.config,e)});return{data:ft(t.body)}}async getUserForCommit(n,e={}){var a;let s=(await this.config.request({url:`${$}/repositories/${n.repo.namespace}/${n.repo.name}/commit/${n.oid}`,headers:D(this.config,e)})).body.author,o=s.raw.match(/([^<]+)<(.+)>/);return{data:{name:o?o[1].trim():null,email:o?o[2]:null,avatarUrl:((a=s.user)==null?void 0:a.links.avatar.href)||null}}}async getRepo(n,e={}){let t=await this.config.request({url:`${$}/repositories/${n.namespace}/${n.name}`,headers:D(this.config,e)});return{data:ht(t.body)}}async getRepos(n,e={}){let t=[],s=[];return await Promise.all(n.map(async o=>{try{let a=await this.getRepo(o,e);t.push(a.data)}catch(a){s.push({input:o,error:a})}})),{data:t,errors:s}}async getReposForCurrentUser(n,e={}){let t=new URL(`${$}/repositories`);t.searchParams.set("role","member"),t.searchParams.set("pagelen",E.toString()),n.cursor&&t.searchParams.set("after",n.cursor);let s=await this.config.request({url:t.toString(),headers:D(this.config,e)}),o=!!s.body.next,a=null;return s.body.next&&(a=new URL(s.body.next).searchParams.get("after")),{pageInfo:{hasNextPage:o,endCursor:a},data:s.body.values.map(ht)}}async getBranches(n,e={}){var a;let t=new URL(`${$}/repositories/${n.repo.namespace}/${n.repo.name}/refs/branches`);t.searchParams.set("page",((a=n.page)==null?void 0:a.toString())||"1"),t.searchParams.set("pagelen",E.toString());let s=await this.config.request({url:t.toString(),headers:D(this.config,e)}),o=!!s.body.next;return{pageInfo:{hasNextPage:o,nextPage:o?s.body.page+1:null},data:s.body.values.map(i=>{let u=new Date(i.target.date);return{name:i.name,commit:{oid:i.target.hash,authoredDate:u,committedDate:u}}})}}async getTags(n,e={}){let t=new URL(`${$}/repositories/${n.repo.namespace}/${n.repo.name}/refs/tags`);t.searchParams.set("pagelen",E.toString()),n.cursor&&t.searchParams.set("page",n.cursor);let s=await this.config.request({url:t.toString(),headers:D(this.config,e)}),o=!!s.body.next,a=null;return s.body.next&&(a=new URL(s.body.next).searchParams.get("page")),{pageInfo:{hasNextPage:o,endCursor:a},data:s.body.values.map(i=>{let u=new Date(i.target.date);return{name:i.name,commit:{oid:i.target.hash,authoredDate:u,committedDate:u}}})}}async getPullRequestsForUser(n,e={}){var a;let t=new URL(`${$}/pullrequests/${n.userId}`);t.searchParams.set("page",((a=n.page)==null?void 0:a.toString())||"1"),t.searchParams.set("pagelen","50");let s=await this.config.request({url:t.toString(),headers:D(this.config,e)}),o=!!s.body.next;return{pageInfo:{hasNextPage:o,nextPage:o?s.body.page+1:null},data:s.body.values.map(Te)}}async getPullRequestsForRepoBase(n,e={}){var s;let t=new URL(`${$}/repositories/${encodeURI(n.repo.namespace)}/${encodeURI(n.repo.name)}/pullrequests?state=OPEN`);return t.searchParams.set("page",((s=n.page)==null?void 0:s.toString())||"1"),t.searchParams.set("pagelen","50"),await this.config.request({url:t.toString(),headers:D(this.config,e)})}async getPullRequestsForRepo(n,e={}){let t=[],s=await this.getPullRequestsForRepoBase(n,e);s.body.values.forEach(a=>{if(n.authorLogin&&a.author.uuid!==n.authorLogin)return null;t.push(Te(a))});let o=!!s.body.next;return{pageInfo:{hasNextPage:o,nextPage:o?s.body.page+1:null},data:t}}async getPullRequestsForRepos(n,e={}){let t=[];return await Promise.all(n.repos.map(async s=>{try{(await this.getPullRequestsForRepoBase({repo:s,...n},e)).body.values.forEach(a=>{if(n.authorLogin&&a.author.uuid!==n.authorLogin)return null;t.push(Te(a))})}catch(o){if(o.statusCode!==404&&o.statusCode!==401)throw o}})),{data:t}}async closePullRequest(n,e={}){let{pullRequest:t}=n;if(!(await this.config.request({method:"POST",url:`${$}/repositories/${t.repository.owner.login}/${t.repository.name}/pullrequests/${t.id}/decline`,headers:D(this.config,e)})).body.title)throw new Error("Could not close pull request")}async mergePullRequest(n,e={}){let{pullRequest:t,mergeStrategy:s}=n,o;switch(s){case"MERGE_COMMIT":{o="merge_commit";break}case"FAST_FORWARD":{o="fast_forward";break}case"SQUASH":{o="squash";break}}let a={merge_strategy:o,type:"pullrequest"};if(!(await this.config.request({method:"POST",url:`${$}/repositories/${t.repository.owner.login}/${t.repository.name}/pullrequests/${t.id}/merge`,body:JSON.stringify(a),headers:{...D(this.config,e),"Content-Type":"application/json"}})).body.title)throw new Error("Could not merge pull request")}async setPullRequestReviewers(n,e={}){let{pullRequest:t,reviewers:s}=n,o={reviewers:s.map(i=>{if(i.username)throw new Error('Bitbucket reviewer requires "username" for this function.');return{username:i.username}})};if(!(await this.config.request({method:"PUT",url:`${$}/repositories/${t.repository.owner.login}/${t.repository.name}/pullrequests/${t.id}`,body:JSON.stringify(o),headers:{...D(this.config,e),"Content-Type":"application/json"}})).body.title)throw new Error("Could not set pull request reviewers")}};var xe=r=>({name:r.displayName,email:r.emailAddress,avatarUrl:r.avatarUrl??null,id:r.id.toString(),username:r.name,url:r.links.self[0].href}),Oe=r=>{var u,l,p,d,c,g;let n={OPEN:"OPEN",MERGED:"MERGED",DECLINED:"CLOSED"},e={UNAPPROVED:"REVIEW_REQUESTED",NEEDS_WORK:"CHANGES_REQUESTED",APPROVED:"APPROVED"},t=r.reviewers.map(m=>({reviewer:xe(m.user),state:e[m.status]})),s=((u=r.toRef.repository.links.clone.find(m=>m.name==="ssh"))==null?void 0:u.href)??null,o=((l=r.toRef.repository.links.clone.find(m=>m.name==="https"))==null?void 0:l.href)??null;o||(o=((p=r.toRef.repository.links.clone.find(m=>m.name==="http"))==null?void 0:p.href)??null);let a=((d=r.fromRef.repository.links.clone.find(m=>m.name==="ssh"))==null?void 0:d.href)??null,i=((c=r.fromRef.repository.links.clone.find(m=>m.name==="https"))==null?void 0:c.href)??null;return i||(i=((g=r.fromRef.repository.links.clone.find(m=>m.name==="http"))==null?void 0:g.href)??null),{id:r.id.toString(),number:r.id,title:r.title,url:r.links.self[0].href,state:n[r.state],isDraft:!1,createdDate:new Date(r.createdDate),updatedDate:new Date(r.updatedDate),closedDate:r.closedDate?new Date(r.closedDate):null,mergedDate:r.state=="MERGED"&&r.closedDate?new Date(r.closedDate):null,baseRef:{name:r.toRef.displayId,oid:r.toRef.latestCommit},headRef:{name:r.fromRef.displayId,oid:r.fromRef.latestCommit},commentCount:r.properties.commentCount,upvoteCount:null,commitCount:null,fileCount:null,additions:null,deletions:null,author:xe(r.author.user),assignees:null,reviews:t,reviewDecision:Q(t),repository:{id:r.toRef.repository.id.toString(),name:r.toRef.repository.name,owner:{login:r.toRef.repository.project.key},remoteInfo:o&&s?{cloneUrlHTTPS:o,cloneUrlSSH:s}:null},headRepository:{id:r.fromRef.repository.id.toString(),name:r.fromRef.repository.name,owner:{login:r.fromRef.repository.project.key},remoteInfo:i&&a?{cloneUrlHTTPS:i,cloneUrlSSH:a}:null},headCommit:null,mergeableState:"UNKNOWN",permissions:null,version:r.version}},It=r=>{var n,e,t;return{id:r.id.toString(),namespace:r.project.key,name:r.slug,webUrl:((n=r.links.self[0])==null?void 0:n.href)??null,httpsUrl:((e=r.links.clone.find(s=>s.name==="https"||s.name==="http"))==null?void 0:e.href)??null,sshUrl:((t=r.links.clone.find(s=>s.name==="ssh"))==null?void 0:t.href)??null,defaultBranch:null,permission:null}},V=class extends T{getBaseUrl(n){let e=n.baseUrl||this.config.baseUrl;if(!e)throw new Error('Bitbucket Server requires "baseUrl"');return e}getRequestHeaders(n){return I(n.token||this.config.token)}async getCurrentUser(n={},e={}){let t=await this.config.request({url:`${this.getBaseUrl(e)}/users?limit=2`,headers:this.getRequestHeaders(e)}),{headers:{"x-auserid":s,"x-ausername":o}}=t,a=s?parseInt(s,10):null,i=decodeURIComponent(o),l=(await this.config.request({url:`${this.getBaseUrl(e)}/users?filter=${o}&avatarSize=64`,headers:this.getRequestHeaders(e)})).body.values.find(({emailAddress:p,id:d,name:c,slug:g})=>a?a===d:i===c||i===p||i===g);if(!l)throw new Error("Could not find current Bitbucket Server user");return{data:xe(l)}}async getRepo(n,e={}){let t=await this.config.request({url:`${this.getBaseUrl(e)}/projects/${n.namespace}/repos/${n.name}`,headers:this.getRequestHeaders(e)});return{data:It(t.body)}}async getRepos(n,e={}){let t=[],s=[];return await Promise.all(n.map(async o=>{try{let a=await this.getRepo(o,e);t.push(a.data)}catch(a){s.push({input:o,error:a})}})),{data:t,errors:s}}async getReposForCurrentUser(n,e={}){let t=n.page??0,s=await this.config.request({url:`${this.getBaseUrl(e)}/repos?start=${t}`,headers:this.getRequestHeaders(e)});return{pageInfo:{hasNextPage:!s.body.isLastPage,nextPage:s.body.nextPageStart},data:s.body.values.map(It)}}async getPullRequestsForRepoBase(n,e={}){var s;let t=new URL(`${this.getBaseUrl(e)}/projects/${encodeURI(n.repo.namespace)}/repos/${encodeURI(n.repo.name)}/pull-requests?state=OPEN`);return t.searchParams.set("start",((s=n.page)==null?void 0:s.toString())||"0"),t.searchParams.set("limit","50"),await this.config.request({url:t.toString(),headers:this.getRequestHeaders(e)})}async getPullRequestsForRepo(n,e={}){let t=[],s=await this.getPullRequestsForRepoBase(n,e);s.body.values.forEach(a=>{if(n.authorLogin&&a.author.user.name!==n.authorLogin)return null;t.push(Oe(a))});let o=s.body.values.length!==0;return{pageInfo:{hasNextPage:o,nextPage:o?s.body.start+s.body.values.length:null},data:t}}async getPullRequestsForRepos(n,e={}){let t=[];return await Promise.all(n.repos.map(async s=>{try{(await this.getPullRequestsForRepoBase({repo:s,...n},e)).body.values.forEach(a=>{if(n.authorLogin&&a.author.user.name!==n.authorLogin)return null;t.push(Oe(a))})}catch(o){if(o.statusCode!==404&&o.statusCode!==401)throw o}})),{data:t}}async getPullRequestsForCurrentUser(n,e={}){var a;let t=new URL(`${this.getBaseUrl(e)}/dashboard/pull-requests`);t.searchParams.set("state","OPEN"),t.searchParams.set("start",((a=n.page)==null?void 0:a.toString())||"0"),t.searchParams.set("limit","50");let s=await this.config.request({url:t.toString(),headers:this.getRequestHeaders(e)}),o=s.body.values.length!==0;return{pageInfo:{hasNextPage:o,nextPage:o?s.body.start+s.body.values.length:null},data:s.body.values.map(Oe)}}async closePullRequest(n,e={}){let{pullRequest:t}=n;if(t.version===void 0)throw new Error('Bitbucket Server requires "version" for this function.');if(!(await this.config.request({method:"POST",url:`${this.getBaseUrl(e)}/projects/${t.repository.owner.login}/repos/${t.repository.name}/pull-requests/${t.id}/decline`,body:JSON.stringify({version:t.version}),headers:{...this.getRequestHeaders(e),"Content-Type":"application/json"}})).body.title)throw new Error("Could not close pull request")}async mergePullRequest(n,e={}){let{pullRequest:t,mergeStrategyId:s}=n;if(n.mergeStrategy)throw new Error('Bitbucket Server uses "mergeStrategyId" instead of "mergeStrategy".');if(t.version===void 0)throw new Error('Bitbucket Server requires "version" for this function.');if(!(await this.config.request({method:"POST",url:`${this.getBaseUrl(e)}/projects/${t.repository.owner.login}/repos/${t.repository.name}/pull-requests/${t.id}/merge`,body:JSON.stringify({strategyId:s,version:t.version}),headers:{...this.getRequestHeaders(e),"Content-Type":"application/json"}})).body.title)throw new Error("Could not merge pull request")}async getMergeStrategies(n={}){let e=await this.config.request({url:`${this.getBaseUrl(n)}/admin/pull-requests/git`,headers:{...this.getRequestHeaders(n),"Content-Type":"application/json"}});return{data:{defaultStrategy:e.body.mergeConfig.defaultStrategy,strategies:e.body.mergeConfig.strategies}}}async setPullRequestReviewers(n,e={}){let{pullRequest:t,reviewers:s}=n;if(t.version===void 0)throw new Error('Bitbucket Server requires "version" for this function.');let o={reviewers:s.map(i=>{if(i.username)throw new Error('Bitbucket Server reviewer requires "username" for this function.');return{user:{name:i.username}}}),version:t.version};if(!(await this.config.request({method:"PUT",url:`${this.getBaseUrl(e)}/projects/${t.repository.owner.login}/repos/${t.repository.name}/pull-requests/${t.id}`,body:JSON.stringify(o),headers:{...this.getRequestHeaders(e),"Content-Type":"application/json"}})).body.title)throw new Error("Could not set pull request reviewers")}};var vt=require("js-base64");var pe=(e=>(e.Open="OPEN",e.Closed="CLOSED",e))(pe||{});var R=class extends Error{constructor(e,t){let s=t==null?void 0:t.map(a=>`'${a.message}'`).join(", "),o=s?`${e}: ${s}`:e;super(o);this.graphQLErrors=t??[]}};var Xt={AS_CODE_OWNER:[3,0,0],CHECK_RUN:[3,0,0],LATEST_REVIEWS:[3,0,0],VIEWER_CAN_MERGE_AS_ADMIN:[3,5,0]},Rt=15,bt=100,C=r=>!!r,de=(r,n)=>{let e=Xt[n];for(let t=0;t<3;t++){if(r[t]>e[t])return!0;if(r[t]<e[t])return!1}return!0},ge="https://api.github.com",Zt=`${ge}/graphql`,me=`
2
2
  description
3
3
  dueOn
4
4
  id
@@ -6,7 +6,7 @@ number
6
6
  state
7
7
  title
8
8
  url
9
- `,Zt=`
9
+ `,Yt=`
10
10
  ... on CheckRun {
11
11
  completedAt
12
12
  conclusion
@@ -15,39 +15,39 @@ url
15
15
  permalink
16
16
  startedAt
17
17
  }
18
- `,de=/\/api\/v\d+$/,me=`
18
+ `,ce=/\/api\/v\d+$/,he=`
19
19
  color
20
20
  description
21
21
  id
22
22
  name
23
- `,bt=r=>{if(r.endsWith("/api/graphql"))throw new Error("The graphql endpoint is being used as the baseUrl. This package uses both GraphQL and REST APIs, and the REST version cannot be assumed. Use the REST endpoint as the baseUrl instead.")},Yt=(r,s)=>{let e=s.baseUrl||r.baseUrl;return e?(e=e.replace(/\/$/,""),bt(e),de.test(e)&&(e=e.replace(de,"")),`${e}/api/graphql`):Xt},re=(r,s)=>{let e=s.baseUrl||r.baseUrl;return e?(e=e.replace(/\/$/,""),bt(e),de.test(e)&&(e=e.replace(de,"")),`${e}/api/v3`):ce},R=(r,s,e)=>{let t=I(e.token||r.token);return t["X-Github-Next-Global-ID"]="1",t["Content-Type"]="application/json",t.Accept="application/vnd.github.merge-info-preview+json",r.request({url:Yt(r,e),method:"POST",headers:t,body:JSON.stringify(s)})},er={user:!0,"user:email":!0,"read:user":!0},x=r=>r.some(s=>er[s]),U=(r=!1,s=!1,e)=>`
23
+ `,yt=r=>{if(r.endsWith("/api/graphql"))throw new Error("The graphql endpoint is being used as the baseUrl. This package uses both GraphQL and REST APIs, and the REST version cannot be assumed. Use the REST endpoint as the baseUrl instead.")},er=(r,n)=>{let e=n.baseUrl||r.baseUrl;return e?(e=e.replace(/\/$/,""),yt(e),ce.test(e)&&(e=e.replace(ce,"")),`${e}/api/graphql`):Zt},se=(r,n)=>{let e=n.baseUrl||r.baseUrl;return e?(e=e.replace(/\/$/,""),yt(e),ce.test(e)&&(e=e.replace(ce,"")),`${e}/api/v3`):ge},b=(r,n,e)=>{let t=I(e.token||r.token);return t["X-Github-Next-Global-ID"]="1",t["Content-Type"]="application/json",t.Accept="application/vnd.github.merge-info-preview+json",r.request({url:er(r,e),method:"POST",headers:t,body:JSON.stringify(n)})},tr={user:!0,"user:email":!0,"read:user":!0},k=r=>r.some(n=>tr[n]),L=(r=!1,n=!1,e)=>`
24
24
  __typename
25
- ${Q(e,["graphQLId"],"id")}
26
- ${Q(e,["id"],"databaseId")}
27
- ${Q(e,["name"],"name")}
28
- ${Q(e,["name","username"],"login")}
29
- ${s?Q(e,["email"],"email"):""}
30
- ${Q(e,["avatarUrl"],`avatarUrl${r?"(size: $avatarSize)":""}`)}
31
- ${Q(e,["url"],"url")}
32
- `,tr=(r=!1)=>`
25
+ ${_(e,["graphQLId"],"id")}
26
+ ${_(e,["id"],"databaseId")}
27
+ ${_(e,["name"],"name")}
28
+ ${_(e,["name","username"],"login")}
29
+ ${n?_(e,["email"],"email"):""}
30
+ ${_(e,["avatarUrl"],`avatarUrl${r?"(size: $avatarSize)":""}`)}
31
+ ${_(e,["url"],"url")}
32
+ `,rr=(r=!1)=>`
33
33
  latestReviews(first: 100) {
34
34
  nodes {
35
35
  author {
36
36
  ... on User {
37
- ${U(!1,r)}
37
+ ${L(!1,r)}
38
38
  }
39
39
  }
40
40
  state
41
41
  }
42
42
  }
43
- `,yt=(r=!1)=>`
43
+ `,Pt=(r=!1)=>`
44
44
  __typename
45
45
  id
46
46
  databaseId
47
47
  login
48
48
  avatarUrl${r?"(size: $avatarSize)":""}
49
49
  url
50
- `,he=(r,s=!1,e)=>`
50
+ `,fe=(r,n=!1,e)=>`
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
- ${U(!1,s)}
58
+ ${L(!1,n)}
59
59
  }
60
60
  ... on Bot {
61
- ${yt(!1)}
61
+ ${Pt(!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
- ${!e||pe(e,"CHECK_RUN")?Zt:""}
74
+ ${!e||de(e,"CHECK_RUN")?Yt:""}
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
- ${U(!1,s)}
136
+ ${L(!1,n)}
137
137
  }
138
138
  }
139
139
  reviewRequests(first: 100) {
140
140
  nodes {
141
- ${!e||pe(e,"AS_CODE_OWNER")?"asCodeOwner":""}
141
+ ${!e||de(e,"AS_CODE_OWNER")?"asCodeOwner":""}
142
142
  requestedReviewer {
143
143
  ... on User {
144
- ${U(!1,s)}
144
+ ${L(!1,n)}
145
145
  }
146
146
  }
147
147
  }
148
148
  }
149
- ${!e||pe(e,"LATEST_REVIEWS")?tr(s):""}
149
+ ${!e||de(e,"LATEST_REVIEWS")?rr(n):""}
150
150
  additions
151
151
  deletions
152
152
  changedFiles
153
153
  mergeable
154
154
  mergeStateStatus
155
155
  milestone {
156
- ${ge}
156
+ ${me}
157
157
  }
158
158
  labels(first: 100) {
159
159
  nodes {
160
- ${me}
160
+ ${he}
161
161
  }
162
162
  }
163
- ${!e||pe(e,"VIEWER_CAN_MERGE_AS_ADMIN")?"viewerCanMergeAsAdmin":""}
164
- `,rr=(r=!1)=>`
163
+ ${!e||de(e,"VIEWER_CAN_MERGE_AS_ADMIN")?"viewerCanMergeAsAdmin":""}
164
+ `,sr=(r=!1)=>`
165
165
  id
166
166
  databaseId
167
167
  title
168
168
  author {
169
169
  ... on User {
170
- ${U(!1,r)}
170
+ ${L(!1,r)}
171
171
  }
172
172
  ... on Bot {
173
- ${yt(!1)}
173
+ ${Pt(!1)}
174
174
  }
175
175
  }
176
176
  closedAt
@@ -194,19 +194,19 @@ comments {
194
194
  }
195
195
  assignees(first: 100) {
196
196
  nodes {
197
- ${U(!1,r)}
197
+ ${L(!1,r)}
198
198
  }
199
199
  }
200
200
  state
201
201
  milestone {
202
- ${ge}
202
+ ${me}
203
203
  }
204
204
  labels(first: 100) {
205
205
  nodes {
206
- ${me}
206
+ ${he}
207
207
  }
208
208
  }
209
- `,sr={"-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"},nr=new RegExp('(([^\\s]+:)?\\"(?:[^\\"\\\\]|\\\\.)*\\"?)|([^\\"\\s]+)',"g"),xe=r=>{let s=[];return(r.match(nr)??[]).forEach(t=>{if(t.includes(":")&&t!="is:closed"){let n=t.split(":")[0];sr[n]&&s.push(t)}}),s},ke=(r,s,e,t)=>{let n=r==="issue";return{query:`
209
+ `,nr={"-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"},or=new RegExp('(([^\\s]+:)?\\"(?:[^\\"\\\\]|\\\\.)*\\"?)|([^\\"\\s]+)',"g"),ke=r=>{let n=[];return(r.match(or)??[]).forEach(t=>{if(t.includes(":")&&t!="is:closed"){let s=t.split(":")[0];nr[s]&&n.push(t)}}),n},Ne=(r,n,e,t)=>{let s=r==="issue";return{query:`
210
210
  query SearchIssuesOrPullRequests($query: String! $after: String) {
211
211
  search(type:ISSUE query:$query first: ${t.maxPageSize} after:$after) {
212
212
  pageInfo {
@@ -214,19 +214,19 @@ query SearchIssuesOrPullRequests($query: String! $after: String) {
214
214
  endCursor
215
215
  }
216
216
  nodes {
217
- ... on ${n?"Issue":"PullRequest"} {
218
- ${n?rr(t.supportsEmail):he(t.supportsDrafts??!1,t.supportsEmail,t.enterpriseVersion??null)}
217
+ ... on ${s?"Issue":"PullRequest"} {
218
+ ${s?sr(t.supportsEmail):fe(t.supportsDrafts??!1,t.supportsEmail,t.enterpriseVersion??null)}
219
219
  }
220
220
  }
221
221
  }
222
- }`,variables:{query:`is:${r} is:open ${t.includeFromArchivedRepos?"":"archived:false"} ${s}`,after:e}}},or="Field 'isDraft' doesn't exist on type 'PullRequest'",fe=(r=[])=>r.some(s=>(s==null?void 0:s.message)===or),ar=/@@ -(\d+)(?:,\d+ | )\+(\d+)(?:,\d+ | )@@(?:\\n)?/,ir=`
222
+ }`,variables:{query:`is:${r} is:open ${t.includeFromArchivedRepos?"":"archived:false"} ${n}`,after:e}}},ar="Field 'isDraft' doesn't exist on type 'PullRequest'",Ie=(r=[])=>r.some(n=>(n==null?void 0:n.message)===ar),ir=/@@ -(\d+)(?:,\d+ | )\+(\d+)(?:,\d+ | )@@(?:\\n)?/,ur=`
223
223
  \
224
- +`,wt=(r,s,e,t)=>{let n=ar.exec(r);if(!n||!n[0]||!n[1])return[];let o=parseInt(n[1],10),a=parseInt(n[2],10),i=r.replace(ir,`
224
+ +`,wt=(r,n,e,t)=>{let s=ir.exec(r);if(!s||!s[0]||!s[1])return[];let o=parseInt(s[1],10),a=parseInt(s[2],10),i=r.replace(ur,`
225
225
  +`).split(`
226
226
  `).slice(1),u=o-1,l=a-1,p=i.map(g=>{let m,h;switch(g[0]){case"-":{m="DELETED",u+=1,h=`${g.slice(1)}
227
227
  `;break}case"+":{m="ADDED",l+=1,h=`${g.slice(1)}
228
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=e,c=s;if(d!==null&&c!==null&&t!==null&&d<c){let g=0,m=p.length,h=t==="LEFT"?"oldLineNumber":"newLineNumber";for(let b=0;b<p.length;b++){let f=p[b][h];f===d?g=b:f===c&&(m=b)}p=p.slice(g,m+1)}return p};var Ne=`
229
+ `}return{line:h,oldLineNumber:m!=="ADDED"?u:null,newLineNumber:m!=="DELETED"?l:null,type:m}}),d=e,c=n;if(d!==null&&c!==null&&t!==null&&d<c){let g=0,m=p.length,h=t==="LEFT"?"oldLineNumber":"newLineNumber";for(let y=0;y<p.length;y++){let f=p[y][h];f===d?g=y:f===c&&(m=y)}p=p.slice(g,m+1)}return p};var Fe=`
230
230
  id
231
231
  databaseId
232
232
  owner {
@@ -239,18 +239,18 @@ defaultBranchRef {
239
239
  name
240
240
  }
241
241
  viewerPermission
242
- `,_e={__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"},ur={APPROVED:"APPROVED",CHANGES_REQUESTED:"CHANGES_REQUESTED",COMMENTED:"COMMENTED",REVIEW_REQUESTED:"REVIEW_REQUESTED"},lr={MERGEABLE:"MERGEABLE",CONFLICTING:"CONFLICTS",UNKNOWN:"UNKNOWN"},pr={BEHIND:"BEHIND",BLOCKED:"BLOCKED",UNKNOWN:"UNKNOWN_AND_BLOCKED",UNSTABLE:"UNSTABLE",CLEAN:null,DIRTY:null,DRAFT:null,HAS_HOOKS:null},dr={OPEN:"OPEN",CLOSED:"CLOSED"},cr=["ADMIN","MAINTAIN","TRIAGE","WRITE"],Be=r=>({color:`#${r.color}`,description:r.description,graphQLId:r.id,id:null,name:r.name}),Fe=r=>({id:r.databaseId.toString(),graphQLId:r.id,namespace:r.owner.login,name:r.name,webUrl:r.url,httpsUrl:r.url.endsWith(".git")?r.url:`${r.url}.git`,sshUrl:r.sshUrl,defaultBranch:r.defaultBranchRef,permission:r.viewerPermission}),Pt=r=>{let s=null;return r.permissions.admin?s="ADMIN":r.permissions.maintain?s="MAINTAIN":r.permissions.push?s="WRITE":r.permissions.triage?s="TRIAGE":r.permissions.pull&&(s="READ"),{id:r.id.toString(),graphQLId:r.node_id,namespace:r.owner.login,name:r.name,webUrl:r.html_url,httpsUrl:r.clone_url,sshUrl:r.ssh_url,defaultBranch:{name:r.default_branch},permission:s}},gr={OPEN:"OPEN",CLOSED:"CLOSED",MERGED:"MERGED"},mr={id:!0,graphQLId:!0,name:!0,username:!0,email:!0,avatarUrl:!0,url:!0},$=(r,s=mr)=>{let e={};return s.id&&(e.id=r.databaseId.toString()),s.graphQLId&&(e.graphQLId=r.id),s.name&&(e.name=r.name??r.login),s.username&&(e.username=r.login),s.email&&(e.email=r.email??null),s.avatarUrl&&(e.avatarUrl=r.avatarUrl),s.url&&(e.url=r.url),e},hr=(r,s)=>{let e={IN_PROGRESS:"RUNNING",PENDING:"PENDING",QUEUED:"PENDING",REQUESTED:"PENDING",WAITING:"PENDING"};return r!=="COMPLETED"?e[r]:{ACTION_REQUIRED:"ACTION_REQUIRED",CANCELLED:"CANCELLED",FAILURE:"FAILED",NEUTRAL:null,SKIPPED:"SKIPPED",STALE:"FAILED",STARTUP_FAILURE:"FAILED",SUCCESS:"SUCCESS",TIMED_OUT:"ERROR"}[s]},fr=r=>({ERROR:"ERROR",EXPECTED:"PENDING",FAILURE:"FAILED",PENDING:"PENDING",SUCCESS:"SUCCESS"})[r],Qe=r=>{var a,i,u,l,p,d,c,g,m,h,b,S;let s=null;r.author?s=(r.author.__typename==="Bot",r.author):s=_e;let e=(((a=r.reviewRequests)==null?void 0:a.nodes)||[]).filter(E).filter(f=>!f.asCodeOwner),t=(i=r.headRepository)==null?void 0:i.url;t&&!t.endsWith(".git")&&(t=`${t}.git`);let n=(u=r.repository)==null?void 0:u.url;n&&!n.endsWith(".git")&&(n=`${n}.git`);let o=e.filter(f=>f.requestedReviewer&&"__typename"in f.requestedReviewer).map(f=>({reviewer:$(f.requestedReviewer),state:"REVIEW_REQUESTED"})).concat((((l=r.latestReviews)==null?void 0:l.nodes)||[]).filter(E).map(f=>{let P=_e;return f.author&&Object.keys(f.author).length>0&&(P=f.author),{reviewer:$(P),state:ur[f.state]}}));return{id:r.databaseId.toString(),graphQLId:r.id,title:r.title,number:r.number,state:gr[r.state],commentCount:r.comments.totalCount,upvoteCount:r.reactions.totalCount,author:s?$(s):null,createdDate:new Date(r.createdAt),isDraft:r.isDraft,repository:{id:r.repository.databaseId,graphQLId:r.repository.id,name:r.repository.name,owner:{login:r.repository.owner.login},remoteInfo:{cloneUrlHTTPS:n,cloneUrlSSH:r.repository.sshUrl}},headRepository:r.headRepository?{id:r.headRepository.databaseId,graphQLId:r.headRepository.id,name:r.headRepository.name,owner:{login:r.headRepository.owner.login},remoteInfo:{cloneUrlHTTPS:t,cloneUrlSSH:r.headRepository.sshUrl}}:null,headCommit:{buildStatuses:((g=(c=(d=(p=r.commits.nodes)==null?void 0:p.filter(E)[0])==null?void 0:d.commit.statusCheckRollup)==null?void 0:c.contexts.nodes)==null?void 0:g.filter(E).map(f=>"context"in f?{completedAt:null,description:f.description,name:f.context,state:fr(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:hr(f.status,f.conclusion),startedAt:f.startedAt?new Date(f.startedAt):null,stage:null,url:f.permalink}))??[]},headRef:r.headRef?{name:r.headRef.name,oid:((m=r.headRef.target)==null?void 0:m.oid)??null}:null,baseRef:r.baseRef?{name:r.baseRef.name,oid:((h=r.baseRef.target)==null?void 0:h.oid)??null}:null,url:r.url,updatedDate:new Date(r.updatedAt),closedDate:r.closedAt?new Date(r.closedAt):null,mergedDate:r.mergedAt?new Date(r.mergedAt):null,assignees:r.assignees.nodes?r.assignees.nodes.filter(E).map(f=>$(f)):null,reviews:o,reviewDecision:F(o),additions:r.additions,deletions:r.deletions,fileCount:r.changedFiles,commitCount:r.commits.totalCount,mergeableState:pr[r.mergeStateStatus]??lr[r.mergeable],milestone:r.milestone?je(r.milestone):null,labels:((S=(b=r.labels)==null?void 0:b.nodes)==null?void 0:S.filter(E).map(Be))??[],permissions:{canMerge:cr.includes(r.repository.viewerPermission),canMergeAndBypassProtections:r.viewerCanMergeAsAdmin??!1}}},Ir=r=>{var h,b;let{comments:s,isOutdated:e,isResolved:t,originalLine:n,originalStartLine:o,startDiffSide:a}=r,i=(h=s.nodes)==null?void 0:h[0];if(!i)return null;let{author:u,body:l,databaseId:p,id:d,path:c,publishedAt:g,url:m}=i;return{author:u?{avatarUrl:u.avatarUrl,email:null,name:u.login}:null,body:l,createdAt:g?new Date(g):null,diffLines:wt(i.diffHunk,n,o,a),id:p,isOutdated:e,isResolved:t,graphQLId:d,filename:c,replies:((b=s.nodes)==null?void 0:b.filter(E).slice(1).map(Rr))??[],url:m}},Rr=r=>({author:r.author?{avatarUrl:r.author.avatarUrl,email:null,name:r.author.login}:null,body:r.body,createdAt:r.publishedAt?new Date(r.publishedAt):null,graphQLId:r.id,id:r.databaseId,url:r.url}),br=r=>{var e,t,n;let s=null;return r.author?s=(r.author.__typename==="Bot",r.author):s=_e,{id:r.databaseId.toString(),graphQLId:r.id,number:r.number,title:r.title,author:$(s),commentCount:r.comments.totalCount,closedDate:r.closedAt?new Date(r.closedAt):null,createdDate:new Date(r.createdAt),description:null,state:{name:dr[r.state],color:null},type:null,repository:{id:r.repository.databaseId,graphQLId:r.repository.id,name:r.repository.name,owner:{login:r.repository.owner.login}},url:r.url,updatedDate:new Date(r.updatedAt),assignees:((e=r.assignees.nodes)==null?void 0:e.filter(E).map(o=>$(o)))??[],upvoteCount:r.reactions.totalCount,milestone:r.milestone?je(r.milestone):null,labels:((n=(t=r.labels)==null?void 0:t.nodes)==null?void 0:n.filter(E).map(Be))??[]}},je=r=>({id:r.number.toString(),graphQLId:r.id.toString(),number:r.number,title:r.title,description:r.description,isOpen:r.state=="OPEN",url:r.url,startDate:null,dueDate:r.dueOn?new Date(r.dueOn):null}),V=class extends G{constructor(){super(...arguments);this._scopesCache={};this._enterpriseVersionsCache={}}async getScopes(e){let t=e.token||this.config.token;if(!t)return[];let n=this._scopesCache[t];if(!n){let a=(await R(this.config,{query:"query { rateLimit(dryRun: true) { __typename } }"},e)).headers["x-oauth-scopes"];n=a?a.split(", "):[],this._scopesCache[t]=n}return n}async getEnterpriseVersion(e){let t=e.baseUrl||this.config.baseUrl;if(!t)return null;let n=this._enterpriseVersionsCache[t];if(!n){let o=await this.config.request({url:`${re(this.config,e)}/meta`,headers:I(e.token||this.config.token)});if(!o.body.installed_version)return null;n=o.body.installed_version.split(".").slice(0,3).map(a=>parseInt(a,10)),this._enterpriseVersionsCache[t]=n}return n}getEnterpriseAvatarUrlIfNeeded(e,t,n){let o=n.baseUrl||this.config.baseUrl;return!o||o.startsWith(ce)?e:t?`https://avatars.githubusercontent.com/u/e?email=${encodeURIComponent(t)}`:""}async getCurrentUser(e={},t={}){var u;if(e.fields&&!e.fields.length)throw new Error('"fields" must contain at least one field or be omitted');let n=lt(e.fields),o=await this.getScopes(t),i=(u=(await R(this.config,{query:`
242
+ `,Be={__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"},lr={APPROVED:"APPROVED",CHANGES_REQUESTED:"CHANGES_REQUESTED",COMMENTED:"COMMENTED",REVIEW_REQUESTED:"REVIEW_REQUESTED"},pr={MERGEABLE:"MERGEABLE",CONFLICTING:"CONFLICTS",UNKNOWN:"UNKNOWN"},dr={BEHIND:"BEHIND",BLOCKED:"BLOCKED",UNKNOWN:"UNKNOWN_AND_BLOCKED",UNSTABLE:"UNSTABLE",CLEAN:null,DIRTY:null,DRAFT:null,HAS_HOOKS:null},cr={OPEN:"OPEN",CLOSED:"CLOSED"},gr=["ADMIN","MAINTAIN","TRIAGE","WRITE"],je=r=>({color:`#${r.color}`,description:r.description,graphQLId:r.id,id:null,name:r.name}),Qe=r=>({id:r.databaseId.toString(),graphQLId:r.id,namespace:r.owner.login,name:r.name,webUrl:r.url,httpsUrl:r.url.endsWith(".git")?r.url:`${r.url}.git`,sshUrl:r.sshUrl,defaultBranch:r.defaultBranchRef,permission:r.viewerPermission}),St=r=>{let n=null;return r.permissions.admin?n="ADMIN":r.permissions.maintain?n="MAINTAIN":r.permissions.push?n="WRITE":r.permissions.triage?n="TRIAGE":r.permissions.pull&&(n="READ"),{id:r.id.toString(),graphQLId:r.node_id,namespace:r.owner.login,name:r.name,webUrl:r.html_url,httpsUrl:r.clone_url,sshUrl:r.ssh_url,defaultBranch:{name:r.default_branch},permission:n}},mr={OPEN:"OPEN",CLOSED:"CLOSED",MERGED:"MERGED"},hr={id:!0,graphQLId:!0,name:!0,username:!0,email:!0,avatarUrl:!0,url:!0},A=(r,n=hr)=>{let e={};return n.id&&(e.id=r.databaseId.toString()),n.graphQLId&&(e.graphQLId=r.id),n.name&&(e.name=r.name??r.login),n.username&&(e.username=r.login),n.email&&(e.email=r.email??null),n.avatarUrl&&(e.avatarUrl=r.avatarUrl),n.url&&(e.url=r.url),e},fr=(r,n)=>{let e={IN_PROGRESS:"RUNNING",PENDING:"PENDING",QUEUED:"PENDING",REQUESTED:"PENDING",WAITING:"PENDING"};return r!=="COMPLETED"?e[r]:{ACTION_REQUIRED:"ACTION_REQUIRED",CANCELLED:"CANCELLED",FAILURE:"FAILED",NEUTRAL:null,SKIPPED:"SKIPPED",STALE:"FAILED",STARTUP_FAILURE:"FAILED",SUCCESS:"SUCCESS",TIMED_OUT:"ERROR"}[n]},Ir=r=>({ERROR:"ERROR",EXPECTED:"PENDING",FAILURE:"FAILED",PENDING:"PENDING",SUCCESS:"SUCCESS"})[r],_e=r=>{var a,i,u,l,p,d,c,g,m,h,y,v;let n=null;r.author?n=(r.author.__typename==="Bot",r.author):n=Be;let e=(((a=r.reviewRequests)==null?void 0:a.nodes)||[]).filter(C).filter(f=>!f.asCodeOwner),t=(i=r.headRepository)==null?void 0:i.url;t&&!t.endsWith(".git")&&(t=`${t}.git`);let s=(u=r.repository)==null?void 0:u.url;s&&!s.endsWith(".git")&&(s=`${s}.git`);let o=e.filter(f=>f.requestedReviewer&&"__typename"in f.requestedReviewer).map(f=>({reviewer:A(f.requestedReviewer),state:"REVIEW_REQUESTED"})).concat((((l=r.latestReviews)==null?void 0:l.nodes)||[]).filter(C).map(f=>{let S=Be;return f.author&&Object.keys(f.author).length>0&&(S=f.author),{reviewer:A(S),state:lr[f.state]}}));return{id:r.databaseId.toString(),graphQLId:r.id,title:r.title,number:r.number,state:mr[r.state],commentCount:r.comments.totalCount,upvoteCount:r.reactions.totalCount,author:n?A(n):null,createdDate:new Date(r.createdAt),isDraft:r.isDraft,repository:{id:r.repository.databaseId,graphQLId:r.repository.id,name:r.repository.name,owner:{login:r.repository.owner.login},remoteInfo:{cloneUrlHTTPS:s,cloneUrlSSH:r.repository.sshUrl}},headRepository:r.headRepository?{id:r.headRepository.databaseId,graphQLId:r.headRepository.id,name:r.headRepository.name,owner:{login:r.headRepository.owner.login},remoteInfo:{cloneUrlHTTPS:t,cloneUrlSSH:r.headRepository.sshUrl}}:null,headCommit:{buildStatuses:((g=(c=(d=(p=r.commits.nodes)==null?void 0:p.filter(C)[0])==null?void 0:d.commit.statusCheckRollup)==null?void 0:c.contexts.nodes)==null?void 0:g.filter(C).map(f=>"context"in f?{completedAt:null,description:f.description,name:f.context,state:Ir(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:fr(f.status,f.conclusion),startedAt:f.startedAt?new Date(f.startedAt):null,stage:null,url:f.permalink}))??[]},headRef:r.headRef?{name:r.headRef.name,oid:((m=r.headRef.target)==null?void 0:m.oid)??null}:null,baseRef:r.baseRef?{name:r.baseRef.name,oid:((h=r.baseRef.target)==null?void 0:h.oid)??null}:null,url:r.url,updatedDate:new Date(r.updatedAt),closedDate:r.closedAt?new Date(r.closedAt):null,mergedDate:r.mergedAt?new Date(r.mergedAt):null,assignees:r.assignees.nodes?r.assignees.nodes.filter(C).map(f=>A(f)):null,reviews:o,reviewDecision:Q(o),additions:r.additions,deletions:r.deletions,fileCount:r.changedFiles,commitCount:r.commits.totalCount,mergeableState:dr[r.mergeStateStatus]??pr[r.mergeable],milestone:r.milestone?Me(r.milestone):null,labels:((v=(y=r.labels)==null?void 0:y.nodes)==null?void 0:v.filter(C).map(je))??[],permissions:{canMerge:gr.includes(r.repository.viewerPermission),canMergeAndBypassProtections:r.viewerCanMergeAsAdmin??!1}}},Rr=r=>{var h,y;let{comments:n,isOutdated:e,isResolved:t,originalLine:s,originalStartLine:o,startDiffSide:a}=r,i=(h=n.nodes)==null?void 0:h[0];if(!i)return null;let{author:u,body:l,databaseId:p,id:d,path:c,publishedAt:g,url:m}=i;return{author:u?{avatarUrl:u.avatarUrl,email:null,name:u.login}:null,body:l,createdAt:g?new Date(g):null,diffLines:wt(i.diffHunk,s,o,a),id:p,isOutdated:e,isResolved:t,graphQLId:d,filename:c,replies:((y=n.nodes)==null?void 0:y.filter(C).slice(1).map(br))??[],url:m}},br=r=>({author:r.author?{avatarUrl:r.author.avatarUrl,email:null,name:r.author.login}:null,body:r.body,createdAt:r.publishedAt?new Date(r.publishedAt):null,graphQLId:r.id,id:r.databaseId,url:r.url}),yr=r=>{var e,t,s;let n=null;return r.author?n=(r.author.__typename==="Bot",r.author):n=Be,{id:r.databaseId.toString(),graphQLId:r.id,number:r.number,title:r.title,author:A(n),commentCount:r.comments.totalCount,closedDate:r.closedAt?new Date(r.closedAt):null,createdDate:new Date(r.createdAt),description:null,state:{name:cr[r.state],color:null},type:null,repository:{id:r.repository.databaseId,graphQLId:r.repository.id,name:r.repository.name,owner:{login:r.repository.owner.login}},url:r.url,updatedDate:new Date(r.updatedAt),assignees:((e=r.assignees.nodes)==null?void 0:e.filter(C).map(o=>A(o)))??[],upvoteCount:r.reactions.totalCount,milestone:r.milestone?Me(r.milestone):null,labels:((s=(t=r.labels)==null?void 0:t.nodes)==null?void 0:s.filter(C).map(je))??[]}},Me=r=>({id:r.number.toString(),graphQLId:r.id.toString(),number:r.number,title:r.title,description:r.description,isOpen:r.state=="OPEN",url:r.url,startDate:null,dueDate:r.dueOn?new Date(r.dueOn):null}),X=class extends T{constructor(){super(...arguments);this._scopesCache={};this._enterpriseVersionsCache={}}async getScopes(e){let t=e.token||this.config.token;if(!t)return[];let s=this._scopesCache[t];if(!s){let a=(await b(this.config,{query:"query { rateLimit(dryRun: true) { __typename } }"},e)).headers["x-oauth-scopes"];s=a?a.split(", "):[],this._scopesCache[t]=s}return s}async getEnterpriseVersion(e){let t=e.baseUrl||this.config.baseUrl;if(!t)return null;let s=this._enterpriseVersionsCache[t];if(!s){let o=await this.config.request({url:`${se(this.config,e)}/meta`,headers:I(e.token||this.config.token)});if(!o.body.installed_version)return null;s=o.body.installed_version.split(".").slice(0,3).map(a=>parseInt(a,10)),this._enterpriseVersionsCache[t]=s}return s}getEnterpriseAvatarUrlIfNeeded(e,t,s){let o=s.baseUrl||this.config.baseUrl;return!o||o.startsWith(ge)?e:t?`https://avatars.githubusercontent.com/u/e?email=${encodeURIComponent(t)}`:""}async getCurrentUser(e={},t={}){var u;if(e.fields&&!e.fields.length)throw new Error('"fields" must contain at least one field or be omitted');let s=pt(e.fields),o=await this.getScopes(t),a=await b(this.config,{query:`
243
243
  query getCurrentUser {
244
244
  viewer {
245
- ${U(!1,x(o),n)}
245
+ ${L(!1,k(o),s)}
246
246
  }
247
247
  }
248
- `},t)).body.data)==null?void 0:u.viewer;if(!i)throw new Error("Current user not found.");return{data:$(i,n)}}async getAccountsForRepo(e,t={}){var l,p,d,c,g,m;let n=await this.getScopes(t),{repo:{namespace:o,name:a},cursor:i}=e,u=await R(this.config,{query:`
248
+ `},t),i=(u=a.body.data)==null?void 0:u.viewer;if(!i)throw new R("Current user not found.",a.body.errors);return{data:A(i,s)}}async getAccountsForRepo(e,t={}){var l,p,d,c,g;let s=await this.getScopes(t),{repo:{namespace:o,name:a},cursor:i}=e,u=await b(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
- ${U(!1,x(n))}
253
+ ${L(!1,k(s))}
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:a,cursor:i,first:q}},t);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=>$(h)))??[]}}async getUserForCommit(e,t={}){var i,u;let o=(i=(await R(this.config,{query:`
262
+ `,variables:{owner:o,name:a,cursor:i,first:E}},t);if(!u.body.data)throw new R("Could not fetch accounts for repo",u.body.errors);return{pageInfo:((p=(l=u.body.data.repository)==null?void 0:l.assignableUsers)==null?void 0:p.pageInfo)??{endCursor:null,hasNextPage:!1},data:((g=(c=(d=u.body.data.repository)==null?void 0:d.assignableUsers)==null?void 0:c.nodes)==null?void 0:g.map(m=>A(m)))??[]}}async getUserForCommit(e,t={}){var i,u;let s=await b(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:e.repo.namespace,name:e.repo.name,oid:e.oid,avatarSize:e.avatarSize}},t)).body.data)==null?void 0:i.repository;if(!o)throw new Error("Repository not found.");let a=(u=o.object)==null?void 0:u.author;if(!a)throw new Error("Commit not found.");return{data:{name:a.name,email:a.email,avatarUrl:this.getEnterpriseAvatarUrlIfNeeded(a.avatarUrl,a.email,t)}}}async createCommit(e,t={}){var p;let{commitMessage:n,deletedFiles:o,newOrModifiedFiles:a,repo:i,target:u}=e,l=await R(this.config,{query:`
281
+ `,variables:{owner:e.repo.namespace,name:e.repo.name,oid:e.oid,avatarSize:e.avatarSize}},t),o=(i=s.body.data)==null?void 0:i.repository;if(!o)throw new R("Repository not found.",s.body.errors);let a=(u=o.object)==null?void 0:u.author;if(!a)throw new R("Commit not found.",s.body.errors);return{data:{name:a.name,email:a.email,avatarUrl:this.getEnterpriseAvatarUrlIfNeeded(a.avatarUrl,a.email,t)}}}async createCommit(e,t={}){let{commitMessage:s,deletedFiles:o,newOrModifiedFiles:a,repo:i,target:u}=e,l=await b(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(a).map(([d,c])=>({contents:St.Base64.encode(c),path:d})),deletions:o.map(d=>({path:d}))},message:{body:n.description,headline:n.summary},repositoryNameWithOwner:`${i.namespace}/${i.name}`}},t);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(e,t={}){var i,u,l;let n=await this.getScopes(t),a=(l=(u=(i=(await R(this.config,{query:`
308
+ `,variables:{branchName:u.name,expectedHeadOid:u.oid,fileChanges:{additions:Object.entries(a).map(([p,d])=>({contents:vt.Base64.encode(d),path:p})),deletions:o.map(p=>({path:p}))},message:{body:s.description,headline:s.summary},repositoryNameWithOwner:`${i.namespace}/${i.name}`}},t);if(!l.body.data)throw new R("Could not create commit",l.body.errors);return{data:{name:l.body.data.createCommitOnBranch.ref.name,commit:{authoredDate:new Date(l.body.data.createCommitOnBranch.commit.authoredDate),committedDate:new Date(l.body.data.createCommitOnBranch.commit.committedDate),oid:l.body.data.createCommitOnBranch.commit.oid}}}}async getAccountForEmail(e,t={}){var i,u,l;let s=await this.getScopes(t),o=await b(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
- ${U(!0,x(n))}
313
+ ${L(!0,k(s))}
314
314
  }
315
315
  }
316
316
  }
317
317
  }
318
- `,variables:{query:`in:email ${e.email}`,avatarSize:e.avatarSize}},t)).body.data)==null?void 0:i.search)==null?void 0:u.nodes)==null?void 0:l[0];if(!a)throw new Error("User not found.");return{data:$({...a,avatarUrl:this.getEnterpriseAvatarUrlIfNeeded(a.avatarUrl,a.email,t)})}}async getAccountForUsername(e,t={}){var i;let n=await this.getScopes(t),a=(i=(await R(this.config,{query:`
318
+ `,variables:{query:`in:email ${e.email}`,avatarSize:e.avatarSize}},t),a=(l=(u=(i=o.body.data)==null?void 0:i.search)==null?void 0:u.nodes)==null?void 0:l[0];if(!a)throw new R("Could not find user via email",o.body.errors);return{data:A({...a,avatarUrl:this.getEnterpriseAvatarUrlIfNeeded(a.avatarUrl,a.email,t)})}}async getAccountForUsername(e,t={}){var i;let s=await this.getScopes(t),o=await b(this.config,{query:`
319
319
  query getUserForUsername($login: String! $avatarSize: Int) {
320
320
  user(login: $login) {
321
- ${U(!0,x(n))}
321
+ ${L(!0,k(s))}
322
322
  }
323
323
  }
324
- `,variables:{login:e.username,avatarSize:e.avatarSize}},t)).body.data)==null?void 0:i.user;if(!a)throw new Error("User not found.");return{data:$({...a,avatarUrl:this.getEnterpriseAvatarUrlIfNeeded(a.avatarUrl,a.email,t)})}}async getOrgsForCurrentUser(e={},t={}){var a;let n=await R(this.config,{query:`
324
+ `,variables:{login:e.username,avatarSize:e.avatarSize}},t),a=(i=o.body.data)==null?void 0:i.user;if(!a)throw new R("Could not find user via username",o.body.errors);return{data:A({...a,avatarUrl:this.getEnterpriseAvatarUrlIfNeeded(a.avatarUrl,a.email,t)})}}async getOrgsForCurrentUser(e={},t={}){let s=await b(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:e.cursor,first:q}},t);if(!n.body.data)throw new Error(((a=n.body.errors)==null?void 0:a[0].message)||n.statusText||"Unknown error");let o=n.body.data.viewer.organizations.nodes||[];return{pageInfo:n.body.data.viewer.organizations.pageInfo,data:o.map(i=>({id:i.databaseId.toString(),graphQLId:i.id,username:i.login,name:i.name||null,email:i.email||null,avatarUrl:i.avatarUrl}))}}async getOrgMembers(e,t={}){var a,i,u;let n=await R(this.config,{query:`
343
+ `,variables:{cursor:e.cursor,first:E}},t);if(!s.body.data)throw new R("Could not fetch orgs for current user",s.body.errors);let o=s.body.data.viewer.organizations.nodes||[];return{pageInfo:s.body.data.viewer.organizations.pageInfo,data:o.map(a=>({id:a.databaseId.toString(),graphQLId:a.id,username:a.login,name:a.name||null,email:a.email||null,avatarUrl:a.avatarUrl}))}}async getOrgMembers(e,t={}){var a,i,u,l,p,d,c,g,m;let s=await b(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
- ${U(!1,!0)}
353
+ ${L(!1,!0)}
354
354
  }
355
355
  }
356
356
  }
357
357
  }
358
358
  }
359
- `,variables:{cursor:e.cursor,first:q,login:e.org}},t);if(!n.body.data)throw new Error(((a=n.body.errors)==null?void 0:a[0].message)||n.statusText||"Unknown error");if(!((u=(i=n.body.data)==null?void 0:i.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=>$({...l,avatarUrl:this.getEnterpriseAvatarUrlIfNeeded(l.avatarUrl,l.email,t)}))}}async getRepo(e,t={}){var o;let n=await R(this.config,{query:`
359
+ `,variables:{cursor:e.cursor,first:E,login:e.org}},t);if(!((i=(a=s.body.data)==null?void 0:a.viewer.organization)!=null&&i.membersWithRole)&&((u=s.body.errors)!=null&&u.length))throw new R("Could not read the members of the organization",s.body.errors);let o=((p=(l=s.body.data)==null?void 0:l.viewer.organization)==null?void 0:p.membersWithRole.nodes)||[];return{pageInfo:{hasNextPage:((c=(d=s.body.data)==null?void 0:d.viewer.organization)==null?void 0:c.membersWithRole.pageInfo.hasNextPage)??!1,endCursor:((m=(g=s.body.data)==null?void 0:g.viewer.organization)==null?void 0:m.membersWithRole.pageInfo.endCursor)??null},data:o.map(h=>A({...h,avatarUrl:this.getEnterpriseAvatarUrlIfNeeded(h.avatarUrl,h.email,t)}))}}async getRepo(e,t={}){var o;let s=await b(this.config,{query:`
360
360
  query getRepo($owner: String!, $name: String!) {
361
361
  repository(owner: $owner, name: $name) {
362
- ${Ne}
362
+ ${Fe}
363
363
  }
364
364
  }
365
- `,variables:{owner:e.namespace,name:e.name}},t);if(!((o=n.body.data)!=null&&o.repository))throw new Error(`Repository ${e.namespace}/${e.name} not found`);return{data:Fe(n.body.data.repository)}}async getRepos(e,t={}){let n=e.map(({namespace:u,name:l},p)=>`
365
+ `,variables:{owner:e.namespace,name:e.name}},t);if(!((o=s.body.data)!=null&&o.repository))throw new R(`Repository ${e.namespace}/${e.name} not found`,s.body.errors);return{data:Qe(s.body.data.repository)}}async getRepos(e,t={}){let s=e.map(({namespace:u,name:l},p)=>`
366
366
  getRepo_${p}: repository(owner: "${u}", name: "${l}") {
367
- ${Ne}
367
+ ${Fe}
368
368
  }
369
369
  `).join(`
370
- `),o=await R(this.config,{query:`
370
+ `),o=await b(this.config,{query:`
371
371
  query batchGetRepos {
372
- ${n}
372
+ ${s}
373
373
  }
374
- `},t);if(!o.body.data)throw new Error(o.statusText||"Unknown error");let a=[],i=[];return e.forEach((u,l)=>{let p=o.body.data[`getRepo_${l}`];p?a.push(Fe(p)):i.push({input:u})}),{data:a,errors:i}}async fetchMultipleRESTPages(e,t,n,o){let a=[];for(let d=0;d<t;d++)a.push(n(e+d));let i=await Promise.all(a),u=[];for(let d of i){if(!d.body)throw new Error(d.statusText||"Unknown error");u=u.concat(d.body.map(c=>o(c)))}let l=i.every(d=>d.body.length===100),p=e+t;return{data:u,pageInfo:{hasNextPage:l,nextPage:l?p:null}}}async getReposForCurrentUser(e,t={}){if(e.simultaneousPagesToFetch&&e.simultaneousPagesToFetch>40)throw new Error("The argument 'simultaneousPagesToFetch' cannot exceed 40 for 'getReposForCurrentUser'");let n=new URLSearchParams;n.append("per_page","100"),e.affiliations&&n.append("affiliation",e.affiliations.join(","));let o=a=>this.config.request({url:`${re(this.config,t)}/user/repos?${n.toString()}&page=${a}`,headers:{...I(t.token||this.config.token),Accept:"application/vnd.github.raw+json"}});return await this.fetchMultipleRESTPages(e.page??1,e.simultaneousPagesToFetch??4,o,Pt)}async getReposForOrg(e,t={}){if(e.simultaneousPagesToFetch&&e.simultaneousPagesToFetch>40)throw new Error("The argument 'simultaneousPagesToFetch' cannot exceed 40 for 'getReposForOrg'");let n=o=>this.config.request({url:`${re(this.config,t)}/orgs/${e.orgName}/repos?per_page=100&page=${o}`,headers:{...I(t.token||this.config.token),Accept:"application/vnd.github.raw+json"}});return await this.fetchMultipleRESTPages(e.page??1,e.simultaneousPagesToFetch??4,n,Pt)}async getReposForUsernames(e,t={}){var a;if(!e.usernames.length)return{pageInfo:{endCursor:null,hasNextPage:!1},data:[]};let n=await R(this.config,{query:`
374
+ `},t);if(!o.body.data)throw new R("Could not fetch repos",o.body.errors);let a=[],i=[];return e.forEach((u,l)=>{let p=o.body.data[`getRepo_${l}`];p?a.push(Qe(p)):i.push({input:u})}),{data:a,errors:i}}async fetchMultipleRESTPages(e,t,s,o){let a=[];for(let d=0;d<t;d++)a.push(s(e+d));let i=await Promise.all(a),u=[];for(let d of i){if(!d.body)throw new Error(d.statusText||"Unknown error");u=u.concat(d.body.map(c=>o(c)))}let l=i.every(d=>d.body.length===100),p=e+t;return{data:u,pageInfo:{hasNextPage:l,nextPage:l?p:null}}}async getReposForCurrentUser(e,t={}){if(e.simultaneousPagesToFetch&&e.simultaneousPagesToFetch>40)throw new Error("The argument 'simultaneousPagesToFetch' cannot exceed 40 for 'getReposForCurrentUser'");let s=new URLSearchParams;s.append("per_page","100"),e.affiliations&&s.append("affiliation",e.affiliations.join(","));let o=a=>this.config.request({url:`${se(this.config,t)}/user/repos?${s.toString()}&page=${a}`,headers:{...I(t.token||this.config.token),Accept:"application/vnd.github.raw+json","X-Github-Next-Global-ID":1}});return await this.fetchMultipleRESTPages(e.page??1,e.simultaneousPagesToFetch??4,o,St)}async getReposForOrg(e,t={}){if(e.simultaneousPagesToFetch&&e.simultaneousPagesToFetch>40)throw new Error("The argument 'simultaneousPagesToFetch' cannot exceed 40 for 'getReposForOrg'");let s=o=>this.config.request({url:`${se(this.config,t)}/orgs/${e.orgName}/repos?per_page=100&page=${o}`,headers:{...I(t.token||this.config.token),Accept:"application/vnd.github.raw+json","X-Github-Next-Global-ID":1}});return await this.fetchMultipleRESTPages(e.page??1,e.simultaneousPagesToFetch??4,s,St)}async getReposForUsernames(e,t={}){if(!e.usernames.length)return{pageInfo:{endCursor:null,hasNextPage:!1},data:[]};let s=await b(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
- ${Ne}
383
+ ${Fe}
384
384
  }
385
385
  }
386
386
  }
387
387
  }
388
- `,variables:{query:`fork:true ${e.usernames.map(i=>`user:${i}`).join(" ")}`,cursor:e.cursor,first:q}},t);if(!n.body.data)throw new Error(((a=n.body.errors)==null?void 0:a[0].message)||n.statusText||"Unknown error");let o=n.body.data.search.nodes||[];return{pageInfo:n.body.data.search.pageInfo,data:o.map(Fe)}}async getReposForOwners(e,t={}){return this.getReposForUsernames({usernames:e.owners.filter(n=>n.username).map(n=>n.username),cursor:e.cursor},t)}async getRefs(e,t,n={}){var u;let a=(u=(await R(this.config,{query:`
388
+ `,variables:{query:`fork:true ${e.usernames.map(a=>`user:${a}`).join(" ")}`,cursor:e.cursor,first:E}},t);if(!s.body.data)throw new R("Could not fetch repos for usernames",s.body.errors);let o=s.body.data.search.nodes||[];return{pageInfo:s.body.data.search.pageInfo,data:o.map(Qe)}}async getReposForOwners(e,t={}){return this.getReposForUsernames({usernames:e.owners.filter(s=>s.username).map(s=>s.username),cursor:e.cursor},t)}async getRefs(e,t,s={}){var u;let o=await b(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:t.repo.namespace,name:t.repo.name,refPrefix:e,cursor:t.cursor,first:q}},n)).body.data)==null?void 0:u.repository;if(!a)throw new Error("Repository not found.");let i=a.refs;return i?{pageInfo:i.pageInfo,data:(i.nodes||[]).map(l=>{var d;let p=(d=l.target)!=null&&d.oid?l.target:null;return{name:l.name,commit:p?{oid:p.oid,authoredDate:new Date(p.authoredDate),committedDate:new Date(p.committedDate)}:null}})}:{pageInfo:{endCursor:null,hasNextPage:!1},data:[]}}async getBranches(e,t={}){return this.getRefs("refs/heads/",e,t)}async getTags(e,t={}){return this.getRefs("refs/tags/",e,t)}async getBlame(e,t={}){var i;let o=(i=(await R(this.config,{query:`
409
+ `,variables:{owner:t.repo.namespace,name:t.repo.name,refPrefix:e,cursor:t.cursor,first:E}},s),a=(u=o.body.data)==null?void 0:u.repository;if(!a)throw new R("Ref repository not found.",o.body.errors);let i=a.refs;return i?{pageInfo:i.pageInfo,data:(i.nodes||[]).map(l=>{var d;let p=(d=l.target)!=null&&d.oid?l.target:null;return{name:l.name,commit:p?{oid:p.oid,authoredDate:new Date(p.authoredDate),committedDate:new Date(p.committedDate)}:null}})}:{pageInfo:{endCursor:null,hasNextPage:!1},data:[]}}async getBranches(e,t={}){return this.getRefs("refs/heads/",e,t)}async getTags(e,t={}){return this.getRefs("refs/tags/",e,t)}async getBlame(e,t={}){var i;let s=await b(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:e.repo.namespace,name:e.repo.name,ref:e.ref,path:e.path}},t)).body.data)==null?void 0:i.repository;if(!o)throw new Error("Repository not found.");let a=o.object;if(!a||!("blame"in a))throw new Error("Ref not found.");if(a.blame.ranges.length===0)throw new Error("File not found.");return{data:{ranges:a.blame.ranges.map(u=>{var l;return{startingLine:u.startingLine,endingLine:u.endingLine,commit:{oid:u.commit.oid,parentOids:((l=u.commit.parents.nodes)==null?void 0:l.map(p=>p.oid))||[],authoredDate:new Date(u.commit.authoredDate),author:u.commit.author?{name:u.commit.author.name,email:u.commit.author.email,avatarUrl:u.commit.author.avatarUrl}:null,committedDate:new Date(u.commit.committedDate),committer:u.commit.committer?{name:u.commit.committer.name,email:u.commit.committer.email,avatarUrl:u.commit.committer.avatarUrl}:null,message:u.commit.message,fileCount:u.commit.changedFilesIfAvailable,additions:u.commit.additions,deletions:u.commit.deletions}}})}}}async getFileContents(e,t={}){let n=await this.config.request({url:`${re(this.config,t)}/repos/${e.repo.namespace}/${e.repo.name}/contents/${encodeURIComponent(e.path)}?ref=${e.ref}`,headers:{...I(t.token||this.config.token),Accept:"application/vnd.github.raw+json"}});if(n.headers["content-type"].startsWith("application/json"))throw new Error(`GitHub: got directory when fetching "${e.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 "${e.path}"`);return{data:new Blob([n.body])}}async searchPullRequests(e,t={}){var p,d;let n=await this.getEnterpriseVersion(t),o=await this.getScopes(t),a=x(o),i=c=>{let g=c&&typeof e.isDraft=="boolean"?`${e.query} draft:${e.isDraft}`:e.query;return ke("pr",g,e.cursor,{maxPageSize:e.maxPageSize??It,supportsEmail:a,supportsDrafts:c,enterpriseVersion:n,includeFromArchivedRepos:e.includeFromArchivedRepos})},u=await R(this.config,i(!0),t);u.body.errors&&fe(u.body.errors)&&(this.config.baseUrl||t.baseUrl)&&(u=await R(this.config,i(!1),t));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(E).map(Qe))||[]}}async searchIssues(e,t={}){var u,l;let n=await this.getScopes(t),o=x(n),a=await R(this.config,ke("issue",e.query,e.cursor,{supportsEmail:o,includeFromArchivedRepos:e.includeFromArchivedRepos,maxPageSize:e.maxPageSize??Rt}),t),{data:i}=a.body;if(!i)throw new Error(((u=a.body.errors)==null?void 0:u[0].message)||a.statusText||"Unknown error");return{pageInfo:{hasNextPage:i.search.pageInfo.hasNextPage,endCursor:i.search.pageInfo.endCursor},data:((l=i.search.nodes)==null?void 0:l.filter(E).map(br))||[]}}async getPullRequestsAssociatedWithUser(e,t={}){let n=[`involves:${e.username}`];return e.labelNames&&e.labelNames.forEach(o=>{n.push(`label:"${o}"`)}),this.searchPullRequests({query:n.join(" "),cursor:e.cursor,includeFromArchivedRepos:e.includeFromArchivedRepos,maxPageSize:e.maxPageSize},t)}async getPullRequestsForRepos(e,t={}){let{assigneeLogins:n,updatedBefore:o,authorLogin:a,repos:i,reviewRequestedLogin:u,startQuery:l,mentionLogin:p,labelNames:d,maxPageSize:c}=e,g=xe(l||"");return i.forEach(m=>{g.push(`repo:${m.namespace}/${m.name}`)}),n&&n.forEach(m=>{g.push(`assignee:${m}`)}),o&&g.push(`updated:<${o}`),a&&g.push(`author:${a}`),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:e.isDraft,cursor:e.cursor,includeFromArchivedRepos:e.includeFromArchivedRepos,maxPageSize:c},t)}async getPullRequestForRepo(e,t={}){var d,c;let n=await this.getEnterpriseVersion(t),o=await this.getScopes(t),a=x(o),i=g=>({query:`query getPullRequest(
448
+ `,variables:{owner:e.repo.namespace,name:e.repo.name,ref:e.ref,path:e.path}},t),o=(i=s.body.data)==null?void 0:i.repository;if(!o)throw new R("Blame repository not found.",s.body.errors);let a=o.object;if(!a||!("blame"in a))throw new R("Ref not found.",s.body.errors);if(a.blame.ranges.length===0)throw new R("File not found.",s.body.errors);return{data:{ranges:a.blame.ranges.map(u=>{var l;return{startingLine:u.startingLine,endingLine:u.endingLine,commit:{oid:u.commit.oid,parentOids:((l=u.commit.parents.nodes)==null?void 0:l.map(p=>p.oid))||[],authoredDate:new Date(u.commit.authoredDate),author:u.commit.author?{name:u.commit.author.name,email:u.commit.author.email,avatarUrl:u.commit.author.avatarUrl}:null,committedDate:new Date(u.commit.committedDate),committer:u.commit.committer?{name:u.commit.committer.name,email:u.commit.committer.email,avatarUrl:u.commit.committer.avatarUrl}:null,message:u.commit.message,fileCount:u.commit.changedFilesIfAvailable,additions:u.commit.additions,deletions:u.commit.deletions}}})}}}async getFileContents(e,t={}){let s=await this.config.request({url:`${se(this.config,t)}/repos/${e.repo.namespace}/${e.repo.name}/contents/${encodeURIComponent(e.path)}?ref=${e.ref}`,headers:{...I(t.token||this.config.token),Accept:"application/vnd.github.raw+json"}});if(s.headers["content-type"].startsWith("application/json"))throw new Error(`GitHub: got directory when fetching "${e.path}", getFileContents does not support fetching directories`);if(!s.headers["content-type"].startsWith("application/vnd.github.raw+json"))throw new Error(`GitHub: unsupported content type "${s.headers["content-type"]}" when fetching "${e.path}"`);return{data:new Blob([s.body])}}async searchPullRequests(e,t={}){var p;let s=await this.getEnterpriseVersion(t),o=await this.getScopes(t),a=k(o),i=d=>{let c=d&&typeof e.isDraft=="boolean"?`${e.query} draft:${e.isDraft}`:e.query;return Ne("pr",c,e.cursor,{maxPageSize:e.maxPageSize??Rt,supportsEmail:a,supportsDrafts:d,enterpriseVersion:s,includeFromArchivedRepos:e.includeFromArchivedRepos})},u=await b(this.config,i(!0),t);u.body.errors&&Ie(u.body.errors)&&(this.config.baseUrl||t.baseUrl)&&(u=await b(this.config,i(!1),t));let{data:l}=u.body;if(!l)throw new R("Could not search pull requests",u.body.errors);return{pageInfo:{hasNextPage:l.search.pageInfo.hasNextPage,endCursor:l.search.pageInfo.endCursor},data:((p=l.search.nodes)==null?void 0:p.filter(C).map(_e))||[]}}async searchIssues(e,t={}){var u;let s=await this.getScopes(t),o=k(s),a=await b(this.config,Ne("issue",e.query,e.cursor,{supportsEmail:o,includeFromArchivedRepos:e.includeFromArchivedRepos,maxPageSize:e.maxPageSize??bt}),t),{data:i}=a.body;if(!i)throw new R("Could not search issues",a.body.errors);return{pageInfo:{hasNextPage:i.search.pageInfo.hasNextPage,endCursor:i.search.pageInfo.endCursor},data:((u=i.search.nodes)==null?void 0:u.filter(C).map(yr))||[]}}async getPullRequestsAssociatedWithUser(e,t={}){let s=[`involves:${e.username}`];return e.labelNames&&e.labelNames.forEach(o=>{s.push(`label:"${o}"`)}),this.searchPullRequests({query:s.join(" "),cursor:e.cursor,includeFromArchivedRepos:e.includeFromArchivedRepos,maxPageSize:e.maxPageSize},t)}async getPullRequestsForRepos(e,t={}){let{assigneeLogins:s,updatedBefore:o,authorLogin:a,repos:i,reviewRequestedLogin:u,startQuery:l,mentionLogin:p,labelNames:d,maxPageSize:c}=e,g=ke(l||"");return i.forEach(m=>{g.push(`repo:${m.namespace}/${m.name}`)}),s&&s.forEach(m=>{g.push(`assignee:${m}`)}),o&&g.push(`updated:<${o}`),a&&g.push(`author:${a}`),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:e.isDraft,cursor:e.cursor,includeFromArchivedRepos:e.includeFromArchivedRepos,maxPageSize:c},t)}async getPullRequestForRepo(e,t={}){var d;let s=await this.getEnterpriseVersion(t),o=await this.getScopes(t),a=k(o),i=c=>({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
- ${he(g,a,n)}
458
+ ${fe(c,a,s)}
459
459
  }
460
460
  }
461
- }`,variables:{owner:e.repo.namespace,name:e.repo.name,number:e.number}}),u=await R(this.config,i(!0),t);u.body.errors&&fe(u.body.errors)&&(this.config.baseUrl||t.baseUrl)&&(u=await R(this.config,i(!1),t));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?Qe(p):null}}async getPullRequestByGraphQLId(e,t={}){var d,c;let n=await this.getEnterpriseVersion(t),o=await this.getScopes(t),a=x(o),i=g=>({query:`query getPullRequest(
461
+ }`,variables:{owner:e.repo.namespace,name:e.repo.name,number:e.number}}),u=await b(this.config,i(!0),t);u.body.errors&&Ie(u.body.errors)&&(this.config.baseUrl||t.baseUrl)&&(u=await b(this.config,i(!1),t));let{data:l}=u.body;if(!l)throw new R("Could not fetch pull request by number",u.body.errors);let p=(d=u.body.data)==null?void 0:d.repository.pullRequest;return{data:p?_e(p):null}}async getPullRequestByGraphQLId(e,t={}){var d;let s=await this.getEnterpriseVersion(t),o=await this.getScopes(t),a=k(o),i=c=>({query:`query getPullRequest(
462
462
  $graphQLId: ID!
463
463
  ) {
464
464
  node(id: $graphQLId) {
465
465
  ... on PullRequest {
466
- ${he(g,a,n)}
466
+ ${fe(c,a,s)}
467
467
  }
468
468
  }
469
- }`,variables:{graphQLId:e.graphQLId}}),u=await R(this.config,i(!0),t);u.body.errors&&fe(u.body.errors)&&(this.config.baseUrl||t.baseUrl)&&(u=await R(this.config,i(!1),t));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?Qe(p):null}}async closePullRequest(e,t={}){var i,u,l;let{pullRequest:{graphQLId:n}}=e;if(!n)throw new Error('GitHub requires "graphQLId" for this function.');let o=`mutation ClosePullRequest($pullRequestGraphQLId: ID!) {
469
+ }`,variables:{graphQLId:e.graphQLId}}),u=await b(this.config,i(!0),t);u.body.errors&&Ie(u.body.errors)&&(this.config.baseUrl||t.baseUrl)&&(u=await b(this.config,i(!1),t));let{data:l}=u.body;if(!l)throw new R("Could not fetch pull request by id",u.body.errors);let p=(d=u.body.data)==null?void 0:d.node;return{data:p?_e(p):null}}async closePullRequest(e,t={}){var i,u,l;let{pullRequest:{graphQLId:s}}=e;if(!s)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=(i=(await R(this.config,{query:`${o}`,variables:{pullRequestGraphQLId:n}},t)).body.data)==null?void 0:i.closePullRequest)==null?void 0:u.pullRequest)!=null&&l.id))throw new Error("Could not close pull request")}async mergePullRequest(e,t={}){var l,p,d,c;let{pullRequest:n,mergeStrategy:o}=e;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 a;switch(o){case"MERGE_COMMIT":{a="MERGE";break}case"REBASE":{a="REBASE";break}case"SQUASH":{a="SQUASH";break}}let i=`mutation MergePullRequest(
475
+ }`,a=await b(this.config,{query:`${o}`,variables:{pullRequestGraphQLId:s}},t);if(!((l=(u=(i=a.body.data)==null?void 0:i.closePullRequest)==null?void 0:u.pullRequest)!=null&&l.id))throw new R("Could not close pull request",a.body.errors)}async mergePullRequest(e,t={}){var l,p,d,c;let{pullRequest:s,mergeStrategy:o}=e;if(!s.graphQLId)throw new Error('GitHub requires "graphQLId" for this function.');if(!((l=s.headRef)!=null&&l.oid))throw new Error('GitHub requires "headRef.oid" for this function.');let a;switch(o){case"MERGE_COMMIT":{a="MERGE";break}case"REBASE":{a="REBASE";break}case"SQUASH":{a="SQUASH";break}}let i=`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:`${i}`,variables:{pullRequestGraphQLId:n.graphQLId,expectedSourceSha:n.headRef.oid,mergeStrategy:a}},t)).body.data)==null?void 0:p.mergePullRequest)==null?void 0:d.pullRequest)!=null&&c.id))throw new Error("Could not merge pull request")}async setPullRequestMilestone(e,t={}){var u,l,p;let{pullRequest:n,milestone:o}=e;if(!n.graphQLId)throw new Error('GitHub requires "graphQLId" for this function.');let a=`mutation SetPullRequestMilestone($pullRequestGraphQLId: ID!, $milestoneGraphQLId: ID) {
489
+ }`,u=await b(this.config,{query:`${i}`,variables:{pullRequestGraphQLId:s.graphQLId,expectedSourceSha:s.headRef.oid,mergeStrategy:a}},t);if(!((c=(d=(p=u.body.data)==null?void 0:p.mergePullRequest)==null?void 0:d.pullRequest)!=null&&c.id))throw new R("Could not merge pull request",u.body.errors)}async setPullRequestMilestone(e,t={}){var u,l,p;let{pullRequest:s,milestone:o}=e;if(!s.graphQLId)throw new Error('GitHub requires "graphQLId" for this function.');let a=`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:`${a}`,variables:{pullRequestGraphQLId:n.graphQLId,milestoneGraphQLId:(o==null?void 0:o.graphQLId)??null}},t)).body.data)==null?void 0:u.updatePullRequest)==null?void 0:l.pullRequest)!=null&&p.id))throw new Error("Could not set milestone of pull request")}async markPullRequestReadyForReview(e,t){var a,i,u;let n=`mutation MarkReadyToReview($pullRequestGraphQLId: ID!) {
495
+ }`,i=await b(this.config,{query:`${a}`,variables:{pullRequestGraphQLId:s.graphQLId,milestoneGraphQLId:(o==null?void 0:o.graphQLId)??null}},t);if(!((p=(l=(u=i.body.data)==null?void 0:u.updatePullRequest)==null?void 0:l.pullRequest)!=null&&p.id))throw new R("Could not set milestone of pull request",i.body.errors)}async markPullRequestReadyForReview(e,t){var a,i,u;let s=`mutation MarkReadyToReview($pullRequestGraphQLId: ID!) {
496
496
  markPullRequestReadyForReview(input: { pullRequestId: $pullRequestGraphQLId }) {
497
497
  pullRequest {
498
498
  id
499
499
  }
500
500
  }
501
- }`;if(!((u=(i=(a=(await R(this.config,{query:n,variables:{pullRequestGraphQLId:e}},t)).body.data)==null?void 0:a.markPullRequestReadyForReview)==null?void 0:i.pullRequest)!=null&&u.id))throw new Error("Could not mark pull request ready to review")}async convertPullRequestToDraft(e,t){var a,i,u;let n=`mutation ConvertToDraft($pullRequestGraphQLId: ID!) {
501
+ }`,o=await b(this.config,{query:s,variables:{pullRequestGraphQLId:e}},t);if(!((u=(i=(a=o.body.data)==null?void 0:a.markPullRequestReadyForReview)==null?void 0:i.pullRequest)!=null&&u.id))throw new R("Could not mark pull request ready to review",o.body.errors)}async convertPullRequestToDraft(e,t){var a,i,u;let s=`mutation ConvertToDraft($pullRequestGraphQLId: ID!) {
502
502
  convertPullRequestToDraft(input: { pullRequestId: $pullRequestGraphQLId }) {
503
503
  pullRequest {
504
504
  id
505
505
  }
506
506
  }
507
- }`;if(!((u=(i=(a=(await R(this.config,{query:n,variables:{pullRequestGraphQLId:e}},t)).body.data)==null?void 0:a.convertPullRequestToDraft)==null?void 0:i.pullRequest)!=null&&u.id))throw new Error("Could not convert pull request to draft")}async setPullRequestAsDraft(e,t={}){let{pullRequest:{graphQLId:n},isDraft:o}=e;if(!n)throw new Error('GitHub requires "graphQLId" for this function.');if(o){await this.convertPullRequestToDraft(n,t);return}await this.markPullRequestReadyForReview(n,t)}async setPullRequestReviewers(e,t={}){var d,c,g;let{pullRequest:{reviews:n,graphQLId:o},reviewers:a}=e;if(!n)throw new Error('GitHub requires "reviews" for this function');if(!o)throw new Error('GitHub requires "graphQLId" for this function.');let i=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=a.map(m=>{if(!m.graphQLId)throw new Error('GitHub requires reviewer "graphQLId" for this function.');return m.graphQLId}).filter(m=>i.indexOf(m)===-1),l=`mutation SetPullRequestReviewers($pullRequestGraphQLId: ID!, $reviewerGraphQLIds: [ID!]!) {
507
+ }`,o=await b(this.config,{query:s,variables:{pullRequestGraphQLId:e}},t);if(!((u=(i=(a=o.body.data)==null?void 0:a.convertPullRequestToDraft)==null?void 0:i.pullRequest)!=null&&u.id))throw new R("Could not convert pull request to draft",o.body.errors)}async setPullRequestAsDraft(e,t={}){let{pullRequest:{graphQLId:s},isDraft:o}=e;if(!s)throw new Error('GitHub requires "graphQLId" for this function.');if(o){await this.convertPullRequestToDraft(s,t);return}await this.markPullRequestReadyForReview(s,t)}async setPullRequestReviewers(e,t={}){var d,c,g;let{pullRequest:{reviews:s,graphQLId:o},reviewers:a}=e;if(!s)throw new Error('GitHub requires "reviews" for this function');if(!o)throw new Error('GitHub requires "graphQLId" for this function.');let i=s.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=a.map(m=>{if(!m.graphQLId)throw new Error('GitHub requires reviewer "graphQLId" for this function.');return m.graphQLId}).filter(m=>i.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}},t)).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(e,t={}){var p,d,c;let{pullRequest:{reviews:n,graphQLId:o},reviewers:a}=e;if(!o)throw new Error('GitHub requires "graphQLId" for this function.');if(!n)throw new Error('GitHub requires "reviews" for this function.');let i=[];for(let g of a){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.");i.push(g.graphQLId)}let u=`mutation SetPullRequestReviewers($pullRequestGraphQLId: ID!, $reviewerGraphQLIds: [ID!]!) {
513
+ }`,p=await b(this.config,{query:l,variables:{pullRequestGraphQLId:o,reviewerGraphQLIds:u}},t);if(!((g=(c=(d=p.body.data)==null?void 0:d.requestReviews)==null?void 0:c.pullRequest)!=null&&g.id))throw new R("Could not set pull request reviewers",p.body.errors)}async reRequestPullRequestReviews(e,t={}){var p,d,c;let{pullRequest:{reviews:s,graphQLId:o},reviewers:a}=e;if(!o)throw new Error('GitHub requires "graphQLId" for this function.');if(!s)throw new Error('GitHub requires "reviews" for this function.');let i=[];for(let g of a){if(!g.graphQLId)throw new Error('GitHub requires reviwer "graphQLId" for this function.');if(!s.find(m=>m.reviewer.graphQLId===g.graphQLId))throw new Error("Can only re-request review from existing reviewer.");i.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:i}},t)).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(e,t={}){var l,p,d;let{pullRequest:n,assignees:o}=e;if(!n.graphQLId)throw new Error('GitHub requires "graphQLId" for this function.');let a=o.map(c=>{if(!c.graphQLId)throw new Error('GitHub requires assignee "graphQLId" for this function.');return c.graphQLId}),i=`mutation SetPullRequestAssignees($pullRequestGraphQLId: ID!, $assigneeGraphQLIds: [ID!]!) {
519
+ }`,l=await b(this.config,{query:u,variables:{pullRequestGraphQLId:o,reviewerGraphQLIds:i}},t);if(!((c=(d=(p=l.body.data)==null?void 0:p.requestReviews)==null?void 0:d.pullRequest)!=null&&c.id))throw new R("Could not re-request pull request reviews",l.body.errors)}async setPullRequestAssignees(e,t={}){var l,p,d;let{pullRequest:s,assignees:o}=e;if(!s.graphQLId)throw new Error('GitHub requires "graphQLId" for this function.');let a=o.map(c=>{if(!c.graphQLId)throw new Error('GitHub requires assignee "graphQLId" for this function.');return c.graphQLId}),i=`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:i,variables:{pullRequestGraphQLId:n.graphQLId,assigneeGraphQLIds:a}},t)).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(e,t={}){var d,c,g,m;let{repo:{namespace:n,name:o},pullRequestId:a}=e,i=`query getPullRequests(
525
+ }`,u=await b(this.config,{query:i,variables:{pullRequestGraphQLId:s.graphQLId,assigneeGraphQLIds:a}},t);if(!((d=(p=(l=u.body.data)==null?void 0:l.updatePullRequest)==null?void 0:p.pullRequest)!=null&&d.id))throw new R("Could not set pull request assignees",u.body.errors)}async getReviewsForPullRequest(e,t={}){var d,c,g,m;let{repo:{namespace:s,name:o},pullRequestId:a}=e,i=`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:i,variables:{namespace:n,name:o,pullRequestId:a}},t),l=((c=(d=u.body.data)==null?void 0:d.repository.pullRequest.reviewThreads.nodes)==null?void 0:c.filter(E).reduce((h,b)=>{var P,O;if(!((O=(P=b.comments.nodes)==null?void 0:P[0])!=null&&O.pullRequestReview))return h;let S=b.comments.nodes[0].pullRequestReview,f=Ir(b);return f&&(h[S.id]||(h[S.id]=[]),h[S.id].push(f)),h},{}))??{};return{data:((m=(g=u.body.data)==null?void 0:g.repository.pullRequest.reviews.nodes)==null?void 0:m.filter(E).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(e,t={}){var c;let[n,o]=((c=e.cursor)==null?void 0:c.split(";"))||[void 0,void 0],a=[];e.labelNames&&e.labelNames.forEach(g=>{a.push(`label:"${g}"`)});let[i,u]=await Promise.all([n==="null"?null:this.searchIssues({query:`author:${e.username} ${a.join(" ")}`,cursor:n,includeFromArchivedRepos:e.includeFromArchivedRepos,maxPageSize:e.maxPageSize},t),o==="null"?null:this.searchIssues({query:`assignee:${e.username} ${a.join(" ")}`,cursor:o,includeFromArchivedRepos:e.includeFromArchivedRepos,maxPageSize:e.maxPageSize},t)]),l={},p=[],d=g=>{l[g.id]||(l[g.id]=!0,p.push(g))};return i==null||i.data.forEach(d),u==null||u.data.forEach(d),{pageInfo:{hasNextPage:(i==null?void 0:i.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"};${(u==null?void 0:u.pageInfo.hasNextPage)&&(u==null?void 0:u.pageInfo.endCursor)||"null"}`},data:p}}async setPullRequestLabels(e,t={}){var u,l,p;let{pullRequest:n,labels:o}=e;if(!n.graphQLId)throw new Error('GitHub requires "graphQLId" for this function.');let a=`mutation SetPullRequestLabels($pullRequestGraphQLId: ID!, $labelGraphQLIds: [ID!]) {
577
+ }`,u=await b(this.config,{query:i,variables:{namespace:s,name:o,pullRequestId:a}},t),l=((c=(d=u.body.data)==null?void 0:d.repository.pullRequest.reviewThreads.nodes)==null?void 0:c.filter(C).reduce((h,y)=>{var S,x;if(!((x=(S=y.comments.nodes)==null?void 0:S[0])!=null&&x.pullRequestReview))return h;let v=y.comments.nodes[0].pullRequestReview,f=Rr(y);return f&&(h[v.id]||(h[v.id]=[]),h[v.id].push(f)),h},{}))??{};return{data:((m=(g=u.body.data)==null?void 0:g.repository.pullRequest.reviews.nodes)==null?void 0:m.filter(C).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(e,t={}){var c;let[s,o]=((c=e.cursor)==null?void 0:c.split(";"))||[void 0,void 0],a=[];e.labelNames&&e.labelNames.forEach(g=>{a.push(`label:"${g}"`)});let[i,u]=await Promise.all([s==="null"?null:this.searchIssues({query:`author:${e.username} ${a.join(" ")}`,cursor:s,includeFromArchivedRepos:e.includeFromArchivedRepos,maxPageSize:e.maxPageSize},t),o==="null"?null:this.searchIssues({query:`assignee:${e.username} ${a.join(" ")}`,cursor:o,includeFromArchivedRepos:e.includeFromArchivedRepos,maxPageSize:e.maxPageSize},t)]),l={},p=[],d=g=>{l[g.id]||(l[g.id]=!0,p.push(g))};return i==null||i.data.forEach(d),u==null||u.data.forEach(d),{pageInfo:{hasNextPage:(i==null?void 0:i.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"};${(u==null?void 0:u.pageInfo.hasNextPage)&&(u==null?void 0:u.pageInfo.endCursor)||"null"}`},data:p}}async setPullRequestLabels(e,t={}){var u,l,p;let{pullRequest:s,labels:o}=e;if(!s.graphQLId)throw new Error('GitHub requires "graphQLId" for this function.');let a=`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:a,variables:{pullRequestGraphQLId:n.graphQLId,labelGraphQLIds:o.map(d=>{if(!d.graphQLId)throw new Error('GitHub requires label "graphQLId" for this function.');return d.graphQLId})}},t)).body.data)==null?void 0:u.updatePullRequest)==null?void 0:l.pullRequest)!=null&&p.id))throw new Error("Could not set pull request labels")}async getIssuesForRepos(e,t={}){let n=xe(e.startQuery||""),{cursor:o,assigneeLogins:a,updatedBefore:i,authorLogin:u,mentionLogin:l,labelNames:p}=e;return e.repos.forEach(d=>{n.push(`repo:${d.namespace}/${d.name}`)}),a&&a.forEach(d=>{n.push(`assignee:${d}`)}),i&&n.push(`updated:<${i}`),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:e.includeFromArchivedRepos,maxPageSize:e.maxPageSize},t)}async closeIssueWithReason(e,t={}){var u,l,p;let{issue:n,reason:o}=e;if(!n.graphQLId)throw new Error('GitHub requires "graphQLId" for this function.');let a=`mutation CloseIssueWithReason($issueGraphQLId: ID!, $reason: IssueClosedStateReason!) {
583
+ }`,i=await b(this.config,{query:a,variables:{pullRequestGraphQLId:s.graphQLId,labelGraphQLIds:o.map(d=>{if(!d.graphQLId)throw new Error('GitHub requires label "graphQLId" for this function.');return d.graphQLId})}},t);if(!((p=(l=(u=i.body.data)==null?void 0:u.updatePullRequest)==null?void 0:l.pullRequest)!=null&&p.id))throw new R("Could not set pull request labels",i.body.errors)}async getIssuesForRepos(e,t={}){let s=ke(e.startQuery||""),{cursor:o,assigneeLogins:a,updatedBefore:i,authorLogin:u,mentionLogin:l,labelNames:p}=e;return e.repos.forEach(d=>{s.push(`repo:${d.namespace}/${d.name}`)}),a&&a.forEach(d=>{s.push(`assignee:${d}`)}),i&&s.push(`updated:<${i}`),u&&s.push(`author:${u}`),l&&s.push(`mentions:${l}`),p&&p.forEach(d=>{s.push(`label:"${d}"`)}),this.searchIssues({query:`sort:updated ${s.join(" ")}`,cursor:o,includeFromArchivedRepos:e.includeFromArchivedRepos,maxPageSize:e.maxPageSize},t)}async closeIssueWithReason(e,t={}){var u,l,p;let{issue:s,reason:o}=e;if(!s.graphQLId)throw new Error('GitHub requires "graphQLId" for this function.');let a=`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:a,variables:{issueGraphQLId:n.graphQLId,reason:o}},t)).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(e,t={}){var i,u,l;let{issue:n}=e;if(!n.graphQLId)throw new Error('GitHub requires "graphQLId" for this function.');let o=`mutation SetIssueState($issueGraphQLId: ID!) {
589
+ }`,i=await b(this.config,{query:a,variables:{issueGraphQLId:s.graphQLId,reason:o}},t);if(!((p=(l=(u=i.body.data)==null?void 0:u.closeIssue)==null?void 0:l.issue)!=null&&p.id))throw new R("Could not close issue with reason",i.body.errors)}async closeIssue(e,t={}){var i,u,l;let{issue:s}=e;if(!s.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=(i=(await R(this.config,{query:o,variables:{issueGraphQLId:n.graphQLId}},t)).body.data)==null?void 0:i.updateIssue)==null?void 0:u.issue)!=null&&l.id))throw new Error("Could not close issue")}async reOpenIssue(e,t={}){var i,u,l;let{issue:n}=e;if(!n.graphQLId)throw new Error('GitHub requires "graphQLId" for this function.');let o=`mutation ReOpenIssue($issueGraphQLId: ID!) {
595
+ }`,a=await b(this.config,{query:o,variables:{issueGraphQLId:s.graphQLId}},t);if(!((l=(u=(i=a.body.data)==null?void 0:i.updateIssue)==null?void 0:u.issue)!=null&&l.id))throw new R("Could not close issue",a.body.errors)}async reOpenIssue(e,t={}){var i,u,l;let{issue:s}=e;if(!s.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=(i=(await R(this.config,{query:o,variables:{issueGraphQLId:n.graphQLId}},t)).body.data)==null?void 0:i.reopenIssue)==null?void 0:u.issue)!=null&&l.id))throw new Error("Could not reopen issue")}async setIssueLabels(e,t={}){var l,p,d;let{issue:n,labels:o}=e;if(!n.graphQLId)throw new Error('GitHub requires "graphQLId" for this function.');let a=o.map(c=>c.graphQLId),i=`mutation SetIssueLabels($issueGraphQLId: ID!, $labelGraphQLIds: [ID!]) {
601
+ }`,a=await b(this.config,{query:o,variables:{issueGraphQLId:s.graphQLId}},t);if(!((l=(u=(i=a.body.data)==null?void 0:i.reopenIssue)==null?void 0:u.issue)!=null&&l.id))throw new R("Could not reopen issue",a.body.errors)}async setIssueLabels(e,t={}){var l,p,d;let{issue:s,labels:o}=e;if(!s.graphQLId)throw new Error('GitHub requires "graphQLId" for this function.');let a=o.map(c=>c.graphQLId),i=`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:i,variables:{issueGraphQLId:n.graphQLId,labelGraphQLIds:a}},t)).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(e,t={}){var u,l,p;let{issue:n,milestone:o}=e;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 a=`mutation SetIssueMilestone($issueGraphQLId: ID!, $milestoneGraphQLId: ID) {
607
+ }`,u=await b(this.config,{query:i,variables:{issueGraphQLId:s.graphQLId,labelGraphQLIds:a}},t);if(!((d=(p=(l=u.body.data)==null?void 0:l.updateIssue)==null?void 0:p.issue)!=null&&d.id))throw new R("Could not set issue labels",u.body.errors)}async setIssueMilestone(e,t={}){var u,l,p;let{issue:s,milestone:o}=e;if(!s.graphQLId)throw new Error('GitHub requires "graphQLId" for this function.');if(o&&!o.graphQLId)throw new Error('GitHub requires milestone "graphQLId" for this function.');let a=`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:`${a}`,variables:{issueGraphQLId:n.graphQLId,milestoneGraphQLId:(o==null?void 0:o.graphQLId)??null}},t)).body.data)==null?void 0:u.updateIssue)==null?void 0:l.issue)!=null&&p.id))throw new Error("Could not set milestone of issue")}async setIssueAssignees(e,t={}){var l,p,d;let{issue:n,assignees:o}=e;if(!n.graphQLId)throw new Error('GitHub requires "graphQLId" for this function.');let a=o.map(c=>{if(!c.graphQLId)throw new Error('GitHub requires assignee "graphQLId" for this function.');return c.graphQLId}),i=`mutation SetIssueAssignees($issueGraphQLId: ID!, $assigneeGraphQLIds: [ID!]!) {
613
+ }`,i=await b(this.config,{query:`${a}`,variables:{issueGraphQLId:s.graphQLId,milestoneGraphQLId:(o==null?void 0:o.graphQLId)??null}},t);if(!((p=(l=(u=i.body.data)==null?void 0:u.updateIssue)==null?void 0:l.issue)!=null&&p.id))throw new R("Could not set milestone of issue",i.body.errors)}async setIssueAssignees(e,t={}){var l,p,d;let{issue:s,assignees:o}=e;if(!s.graphQLId)throw new Error('GitHub requires "graphQLId" for this function.');let a=o.map(c=>{if(!c.graphQLId)throw new Error('GitHub requires assignee "graphQLId" for this function.');return c.graphQLId}),i=`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:i,variables:{issueGraphQLId:n.graphQLId,assigneeGraphQLIds:a}},t)).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(e,t={}){var u,l,p,d;let{repo:{namespace:n,name:o},cursor:a}=e,i=await R(this.config,{query:`
619
+ }`,u=await b(this.config,{query:i,variables:{issueGraphQLId:s.graphQLId,assigneeGraphQLIds:a}},t);if(!((d=(p=(l=u.body.data)==null?void 0:l.updateIssue)==null?void 0:p.issue)!=null&&d.id))throw new R("Could not set issue assignees",u.body.errors)}async getMilestonesForRepo(e,t={}){var u,l,p;let{repo:{namespace:s,name:o},cursor:a}=e,i=await b(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
- ${ge}
624
+ ${me}
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:a,first:q}},t);if(!i.body.data)throw new Error(((u=i.body.errors)==null?void 0:u[0].message)||i.statusText||"Unknown error");return{pageInfo:((l=i.body.data.repository.milestones)==null?void 0:l.pageInfo)??{endCursor:null,hasNextPage:!1},data:((d=(p=i.body.data.repository.milestones)==null?void 0:p.nodes)==null?void 0:d.map(je))??[]}}async getLabelsForRepo(e,t={}){var u,l,p,d;let{repo:{namespace:n,name:o},cursor:a}=e,i=await R(this.config,{query:`
633
+ `,variables:{owner:s,name:o,cursor:a,first:E}},t);if(!i.body.data)throw new R("Could not fetch milestones",i.body.errors);return{pageInfo:((u=i.body.data.repository.milestones)==null?void 0:u.pageInfo)??{endCursor:null,hasNextPage:!1},data:((p=(l=i.body.data.repository.milestones)==null?void 0:l.nodes)==null?void 0:p.map(Me))??[]}}async getLabelsForRepo(e,t={}){var u,l,p;let{repo:{namespace:s,name:o},cursor:a}=e,i=await b(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
- ${me}
638
+ ${he}
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:a,first:q}},t);if(!i.body.data)throw new Error(((u=i.body.errors)==null?void 0:u[0].message)||i.statusText||"Unknown error");return{pageInfo:((l=i.body.data.repository.labels)==null?void 0:l.pageInfo)??{endCursor:null,hasNextPage:!1},data:((d=(p=i.body.data.repository.labels)==null?void 0:p.nodes)==null?void 0:d.map(Be))??[]}}};var yr="https://gitlab.com/api/v4",wr="https://gitlab.com/api/graphql",vt=/\/api\/v\d+$/,qt=r=>{if(r.endsWith("/api/graphql"))throw new Error("The graphql endpoint is being used as the baseUrl. This package uses both GraphQL and REST APIs, and the REST version cannot be assumed. Use the REST endpoint as the baseUrl instead.")},Me=(r,s)=>{let e=s.baseUrl||r.baseUrl;return e?(e=e.replace(/\/$/,""),qt(e),e):yr},Pr=(r,s)=>{let e=s.baseUrl||r.baseUrl;return e?(e=e.replace(/\/$/,""),qt(e),vt.test(e)&&(e=e.replace(vt,"")),`${e}/api/graphql`):wr},y=(r,s,e)=>{let t=I(e.token||r.token);return r.request({url:Pr(r,e),method:"POST",headers:{...t,"Content-Type":"application/json"},body:JSON.stringify(s)})},Ie=r=>r==null?void 0:r.map(s=>`"${s.message}"`).join(", ");var Ke=r=>r.split("/").slice(0,-1).join("/"),Ve=r=>r.split("/").at(-1)??"",Re=r=>({id:r.id.replace(X,""),graphQLId:r.id,namespace:Ke(r.fullPath),name:Ve(r.fullPath),webUrl:r.webUrl}),Et=r=>({id:r.id.replace(X,""),graphQLId:r.id,httpsUrl:r.httpUrlToRepo,namespace:Ke(r.fullPath),name:Ve(r.fullPath),sshUrl:r.sshUrlToRepo,webUrl:r.webUrl}),Sr={assigned:"assignedMergeRequests",authored:"authoredMergeRequests",reviewRequested:"reviewRequestedMergeRequests"},vr={CAN_BE_MERGED:"MERGEABLE",CANNOT_BE_MERGED:"CONFLICTS",CANNOT_BE_MERGED_RECHECK:"UNKNOWN",UNCHECKED:"UNKNOWN",CHECKING:"UNKNOWN"};var qr="gid://gitlab/User/",X="gid://gitlab/Project/",Er="gid://gitlab/MergeRequest/",Cr="gid://gitlab/Issue/",Ur="gid://gitlab/ProjectLabel/",Dr="gid://gitlab/Milestone/",Lr="gid://gitlab/Ci::Build/",Xe=`
647
+ `,variables:{owner:s,name:o,cursor:a,first:E}},t);if(!i.body.data)throw new R("Could not fetch labels",i.body.errors);return{pageInfo:((u=i.body.data.repository.labels)==null?void 0:u.pageInfo)??{endCursor:null,hasNextPage:!1},data:((p=(l=i.body.data.repository.labels)==null?void 0:l.nodes)==null?void 0:p.map(je))??[]}}};var Pr="https://gitlab.com/api/v4",wr="https://gitlab.com/api/graphql",qt=/\/api\/v\d+$/,Et=r=>{if(r.endsWith("/api/graphql"))throw new Error("The graphql endpoint is being used as the baseUrl. This package uses both GraphQL and REST APIs, and the REST version cannot be assumed. Use the REST endpoint as the baseUrl instead.")},ze=(r,n)=>{let e=n.baseUrl||r.baseUrl;return e?(e=e.replace(/\/$/,""),Et(e),e):Pr},Sr=(r,n)=>{let e=n.baseUrl||r.baseUrl;return e?(e=e.replace(/\/$/,""),Et(e),qt.test(e)&&(e=e.replace(qt,"")),`${e}/api/graphql`):wr},P=(r,n,e)=>{let t=I(e.token||r.token);return r.request({url:Sr(r,e),method:"POST",headers:{...t,"Content-Type":"application/json"},body:JSON.stringify(n)})},Re=r=>r==null?void 0:r.map(n=>`"${n.message}"`).join(", ");var Ve=r=>r.split("/").slice(0,-1).join("/"),Xe=r=>r.split("/").at(-1)??"",be=r=>({id:r.id.replace(Z,""),graphQLId:r.id,namespace:Ve(r.fullPath),name:Xe(r.fullPath),webUrl:r.webUrl}),Ct=r=>({id:r.id.replace(Z,""),graphQLId:r.id,httpsUrl:r.httpUrlToRepo,namespace:Ve(r.fullPath),name:Xe(r.fullPath),sshUrl:r.sshUrlToRepo,webUrl:r.webUrl}),vr={assigned:"assignedMergeRequests",authored:"authoredMergeRequests",reviewRequested:"reviewRequestedMergeRequests"},qr={CAN_BE_MERGED:"MERGEABLE",CANNOT_BE_MERGED:"CONFLICTS",CANNOT_BE_MERGED_RECHECK:"UNKNOWN",UNCHECKED:"UNKNOWN",CHECKING:"UNKNOWN"};var Er="gid://gitlab/User/",Z="gid://gitlab/Project/",Cr="gid://gitlab/MergeRequest/",Dr="gid://gitlab/Issue/",Lr="gid://gitlab/ProjectLabel/",Ur="gid://gitlab/Milestone/",$r="gid://gitlab/Ci::Build/",Ze=`
648
648
  description
649
649
  dueDate
650
650
  id
@@ -653,7 +653,7 @@ startDate
653
653
  state
654
654
  title
655
655
  webPath
656
- `,ze=`
656
+ `,He=`
657
657
  id
658
658
  fullPath
659
659
  webUrl
@@ -662,25 +662,25 @@ sshUrlToRepo
662
662
  repository {
663
663
  rootRef
664
664
  }
665
- `,k=`
665
+ `,N=`
666
666
  id
667
667
  name
668
668
  username
669
669
  publicEmail
670
670
  avatarUrl
671
671
  webUrl
672
- `,Ze=`
672
+ `,Ye=`
673
673
  color
674
674
  description
675
675
  id
676
676
  title
677
- `,He=`
677
+ `,We=`
678
678
  author {
679
- ${k}
679
+ ${N}
680
680
  }
681
681
  assignees {
682
682
  nodes {
683
- ${k}
683
+ ${N}
684
684
  }
685
685
  }
686
686
  closedAt
@@ -691,7 +691,7 @@ id
691
691
  iid
692
692
  labels {
693
693
  nodes {
694
- ${Ze}
694
+ ${Ye}
695
695
  }
696
696
  }
697
697
  state
@@ -702,9 +702,9 @@ upvotes
702
702
  userNotesCount
703
703
  webUrl
704
704
  milestone {
705
- ${Xe}
705
+ ${Ze}
706
706
  }
707
- `,$r=`
707
+ `,Ar=`
708
708
  stages {
709
709
  nodes {
710
710
  jobs {
@@ -720,12 +720,12 @@ stages {
720
720
  name
721
721
  }
722
722
  }
723
- `,Ct=(r,s,e)=>`
723
+ `,Dt=(r,n,e)=>`
724
724
  id
725
725
  state
726
726
  approved
727
727
  author {
728
- ${k}
728
+ ${N}
729
729
  }
730
730
  diffRefs {
731
731
  baseSha
@@ -750,12 +750,12 @@ targetBranch
750
750
  sourceBranch
751
751
  assignees {
752
752
  nodes {
753
- ${k}
753
+ ${N}
754
754
  }
755
755
  }
756
756
  reviewers {
757
757
  nodes {
758
- ${k}
758
+ ${N}
759
759
  mergeRequestInteraction {
760
760
  approved
761
761
  reviewState
@@ -765,19 +765,19 @@ reviewers {
765
765
  mergeStatusEnum
766
766
  labels {
767
767
  nodes {
768
- ${Ze}
768
+ ${Ye}
769
769
  }
770
770
  }
771
771
  ${r?"project { id httpUrlToRepo fullPath sshUrlToRepo webUrl archived } sourceProject { id httpUrlToRepo fullPath sshUrlToRepo webUrl }":""}
772
- ${s?`milestone { ${Xe} }`:""}
773
- ${e?`headPipeline { ${$r} }`:""}
774
- `,z=r=>`${r.namespace}/${r.name}`,Ar=r=>`${r.namespace}/${r.name}`,We=r=>{var s;return{id:r.id.replace(X,""),graphQLId:r.id,namespace:Ke(r.fullPath),name:Ve(r.fullPath),webUrl:r.webUrl,httpsUrl:r.httpUrlToRepo,sshUrl:r.sshUrlToRepo,defaultBranch:(s=r.repository)!=null&&s.rootRef?{name:r.repository.rootRef}:null,permission:null}},Gr={opened:"OPEN",merged:"MERGED",closed:"CLOSED"},N=(r,s,e)=>{let t=r.avatarUrl;return!s&&(t!=null&&t.startsWith("/"))?t=`https://gitlab.com${t}`:s&&(t!=null&&t.startsWith("/"))&&e&&(t=`${e.replace(/\/+?$/,"")}${t}`),{id:r.id.replace(qr,""),graphQLId:r.id,name:r.name,username:r.username,email:r.publicEmail??null,avatarUrl:t,url:r.webUrl}},Ye=r=>({color:r.color,description:r.description,id:r.id.replace(Ur,""),graphQLId:r.id,name:r.title}),Tr=(r,s)=>r?r==="FAILED"&&s?"WARNING":{CANCELED:"CANCELLED",CREATED:"PENDING",FAILED:"FAILED",MANUAL:"OPTIONAL_ACTION_REQUIRED",PENDING:"PENDING",PREPARING:"RUNNING",RUNNING:"RUNNING",SCHEDULED:"PENDING",SKIPPED:"SKIPPED",SUCCESS:"SUCCESS",WAITING_FOR_CALLBACK:"PENDING",WAITING_FOR_RESOURCE:"PENDING"}[r]:null,Or=(r,s,e)=>{var n;let t={APPROVED:"APPROVED",REQUESTED_CHANGES:"CHANGES_REQUESTED",REVIEWED:"COMMENTED",UNAPPROVED:"REVIEW_REQUESTED",UNREVIEWED:"REVIEW_REQUESTED"};return{reviewer:N(r,s,e),state:(n=r.mergeRequestInteraction)!=null&&n.reviewState?t[r.mergeRequestInteraction.reviewState]:"REVIEW_REQUESTED"}},Ut=(r,s,e,t,n)=>{var a,i,u,l,p,d,c,g,m,h,b,S;let o=(a=r.reviewers)!=null&&a.nodes?r.reviewers.nodes.map(f=>Or(f,t,n)):null;return{id:r.id.replace(Er,""),graphQLId:r.id,title:r.title,number:parseInt(r.iid,10),state:Gr[r.state],commentCount:r.userNotesCount||0,upvoteCount:r.upvotes,author:r.author?N(r.author,t,n):null,createdDate:new Date(r.createdAt),isDraft:r.draft,repository:{id:s.id,graphQLId:s.graphQLId,name:s.name,owner:{login:s.namespace},remoteInfo:s.httpsUrl&&s.sshUrl?{cloneUrlHTTPS:s.httpsUrl,cloneUrlSSH:s.sshUrl}:null},headRepository:e?{id:e.id,graphQLId:e.graphQLId,name:e.name,owner:{login:e.namespace},remoteInfo:{cloneUrlHTTPS:e.httpsUrl,cloneUrlSSH:e.sshUrl}}:null,headCommit:{buildStatuses:((l=(u=(i=r.headPipeline)==null?void 0:i.stages)==null?void 0:u.nodes)==null?void 0:l.flatMap(f=>{var P,O;return((O=(P=f.jobs)==null?void 0:P.nodes)==null?void 0:O.map(A=>({completedAt:A.finishedAt?new Date(A.finishedAt):null,description:null,name:A.name??null,state:Tr(A.status,A.allowFailure),stage:f.name??null,startedAt:new Date(A.createdAt),url:`${s.webUrl}/-/jobs/${A.id.replace(Lr,"")}`})))??[]}))??[]},baseRef:{name:r.targetBranch,oid:((p=r.diffRefs)==null?void 0:p.baseSha)??null},headRef:{name:r.sourceBranch,oid:((d=r.diffRefs)==null?void 0:d.headSha)??null},url:r.webUrl,updatedDate:new Date(r.updatedAt),closedDate:r.mergedAt?new Date(r.mergedAt):null,mergedDate:r.mergedAt?new Date(r.mergedAt):null,assignees:(c=r.assignees)!=null&&c.nodes?r.assignees.nodes.map(f=>N(f,t,n)):null,reviews:o,reviewDecision:r.approved?"APPROVED":F(o),additions:((g=r.diffStatsSummary)==null?void 0:g.additions)||0,deletions:((m=r.diffStatsSummary)==null?void 0:m.deletions)||0,fileCount:((h=r.diffStatsSummary)==null?void 0:h.fileCount)||0,commitCount:r.commitCount||0,mergeableState:vr[r.mergeStatusEnum],milestone:r.milestone?et(r.milestone,s.webUrl):null,labels:((S=(b=r.labels)==null?void 0:b.nodes)==null?void 0:S.map(Ye))??[],permissions:null}},Je=(r,s,e,t)=>{var n,o;return{author:N(r.author,e,t),assignees:r.assignees.nodes.map(a=>N(a,e,t)),commentCount:r.userNotesCount,closedDate:r.closedAt?new Date(r.closedAt):null,createdDate:new Date(r.createdAt),description:r.description,graphQLId:r.id,id:r.id.replace(Cr,""),labels:((o=(n=r.labels)==null?void 0:n.nodes)==null?void 0:o.map(Ye))??[],number:r.iid,repository:{id:s.id.replace(X,""),graphQLId:s.id,name:s.name,owner:{login:s.namespace}},updatedDate:new Date(r.updatedAt),upvoteCount:r.upvotes,state:{name:r.state,color:null},type:r.type,title:r.title,url:r.webUrl,milestone:r.milestone?et(r.milestone,s.webUrl):null}},et=(r,s)=>({id:r.id.replace(Dr,""),graphQLId:r.id,number:parseInt(r.iid,10),title:r.title,description:r.description,isOpen:r.state==="active",url:`${s}/-/${r.webPath.replace(/.+?\/-\//,"")}`,startDate:r.startDate?new Date(r.startDate):null,dueDate:r.dueDate?new Date(r.dueDate):null}),Z=class extends G{getIsSelfHosted(s){return!!s.baseUrl||!!this.config.baseUrl}async getCurrentUser(s={},e={}){var o;let n=(o=(await y(this.config,{query:`
772
+ ${n?`milestone { ${Ze} }`:""}
773
+ ${e?`headPipeline { ${Ar} }`:""}
774
+ `,H=r=>`${r.namespace}/${r.name}`,Gr=r=>`${r.namespace}/${r.name}`,Je=r=>{var n;return{id:r.id.replace(Z,""),graphQLId:r.id,namespace:Ve(r.fullPath),name:Xe(r.fullPath),webUrl:r.webUrl,httpsUrl:r.httpUrlToRepo,sshUrl:r.sshUrlToRepo,defaultBranch:(n=r.repository)!=null&&n.rootRef?{name:r.repository.rootRef}:null,permission:null}},Tr={opened:"OPEN",merged:"MERGED",closed:"CLOSED"},F=(r,n,e)=>{let t=r.avatarUrl;return!n&&(t!=null&&t.startsWith("/"))?t=`https://gitlab.com${t}`:n&&(t!=null&&t.startsWith("/"))&&e&&(t=`${e.replace(/\/+?$/,"")}${t}`),{id:r.id.replace(Er,""),graphQLId:r.id,name:r.name,username:r.username,email:r.publicEmail??null,avatarUrl:t,url:r.webUrl}},et=r=>({color:r.color,description:r.description,id:r.id.replace(Lr,""),graphQLId:r.id,name:r.title}),Or=(r,n)=>r?r==="FAILED"&&n?"WARNING":{CANCELED:"CANCELLED",CREATED:"PENDING",FAILED:"FAILED",MANUAL:"OPTIONAL_ACTION_REQUIRED",PENDING:"PENDING",PREPARING:"RUNNING",RUNNING:"RUNNING",SCHEDULED:"PENDING",SKIPPED:"SKIPPED",SUCCESS:"SUCCESS",WAITING_FOR_CALLBACK:"PENDING",WAITING_FOR_RESOURCE:"PENDING"}[r]:null,xr=(r,n,e)=>{var s;let t={APPROVED:"APPROVED",REQUESTED_CHANGES:"CHANGES_REQUESTED",REVIEWED:"COMMENTED",UNAPPROVED:"REVIEW_REQUESTED",UNREVIEWED:"REVIEW_REQUESTED"};return{reviewer:F(r,n,e),state:(s=r.mergeRequestInteraction)!=null&&s.reviewState?t[r.mergeRequestInteraction.reviewState]:"REVIEW_REQUESTED"}},Lt=(r,n,e,t,s)=>{var a,i,u,l,p,d,c,g,m,h,y,v;let o=(a=r.reviewers)!=null&&a.nodes?r.reviewers.nodes.map(f=>xr(f,t,s)):null;return{id:r.id.replace(Cr,""),graphQLId:r.id,title:r.title,number:parseInt(r.iid,10),state:Tr[r.state],commentCount:r.userNotesCount||0,upvoteCount:r.upvotes,author:r.author?F(r.author,t,s):null,createdDate:new Date(r.createdAt),isDraft:r.draft,repository:{id:n.id,graphQLId:n.graphQLId,name:n.name,owner:{login:n.namespace},remoteInfo:n.httpsUrl&&n.sshUrl?{cloneUrlHTTPS:n.httpsUrl,cloneUrlSSH:n.sshUrl}:null},headRepository:e?{id:e.id,graphQLId:e.graphQLId,name:e.name,owner:{login:e.namespace},remoteInfo:{cloneUrlHTTPS:e.httpsUrl,cloneUrlSSH:e.sshUrl}}:null,headCommit:{buildStatuses:((l=(u=(i=r.headPipeline)==null?void 0:i.stages)==null?void 0:u.nodes)==null?void 0:l.flatMap(f=>{var S,x;return((x=(S=f.jobs)==null?void 0:S.nodes)==null?void 0:x.map(G=>({completedAt:G.finishedAt?new Date(G.finishedAt):null,description:null,name:G.name??null,state:Or(G.status,G.allowFailure),stage:f.name??null,startedAt:new Date(G.createdAt),url:`${n.webUrl}/-/jobs/${G.id.replace($r,"")}`})))??[]}))??[]},baseRef:{name:r.targetBranch,oid:((p=r.diffRefs)==null?void 0:p.baseSha)??null},headRef:{name:r.sourceBranch,oid:((d=r.diffRefs)==null?void 0:d.headSha)??null},url:r.webUrl,updatedDate:new Date(r.updatedAt),closedDate:r.mergedAt?new Date(r.mergedAt):null,mergedDate:r.mergedAt?new Date(r.mergedAt):null,assignees:(c=r.assignees)!=null&&c.nodes?r.assignees.nodes.map(f=>F(f,t,s)):null,reviews:o,reviewDecision:r.approved?"APPROVED":Q(o),additions:((g=r.diffStatsSummary)==null?void 0:g.additions)||0,deletions:((m=r.diffStatsSummary)==null?void 0:m.deletions)||0,fileCount:((h=r.diffStatsSummary)==null?void 0:h.fileCount)||0,commitCount:r.commitCount||0,mergeableState:qr[r.mergeStatusEnum],milestone:r.milestone?tt(r.milestone,n.webUrl):null,labels:((v=(y=r.labels)==null?void 0:y.nodes)==null?void 0:v.map(et))??[],permissions:null}},Ke=(r,n,e,t)=>{var s,o;return{author:F(r.author,e,t),assignees:r.assignees.nodes.map(a=>F(a,e,t)),commentCount:r.userNotesCount,closedDate:r.closedAt?new Date(r.closedAt):null,createdDate:new Date(r.createdAt),description:r.description,graphQLId:r.id,id:r.id.replace(Dr,""),labels:((o=(s=r.labels)==null?void 0:s.nodes)==null?void 0:o.map(et))??[],number:r.iid,repository:{id:n.id.replace(Z,""),graphQLId:n.id,name:n.name,owner:{login:n.namespace}},updatedDate:new Date(r.updatedAt),upvoteCount:r.upvotes,state:{name:r.state,color:null},type:r.type,title:r.title,url:r.webUrl,milestone:r.milestone?tt(r.milestone,n.webUrl):null}},tt=(r,n)=>({id:r.id.replace(Ur,""),graphQLId:r.id,number:parseInt(r.iid,10),title:r.title,description:r.description,isOpen:r.state==="active",url:`${n}/-/${r.webPath.replace(/.+?\/-\//,"")}`,startDate:r.startDate?new Date(r.startDate):null,dueDate:r.dueDate?new Date(r.dueDate):null}),Y=class extends T{getIsSelfHosted(n){return!!n.baseUrl||!!this.config.baseUrl}async getCurrentUser(n={},e={}){var o;let s=(o=(await P(this.config,{query:`
775
775
  query getCurrentUser {
776
776
  currentUser {
777
- ${k}
777
+ ${N}
778
778
  }
779
779
  }
780
- `},e)).body.data)==null?void 0:o.currentUser;if(!n)throw new Error("Current user not found.");return{data:N(n,this.getIsSelfHosted(e),this.config.baseUrl??e.baseUrl)}}async getUserForCommit(s,e={}){var a,i,u,l;let t=z(s.repo),o=(l=(u=(i=(a=(await y(this.config,{query:`
780
+ `},e)).body.data)==null?void 0:o.currentUser;if(!s)throw new Error("Current user not found.");return{data:F(s,this.getIsSelfHosted(e),this.config.baseUrl??e.baseUrl)}}async getUserForCommit(n,e={}){var a,i,u,l;let t=H(n.repo),o=(l=(u=(i=(a=(await P(this.config,{query:`
781
781
  query getUserForCommit($fullPath: ID!, $oid: String!) {
782
782
  project(fullPath: $fullPath) {
783
783
  repository {
@@ -791,21 +791,21 @@ query getUserForCommit($fullPath: ID!, $oid: String!) {
791
791
  }
792
792
  }
793
793
  }
794
- `,variables:{fullPath:t,oid:s.oid}},e)).body.data)==null?void 0:a.project)==null?void 0:i.repository)==null?void 0:u.tree)==null?void 0:l.lastCommit;if(!o)throw new Error("Commit not found.");return{data:{name:o.authorName,email:o.authorEmail,avatarUrl:o.authorGravatar}}}async getAccountForEmail(s,e={}){var o,a,i;let n=(i=(a=(o=(await y(this.config,{query:`
794
+ `,variables:{fullPath:t,oid:n.oid}},e)).body.data)==null?void 0:a.project)==null?void 0:i.repository)==null?void 0:u.tree)==null?void 0:l.lastCommit;if(!o)throw new Error("Commit not found.");return{data:{name:o.authorName,email:o.authorEmail,avatarUrl:o.authorGravatar}}}async getAccountForEmail(n,e={}){var o,a,i;let s=(i=(a=(o=(await P(this.config,{query:`
795
795
  query getAccountForEmail($email: String!) {
796
796
  users(search: $email) {
797
797
  nodes {
798
- ${k}
798
+ ${N}
799
799
  }
800
800
  }
801
801
  }
802
- `,variables:{email:s.email}},e)).body.data)==null?void 0:o.users)==null?void 0:a.nodes)==null?void 0:i[0];if(!n)throw new Error("User not found.");return{data:N(n,this.getIsSelfHosted(e),this.config.baseUrl??e.baseUrl)}}async getAccountForUsername(s,e={}){var o;let n=(o=(await y(this.config,{query:`
802
+ `,variables:{email:n.email}},e)).body.data)==null?void 0:o.users)==null?void 0:a.nodes)==null?void 0:i[0];if(!s)throw new Error("User not found.");return{data:F(s,this.getIsSelfHosted(e),this.config.baseUrl??e.baseUrl)}}async getAccountForUsername(n,e={}){var o;let s=(o=(await P(this.config,{query:`
803
803
  query getAccountForUsername($username: String!) {
804
804
  user(username: $username) {
805
- ${k}
805
+ ${N}
806
806
  }
807
807
  }
808
- `,variables:{username:s.username}},e)).body.data)==null?void 0:o.user;if(!n)throw new Error("User not found.");return{data:N(n,this.getIsSelfHosted(e),this.config.baseUrl??e.baseUrl)}}async getAccountsForRepo(s,e={}){var u,l,p,d,c,g,m;let{repo:{namespace:t,name:n},cursor:o}=s,a=await y(this.config,{query:`
808
+ `,variables:{username:n.username}},e)).body.data)==null?void 0:o.user;if(!s)throw new Error("User not found.");return{data:F(s,this.getIsSelfHosted(e),this.config.baseUrl??e.baseUrl)}}async getAccountsForRepo(n,e={}){var u,l,p,d,c,g,m;let{repo:{namespace:t,name:s},cursor:o}=n,a=await P(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
- ${k}
819
+ ${N}
820
820
  }
821
821
  }
822
822
  pageInfo {
@@ -826,22 +826,22 @@ query getAccountsForRepo(
826
826
  }
827
827
  }
828
828
  }
829
- `,variables:{fullPath:`${t}/${n}`,after:o}},e),i=(d=(p=(l=(u=a.body.data)==null?void 0:u.project)==null?void 0:l.projectMembers)==null?void 0:p.nodes)==null?void 0:d.map(h=>h.user).filter(h=>h!==null);return{pageInfo:((m=(g=(c=a.body.data)==null?void 0:c.project)==null?void 0:g.projectMembers)==null?void 0:m.pageInfo)??{endCursor:null,hasNextPage:!1},data:(i==null?void 0:i.map(h=>N(h,this.getIsSelfHosted(e),this.config.baseUrl??e.baseUrl)))??[]}}async getRepo(s,e={}){var o;let t=z(s),n=await y(this.config,{query:`
829
+ `,variables:{fullPath:`${t}/${s}`,after:o}},e),i=(d=(p=(l=(u=a.body.data)==null?void 0:u.project)==null?void 0:l.projectMembers)==null?void 0:p.nodes)==null?void 0:d.map(h=>h.user).filter(h=>h!==null);return{pageInfo:((m=(g=(c=a.body.data)==null?void 0:c.project)==null?void 0:g.projectMembers)==null?void 0:m.pageInfo)??{endCursor:null,hasNextPage:!1},data:(i==null?void 0:i.map(h=>F(h,this.getIsSelfHosted(e),this.config.baseUrl??e.baseUrl)))??[]}}async getRepo(n,e={}){var o;let t=H(n),s=await P(this.config,{query:`
830
830
  query getRepo($fullPath: ID!) {
831
831
  project(fullPath: $fullPath) {
832
- ${ze}
832
+ ${He}
833
833
  }
834
834
  }
835
- `,variables:{fullPath:t}},e);if(!((o=n.body.data)!=null&&o.project))throw new Error(`Repository ${t} not found`);return{data:We(n.body.data.project)}}async getReposBase(s,e={}){let n=s.map(z).map((u,l)=>`
835
+ `,variables:{fullPath:t}},e);if(!((o=s.body.data)!=null&&o.project))throw new Error(`Repository ${t} not found`);return{data:Je(s.body.data.project)}}async getReposBase(n,e={}){let s=n.map(H).map((u,l)=>`
836
836
  getRepo_${l}: project(fullPath: "${u}") {
837
- ${ze}
837
+ ${He}
838
838
  }
839
839
  `).join(`
840
- `),o=await y(this.config,{query:`
840
+ `),o=await P(this.config,{query:`
841
841
  query batchGetRepos {
842
- ${n}
842
+ ${s}
843
843
  }
844
- `},e);if(!o.body.data)throw new Error(Ie(o.body.errors)||o.statusText||"Unknown error");let a=[],i=[];return s.forEach((u,l)=>{let p=o.body.data[`getRepo_${l}`];p?a.push(We(p)):i.push({input:u})}),{data:a,errors:i}}async getRepos(s,e={}){let t=[];for(let a=0;a<s.length;a+=20)t.push(s.slice(a,a+20));return(await Promise.all(t.map(a=>this.getReposBase(a,e)))).reduce((a,i)=>({data:[...a.data,...i.data],errors:[...a.errors,...i.errors]}),{data:[],errors:[]})}async getReposForCurrentUser(s,e={}){var o,a,i,u,l;let t=await y(this.config,{query:`
844
+ `},e);if(!o.body.data)throw new Error(Re(o.body.errors)||o.statusText||"Unknown error");let a=[],i=[];return n.forEach((u,l)=>{let p=o.body.data[`getRepo_${l}`];p?a.push(Je(p)):i.push({input:u})}),{data:a,errors:i}}async getRepos(n,e={}){let t=[];for(let a=0;a<n.length;a+=20)t.push(n.slice(a,a+20));return(await Promise.all(t.map(a=>this.getReposBase(a,e)))).reduce((a,i)=>({data:[...a.data,...i.data],errors:[...a.errors,...i.errors]}),{data:[],errors:[]})}async getReposForCurrentUser(n,e={}){var o,a,i,u,l;let t=await P(this.config,{query:`
845
845
  query getReposForCurrentUser($after: String) {
846
846
  projects(membership: true first: 100 after: $after) {
847
847
  pageInfo {
@@ -849,11 +849,11 @@ query getReposForCurrentUser($after: String) {
849
849
  hasNextPage
850
850
  }
851
851
  nodes {
852
- ${ze}
852
+ ${He}
853
853
  }
854
854
  }
855
855
  }
856
- `,variables:{after:s.cursor}},e);if(!((o=t.body.data)!=null&&o.projects))throw new Error(Ie(t.body.errors)||t.statusText||"Unknown error");let n=((i=(a=t.body.data)==null?void 0:a.projects)==null?void 0:i.nodes)||[];return{pageInfo:(l=(u=t.body.data)==null?void 0:u.projects)==null?void 0:l.pageInfo,data:n.map(We)}}async getRefs(s,e,t={}){var u;let n=z(e.repo),o=new URL(`${Me(this.config,t)}/projects/${encodeURIComponent(n)}/repository/${s}`);o.searchParams.set("page",((u=e.page)==null?void 0:u.toString())||"1"),o.searchParams.set("per_page",q.toString());let a=await this.config.request({url:o.toString(),headers:I(t.token||this.config.token)}),i=a.headers["x-next-page"];return{pageInfo:{hasNextPage:!!i,nextPage:i?parseInt(i,10):null},data:a.body.map(l=>({name:l.name,commit:{oid:l.commit.id,authoredDate:new Date(l.commit.authored_date),committedDate:new Date(l.commit.committed_date)}}))}}async getBranches(s,e={}){return this.getRefs("branches",s,e)}async getTags(s,e={}){return this.getRefs("tags",s,e)}async getBlame(s,e={}){let t=z(s.repo),n=new URL(`${Me(this.config,e)}/projects/${encodeURIComponent(t)}/repository/files/${encodeURIComponent(s.path)}/blame`);n.searchParams.set("ref",s.ref);let o=await this.config.request({url:n.toString(),headers:I(e.token||this.config.token)}),a=0;return{data:{ranges:o.body.map(i=>{let u=a+1;return a+=i.lines.length,{startingLine:u,endingLine:a,commit:{oid:i.commit.id,parentOids:i.commit.parent_ids,authoredDate:new Date(i.commit.authored_date),author:{name:i.commit.author_name,email:i.commit.author_email,avatarUrl:null},committedDate:new Date(i.commit.committed_date),committer:{name:i.commit.committer_name,email:i.commit.committer_email,avatarUrl:null},message:i.commit.message,fileCount:null,additions:null,deletions:null}}})}}}async getPullRequestsForUser(s,e={}){var a;let t=Sr[s.association],n=await y(this.config,{query:`
856
+ `,variables:{after:n.cursor}},e);if(!((o=t.body.data)!=null&&o.projects))throw new Error(Re(t.body.errors)||t.statusText||"Unknown error");let s=((i=(a=t.body.data)==null?void 0:a.projects)==null?void 0:i.nodes)||[];return{pageInfo:(l=(u=t.body.data)==null?void 0:u.projects)==null?void 0:l.pageInfo,data:s.map(Je)}}async getRefs(n,e,t={}){var u;let s=H(e.repo),o=new URL(`${ze(this.config,t)}/projects/${encodeURIComponent(s)}/repository/${n}`);o.searchParams.set("page",((u=e.page)==null?void 0:u.toString())||"1"),o.searchParams.set("per_page",E.toString());let a=await this.config.request({url:o.toString(),headers:I(t.token||this.config.token)}),i=a.headers["x-next-page"];return{pageInfo:{hasNextPage:!!i,nextPage:i?parseInt(i,10):null},data:a.body.map(l=>({name:l.name,commit:{oid:l.commit.id,authoredDate:new Date(l.commit.authored_date),committedDate:new Date(l.commit.committed_date)}}))}}async getBranches(n,e={}){return this.getRefs("branches",n,e)}async getTags(n,e={}){return this.getRefs("tags",n,e)}async getBlame(n,e={}){let t=H(n.repo),s=new URL(`${ze(this.config,e)}/projects/${encodeURIComponent(t)}/repository/files/${encodeURIComponent(n.path)}/blame`);s.searchParams.set("ref",n.ref);let o=await this.config.request({url:s.toString(),headers:I(e.token||this.config.token)}),a=0;return{data:{ranges:o.body.map(i=>{let u=a+1;return a+=i.lines.length,{startingLine:u,endingLine:a,commit:{oid:i.commit.id,parentOids:i.commit.parent_ids,authoredDate:new Date(i.commit.authored_date),author:{name:i.commit.author_name,email:i.commit.author_email,avatarUrl:null},committedDate:new Date(i.commit.committed_date),committer:{name:i.commit.committer_name,email:i.commit.committer_email,avatarUrl:null},message:i.commit.message,fileCount:null,additions:null,deletions:null}}})}}}async getPullRequestsForUser(n,e={}){var a;let t=vr[n.association],s=await P(this.config,{query:`
857
857
  query getPullRequestsForUser($username: String! $cursor: String $labelNames: [String!]) {
858
858
  user(username: $username) {
859
859
  ${t}(state:opened first:100 after:$cursor labels: $labelNames) {
@@ -862,12 +862,12 @@ query getPullRequestsForUser($username: String! $cursor: String $labelNames: [St
862
862
  hasNextPage
863
863
  }
864
864
  nodes {
865
- ${Ct(!0,!0,!0)}
865
+ ${Dt(!0,!0,!0)}
866
866
  }
867
867
  }
868
868
  }
869
869
  }
870
- `,variables:{username:s.username,cursor:s.cursor,labelNames:s.labelNames}},e);if(!n.body.data)throw new Error(Ie(n.body.errors)||n.statusText||"Unknown error");if(!n.body.data.user)throw new Error("User not found");let o=n.body.data.user[t];if(!o)throw new Error("Unexpected response");return{pageInfo:o.pageInfo,data:((a=o.nodes)==null?void 0:a.filter(i=>s.includeFromArchivedRepos||!i.project.archived).map(i=>Ut(i,Et(i.project),Et(i.sourceProject),this.getIsSelfHosted(e),this.config.baseUrl??e.baseUrl)))||[]}}async getPullRequestsAssociatedWithUser(s,e={}){var c;let[t,n,o]=((c=s.cursor)==null?void 0:c.split(";"))||[void 0,void 0,void 0],[a,i,u]=await Promise.all([t==="null"?null:this.getPullRequestsForUser({username:s.username,association:"authored",cursor:t,includeFromArchivedRepos:s.includeFromArchivedRepos,labelNames:s.labelNames},e),n==="null"?null:this.getPullRequestsForUser({username:s.username,association:"assigned",cursor:n,includeFromArchivedRepos:s.includeFromArchivedRepos,labelNames:s.labelNames},e),o==="null"?null:this.getPullRequestsForUser({username:s.username,association:"reviewRequested",cursor:o,includeFromArchivedRepos:s.includeFromArchivedRepos,labelNames:s.labelNames},e)]),l={},p=[],d=g=>{l[g.id]||(l[g.id]=!0,p.push(g))};return a==null||a.data.forEach(d),i==null||i.data.forEach(d),u==null||u.data.forEach(d),{pageInfo:{hasNextPage:(a==null?void 0:a.pageInfo.hasNextPage)||(i==null?void 0:i.pageInfo.hasNextPage)||(u==null?void 0:u.pageInfo.hasNextPage)||!1,endCursor:`${(a==null?void 0:a.pageInfo.hasNextPage)&&(a==null?void 0:a.pageInfo.endCursor)||"null"};${(i==null?void 0:i.pageInfo.hasNextPage)&&(i==null?void 0:i.pageInfo.endCursor)||"null"};${(u==null?void 0:u.pageInfo.hasNextPage)&&(u==null?void 0:u.pageInfo.endCursor)||"null"}`},data:p}}getVariablesForPullRequests(s){let{updatedBefore:e,isDraft:t,authorLogin:n,assigneeLogins:o,labelNames:a,reviewRequestedLogin:i}=s||{},u={},l=[],p=[],d=(c,g,m)=>{l.push(`$${c}: ${m}`),p.push(`${c}: $${c}`),u[c]=g};return e&&d("updatedBefore",e,"Time"),n&&d("authorUsername",n,"String"),o&&d("assigneeUsername",o[0],"String"),a&&d("labelName",a,"[String]"),t!=null&&d("draft",t,"Boolean"),i&&d("reviewerUsername",i,"String"),{variables:u,variableTypes:l,mergeRequestArguments:p}}async getPullRequestsForRepoBase(s,e={},t){var b,S,f;let{cursor:n,repo:o}=s||{},a=z(o),{variables:i,variableTypes:u,mergeRequestArguments:l}=this.getVariablesForPullRequests(s),p={fullPath:a,...i},d=await y(this.config,{query:`
870
+ `,variables:{username:n.username,cursor:n.cursor,labelNames:n.labelNames}},e);if(!s.body.data)throw new Error(Re(s.body.errors)||s.statusText||"Unknown error");if(!s.body.data.user)throw new Error("User not found");let o=s.body.data.user[t];if(!o)throw new Error("Unexpected response");return{pageInfo:o.pageInfo,data:((a=o.nodes)==null?void 0:a.filter(i=>n.includeFromArchivedRepos||!i.project.archived).map(i=>Lt(i,Ct(i.project),Ct(i.sourceProject),this.getIsSelfHosted(e),this.config.baseUrl??e.baseUrl)))||[]}}async getPullRequestsAssociatedWithUser(n,e={}){var c;let[t,s,o]=((c=n.cursor)==null?void 0:c.split(";"))||[void 0,void 0,void 0],[a,i,u]=await Promise.all([t==="null"?null:this.getPullRequestsForUser({username:n.username,association:"authored",cursor:t,includeFromArchivedRepos:n.includeFromArchivedRepos,labelNames:n.labelNames},e),s==="null"?null:this.getPullRequestsForUser({username:n.username,association:"assigned",cursor:s,includeFromArchivedRepos:n.includeFromArchivedRepos,labelNames:n.labelNames},e),o==="null"?null:this.getPullRequestsForUser({username:n.username,association:"reviewRequested",cursor:o,includeFromArchivedRepos:n.includeFromArchivedRepos,labelNames:n.labelNames},e)]),l={},p=[],d=g=>{l[g.id]||(l[g.id]=!0,p.push(g))};return a==null||a.data.forEach(d),i==null||i.data.forEach(d),u==null||u.data.forEach(d),{pageInfo:{hasNextPage:(a==null?void 0:a.pageInfo.hasNextPage)||(i==null?void 0:i.pageInfo.hasNextPage)||(u==null?void 0:u.pageInfo.hasNextPage)||!1,endCursor:`${(a==null?void 0:a.pageInfo.hasNextPage)&&(a==null?void 0:a.pageInfo.endCursor)||"null"};${(i==null?void 0:i.pageInfo.hasNextPage)&&(i==null?void 0:i.pageInfo.endCursor)||"null"};${(u==null?void 0:u.pageInfo.hasNextPage)&&(u==null?void 0:u.pageInfo.endCursor)||"null"}`},data:p}}getVariablesForPullRequests(n){let{updatedBefore:e,isDraft:t,authorLogin:s,assigneeLogins:o,labelNames:a,reviewRequestedLogin:i}=n||{},u={},l=[],p=[],d=(c,g,m)=>{l.push(`$${c}: ${m}`),p.push(`${c}: $${c}`),u[c]=g};return e&&d("updatedBefore",e,"Time"),s&&d("authorUsername",s,"String"),o&&d("assigneeUsername",o[0],"String"),a&&d("labelName",a,"[String]"),t!=null&&d("draft",t,"Boolean"),i&&d("reviewerUsername",i,"String"),{variables:u,variableTypes:l,mergeRequestArguments:p}}async getPullRequestsForRepoBase(n,e={},t){var y,v,f;let{cursor:s,repo:o}=n||{},a=H(o),{variables:i,variableTypes:u,mergeRequestArguments:l}=this.getVariablesForPullRequests(n),p={fullPath:a,...i},d=await P(this.config,{query:`
871
871
  query getPullRequestsForRepo(
872
872
  $fullPath: ID!
873
873
  $after: String
@@ -892,19 +892,19 @@ query getPullRequestsForRepo(
892
892
  hasNextPage
893
893
  }
894
894
  nodes {
895
- ${Ct(!1,!0,!0)}
895
+ ${Dt(!1,!0,!0)}
896
896
  }
897
897
  }
898
898
  }
899
899
  }
900
- `,variables:{...p,after:n}},e),c=[],g=(b=d.body.data)==null?void 0:b.project;if(!t&&(g!=null&&g.archived))return{pageInfo:null,data:[]};let m=Re(g||{id:"",fullPath:"",webUrl:""});return(((S=g==null?void 0:g.mergeRequests)==null?void 0:S.nodes)||[]).forEach(P=>{c.push(Ut(P,m,null,this.getIsSelfHosted(e),this.config.baseUrl??e.baseUrl))}),{pageInfo:(f=g==null?void 0:g.mergeRequests)==null?void 0:f.pageInfo,data:c}}async getPullRequestsForRepo(s,e={}){return this.getPullRequestsForRepoBase(s,e,!1)}async getPullRequestsForRepos(s,e={}){let{repos:t,assigneeLogins:n,updatedBefore:o,authorLogin:a,labelNames:i,isDraft:u,reviewRequestedLogin:l}=s;return{data:(await Promise.all(t.map(d=>this.getPullRequestsForRepoBase({repo:d,assigneeLogins:n,updatedBefore:o,authorLogin:a,labelNames:i,isDraft:u,reviewRequestedLogin:l},e,s.includeFromArchivedRepos??!1)))).flatMap(d=>d.data)}}async closePullRequest(s,e={}){var i,u,l;let{pullRequest:t}=s,n=`mutation ClosePullRequest($fullPath: ID!, $pullRequestId: String!) {
900
+ `,variables:{...p,after:s}},e),c=[],g=(y=d.body.data)==null?void 0:y.project;if(!t&&(g!=null&&g.archived))return{pageInfo:null,data:[]};let m=be(g||{id:"",fullPath:"",webUrl:""});return(((v=g==null?void 0:g.mergeRequests)==null?void 0:v.nodes)||[]).forEach(S=>{c.push(Lt(S,m,null,this.getIsSelfHosted(e),this.config.baseUrl??e.baseUrl))}),{pageInfo:(f=g==null?void 0:g.mergeRequests)==null?void 0:f.pageInfo,data:c}}async getPullRequestsForRepo(n,e={}){return this.getPullRequestsForRepoBase(n,e,!1)}async getPullRequestsForRepos(n,e={}){let{repos:t,assigneeLogins:s,updatedBefore:o,authorLogin:a,labelNames:i,isDraft:u,reviewRequestedLogin:l}=n;return{data:(await Promise.all(t.map(d=>this.getPullRequestsForRepoBase({repo:d,assigneeLogins:s,updatedBefore:o,authorLogin:a,labelNames:i,isDraft:u,reviewRequestedLogin:l},e,n.includeFromArchivedRepos??!1)))).flatMap(d=>d.data)}}async closePullRequest(n,e={}){var i,u,l;let{pullRequest:t}=n,s=`mutation ClosePullRequest($fullPath: ID!, $pullRequestId: String!) {
901
901
  mergeRequestUpdate(input: { projectPath: $fullPath, iid: $pullRequestId, state: CLOSED }) {
902
902
  errors,
903
903
  mergeRequest {
904
904
  id
905
905
  }
906
906
  }
907
- }`,a=(i=(await y(this.config,{query:n,variables:{fullPath:`${t.repository.owner.login}/${t.repository.name}`,pullRequestId:t.number.toString()}},e)).body.data)==null?void 0:i.mergeRequestUpdate;if(!((u=a==null?void 0:a.mergeRequest)!=null&&u.id)||((l=a==null?void 0:a.errors)==null?void 0:l.length)!==0)throw new Error("Could not close pull request")}async mergePullRequest(s,e={}){var u,l,p,d;let{pullRequest:t,mergeStrategy:n}=s;if(!((u=t.headRef)!=null&&u.oid))throw new Error('GitLab requires "headRef.oid" for this function.');let o=`mutation MergePullRequest(
907
+ }`,a=(i=(await P(this.config,{query:s,variables:{fullPath:`${t.repository.owner.login}/${t.repository.name}`,pullRequestId:t.number.toString()}},e)).body.data)==null?void 0:i.mergeRequestUpdate;if(!((u=a==null?void 0:a.mergeRequest)!=null&&u.id)||((l=a==null?void 0:a.errors)==null?void 0:l.length)!==0)throw new Error("Could not close pull request")}async mergePullRequest(n,e={}){var u,l,p,d;let{pullRequest:t,mergeStrategy:s}=n;if(!((u=t.headRef)!=null&&u.oid))throw new Error('GitLab requires "headRef.oid" for this function.');let o=`mutation MergePullRequest(
908
908
  $fullPath: ID!,
909
909
  $pullRequestId: String!,
910
910
  $expectedSourceSha: String!,
@@ -921,59 +921,59 @@ query getPullRequestsForRepo(
921
921
  id
922
922
  }
923
923
  }
924
- }`,i=(l=(await y(this.config,{query:o,variables:{fullPath:`${t.repository.owner.login}/${t.repository.name}`,pullRequestId:t.number.toString(),expectedSourceSha:t.headRef.oid,squash:n==="SQUASH"}},e)).body.data)==null?void 0:l.mergeRequestAccept;if(!((p=i==null?void 0:i.mergeRequest)!=null&&p.id)||((d=i==null?void 0:i.errors)==null?void 0:d.length)!==0)throw new Error("Could not merge pull request")}async setPullRequestMilestone(s,e={}){var u,l,p;let{pullRequest:t,milestone:n}=s;if(!t.graphQLId)throw new Error('GitHub requires "graphQLId" for this function.');let o=`mutation SetPullRequestMilestone($fullPath: ID!, $pullRequestId: String!, $milestoneGraphQLId: MilestoneID) {
924
+ }`,i=(l=(await P(this.config,{query:o,variables:{fullPath:`${t.repository.owner.login}/${t.repository.name}`,pullRequestId:t.number.toString(),expectedSourceSha:t.headRef.oid,squash:s==="SQUASH"}},e)).body.data)==null?void 0:l.mergeRequestAccept;if(!((p=i==null?void 0:i.mergeRequest)!=null&&p.id)||((d=i==null?void 0:i.errors)==null?void 0:d.length)!==0)throw new Error("Could not merge pull request")}async setPullRequestMilestone(n,e={}){var u,l,p;let{pullRequest:t,milestone:s}=n;if(!t.graphQLId)throw new Error('GitHub requires "graphQLId" for this function.');let o=`mutation SetPullRequestMilestone($fullPath: ID!, $pullRequestId: String!, $milestoneGraphQLId: MilestoneID) {
925
925
  mergeRequestSetMilestone(input: { projectPath: $fullPath, iid: $pullRequestId, milestoneId: $milestoneGraphQLId }) {
926
926
  errors,
927
927
  mergeRequest {
928
928
  id
929
929
  }
930
930
  }
931
- }`,a=await y(this.config,{query:o,variables:{fullPath:`${t.repository.owner.login}/${t.repository.name}`,pullRequestId:t.number.toString(),milestoneGraphQLId:n==null?void 0:n.graphQLId}},e),i=(u=a.body.data)==null?void 0:u.mergeRequestSetMilestone;if(!((l=i==null?void 0:i.mergeRequest)!=null&&l.id)||a.body.errors||((p=i==null?void 0:i.errors)==null?void 0:p.length)!==0)throw new Error("Could not set milestone of pull request")}async setPullRequestAsDraft(s,e={}){var u,l,p;let{pullRequest:t,isDraft:n}=s,o=`mutation MergeRequestSetDraft($fullPath: ID!, $pullRequestId: String!, $isDraft: Boolean!) {
931
+ }`,a=await P(this.config,{query:o,variables:{fullPath:`${t.repository.owner.login}/${t.repository.name}`,pullRequestId:t.number.toString(),milestoneGraphQLId:s==null?void 0:s.graphQLId}},e),i=(u=a.body.data)==null?void 0:u.mergeRequestSetMilestone;if(!((l=i==null?void 0:i.mergeRequest)!=null&&l.id)||a.body.errors||((p=i==null?void 0:i.errors)==null?void 0:p.length)!==0)throw new Error("Could not set milestone of pull request")}async setPullRequestAsDraft(n,e={}){var u,l,p;let{pullRequest:t,isDraft:s}=n,o=`mutation MergeRequestSetDraft($fullPath: ID!, $pullRequestId: String!, $isDraft: Boolean!) {
932
932
  mergeRequestSetDraft(input: { projectPath: $fullPath, iid: $pullRequestId, draft: $isDraft }) {
933
933
  errors,
934
934
  mergeRequest {
935
935
  id
936
936
  }
937
937
  }
938
- }`,i=(u=(await y(this.config,{query:o,variables:{fullPath:`${t.repository.owner.login}/${t.repository.name}`,pullRequestId:t.number.toString(),isDraft:n}},e)).body.data)==null?void 0:u.mergeRequestSetDraft;if(!((l=i==null?void 0:i.mergeRequest)!=null&&l.id)||((p=i==null?void 0:i.errors)==null?void 0:p.length)!==0)throw new Error("Could not set pull request as draft")}async setPullRequestReviewers(s,e={}){var l,p,d;let{pullRequest:t,reviewers:n}=s,o=n.map(c=>{if(!c.username)throw new Error('GitLab requires reviewer "username" for this function.');return c.username}),a=`mutation MergeRequestSetReviewers($fullPath: ID!, $pullRequestId: String!, $reviewerUsernames: [String!]!) {
938
+ }`,i=(u=(await P(this.config,{query:o,variables:{fullPath:`${t.repository.owner.login}/${t.repository.name}`,pullRequestId:t.number.toString(),isDraft:s}},e)).body.data)==null?void 0:u.mergeRequestSetDraft;if(!((l=i==null?void 0:i.mergeRequest)!=null&&l.id)||((p=i==null?void 0:i.errors)==null?void 0:p.length)!==0)throw new Error("Could not set pull request as draft")}async setPullRequestReviewers(n,e={}){var l,p,d;let{pullRequest:t,reviewers:s}=n,o=s.map(c=>{if(!c.username)throw new Error('GitLab requires reviewer "username" for this function.');return c.username}),a=`mutation MergeRequestSetReviewers($fullPath: ID!, $pullRequestId: String!, $reviewerUsernames: [String!]!) {
939
939
  mergeRequestSetReviewers(input: { projectPath: $fullPath, iid: $pullRequestId, reviewerUsernames: $reviewerUsernames }) {
940
940
  errors,
941
941
  mergeRequest {
942
942
  id
943
943
  }
944
944
  }
945
- }`,u=(l=(await y(this.config,{query:a,variables:{fullPath:`${t.repository.owner.login}/${t.repository.name}`,pullRequestId:t.number.toString(),reviewerUsernames:o}},e)).body.data)==null?void 0:l.mergeRequestSetReviewers;if(!((p=u==null?void 0:u.mergeRequest)!=null&&p.id)||((d=u==null?void 0:u.errors)==null?void 0:d.length)!==0)throw new Error("Could not set pull request reviewers")}async reRequestPullRequestReview(s,e={}){var u,l,p;let{pullRequest:t,reviewer:n}=s;if(!n.graphQLId)throw new Error('GitLab requires reviwer "graphQLId" for this function.');let o=`mutation MergeRequestReviewerRereview($fullPath: ID!, $pullRequestId: String!, $reviewerUserId: UserID!) {
945
+ }`,u=(l=(await P(this.config,{query:a,variables:{fullPath:`${t.repository.owner.login}/${t.repository.name}`,pullRequestId:t.number.toString(),reviewerUsernames:o}},e)).body.data)==null?void 0:l.mergeRequestSetReviewers;if(!((p=u==null?void 0:u.mergeRequest)!=null&&p.id)||((d=u==null?void 0:u.errors)==null?void 0:d.length)!==0)throw new Error("Could not set pull request reviewers")}async reRequestPullRequestReview(n,e={}){var u,l,p;let{pullRequest:t,reviewer:s}=n;if(!s.graphQLId)throw new Error('GitLab requires reviwer "graphQLId" for this function.');let o=`mutation MergeRequestReviewerRereview($fullPath: ID!, $pullRequestId: String!, $reviewerUserId: UserID!) {
946
946
  mergeRequestReviewerRereview(input: { projectPath: $fullPath, iid: $pullRequestId, userId: $reviewerUserId }) {
947
947
  errors,
948
948
  mergeRequest {
949
949
  id
950
950
  }
951
951
  }
952
- }`,i=(u=(await y(this.config,{query:o,variables:{fullPath:`${t.repository.owner.login}/${t.repository.name}`,pullRequestId:t.number.toString(),reviewerUserId:n.graphQLId}},e)).body.data)==null?void 0:u.mergeRequestReviewerRereview;if(!((l=i==null?void 0:i.mergeRequest)!=null&&l.id)||((p=i==null?void 0:i.errors)==null?void 0:p.length)!==0)throw new Error("Could not set pull request reviewers")}async reRequestPullRequestReviews(s,e={}){let{pullRequest:t,reviewers:n}=s,o=t.reviews;if(!o)throw new Error('GitLab requires "reviews" for this function.');let a=n.filter(i=>o.find(u=>u.reviewer.graphQLId===i.graphQLId));await Promise.all(a.map(i=>this.reRequestPullRequestReview({pullRequest:t,reviewer:i},e)))}async setPullRequestAssignees(s,e={}){var l,p,d;let{pullRequest:t,assignees:n}=s,o=n.map(c=>{if(!c.username)throw new Error('GitLab requires assignee "username" for this function.');return c.username}),a=`mutation MergeRequestSetAssignees($fullPath: ID!, $pullRequestId: String!, $assigneeUsernames: [String!]!) {
952
+ }`,i=(u=(await P(this.config,{query:o,variables:{fullPath:`${t.repository.owner.login}/${t.repository.name}`,pullRequestId:t.number.toString(),reviewerUserId:s.graphQLId}},e)).body.data)==null?void 0:u.mergeRequestReviewerRereview;if(!((l=i==null?void 0:i.mergeRequest)!=null&&l.id)||((p=i==null?void 0:i.errors)==null?void 0:p.length)!==0)throw new Error("Could not set pull request reviewers")}async reRequestPullRequestReviews(n,e={}){let{pullRequest:t,reviewers:s}=n,o=t.reviews;if(!o)throw new Error('GitLab requires "reviews" for this function.');let a=s.filter(i=>o.find(u=>u.reviewer.graphQLId===i.graphQLId));await Promise.all(a.map(i=>this.reRequestPullRequestReview({pullRequest:t,reviewer:i},e)))}async setPullRequestAssignees(n,e={}){var l,p,d;let{pullRequest:t,assignees:s}=n,o=s.map(c=>{if(!c.username)throw new Error('GitLab requires assignee "username" for this function.');return c.username}),a=`mutation MergeRequestSetAssignees($fullPath: ID!, $pullRequestId: String!, $assigneeUsernames: [String!]!) {
953
953
  mergeRequestSetAssignees(input: { projectPath: $fullPath, iid: $pullRequestId, assigneeUsernames: $assigneeUsernames }) {
954
954
  errors,
955
955
  mergeRequest {
956
956
  id
957
957
  }
958
958
  }
959
- }`,u=(l=(await y(this.config,{query:a,variables:{fullPath:`${t.repository.owner.login}/${t.repository.name}`,pullRequestId:t.number.toString(),assigneeUsernames:o}},e)).body.data)==null?void 0:l.mergeRequestSetAssignees;if(!((p=u==null?void 0:u.mergeRequest)!=null&&p.id)||((d=u==null?void 0:u.errors)==null?void 0:d.length)!==0)throw new Error("Could not set pull request assignees")}async setPullRequestLabels(s,e={}){var u,l,p;let{pullRequest:t,labels:n}=s,o=n.map(d=>{if(!d.graphQLId)throw new Error('GitLab requires "graphQLId" for labels in this function.');return d.graphQLId}),a=`mutation SetPullRequestLabels($fullPath: ID!, $pullRequestId: String!, $labelGraphQLIds: [LabelID!]!) {
959
+ }`,u=(l=(await P(this.config,{query:a,variables:{fullPath:`${t.repository.owner.login}/${t.repository.name}`,pullRequestId:t.number.toString(),assigneeUsernames:o}},e)).body.data)==null?void 0:l.mergeRequestSetAssignees;if(!((p=u==null?void 0:u.mergeRequest)!=null&&p.id)||((d=u==null?void 0:u.errors)==null?void 0:d.length)!==0)throw new Error("Could not set pull request assignees")}async setPullRequestLabels(n,e={}){var u,l,p;let{pullRequest:t,labels:s}=n,o=s.map(d=>{if(!d.graphQLId)throw new Error('GitLab requires "graphQLId" for labels in this function.');return d.graphQLId}),a=`mutation SetPullRequestLabels($fullPath: ID!, $pullRequestId: String!, $labelGraphQLIds: [LabelID!]!) {
960
960
  mergeRequestSetLabels(input: { projectPath: $fullPath, iid: $pullRequestId, labelIds: $labelGraphQLIds }) {
961
961
  mergeRequest {
962
962
  id
963
963
  }
964
964
  }
965
- }`;if(!((p=(l=(u=(await y(this.config,{query:a,variables:{fullPath:`${t.repository.owner.login}/${t.repository.name}`,pullRequestId:t.number.toString(),labelGraphQLIds:o}},e)).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(s,e={}){var o,a,i;let t=Ar(s),n=await y(this.config,{query:`
965
+ }`;if(!((p=(l=(u=(await P(this.config,{query:a,variables:{fullPath:`${t.repository.owner.login}/${t.repository.name}`,pullRequestId:t.number.toString(),labelGraphQLIds:o}},e)).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(n,e={}){var o,a,i;let t=Gr(n),s=await P(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
- ${He}
972
+ ${We}
973
973
  }
974
974
  }
975
975
  }
976
- `,variables:{issueNumber:s.number,projectId:t}},e);if(!((o=n.body.data)!=null&&o.project))throw new Error(`Repository ${t} not found`);if(!((i=(a=n.body.data)==null?void 0:a.project)!=null&&i.issue))throw new Error(`Issue ${s.number} not found`);return{data:Je(n.body.data.project.issue,Re(n.body.data.project),this.getIsSelfHosted(e),this.config.baseUrl??e.baseUrl)}}getVariablesForIssues(s){let{updatedBefore:e,authorLogin:t,assigneeLogins:n,labelNames:o}=s||{},a={},i=[],u=[],l=(p,d,c)=>{i.push(`$${p}: ${c}`),u.push(`${p}: $${p}`),a[p]=d};return e&&l("updatedBefore",e,"Time"),t&&l("authorUsername",t,"String"),n&&l("assigneeUsername",n[0],"String"),o&&l("labelName",o,"[String]"),{variables:a,variableTypes:i,issueArguments:u}}async getIssuesForRepo(s,e={}){var b,S,f;let{cursor:t,repo:n}=s||{},o=z(n),{variables:a,variableTypes:i,issueArguments:u}=this.getVariablesForIssues(s),l={fullPath:o,...a},p=`
976
+ `,variables:{issueNumber:n.number,projectId:t}},e);if(!((o=s.body.data)!=null&&o.project))throw new Error(`Repository ${t} not found`);if(!((i=(a=s.body.data)==null?void 0:a.project)!=null&&i.issue))throw new Error(`Issue ${n.number} not found`);return{data:Ke(s.body.data.project.issue,be(s.body.data.project),this.getIsSelfHosted(e),this.config.baseUrl??e.baseUrl)}}getVariablesForIssues(n){let{updatedBefore:e,authorLogin:t,assigneeLogins:s,labelNames:o}=n||{},a={},i=[],u=[],l=(p,d,c)=>{i.push(`$${p}: ${c}`),u.push(`${p}: $${p}`),a[p]=d};return e&&l("updatedBefore",e,"Time"),t&&l("authorUsername",t,"String"),s&&l("assigneeUsername",s[0],"String"),o&&l("labelName",o,"[String]"),{variables:a,variableTypes:i,issueArguments:u}}async getIssuesForRepo(n,e={}){var y,v,f;let{cursor:t,repo:s}=n||{},o=H(s),{variables:a,variableTypes:i,issueArguments:u}=this.getVariablesForIssues(n),l={fullPath:o,...a},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
- ${He}
996
+ ${We}
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 y(this.config,{query:p,variables:{...l,after:t}},e),c=[],g=(b=d.body.data)==null?void 0:b.project,m=Re(g||{id:"",fullPath:"",webUrl:""});return(((S=g==null?void 0:g.issues)==null?void 0:S.nodes)||[]).forEach(P=>{c.push(Je(P,m,this.getIsSelfHosted(e),this.config.baseUrl??e.baseUrl))}),{pageInfo:((f=g==null?void 0:g.issues)==null?void 0:f.pageInfo)??{endCursor:null,hasNextPage:!1},data:c.sort((P,O)=>(P.updatedDate||P.createdDate).getTime()-(O.updatedDate||O.createdDate).getTime())}}async getIssuesForRepos(s,e={}){var g,m,h,b,S;let{cursor:t}=s||{},n=s.repoIds.map(f=>f.toString().startsWith(X)?f:`${X}${f}`),{variables:o,variableTypes:a,mergeRequestArguments:i}=this.getVariablesForPullRequests(s),u={projectIds:n,...o},l=`
1004
+ }`,d=await P(this.config,{query:p,variables:{...l,after:t}},e),c=[],g=(y=d.body.data)==null?void 0:y.project,m=be(g||{id:"",fullPath:"",webUrl:""});return(((v=g==null?void 0:g.issues)==null?void 0:v.nodes)||[]).forEach(S=>{c.push(Ke(S,m,this.getIsSelfHosted(e),this.config.baseUrl??e.baseUrl))}),{pageInfo:((f=g==null?void 0:g.issues)==null?void 0:f.pageInfo)??{endCursor:null,hasNextPage:!1},data:c.sort((S,x)=>(S.updatedDate||S.createdDate).getTime()-(x.updatedDate||x.createdDate).getTime())}}async getIssuesForRepos(n,e={}){var g,m,h,y,v;let{cursor:t}=n||{},s=n.repoIds.map(f=>f.toString().startsWith(Z)?f:`${Z}${f}`),{variables:o,variableTypes:a,mergeRequestArguments:i}=this.getVariablesForPullRequests(n),u={projectIds:s,...o},l=`
1005
1005
  query GetIssuesFromProject(
1006
1006
  $projectIds: [ID!]
1007
1007
  $after: String
@@ -1027,24 +1027,24 @@ query GetSingleIssue($projectId: ID!, $issueNumber: String!) {
1027
1027
  ${i.length?i.join(" "):""}
1028
1028
  ) {
1029
1029
  nodes {
1030
- ${He}
1030
+ ${We}
1031
1031
  }
1032
1032
  }
1033
1033
  }
1034
1034
  }
1035
- }`,p=await y(this.config,{query:l,variables:{...u,after:t}},e),d=[];return(((m=(g=p.body.data)==null?void 0:g.projects)==null?void 0:m.nodes)||[]).forEach(f=>{var A;if(!s.includeFromArchivedRepos&&f.archived)return;let P=Re(f);(((A=f.issues)==null?void 0:A.nodes)||[]).forEach(xt=>d.push(Je(xt,P,this.getIsSelfHosted(e),this.config.baseUrl??e.baseUrl)))}),{pageInfo:((S=(b=(h=p.body)==null?void 0:h.data)==null?void 0:b.projects)==null?void 0:S.pageInfo)??{endCursor:null,hasNextPage:!1},data:d.sort((f,P)=>(f.updatedDate||f.createdDate).getTime()-(P.updatedDate||P.createdDate).getTime())}}async setIssueState(s,e={}){var i,u,l;let{issue:t,state:n}=s;if(!t.repository)throw new Error('GitLab requires "repository" for this function.');let o=`mutation SetIssueState($fullPath: ID!, $issueId: String!, $status: IssueStateEvent!) {
1035
+ }`,p=await P(this.config,{query:l,variables:{...u,after:t}},e),d=[];return(((m=(g=p.body.data)==null?void 0:g.projects)==null?void 0:m.nodes)||[]).forEach(f=>{var G;if(!n.includeFromArchivedRepos&&f.archived)return;let S=be(f);(((G=f.issues)==null?void 0:G.nodes)||[]).forEach(kt=>d.push(Ke(kt,S,this.getIsSelfHosted(e),this.config.baseUrl??e.baseUrl)))}),{pageInfo:((v=(y=(h=p.body)==null?void 0:h.data)==null?void 0:y.projects)==null?void 0:v.pageInfo)??{endCursor:null,hasNextPage:!1},data:d.sort((f,S)=>(f.updatedDate||f.createdDate).getTime()-(S.updatedDate||S.createdDate).getTime())}}async setIssueState(n,e={}){var i,u,l;let{issue:t,state:s}=n;if(!t.repository)throw new Error('GitLab requires "repository" for this function.');let o=`mutation SetIssueState($fullPath: ID!, $issueId: String!, $status: IssueStateEvent!) {
1036
1036
  updateIssue(input: { projectPath: $fullPath, iid: $issueId, stateEvent: $status }) {
1037
1037
  issue {
1038
1038
  id
1039
1039
  }
1040
1040
  }
1041
- }`;if(!((l=(u=(i=(await y(this.config,{query:o,variables:{fullPath:`${t.repository.owner.login}/${t.repository.name}`,issueId:t.number,status:n==="OPEN"?"REOPEN":"CLOSE"}},e)).body.data)==null?void 0:i.updateIssue)==null?void 0:u.issue)!=null&&l.id))throw new Error("Could not set issue status")}async closeIssue(s,e={}){await this.setIssueState({...s,state:"CLOSED"},e)}async reOpenIssue(s,e={}){await this.setIssueState({...s,state:"OPEN"},e)}async setIssueLabels(s,e={}){var u,l,p;let{issue:t,labels:n}=s;if(!t.repository)throw new Error('GitLab requires a "repository" for this function.');let o=n.map(d=>{if(!d.graphQLId)throw new Error('GitLab requires label "graphQLId" for this function.');return d.graphQLId}),a=`mutation SetIssueLabels($fullPath: ID!, $issueId: String!, $labelGraphQLIds: [ID!]) {
1041
+ }`;if(!((l=(u=(i=(await P(this.config,{query:o,variables:{fullPath:`${t.repository.owner.login}/${t.repository.name}`,issueId:t.number,status:s==="OPEN"?"REOPEN":"CLOSE"}},e)).body.data)==null?void 0:i.updateIssue)==null?void 0:u.issue)!=null&&l.id))throw new Error("Could not set issue status")}async closeIssue(n,e={}){await this.setIssueState({...n,state:"CLOSED"},e)}async reOpenIssue(n,e={}){await this.setIssueState({...n,state:"OPEN"},e)}async setIssueLabels(n,e={}){var u,l,p;let{issue:t,labels:s}=n;if(!t.repository)throw new Error('GitLab requires a "repository" for this function.');let o=s.map(d=>{if(!d.graphQLId)throw new Error('GitLab requires label "graphQLId" for this function.');return d.graphQLId}),a=`mutation SetIssueLabels($fullPath: ID!, $issueId: String!, $labelGraphQLIds: [ID!]) {
1042
1042
  updateIssue(input: { projectPath: $fullPath, iid: $issueId, labelIds: $labelGraphQLIds }) {
1043
1043
  issue {
1044
1044
  id
1045
1045
  }
1046
1046
  }
1047
- }`;if(!((p=(l=(u=(await y(this.config,{query:a,variables:{fullPath:`${t.repository.owner.login}/${t.repository.name}`,issueId:t.number,labelGraphQLIds:o}},e)).body.data)==null?void 0:u.updateIssue)==null?void 0:l.issue)!=null&&p.id))throw new Error("Could not set issue labels")}async setIssueMilestone(s,e={}){var u,l,p;let{issue:t,milestone:n}=s;if(!t.repository)throw new Error('GitLab requires "repository" for this function.');let o=`mutation SetIssueMilestone($fullPath: ID!, $issueId: String!, $milestoneId: ID) {
1047
+ }`;if(!((p=(l=(u=(await P(this.config,{query:a,variables:{fullPath:`${t.repository.owner.login}/${t.repository.name}`,issueId:t.number,labelGraphQLIds:o}},e)).body.data)==null?void 0:u.updateIssue)==null?void 0:l.issue)!=null&&p.id))throw new Error("Could not set issue labels")}async setIssueMilestone(n,e={}){var u,l,p;let{issue:t,milestone:s}=n;if(!t.repository)throw new Error('GitLab requires "repository" for this function.');let o=`mutation SetIssueMilestone($fullPath: ID!, $issueId: String!, $milestoneId: ID) {
1048
1048
  updateIssue(input: { projectPath: $fullPath, iid: $issueId, milestoneId: $milestoneId }) {
1049
1049
  errors
1050
1050
  issue {
@@ -1054,14 +1054,14 @@ query GetSingleIssue($projectId: ID!, $issueNumber: String!) {
1054
1054
  }
1055
1055
  }
1056
1056
  }
1057
- }`,a=await y(this.config,{query:o,variables:{fullPath:`${t.repository.owner.login}/${t.repository.name}`,issueId:t.number,milestoneId:(n==null?void 0:n.id)??null}},e),i=(u=a.body.data)==null?void 0:u.updateIssue;if(!((l=i==null?void 0:i.issue)!=null&&l.id)||a.body.errors||((p=i==null?void 0:i.errors)==null?void 0:p.length)!==0)throw new Error("Could not set milestone of issue")}async setIssueAssignees(s,e={}){var l,p,d;let{issue:t,assignees:n}=s;if(!t.repository)throw new Error('GitLab requires "repository" for this function.');let o=n.map(c=>c.username),a=`mutation SetIssueAssignees($fullPath: ID!, $issueId: String!, $assigneeUsernames: [String!]!) {
1057
+ }`,a=await P(this.config,{query:o,variables:{fullPath:`${t.repository.owner.login}/${t.repository.name}`,issueId:t.number,milestoneId:(s==null?void 0:s.id)??null}},e),i=(u=a.body.data)==null?void 0:u.updateIssue;if(!((l=i==null?void 0:i.issue)!=null&&l.id)||a.body.errors||((p=i==null?void 0:i.errors)==null?void 0:p.length)!==0)throw new Error("Could not set milestone of issue")}async setIssueAssignees(n,e={}){var l,p,d;let{issue:t,assignees:s}=n;if(!t.repository)throw new Error('GitLab requires "repository" for this function.');let o=s.map(c=>c.username),a=`mutation SetIssueAssignees($fullPath: ID!, $issueId: String!, $assigneeUsernames: [String!]!) {
1058
1058
  issueSetAssignees(input: { projectPath: $fullPath, iid: $issueId, assigneeUsernames: $assigneeUsernames }) {
1059
1059
  errors,
1060
1060
  issue {
1061
1061
  id
1062
1062
  }
1063
1063
  }
1064
- }`,u=(l=(await y(this.config,{query:a,variables:{fullPath:`${t.repository.owner.login}/${t.repository.name}`,issueId:t.number,assigneeUsernames:o}},e)).body.data)==null?void 0:l.issueSetAssignees;if(!((p=u==null?void 0:u.issue)!=null&&p.id)||((d=u==null?void 0:u.errors)==null?void 0:d.length)!==0)throw new Error("Could not set issue assignees")}async getMilestonesForRepo(s,e={}){var i,u,l,p,d,c,g;let{repo:{namespace:t,name:n},cursor:o}=s,a=await y(this.config,{query:`
1064
+ }`,u=(l=(await P(this.config,{query:a,variables:{fullPath:`${t.repository.owner.login}/${t.repository.name}`,issueId:t.number,assigneeUsernames:o}},e)).body.data)==null?void 0:l.issueSetAssignees;if(!((p=u==null?void 0:u.issue)!=null&&p.id)||((d=u==null?void 0:u.errors)==null?void 0:d.length)!==0)throw new Error("Could not set issue assignees")}async getMilestonesForRepo(n,e={}){var i,u,l,p,d,c,g;let{repo:{namespace:t,name:s},cursor:o}=n,a=await P(this.config,{query:`
1065
1065
  query getLabelsForRepo(
1066
1066
  $fullPath: ID!
1067
1067
  $after: String
@@ -1072,7 +1072,7 @@ query getLabelsForRepo(
1072
1072
  webUrl
1073
1073
  milestones(after: $after) {
1074
1074
  nodes {
1075
- ${Xe}
1075
+ ${Ze}
1076
1076
  }
1077
1077
  pageInfo {
1078
1078
  endCursor
@@ -1081,7 +1081,7 @@ query getLabelsForRepo(
1081
1081
  }
1082
1082
  }
1083
1083
  }
1084
- `,variables:{fullPath:`${t}/${n}`,after:o}},e);return{pageInfo:((l=(u=(i=a.body.data)==null?void 0:i.project)==null?void 0:u.milestones)==null?void 0:l.pageInfo)??{endCursor:null,hasNextPage:!1},data:((g=(c=(d=(p=a.body.data)==null?void 0:p.project)==null?void 0:d.milestones)==null?void 0:c.nodes)==null?void 0:g.map(m=>{var h,b;return et(m,((b=(h=a.body.data)==null?void 0:h.project)==null?void 0:b.webUrl)||"")}))??[]}}async getLabelsForRepo(s,e={}){var i,u,l,p,d,c,g;let{repo:{namespace:t,name:n},cursor:o}=s,a=await y(this.config,{query:`
1084
+ `,variables:{fullPath:`${t}/${s}`,after:o}},e);return{pageInfo:((l=(u=(i=a.body.data)==null?void 0:i.project)==null?void 0:u.milestones)==null?void 0:l.pageInfo)??{endCursor:null,hasNextPage:!1},data:((g=(c=(d=(p=a.body.data)==null?void 0:p.project)==null?void 0:d.milestones)==null?void 0:c.nodes)==null?void 0:g.map(m=>{var h,y;return tt(m,((y=(h=a.body.data)==null?void 0:h.project)==null?void 0:y.webUrl)||"")}))??[]}}async getLabelsForRepo(n,e={}){var i,u,l,p,d,c,g;let{repo:{namespace:t,name:s},cursor:o}=n,a=await P(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
- ${Ze}
1094
+ ${Ye}
1095
1095
  }
1096
1096
  pageInfo {
1097
1097
  endCursor
@@ -1100,5 +1100,5 @@ query getLabelsForRepo(
1100
1100
  }
1101
1101
  }
1102
1102
  }
1103
- `,variables:{fullPath:`${t}/${n}`,after:o}},e);return{pageInfo:((l=(u=(i=a.body.data)==null?void 0:i.project)==null?void 0:u.labels)==null?void 0:l.pageInfo)??{endCursor:null,hasNextPage:!1},data:((g=(c=(d=(p=a.body.data)==null?void 0:p.project)==null?void 0:d.labels)==null?void 0:c.nodes)==null?void 0:g.map(Ye))??[]}}};var xr="https://api.atlassian.com/ex/jira",be=100,tt=["assignee","comment","summary","created","creator","updated","votes","issuetype","status","labels","components","project","fixVersions","description"],rt=(r,s,e,t)=>{var i,u,l,p;let n=r.fields.assignee,o=!t,a=r.fields[(s==null?void 0:s.Sprint)??""]??[];return{id:r.id,commentCount:r.fields.comment.comments.length,number:r.key,title:r.fields.summary,url:e?`${e}/browse/${r.key}`:null,closedDate:null,createdDate:new Date(r.fields.created),author:ye(r.fields.creator,e,o),updatedDate:new Date(r.fields.updated),assignees:n?[ye(n,e,o)]:[],description:r.fields.description,repository:null,project:{name:r.fields.project.name,resourceId:t??null,key:r.fields.project.key,namespace:null,id:r.fields.project.id},state:Qr(r.fields.status),statusTransitions:((i=r.transitions)==null?void 0:i.map(kr))??[],components:((u=r.fields.components)==null?void 0:u.map(Nr))??[],type:r.fields.issuetype.name,upvoteCount:((l=r.fields.votes)==null?void 0:l.votes)||0,labels:((p=r.fields.labels)==null?void 0:p.map(d=>({color:null,description:null,id:null,name:d})))??[],sprints:a.map(_r),fixVersions:r.fields.fixVersions.map(Br)}},kr=r=>{let s;switch(r.to.statusCategory.name){case"To Do":s="TO_DO";break;case"In Progress":s="IN_PROGRESS";break;default:s="DONE";break}return{name:r.name,id:r.id,to:{id:r.to.id,name:r.to.name,color:r.to.statusCategory.colorName,category:s}}},Nr=r=>({description:r.description??null,id:r.id,name:r.name}),Fr=(r,s,e)=>e&&r.name?`${s}/secure/ViewProfile.jspa?name=${encodeURIComponent(r.name)}`:`${s}/jira/people/${r.accountId}`,ye=(r,s,e)=>({id:(e?r.key:r.accountId)??"",name:r.displayName,email:r.emailAddress,avatarUrl:r.avatarUrls["48x48"],username:r.displayName,url:Fr(r,s,e)}),Qr=r=>{let s;switch(r.statusCategory.name){case"To Do":s="TO_DO";break;case"In Progress":s="IN_PROGRESS";break;default:s="DONE";break}return{id:r.id,name:r.name,color:r.statusCategory.colorName,category:s}},_r=r=>({id:r.id.toString(),name:r.name,isActive:r.state==="active",startDate:r.startDate?new Date(r.startDate):null,endDate:r.endDate?new Date(r.endDate):null,completedDate:r.completeDate?new Date(r.completeDate):null}),Br=r=>({id:r.id,description:r.description,name:r.name,archived:r.archived,released:r.released,releaseDate:r.releaseDate?new Date(r.releaseDate):null}),_=(r,s,e)=>e?`${s.baseUrl||xr}/${e}`:`${(s==null?void 0:s.baseUrl)||r.baseUrl}`,we=async(r,s,e={})=>{let{resourceId:t}=s;return(await r.request({url:`${_(r,e,t)}/rest/api/2/field`,headers:I(e.token||r.token)})).body},Pe=async(r,s,e,t={})=>{let{number:n,resourceId:o,fields:a}=s||{},i=await r.request({url:`${_(r,t,o)}/rest/api/2/issue/${n}?fields=${tt.join(",")}&expand=transitions`,headers:I(t.token||r.token)});return{data:rt(i.body,a,e,o)}},Se=async(r,s,e,t={})=>{let{page:n,resourceId:o,labelNames:a,fields:i}=s||{},u=n??0,l=["statusCategory != Done",`(creator = currentUser() OR assignee = currentUser()
1104
- OR comment ~ currentUser() OR summary ~ currentUser() OR description ~ currentUser())`];a&&a.forEach(m=>l.push(`labels = "${m}"`));let p=`${l.join(" AND ")} ORDER BY updated DESC`,c=(await r.request({url:`${_(r,t,o)}/rest/api/2/search?jql=${p}&startAt=${u}&maxResults=${be}&fields=${tt.join(",")}&expand=transitions`,headers:I(t.token||r.token)})).body.issues.map(m=>rt(m,i,e,o)),g=c.length==be;return{data:c,pageInfo:{hasNextPage:g,nextPage:g?u+c.length:null}}},Dt=async(r,s,e,t={})=>{let{page:n,resourceId:o,jql:a,fields:i}=s||{},u=n??0,l=[...tt],p=i==null?void 0:i.Sprint;p&&l.push(p);let c=(await r.request({url:`${_(r,t,o)}/rest/api/2/search?jql=${a.join(" AND ")}&startAt=${u}&maxResults=${be}&fields=${l.join(",")}&expand=transitions`,headers:I(t.token||r.token)})).body.issues.map(m=>rt(m,i,e,o)),g=c.length==be;return{data:c,pageInfo:{hasNextPage:g,nextPage:g?u+c.length:null}}},ve=async(r,s,e,t={})=>{let{assigneeLogins:n,authorLogin:o,mentionLogin:a,labelNames:i,page:u,projectKey:l,resourceId:p,fields:d}=s||{},c=u??0,g=[`project = "${l}"`,"statusCategory != Done"];return o&&g.push(`creator in ("${o}")`),n&&n.length!==0&&g.push(`assignee in ("${n.join('", "')}")`),a&&g.push(`comment ~ "${a}"`),i&&i.forEach(m=>g.push(`labels = "${m}"`)),Dt(r,{resourceId:p,jql:g,page:c,fields:d},e,t)},qe=async(r,s,e,t={})=>{let{assigneeLogins:n,authorLogin:o,mentionLogin:a,labelNames:i,page:u,projectKeys:l,resourceId:p,fields:d}=s||{},c=u??0,m=["("+l.map(h=>`project = "${h}"`).join(" OR ")+")","statusCategory != Done"];return o&&m.push(`creator in ("${o}")`),n&&n.length!==0&&m.push(`assignee in ("${n.join('", "')}")`),a&&m.push(`comment ~ "${a}"`),i&&i.forEach(h=>m.push(`labels = "${h}"`)),Dt(r,{resourceId:p,jql:m,fields:d,page:c},e,t)},Ee=async(r,s,e={})=>{let{issue:t,labels:n}=s;if(!t.project)throw new Error('Jira requires a "project" for this function.');let o={fields:{labels:n.map(a=>a.name)}};await r.request({method:"PUT",url:`${_(r,e,t.project.resourceId??void 0)}/rest/api/2/issue/${t.id}`,body:JSON.stringify(o),headers:{...I(e.token||r.token),"Content-Type":"application/json"}})},Ce=async(r,s,e={})=>{let{issue:t,components:n}=s;if(!t.project)throw new Error('Jira requires a "project" for this function.');let o={fields:{components:n.map(a=>({id:a.id}))}};await r.request({method:"PUT",url:`${_(r,e,t.project.resourceId??void 0)}/rest/api/2/issue/${t.id}`,body:JSON.stringify(o),headers:{...I(e.token||r.token),"Content-Type":"application/json"}})},Ue=async(r,s,e={})=>{let{issue:t,status:n}=s;if(!t.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 r.request({method:"POST",url:`${_(r,e,t.project.resourceId??void 0)}/rest/api/2/issue/${t.id}/transitions`,body:JSON.stringify(o),headers:{...I(e.token||r.token),"Content-Type":"application/json"}})},De=async(r,s,e={})=>{let{resourceId:t,projectIdOrKey:n}=s,o=new URL(`${_(r,e,t)}/rest/api/2/project/${n}/components`);return{data:(await r.request({url:o.toString(),headers:I(e.token||r.token)})).body}};var se="https://api.atlassian.com/ex/jira",st=100,Y=class extends D{constructor(){super(...arguments);this._resourceUrlCache={};this._issueFieldsCache={}}async getIssueFieldsForResource(e,t={}){if(!this._issueFieldsCache[e.resourceId]){let n=await we(this.config,e,t);this._issueFieldsCache[e.resourceId]=n.reduce((o,a)=>({...o,[a.name]:a.id}),{})}return this._issueFieldsCache[e.resourceId]??null}async getResourceUrl(e,t={}){var a;let n=t.token||this.config.token;if(!n)return null;let o=this._resourceUrlCache[n];return o?o[e.resourceId]??null:(await this.getJiraResourcesForCurrentUser(t),((a=this._resourceUrlCache[n])==null?void 0:a[e.resourceId])??null)}async getCurrentUserForResource(e,t={}){let n=await this.getResourceUrl({resourceId:e.resourceId},t),o=await this.config.request({url:`${t.baseUrl||se}/${e.resourceId}/rest/api/2/myself`,headers:I(t.token||this.config.token)});return{data:{name:o.body.displayName,email:o.body.emailAddress,avatarUrl:o.body.avatarUrls["48x48"],id:o.body.accountId,username:o.body.displayName,url:n?`${n}/jira/people/${o.body.accountId}`:null}}}async getJiraResourcesForCurrentUser(e={}){let t=await this.config.request({url:`${e.baseUrl||"https://api.atlassian.com/"}/oauth/token/accessible-resources`,headers:I(e.token||this.config.token)}),n=e.token||this.config.token,o=n?this._resourceUrlCache[n]||{}:void 0,a=t.body.map(i=>(o&&(o[i.id]=i.url),{avatarUrl:i.avatarUrl,id:i.id,name:i.name,url:i.url}));return n&&(this._resourceUrlCache[n]=o),{data:a}}async getJiraProjectsForResource(e,t={}){let n=new URL(`${t.baseUrl||se}/${e.resourceId}/rest/api/2/project/search`);n.searchParams.set("maxResults",st.toString()),e.cursor&&n.searchParams.set("startAt",e.cursor);let o=await this.config.request({url:n.toString(),headers:I(t.token||this.config.token)});return{pageInfo:{hasNextPage:o.body.values.length!==0,endCursor:(o.body.startAt+o.body.values.length).toString()},data:o.body.values.map(a=>({id:a.id,key:a.key,name:a.name,resourceId:e.resourceId}))}}async getJiraProjectsForResources(e,t={}){let n=[];return await Promise.all(e.resourceIds.map(async o=>{try{return await pt(a=>this.getJiraProjectsForResource({resourceId:o,cursor:a},t))}catch{return[]}})).then((...o)=>{o.forEach(a=>{n=n.concat(...a)})}),{data:n}}async getAccountsForJiraProject(e,t={}){let{resourceId:n,projectKey:o,cursor:a}=e,i=await this.getResourceUrl({resourceId:n},t),u=new URL(`${t.baseUrl||se}/${n}/rest/api/2/user/assignable/search`);u.searchParams.set("maxResults",st.toString()),a&&u.searchParams.set("startAt",a),u.searchParams.set("project",o);let l=await this.config.request({url:u.toString(),headers:I(t.token||this.config.token)});return{pageInfo:{hasNextPage:l.body.length!==0,endCursor:((a?parseInt(a):0)+l.body.length).toString()},data:l.body.filter(p=>p.accountType!=="app"&&p.active).map(p=>ye(p,i,!1))}}async getComponentsForJiraProject(e,t={}){return await De(this.config,e,t)}async getIssue(e,t={}){let n=await this.getIssueFieldsForResource({resourceId:e.resourceId},t),o=await this.getResourceUrl({resourceId:e.resourceId},t);return await Pe(this.config,{...e,fields:n},o,t)}async getIssuesForProject(e,t={}){let n=await this.getIssueFieldsForResource({resourceId:e.resourceId},t),o=await this.getResourceUrl({resourceId:e.resourceId},t);return await ve(this.config,{...e,fields:n},o,t)}async getIssuesForProjects(e,t={}){let n=await this.getIssueFieldsForResource({resourceId:e.resourceId},t),o=await this.getResourceUrl({resourceId:e.resourceId},t);return await qe(this.config,{...e,fields:n},o,t)}async getIssuesForResourceForCurrentUser(e,t={}){let n=await this.getIssueFieldsForResource({resourceId:e.resourceId},t),o=await this.getResourceUrl({resourceId:e.resourceId},t);return await Se(this.config,{...e,fields:n},o,t)}async setIssueStatus(e,t={}){await Ue(this.config,e,t)}async setIssueAssignee(e,t={}){let{issue:n,assignee:o}=e;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 a={accountId:o==null?void 0:o.id};await this.config.request({method:"PUT",url:`${t.baseUrl||se}/${n.project.resourceId}/rest/api/2/issue/${n.id}/assignee`,body:JSON.stringify(a),headers:{...I(t.token||this.config.token),"Content-Type":"application/json"}})}async setIssueComponents(e,t={}){await Ce(this.config,e,t)}async setIssueLabels(e,t={}){await Ee(this.config,e,t)}async getLabelsForResource(e,t={}){let{resourceId:n,cursor:o}=e,a=new URL(`${t.baseUrl||se}/${n}/rest/api/2/label`);a.searchParams.set("maxResults",st.toString()),o&&a.searchParams.set("startAt",o);let i=await this.config.request({url:a.toString(),headers:I(t.token||this.config.token)});return{pageInfo:{hasNextPage:!i.body.isLast,endCursor:(i.body.startAt+i.body.values.length).toString()},data:i.body.values.map(u=>({color:null,description:null,id:null,name:u}))}}};var ee=class extends G{constructor(){super(...arguments);this._issueFieldsCache={}}async getIssueFieldsForResource(e={}){let t=(e==null?void 0:e.baseUrl)||this.config.baseUrl||"";if(!this._issueFieldsCache[t]){let n=await we(this.config,{},e);this._issueFieldsCache[t]=n.reduce((o,a)=>({...o,[a.name]:a.id}),{})}return this._issueFieldsCache[t]??null}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(n=>({id:n.id,name:n.name}))}}async getIssue(e,t={}){let n=e.resourceUrl||t.baseUrl||this.config.baseUrl;if(!n)throw new Error('Jira Server requires a "resourceUrl" or "baseUrl" for this function.');let o=await this.getIssueFieldsForResource(t);return await Pe(this.config,{...e,fields:o},n,t)}async getIssuesForProject(e,t={}){let n=e.resourceUrl||t.baseUrl||this.config.baseUrl;if(!n)throw new Error('Jira Server requires a "resourceUrl" or "baseUrl" for this function.');let o=await this.getIssueFieldsForResource(t);return await ve(this.config,{...e,fields:o},n,t)}async getIssuesForProjects(e,t={}){let n=e.resourceUrl||t.baseUrl||this.config.baseUrl;if(!n)throw new Error('Jira Server requires a "resourceUrl" or "baseUrl" for this function.');let o=await this.getIssueFieldsForResource(t);return await qe(this.config,{...e,fields:o},n,t)}async getIssuesForResourceForCurrentUser(e,t={}){let n=e.resourceUrl||t.baseUrl||this.config.baseUrl;if(!n)throw new Error('Jira Server requires a "resourceUrl" or "baseUrl" for this function.');let o=await this.getIssueFieldsForResource(t);return await Se(this.config,{...e,fields:o},n,t)}async setIssueStatus(e,t={}){await Ue(this.config,e,t)}async setIssueLabels(e,t={}){await Ee(this.config,e,t)}async setIssueComponents(e,t={}){await Ce(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:n})=>({color:null,description:null,id:null,name:n}))}}async getComponentsForJiraProject(e,t={}){return await De(this.config,e,t)}};var T="https://api.trello.com",jr=1e3,Mr=r=>({id:r.id,username:r.username,url:r.url,name:r.fullName,email:r.email,avatarUrl:r.avatarUrl}),zr=(r,s)=>{let e=new Date(1e3*parseInt(r.id.substring(0,8),16));return{id:r.id,commentCount:r.badges.comments,number:r.idShort.toString(),title:r.name,url:r.url,closedDate:null,createdDate:new Date(e.toISOString()),author:null,updatedDate:new Date(r.dateLastActivity),assignees:r.members.map(t=>({id:t.id,username:t.username,name:t.fullName,email:null,avatarUrl:t.avatarUrl,url:null})),description:null,state:s[r.idList??""]?{id:r.idList,name:s[r.idList].name,color:null}:null,type:null,repository:null,upvoteCount:r.badges.votes,labels:r.labels.map(t=>({color:t.color,description:null,id:t.id,name:t.name}))}},te=class extends D{async getCurrentUser(s,e={}){let t=await this.config.request({url:`${e.baseUrl||T}/1/members/me?key=${s.appKey}&token=${e.token||this.config.token}`,headers:I(e.token||this.config.token)});return{data:{name:t.body.fullName,email:t.body.email,avatarUrl:t.body.avatarHash?`https://trello-members.s3.amazonaws.com/${t.body.id}/${t.body.avatarHash}/50.png`:null,id:t.body.id,username:t.body.username,url:t.body.url}}}async getBoardsForCurrentUser(s,e={}){return{data:(await this.config.request({url:`${e.baseUrl||T}/1/members/me/boards?fields=name&key=${s.appKey}&token=${e.token||this.config.token}&filter=open`,headers:I(e.token||this.config.token)})).body.map(n=>({id:n.id,name:n.name}))}}async getListsForTrelloBoard(s,e={}){let{appKey:t,boardId:n}=s;return{data:(await this.config.request({url:`${e.baseUrl||T}/1/boards/${n}/lists?key=${t}&token=${e.token||this.config.token}`,headers:I(e.token||this.config.token)})).body}}async getAccountForId(s,e={}){let{appKey:t,memberId:n}=s,o=await this.config.request({url:`${e.baseUrl||T}/1/members/${n}/?key=${t}&token=${e.token||this.config.token}`});return{data:Mr(o.body)}}async getAccountsForTrelloBoard(s,e={}){let{appKey:t,boardId:n}=s;return{data:(await this.config.request({url:`${e.baseUrl||T}/1/boards/${n}/members?key=${t}&token=${e.token||this.config.token}`,headers:I(e.token||this.config.token)})).body.map(a=>({id:a.id,name:a.fullName,username:a.username,email:null,avatarUrl:null,url:null}))}}async getIssuesForBoard(s,e={}){let t=["-is:archived","sort:edited"],{appKey:n,boardId:o,filterText:a,assigneeLogins:i,labelNamesOrColors:u,trelloBoardListsById:l}=s||{};i&&t.push("@me"),u&&u.forEach(c=>t.push(`label:"${c}"`));let p=`${a?`${a}`:""}${t.join(" ")} board:${o}`;return{data:(await this.config.request({url:`${e.baseUrl||T}/1/search?key=${n}&query=${p}&cards_limit=${jr}&token=${e.token||this.config.token}&card_members=true`,headers:I(e.token||this.config.token)})).body.cards.map(c=>zr(c,l||{}))}}async updateIssue(s,e,t,n){return await this.config.request({method:"PUT",url:`${n.baseUrl||T}/1/cards/${e.id}?key=${s}&token=${n.token||this.config.token}&${t}`,headers:I(n.token||this.config.token)})}async setIssueStatus(s,e={}){let{appKey:t,issue:n,status:o}=s;if(!o.id)throw new Error('Trello requires a status "id" for this function.');let a=`idList=${o.id}`;if(!(await this.updateIssue(t,n,a,e)).body.id)throw new Error("Could not set issue status")}async setIssueAssignees(s,e={}){let{appKey:t,issue:n,assignees:o}=s,a=o.map(l=>l.id),i=`idMembers=${encodeURIComponent(a.join(","))}`;if(!(await this.updateIssue(t,n,i,e)).body.id)throw new Error("Could not set issue status")}async setIssueLabels(s,e={}){let{appKey:t,issue:n,labels:o}=s,a=o.map(u=>u.id).join(",");if(!(await this.config.request({method:"PUT",url:`${e.baseUrl||T}/1/cards/${n.id}?key=${t}&token=${e.token||this.config.token}&idLabels=${encodeURIComponent(a)}`,headers:I(e.token||this.config.token)})).body.id)throw new Error("Could not set issue status")}async setIssueArchived(s,e={}){let{appKey:t,issue:n,archived:o}=s;if(!(await this.config.request({method:"PUT",url:`${e.baseUrl||T}/1/cards/${n.id}?key=${t}&token=${e.token||this.config.token}&closed=${o}`,headers:I(e.token||this.config.token)})).body.id)throw new Error("Could not update issue archived status")}async archiveIssue(s,e={}){await this.setIssueArchived({...s,archived:!0},e)}async unArchiveIssue(s,e={}){await this.setIssueArchived({...s,archived:!1},e)}async getLabelsForBoard(s,e={}){let{appKey:t,boardId:n}=s;return{data:(await this.config.request({url:`${e.baseUrl||T}/1/boards/${n}/labels?key=${t}&token=${e.token||this.config.token}`,headers:I(e.token||this.config.token)})).body.map(a=>({color:a.color,description:null,id:a.id,name:a.name}))}}};var Lt=r=>{let s={request:r==null?void 0:r.request};return{azureDevOps:new W({...s,...r==null?void 0:r.azureDevOps}),bitbucket:new J({...s,...r==null?void 0:r.bitbucket}),bitbucketServer:new K({...s,...r==null?void 0:r.bitbucketServer}),github:new V({...s,...r==null?void 0:r.github}),gitlab:new Z({...s,...r==null?void 0:r.gitlab}),jira:new Y({...s,...r==null?void 0:r.jira}),jiraServer:new ee({...s,...r==null?void 0:r.jiraServer}),trello:new te({...s,...r==null?void 0:r.trello})}};var $t=(a=>(a.Conflicts="conflicts",a.Failure="failure",a.NotSet="notSet",a.Queued="queued",a.RejectedByPolicy="rejectedByPolicy",a.Succeeded="succeeded",a))($t||{});var At=(e=>(e.Zero="0",e.One="1",e))(At||{}),Gt=(e=>(e.PullRequest="pr",e.Issue="issue",e))(Gt||{}),Tt=(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))(Tt||{});var Ot=(e=>(e.Completed="COMPLETED",e.NotPlanned="NOT_PLANNED",e))(Ot||{});var Hr=Lt;
1103
+ `,variables:{fullPath:`${t}/${s}`,after:o}},e);return{pageInfo:((l=(u=(i=a.body.data)==null?void 0:i.project)==null?void 0:u.labels)==null?void 0:l.pageInfo)??{endCursor:null,hasNextPage:!1},data:((g=(c=(d=(p=a.body.data)==null?void 0:p.project)==null?void 0:d.labels)==null?void 0:c.nodes)==null?void 0:g.map(et))??[]}}};var kr="https://api.atlassian.com/ex/jira",ye=100,rt=["assignee","comment","summary","created","creator","updated","votes","issuetype","status","labels","components","project","fixVersions","description"],st=(r,n,e,t)=>{var i,u,l,p;let s=r.fields.assignee,o=!t,a=r.fields[(n==null?void 0:n.Sprint)??""]??[];return{id:r.id,commentCount:r.fields.comment.comments.length,number:r.key,title:r.fields.summary,url:e?`${e}/browse/${r.key}`:null,closedDate:null,createdDate:new Date(r.fields.created),author:Pe(r.fields.creator,e,o),updatedDate:new Date(r.fields.updated),assignees:s?[Pe(s,e,o)]:[],description:r.fields.description,repository:null,project:{name:r.fields.project.name,resourceId:t??null,key:r.fields.project.key,namespace:null,id:r.fields.project.id},state:_r(r.fields.status),statusTransitions:((i=r.transitions)==null?void 0:i.map(Nr))??[],components:((u=r.fields.components)==null?void 0:u.map(Fr))??[],type:r.fields.issuetype.name,upvoteCount:((l=r.fields.votes)==null?void 0:l.votes)||0,labels:((p=r.fields.labels)==null?void 0:p.map(d=>({color:null,description:null,id:null,name:d})))??[],sprints:a.map(Br),fixVersions:r.fields.fixVersions.map(jr)}},Nr=r=>{let n;switch(r.to.statusCategory.name){case"To Do":n="TO_DO";break;case"In Progress":n="IN_PROGRESS";break;default:n="DONE";break}return{name:r.name,id:r.id,to:{id:r.to.id,name:r.to.name,color:r.to.statusCategory.colorName,category:n}}},Fr=r=>({description:r.description??null,id:r.id,name:r.name}),Qr=(r,n,e)=>e&&r.name?`${n}/secure/ViewProfile.jspa?name=${encodeURIComponent(r.name)}`:`${n}/jira/people/${r.accountId}`,Pe=(r,n,e)=>({id:(e?r.key:r.accountId)??"",name:r.displayName,email:r.emailAddress,avatarUrl:r.avatarUrls["48x48"],username:r.displayName,url:Qr(r,n,e)}),_r=r=>{let n;switch(r.statusCategory.name){case"To Do":n="TO_DO";break;case"In Progress":n="IN_PROGRESS";break;default:n="DONE";break}return{id:r.id,name:r.name,color:r.statusCategory.colorName,category:n}},Br=r=>({id:r.id.toString(),name:r.name,isActive:r.state==="active",startDate:r.startDate?new Date(r.startDate):null,endDate:r.endDate?new Date(r.endDate):null,completedDate:r.completeDate?new Date(r.completeDate):null}),jr=r=>({id:r.id,description:r.description,name:r.name,archived:r.archived,released:r.released,releaseDate:r.releaseDate?new Date(r.releaseDate):null}),B=(r,n,e)=>e?`${n.baseUrl||kr}/${e}`:`${(n==null?void 0:n.baseUrl)||r.baseUrl}`,we=async(r,n,e={})=>{let{resourceId:t}=n;return(await r.request({url:`${B(r,e,t)}/rest/api/2/field`,headers:I(e.token||r.token)})).body},Se=async(r,n,e,t={})=>{let{number:s,resourceId:o,fields:a}=n||{},i=await r.request({url:`${B(r,t,o)}/rest/api/2/issue/${s}?fields=${rt.join(",")}&expand=transitions`,headers:I(t.token||r.token)});return{data:st(i.body,a,e,o)}},ve=async(r,n,e,t={})=>{let{page:s,resourceId:o,labelNames:a,fields:i}=n||{},u=s??0,l=["statusCategory != Done",`(creator = currentUser() OR assignee = currentUser()
1104
+ OR comment ~ currentUser() OR summary ~ currentUser() OR description ~ currentUser())`];a&&a.forEach(m=>l.push(`labels = "${m}"`));let p=`${l.join(" AND ")} ORDER BY updated DESC`,c=(await r.request({url:`${B(r,t,o)}/rest/api/2/search?jql=${p}&startAt=${u}&maxResults=${ye}&fields=${rt.join(",")}&expand=transitions`,headers:I(t.token||r.token)})).body.issues.map(m=>st(m,i,e,o)),g=c.length==ye;return{data:c,pageInfo:{hasNextPage:g,nextPage:g?u+c.length:null}}},Ut=async(r,n,e,t={})=>{let{page:s,resourceId:o,jql:a,fields:i}=n||{},u=s??0,l=[...rt],p=i==null?void 0:i.Sprint;p&&l.push(p);let c=(await r.request({url:`${B(r,t,o)}/rest/api/2/search?jql=${a.join(" AND ")}&startAt=${u}&maxResults=${ye}&fields=${l.join(",")}&expand=transitions`,headers:I(t.token||r.token)})).body.issues.map(m=>st(m,i,e,o)),g=c.length==ye;return{data:c,pageInfo:{hasNextPage:g,nextPage:g?u+c.length:null}}},qe=async(r,n,e,t={})=>{let{assigneeLogins:s,authorLogin:o,mentionLogin:a,labelNames:i,page:u,projectKey:l,resourceId:p,fields:d}=n||{},c=u??0,g=[`project = "${l}"`,"statusCategory != Done"];return o&&g.push(`creator in ("${o}")`),s&&s.length!==0&&g.push(`assignee in ("${s.join('", "')}")`),a&&g.push(`comment ~ "${a}"`),i&&i.forEach(m=>g.push(`labels = "${m}"`)),Ut(r,{resourceId:p,jql:g,page:c,fields:d},e,t)},Ee=async(r,n,e,t={})=>{let{assigneeLogins:s,authorLogin:o,mentionLogin:a,labelNames:i,page:u,projectKeys:l,resourceId:p,fields:d}=n||{},c=u??0,m=["("+l.map(h=>`project = "${h}"`).join(" OR ")+")","statusCategory != Done"];return o&&m.push(`creator in ("${o}")`),s&&s.length!==0&&m.push(`assignee in ("${s.join('", "')}")`),a&&m.push(`comment ~ "${a}"`),i&&i.forEach(h=>m.push(`labels = "${h}"`)),Ut(r,{resourceId:p,jql:m,fields:d,page:c},e,t)},Ce=async(r,n,e={})=>{let{issue:t,labels:s}=n;if(!t.project)throw new Error('Jira requires a "project" for this function.');let o={fields:{labels:s.map(a=>a.name)}};await r.request({method:"PUT",url:`${B(r,e,t.project.resourceId??void 0)}/rest/api/2/issue/${t.id}`,body:JSON.stringify(o),headers:{...I(e.token||r.token),"Content-Type":"application/json"}})},De=async(r,n,e={})=>{let{issue:t,components:s}=n;if(!t.project)throw new Error('Jira requires a "project" for this function.');let o={fields:{components:s.map(a=>({id:a.id}))}};await r.request({method:"PUT",url:`${B(r,e,t.project.resourceId??void 0)}/rest/api/2/issue/${t.id}`,body:JSON.stringify(o),headers:{...I(e.token||r.token),"Content-Type":"application/json"}})},Le=async(r,n,e={})=>{let{issue:t,status:s}=n;if(!t.project)throw new Error('Jira requires a "project" for this function.');if(!s.id)throw new Error('Jira requires a status "id" for this function.');let o={transition:{id:s.id}};await r.request({method:"POST",url:`${B(r,e,t.project.resourceId??void 0)}/rest/api/2/issue/${t.id}/transitions`,body:JSON.stringify(o),headers:{...I(e.token||r.token),"Content-Type":"application/json"}})},Ue=async(r,n,e={})=>{let{resourceId:t,projectIdOrKey:s}=n,o=new URL(`${B(r,e,t)}/rest/api/2/project/${s}/components`);return{data:(await r.request({url:o.toString(),headers:I(e.token||r.token)})).body}};var ne="https://api.atlassian.com/ex/jira",nt=100,ee=class extends U{constructor(){super(...arguments);this._resourceUrlCache={};this._issueFieldsCache={}}async getIssueFieldsForResource(e,t={}){if(!this._issueFieldsCache[e.resourceId]){let s=await we(this.config,e,t);this._issueFieldsCache[e.resourceId]=s.reduce((o,a)=>({...o,[a.name]:a.id}),{})}return this._issueFieldsCache[e.resourceId]??null}async getResourceUrl(e,t={}){var a;let s=t.token||this.config.token;if(!s)return null;let o=this._resourceUrlCache[s];return o?o[e.resourceId]??null:(await this.getJiraResourcesForCurrentUser(t),((a=this._resourceUrlCache[s])==null?void 0:a[e.resourceId])??null)}async getCurrentUserForResource(e,t={}){let s=await this.getResourceUrl({resourceId:e.resourceId},t),o=await this.config.request({url:`${t.baseUrl||ne}/${e.resourceId}/rest/api/2/myself`,headers:I(t.token||this.config.token)});return{data:{name:o.body.displayName,email:o.body.emailAddress,avatarUrl:o.body.avatarUrls["48x48"],id:o.body.accountId,username:o.body.displayName,url:s?`${s}/jira/people/${o.body.accountId}`:null}}}async getJiraResourcesForCurrentUser(e={}){let t=await this.config.request({url:`${e.baseUrl||"https://api.atlassian.com/"}/oauth/token/accessible-resources`,headers:I(e.token||this.config.token)}),s=e.token||this.config.token,o=s?this._resourceUrlCache[s]||{}:void 0,a=t.body.map(i=>(o&&(o[i.id]=i.url),{avatarUrl:i.avatarUrl,id:i.id,name:i.name,url:i.url}));return s&&(this._resourceUrlCache[s]=o),{data:a}}async getJiraProjectsForResource(e,t={}){let s=new URL(`${t.baseUrl||ne}/${e.resourceId}/rest/api/2/project/search`);s.searchParams.set("maxResults",nt.toString()),e.cursor&&s.searchParams.set("startAt",e.cursor);let o=await this.config.request({url:s.toString(),headers:I(t.token||this.config.token)});return{pageInfo:{hasNextPage:o.body.values.length!==0,endCursor:(o.body.startAt+o.body.values.length).toString()},data:o.body.values.map(a=>({id:a.id,key:a.key,name:a.name,resourceId:e.resourceId}))}}async getJiraProjectsForResources(e,t={}){let s=[];return await Promise.all(e.resourceIds.map(async o=>{try{return await dt(a=>this.getJiraProjectsForResource({resourceId:o,cursor:a},t))}catch{return[]}})).then((...o)=>{o.forEach(a=>{s=s.concat(...a)})}),{data:s}}async getAccountsForJiraProject(e,t={}){let{resourceId:s,projectKey:o,cursor:a}=e,i=await this.getResourceUrl({resourceId:s},t),u=new URL(`${t.baseUrl||ne}/${s}/rest/api/2/user/assignable/search`);u.searchParams.set("maxResults",nt.toString()),a&&u.searchParams.set("startAt",a),u.searchParams.set("project",o);let l=await this.config.request({url:u.toString(),headers:I(t.token||this.config.token)});return{pageInfo:{hasNextPage:l.body.length!==0,endCursor:((a?parseInt(a):0)+l.body.length).toString()},data:l.body.filter(p=>p.accountType!=="app"&&p.active).map(p=>Pe(p,i,!1))}}async getComponentsForJiraProject(e,t={}){return await Ue(this.config,e,t)}async getIssue(e,t={}){let s=await this.getIssueFieldsForResource({resourceId:e.resourceId},t),o=await this.getResourceUrl({resourceId:e.resourceId},t);return await Se(this.config,{...e,fields:s},o,t)}async getIssuesForProject(e,t={}){let s=await this.getIssueFieldsForResource({resourceId:e.resourceId},t),o=await this.getResourceUrl({resourceId:e.resourceId},t);return await qe(this.config,{...e,fields:s},o,t)}async getIssuesForProjects(e,t={}){let s=await this.getIssueFieldsForResource({resourceId:e.resourceId},t),o=await this.getResourceUrl({resourceId:e.resourceId},t);return await Ee(this.config,{...e,fields:s},o,t)}async getIssuesForResourceForCurrentUser(e,t={}){let s=await this.getIssueFieldsForResource({resourceId:e.resourceId},t),o=await this.getResourceUrl({resourceId:e.resourceId},t);return await ve(this.config,{...e,fields:s},o,t)}async setIssueStatus(e,t={}){await Le(this.config,e,t)}async setIssueAssignee(e,t={}){let{issue:s,assignee:o}=e;if(!s.project)throw new Error('Jira Cloud requires a "project" for this function.');if(!s.project.resourceId)throw new Error('Jira Cloud requires a project "resourceId" for this function.');let a={accountId:o==null?void 0:o.id};await this.config.request({method:"PUT",url:`${t.baseUrl||ne}/${s.project.resourceId}/rest/api/2/issue/${s.id}/assignee`,body:JSON.stringify(a),headers:{...I(t.token||this.config.token),"Content-Type":"application/json"}})}async setIssueComponents(e,t={}){await De(this.config,e,t)}async setIssueLabels(e,t={}){await Ce(this.config,e,t)}async getLabelsForResource(e,t={}){let{resourceId:s,cursor:o}=e,a=new URL(`${t.baseUrl||ne}/${s}/rest/api/2/label`);a.searchParams.set("maxResults",nt.toString()),o&&a.searchParams.set("startAt",o);let i=await this.config.request({url:a.toString(),headers:I(t.token||this.config.token)});return{pageInfo:{hasNextPage:!i.body.isLast,endCursor:(i.body.startAt+i.body.values.length).toString()},data:i.body.values.map(u=>({color:null,description:null,id:null,name:u}))}}};var te=class extends T{constructor(){super(...arguments);this._issueFieldsCache={}}async getIssueFieldsForResource(e={}){let t=(e==null?void 0:e.baseUrl)||this.config.baseUrl||"";if(!this._issueFieldsCache[t]){let s=await we(this.config,{},e);this._issueFieldsCache[t]=s.reduce((o,a)=>({...o,[a.name]:a.id}),{})}return this._issueFieldsCache[t]??null}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(s=>({id:s.id,name:s.name}))}}async getIssue(e,t={}){let s=e.resourceUrl||t.baseUrl||this.config.baseUrl;if(!s)throw new Error('Jira Server requires a "resourceUrl" or "baseUrl" for this function.');let o=await this.getIssueFieldsForResource(t);return await Se(this.config,{...e,fields:o},s,t)}async getIssuesForProject(e,t={}){let s=e.resourceUrl||t.baseUrl||this.config.baseUrl;if(!s)throw new Error('Jira Server requires a "resourceUrl" or "baseUrl" for this function.');let o=await this.getIssueFieldsForResource(t);return await qe(this.config,{...e,fields:o},s,t)}async getIssuesForProjects(e,t={}){let s=e.resourceUrl||t.baseUrl||this.config.baseUrl;if(!s)throw new Error('Jira Server requires a "resourceUrl" or "baseUrl" for this function.');let o=await this.getIssueFieldsForResource(t);return await Ee(this.config,{...e,fields:o},s,t)}async getIssuesForResourceForCurrentUser(e,t={}){let s=e.resourceUrl||t.baseUrl||this.config.baseUrl;if(!s)throw new Error('Jira Server requires a "resourceUrl" or "baseUrl" for this function.');let o=await this.getIssueFieldsForResource(t);return await ve(this.config,{...e,fields:o},s,t)}async setIssueStatus(e,t={}){await Le(this.config,e,t)}async setIssueLabels(e,t={}){await Ce(this.config,e,t)}async setIssueComponents(e,t={}){await De(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:s})=>({color:null,description:null,id:null,name:s}))}}async getComponentsForJiraProject(e,t={}){return await Ue(this.config,e,t)}};var O="https://api.trello.com",Mr=1e3,zr=r=>({id:r.id,username:r.username,url:r.url,name:r.fullName,email:r.email,avatarUrl:r.avatarUrl}),Hr=(r,n)=>{let e=new Date(1e3*parseInt(r.id.substring(0,8),16));return{id:r.id,commentCount:r.badges.comments,number:r.idShort.toString(),title:r.name,url:r.url,closedDate:null,createdDate:new Date(e.toISOString()),author:null,updatedDate:new Date(r.dateLastActivity),assignees:r.members.map(t=>({id:t.id,username:t.username,name:t.fullName,email:null,avatarUrl:t.avatarUrl,url:null})),description:null,state:n[r.idList??""]?{id:r.idList,name:n[r.idList].name,color:null}:null,type:null,repository:null,upvoteCount:r.badges.votes,labels:r.labels.map(t=>({color:t.color,description:null,id:t.id,name:t.name}))}},re=class extends U{async getCurrentUser(n,e={}){let t=await this.config.request({url:`${e.baseUrl||O}/1/members/me?key=${n.appKey}&token=${e.token||this.config.token}`,headers:I(e.token||this.config.token)});return{data:{name:t.body.fullName,email:t.body.email,avatarUrl:t.body.avatarHash?`https://trello-members.s3.amazonaws.com/${t.body.id}/${t.body.avatarHash}/50.png`:null,id:t.body.id,username:t.body.username,url:t.body.url}}}async getBoardsForCurrentUser(n,e={}){return{data:(await this.config.request({url:`${e.baseUrl||O}/1/members/me/boards?fields=name&key=${n.appKey}&token=${e.token||this.config.token}&filter=open`,headers:I(e.token||this.config.token)})).body.map(s=>({id:s.id,name:s.name}))}}async getListsForTrelloBoard(n,e={}){let{appKey:t,boardId:s}=n;return{data:(await this.config.request({url:`${e.baseUrl||O}/1/boards/${s}/lists?key=${t}&token=${e.token||this.config.token}`,headers:I(e.token||this.config.token)})).body}}async getAccountForId(n,e={}){let{appKey:t,memberId:s}=n,o=await this.config.request({url:`${e.baseUrl||O}/1/members/${s}/?key=${t}&token=${e.token||this.config.token}`});return{data:zr(o.body)}}async getAccountsForTrelloBoard(n,e={}){let{appKey:t,boardId:s}=n;return{data:(await this.config.request({url:`${e.baseUrl||O}/1/boards/${s}/members?key=${t}&token=${e.token||this.config.token}`,headers:I(e.token||this.config.token)})).body.map(a=>({id:a.id,name:a.fullName,username:a.username,email:null,avatarUrl:null,url:null}))}}async getIssuesForBoard(n,e={}){let t=["-is:archived","sort:edited"],{appKey:s,boardId:o,filterText:a,assigneeLogins:i,labelNamesOrColors:u,trelloBoardListsById:l}=n||{};i&&t.push("@me"),u&&u.forEach(c=>t.push(`label:"${c}"`));let p=`${a?`${a}`:""}${t.join(" ")} board:${o}`;return{data:(await this.config.request({url:`${e.baseUrl||O}/1/search?key=${s}&query=${p}&cards_limit=${Mr}&token=${e.token||this.config.token}&card_members=true`,headers:I(e.token||this.config.token)})).body.cards.map(c=>Hr(c,l||{}))}}async updateIssue(n,e,t,s){return await this.config.request({method:"PUT",url:`${s.baseUrl||O}/1/cards/${e.id}?key=${n}&token=${s.token||this.config.token}&${t}`,headers:I(s.token||this.config.token)})}async setIssueStatus(n,e={}){let{appKey:t,issue:s,status:o}=n;if(!o.id)throw new Error('Trello requires a status "id" for this function.');let a=`idList=${o.id}`;if(!(await this.updateIssue(t,s,a,e)).body.id)throw new Error("Could not set issue status")}async setIssueAssignees(n,e={}){let{appKey:t,issue:s,assignees:o}=n,a=o.map(l=>l.id),i=`idMembers=${encodeURIComponent(a.join(","))}`;if(!(await this.updateIssue(t,s,i,e)).body.id)throw new Error("Could not set issue status")}async setIssueLabels(n,e={}){let{appKey:t,issue:s,labels:o}=n,a=o.map(u=>u.id).join(",");if(!(await this.config.request({method:"PUT",url:`${e.baseUrl||O}/1/cards/${s.id}?key=${t}&token=${e.token||this.config.token}&idLabels=${encodeURIComponent(a)}`,headers:I(e.token||this.config.token)})).body.id)throw new Error("Could not set issue status")}async setIssueArchived(n,e={}){let{appKey:t,issue:s,archived:o}=n;if(!(await this.config.request({method:"PUT",url:`${e.baseUrl||O}/1/cards/${s.id}?key=${t}&token=${e.token||this.config.token}&closed=${o}`,headers:I(e.token||this.config.token)})).body.id)throw new Error("Could not update issue archived status")}async archiveIssue(n,e={}){await this.setIssueArchived({...n,archived:!0},e)}async unArchiveIssue(n,e={}){await this.setIssueArchived({...n,archived:!1},e)}async getLabelsForBoard(n,e={}){let{appKey:t,boardId:s}=n;return{data:(await this.config.request({url:`${e.baseUrl||O}/1/boards/${s}/labels?key=${t}&token=${e.token||this.config.token}`,headers:I(e.token||this.config.token)})).body.map(a=>({color:a.color,description:null,id:a.id,name:a.name}))}}};var $t=r=>{let n={request:r==null?void 0:r.request};return{azureDevOps:new J({...n,...r==null?void 0:r.azureDevOps}),bitbucket:new K({...n,...r==null?void 0:r.bitbucket}),bitbucketServer:new V({...n,...r==null?void 0:r.bitbucketServer}),github:new X({...n,...r==null?void 0:r.github}),gitlab:new Y({...n,...r==null?void 0:r.gitlab}),jira:new ee({...n,...r==null?void 0:r.jira}),jiraServer:new te({...n,...r==null?void 0:r.jiraServer}),trello:new re({...n,...r==null?void 0:r.trello})}};var At=(a=>(a.Conflicts="conflicts",a.Failure="failure",a.NotSet="notSet",a.Queued="queued",a.RejectedByPolicy="rejectedByPolicy",a.Succeeded="succeeded",a))(At||{});var Gt=(e=>(e.Zero="0",e.One="1",e))(Gt||{}),Tt=(e=>(e.PullRequest="pr",e.Issue="issue",e))(Tt||{}),Ot=(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))(Ot||{});var xt=(e=>(e.Completed="COMPLETED",e.NotPlanned="NOT_PLANNED",e))(xt||{});var Wr=$t;