@gitkraken/provider-apis 0.17.5 → 0.19.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- "use strict";var Ct=Object.create;var re=Object.defineProperty;var Ut=Object.getOwnPropertyDescriptor;var vt=Object.getOwnPropertyNames;var $t=Object.getPrototypeOf,Lt=Object.prototype.hasOwnProperty;var T=(t,s)=>{for(var e in s)re(t,e,{get:s[e],enumerable:!0})},it=(t,s,e,r)=>{if(s&&typeof s=="object"||typeof s=="function")for(let n of vt(s))!Lt.call(t,n)&&n!==e&&re(t,n,{get:()=>s[n],enumerable:!(r=Ut(s,n))||r.enumerable});return t};var Gt=(t,s,e)=>(e=t!=null?Ct($t(t)):{},it(s||!t||!t.__esModule?re(e,"default",{value:t,enumerable:!0}):e,t)),At=t=>it(re({},"__esModule",{value:!0}),t);var nr={};T(nr,{AzureDevOps:()=>W,AzureDevopsUtils:()=>Ee,Bitbucket:()=>H,BitbucketServer:()=>J,BitbucketServerUtils:()=>qe,BitbucketUtils:()=>Se,GitHub:()=>K,GitHubUtils:()=>Ce,GitLab:()=>X,GitLabUtils:()=>Ue,GitProviderUtils:()=>De,Jira:()=>Z,JiraServer:()=>ee,JiraUtils:()=>ve,Trello:()=>te,TrelloUtils:()=>$e,Utils:()=>rr,default:()=>sr});module.exports=At(nr);var q=100;var ut=Gt(require("node-fetch")),lt=globalThis.fetch||ut.default;var Tt=async t=>{let s=t.headers.get("content-type")||"",e=null;if(s.startsWith("application/json")){let n=await t.text();e=n.trim().length>0?JSON.parse(n):null}else if(s.startsWith("text/")||s==="")e=await t.text();else if(s.startsWith("application/vnd.github.raw+json"))e=await t.arrayBuffer();else throw new Error(`Unsupported content-type: ${s}`);let r={body:e,headers:Object.fromEntries(t.headers.entries()),status:t.status,statusText:t.statusText};if(!t.ok){let n=new Error(t.statusText);throw Object.assign(n,{response:r}),n}return r},Le=t=>async({url:s,...e})=>{let r=await t(s,e);return Tt(r)};var Ge=(t,s=!1)=>t.name==="fetch"||s;var U=class{constructor(s){let e=(s==null?void 0:s.request)||lt;this.config={...s,request:Ge(e,s==null?void 0:s.forceIsFetch)?Le(e):e}}updateConfig(s){this.config={...this.config,...s,request:s.request&&Ge(s.request,(s==null?void 0:s.forceIsFetch)??this.config.forceIsFetch)?Le(s.request):this.config.request}}},L=class extends U{};var R=(t,s)=>{let e={};return t&&(e.Authorization=`${s?"Basic":"Bearer"} ${t}`),e},pt=t=>t?t.reduce((s,e)=>(s[e]=!0,s),{}):void 0,N=(t,s,e)=>!t||s.some(r=>t[r])?e:"";var w=(t,s={})=>R(s.token||t.token,s.isPAT||t.isPAT),dt=t=>t.url.replace("/_apis/git/repositories/","/_git/").replace(`/${t.repository.project.id}/`,`/${encodeURIComponent(t.repository.project.name)}/`).replace(`/${t.repository.id}/`,`/${encodeURIComponent(t.repository.name)}/`).replace("/pullRequests/","/pullrequest/");var ct={APPROVED:0,COMMENTED:1,REVIEW_REQUESTED:2,CHANGES_REQUESTED:3},Q=t=>!t||t.length===0?null:t.reduce((s,e)=>ct[e.state]>ct[s]?e.state:s,"APPROVED");var gt="https://app.vssps.visualstudio.com/_apis",E="https://dev.azure.com",Ot={active:"OPEN",completed:"MERGED",abandoned:"CLOSED"},xt={10:"APPROVED",5:"APPROVED",0:"REVIEW_REQUESTED",[-5]:"CHANGES_REQUESTED",[-10]:"CHANGES_REQUESTED"},Ae=t=>({id:t.id,name:t.displayName,username:t.uniqueName||t.displayName,email:null,avatarUrl:t.imageUrl,url:null}),ae=t=>t.startsWith("refs/heads/")?t.replace("refs/heads/",""):t,ne=(t,s)=>{var r;let e=s.reviewers.filter(n=>n.vote!==0).map(n=>({reviewer:Ae(n),state:xt[n.vote]||"REVIEW_REQUESTED"}));return{id:s.pullRequestId.toString(),title:s.title,number:s.codeReviewId,state:Ot[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:t},remoteInfo:null},headCommit:{buildStatuses:null},baseRef:{name:ae(s.targetRefName),oid:s.lastMergeTargetCommit.commitId},headRef:{name:ae(s.sourceRefName),oid:s.lastMergeSourceCommit.commitId},url:dt(s),assignees:s.reviewers.map(Ae),reviews:e,reviewDecision:Q(e),additions:null,deletions:null,fileCount:null,commitCount:null,headRepository:null,mergeableState:"UNKNOWN",labels:((r=s.labels)==null?void 0:r.map(n=>({color:null,description:null,id:n.id,name:n.name})))??[],permissions:null}},mt=(t,s)=>({id:s.id,name:s.name,namespace:t,project:s.project.name,webUrl:s.webUrl,httpsUrl:s.remoteUrl,sshUrl:s.sshUrl,defaultBranch:s.defaultBranch?{name:ae(s.defaultBranch)}:null,permission:null}),kt=(t,s)=>{var i,u;let e=t.fields,r=e["System.AssignedTo"],n=e["System.State"],a=e["System.WorkItemType"],o;return n&&a&&(o=(i=s[a])==null?void 0:i[n]),{id:t.id.toString(),number:t.id.toString(),title:e["System.Title"],commentCount:e["System.CommentCount"],author:{avatarUrl:e["System.CreatedBy"]._links.avatar.href,email:null,id:e["System.CreatedBy"].id,name:e["System.CreatedBy"].uniqueName,username:e["System.CreatedBy"].displayName,url:null},closedDate:e["Microsoft.VSTS.Common.ClosedDate"]?new Date(e["Microsoft.VSTS.Common.ClosedDate"]):null,createdDate:new Date(e["System.CreatedDate"]),updatedDate:new Date(e["System.ChangedDate"]),url:t._links.html.href,assignees:r?[{avatarUrl:r._links.avatar.href,email:null,id:r.id,name:r.uniqueName,username:r.displayName,url:null}]:[],description:null,state:{name:(o==null?void 0:o.title)||n,color:null},type:e["System.WorkItemType"],repository:null,upvoteCount:0,labels:((u=t.fields["System.Tags"])==null?void 0:u.split(";").map(l=>({color:null,description:null,id:null,name:l.trim()})))??[]}},W=class extends U{async getCurrentUser(s={},e={}){if(e.isPAT||this.config.isPAT)throw new Error("Azure DevOps does not support PATs for this function.");let r=await this.config.request({url:`${gt}/profile/profiles/me`,headers:w(this.config,e)});return{data:{id:r.body.id,name:r.body.displayName,username:r.body.displayName,email:r.body.emailAddress,avatarUrl:null,url:null}}}async getCurrentUserForInstance(s,e={}){let n=(await this.config.request({url:`${E}/${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:`${E}/${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:`${gt}/accounts?memberId=${s.userId}&api-version=6.0`,headers:w(this.config,e)})).body.value.map(n=>({id:n.accountId,name:n.accountName}))}}async getAzureProjects(s,e={}){let r=new URL(`${E}/${encodeURIComponent(s.namespace)}/_apis/projects`);r.searchParams.set("$top",q.toString()),s.cursor&&r.searchParams.set("$skip",s.cursor);let n=await this.config.request({url:r.toString(),headers:w(this.config,e)}),a=n.headers["x-ms-continuationtoken"];return{pageInfo:{hasNextPage:!!a,endCursor:a||null},data:n.body.value.map(o=>({id:o.id,name:o.name,namespace:s.namespace}))}}async getAzureProjectScopeDescriptor(s,e={}){let{namespace:r,projectId:n}=s;return{data:{scope:(await this.config.request({url:`https://vssps.dev.azure.com/${encodeURIComponent(r)}/_apis/graph/descriptors/${n}?api-version=6.0`,headers:w(this.config,e)})).body.value}}}async getAzureGraphAccountsForAzureProject(s,e={}){let{namespace:r,projectScopeDescriptor:n,cursor:a}=s,o=new URL(`https://vssps.dev.azure.com/${encodeURIComponent(r)}/_apis/graph/users`);n&&o.searchParams.set("scopeDescriptor",n),a&&o.searchParams.set("continuationToken",a);let i=await this.config.request({url:o.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;return{avatarUrl:((p=l._links.avatar)==null?void 0:p.href)??null,descriptor:l.descriptor,email:l.mailAddress,name:l.displayName,storageKeyURL:l._links.storageKey.href,username:l.displayName}})}}async getAccountFromAzureGraphAccount(s,e={}){let{azureGraphAccount:r}=s,n=await this.config.request({url:r.storageKeyURL,headers:w(this.config,e)});return{data:{avatarUrl:r.avatarUrl,email:r.email,id:n.body.value,name:r.name,username:r.username,url:null}}}async getAccountsFromAzureGraphAccounts(s,e={}){let r=[];for(let n of s.azureGraphAccounts){let a=await this.getAccountFromAzureGraphAccount({azureGraphAccount:n},e);r.push(a.data)}return{data:r}}async getRepo(s,e={}){if(!s.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let r=await this.config.request({url:`${E}/${encodeURIComponent(s.namespace)}/${encodeURIComponent(s.project)}/_apis/git/repositories/${encodeURIComponent(s.name)}`,headers:w(this.config,e)});return{data:mt(s.namespace,r.body)}}async getRepos(s,e={}){let r=[],n=[];return await Promise.all(s.map(async a=>{try{let o=await this.getRepo(a,e);r.push(o.data)}catch(o){n.push({input:a,error:o})}})),{data:r,errors:n}}async getReposForAzureProject(s,e={}){if(!s.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');return{data:(await this.config.request({url:`${E}/${encodeURIComponent(s.namespace)}/${encodeURIComponent(s.project)}/_apis/git/repositories`,headers:w(this.config,e)})).body.value.map(n=>mt(s.namespace,n))}}async getRefs(s,e,r={}){if(!e.repo.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let n=new URL(`${E}/${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 a=await this.config.request({url:n.toString(),headers:w(this.config,r)}),o=a.headers["x-ms-continuationtoken"];return{pageInfo:{hasNextPage:!!o,endCursor:o||null},data:a.body.value.map(i=>({name:ae(i.name),commit:{oid:i.objectId,authoredDate:null,committedDate:null}}))}}async getBranches(s,e={}){return this.getRefs("heads",s,e)}async getTags(s,e={}){return this.getRefs("tags",s,e)}async getPullRequestsForRepoBase(s,e={},r=100){let{page:n,repo:a,assigneeLogins:o,authorLogin:i}=s||{},u=n||1;if(!a.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let l="searchCriteria.status=1";return o&&o.length&&(l+=`&searchCriteria.reviewerId=${o[0]}`),i&&(l+=`&searchCriteria.creatorId=${i}`),await this.config.request({url:`${e.baseUrl||E}/${encodeURIComponent(a.namespace)}/${encodeURIComponent(a.project||"")}/_apis/git/repositories/${encodeURIComponent(a.name)}/pullRequests?${l}&%24top=${r}&%24skip=${(u-1)*r}`,headers:w(this.config,e)})}async getPullRequestsForRepo(s,e={}){let n=s.page||1,a=await this.getPullRequestsForRepoBase(s,e,100);return{pageInfo:{hasNextPage:a.body.value.length===100,nextPage:n+1},data:a.body.value.map(o=>ne(s.repo.namespace,o))}}async getPullRequestsForRepos(s,e={}){if(!s.repos.every(a=>a.project))throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let{repos:r}=s||{},n=[];return await Promise.all(r.map(async a=>{try{(await this.getPullRequestsForRepoBase({repo:a,...s},e)).body.value.forEach(i=>{n.push(ne(a.namespace,i))})}catch(o){if(o.statusCode!==404&&o.statusCode!==401)throw o}})),{data:n}}async getPullRequestsForProjectBase(s,e={},r=100){let{namespace:n,project:a,page:o,assigneeLogins:i,authorLogin:u}=s,l=o||1,p=new URL(`${e.baseUrl||E}/${encodeURIComponent(n)}/${encodeURIComponent(a)}/_apis/git/pullRequests`);return p.searchParams.set("searchCriteria.status","1"),p.searchParams.set("$top",r.toString()),p.searchParams.set("$skip",((l-1)*r).toString()),i&&i.length&&p.searchParams.set("searchCriteria.reviewerId",i[0]),u&&p.searchParams.set("searchCriteria.creatorId",u),await this.config.request({url:p.toString(),headers:w(this.config,e)})}async getPullRequestsForProject(s,e={}){let n=s.page||1,a=await this.getPullRequestsForProjectBase(s,e,100);return{pageInfo:{hasNextPage:a.body.value.length===100,nextPage:n+1},data:a.body.value.map(o=>ne(s.namespace,o))}}async getPullRequestsForProjects(s,e={}){let{projects:r}=s||{},n=[];return await Promise.all(r.map(async a=>{try{(await this.getPullRequestsForProjectBase({...a,...s},e)).body.value.forEach(i=>{n.push(ne(a.namespace,i))})}catch(o){if(o.statusCode!==404&&o.statusCode!==401)throw o}})),{data:n}}async getAzurePullRequestLastMergeStatus(s,e={}){if(!s.repo.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let{repo:{namespace:r,project:n,name:a},pullRequestId:o}=s,i=await this.config.request({url:`${e.baseUrl||E}/${encodeURIComponent(r)}/${encodeURIComponent(n||"")}/_apis/git/repositories/${a}/pullrequests/${o}?includeCommits=true?api-version=6.0`,headers:{...w(this.config,e)}});if(!i.body.mergeStatus)throw new Error("Could not fetch pull request");return{data:i.body.mergeStatus}}async updatePullRequest(s,e,r,n){let{namespace:a,project:o,name:i}=s;return await this.config.request({method:"PATCH",url:`${n.baseUrl||E}/${encodeURIComponent(a)}/${encodeURIComponent(o||"")}/_apis/git/repositories/${i}/pullrequests/${e}?api-version=6.0`,body:r,headers:{...w(this.config,n),"Content-Type":"application/json"}})}async closePullRequest(s,e={}){if(!s.repo.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let{repo:r,pullRequestId:n}=s,a={status:"abandoned"};if(!(await this.updatePullRequest(r,n,JSON.stringify(a),e)).body.status)throw new Error("Could not close pull request")}async mergePullRequest(s,e={}){if(!s.repo.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let{repo:r,pullRequestId:n,expectedSourceSha:a,mergeStrategy:o}=s,i;switch(o){case"MERGE_COMMIT":{i="noFastForward";break}case"REBASE":{i="rebase";break}case"REBASE_THEN_MERGE_COMMIT":{i="rebaseMerge";break}case"SQUASH":{i="squash";break}}let u={completionOptions:{mergeStrategy:i},lastMergeSourceCommit:{commitId:a},status:"completed"};if(!(await this.updatePullRequest(r,n,JSON.stringify(u),e)).body.status)throw new Error("Could not merge pull request")}async addPullRequestLabel(s,e={}){let{repo:{namespace:r,project:n,name:a},pullRequestId:o,labelName:i}=s;if(!n)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let u={name:i};if(!(await this.config.request({method:"POST",url:`${e.baseUrl||E}/${encodeURIComponent(r)}/${encodeURIComponent(n||"")}/_apis/git/repositories/${a}/pullrequests/${o}/labels?api-version=6.0`,body:JSON.stringify(u),headers:{...w(this.config,e),"Content-Type":"application/json"}})).body.id)throw new Error("Could not add pull request label")}async removePullRequestLabel(s,e={}){let{repo:{namespace:r,project:n,name:a},pullRequestId:o,labelNameOrId:i}=s;if(!n)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');await this.config.request({method:"DELETE",url:`${e.baseUrl||E}/${encodeURIComponent(r)}/${encodeURIComponent(n||"")}/_apis/git/repositories/${a}/pullrequests/${o}/labels/${encodeURIComponent(i)}?api-version=6.0`,headers:{...w(this.config,e)}})}async setPullRequestAsDraft(s,e={}){if(!s.repo.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let{repo:r,pullRequestId:n,isDraft:a}=s,o={isDraft:a};if(!(await this.updatePullRequest(r,n,JSON.stringify(o),e)).body.status)throw new Error("Could not set the pull request as draft")}async addPullRequestReviewer(s,e={}){if(!s.repo.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let{repo:{namespace:r,project:n,name:a},pullRequestId:o,reviewerId:i,isRequired:u}=s,l={id:i,isRequired:u};if(!(await this.config.request({method:"PUT",url:`${e.baseUrl||E}/${encodeURIComponent(r)}/${encodeURIComponent(n||"")}/_apis/git/repositories/${a}/pullrequests/${o}/reviewers/${i}?api-version=6.0`,body:JSON.stringify(l),headers:{...w(this.config,e),"Content-Type":"application/json"}})).body.id)throw new Error("Could not add pull request reviewer")}async removePullRequestReviewer(s,e={}){if(!s.repo.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let{repo:{namespace:r,project:n,name:a},pullRequestId:o,reviewerId:i}=s;await this.config.request({method:"DELETE",url:`${e.baseUrl||E}/${encodeURIComponent(r)}/${encodeURIComponent(n||"")}/_apis/git/repositories/${a}/pullrequests/${o}/reviewers/${i}?api-version=6.0`,headers:{...w(this.config,e),Accept:"application/json"}})}async getIssuesForAzureProject(s,e={}){let{page:r,assigneeLogins:n,authorLogin:a,mentionLogin:o,statusByWorkItemIdByStatusId:i}=s||{},u=r||1,l=200,p=["[Microsoft.VSTS.Common.ClosedDate] = ''","[System.TeamProject] = @project","[Microsoft.VSTS.Common.ResolvedDate] = ''"];a&&p.push(`[System.CreatedBy] = '${a.replace("'","''")}'`),n&&n[0]&&p.push(`[System.AssignedTo] = '${n[0].replace("'","''")}'`),o&&p.push("[System.Id] IN (@recentMentions)");let d=`Select [Microsoft.VSTS.Common.ClosedDate], [Microsoft.VSTS.Common.ResolvedDate] From WorkItems Where ${p.join(" AND ")} order by [System.CreatedDate] desc`,c=await this.config.request({url:`${e.baseUrl||E}/${encodeURIComponent(s.namespace)}/${encodeURIComponent(s.project)}/_apis/wit/wiql?api-version=6.0`,body:JSON.stringify({query:d}),method:"POST",headers:{...w(this.config,e),"Content-Type":"application/json"}}),g=c.body.workItems.slice((u-1)*l,l*u).map(f=>f.id);if(g.length==0)return{pageInfo:{hasNextPage:!1,nextPage:null},data:[]};let m=await this.config.request({url:`${e.baseUrl||E}/${encodeURIComponent(s.namespace)}/${encodeURIComponent(s.project)}/_apis/wit/workitemsbatch?api-version=6.0`,body:JSON.stringify({ids:g,$expand:"Links"}),method:"POST",headers:{...w(this.config,e),"Content-Type":"application/json"}});return{pageInfo:{hasNextPage:c.body.workItems.length>l*u,nextPage:u+1},data:m.body.value.map(f=>kt(f,i||{}))}}async updateIssue(s,e,r,n,a={}){return await this.config.request({method:"PATCH",url:`${a.baseUrl||E}/${encodeURIComponent(s)}/${encodeURIComponent(e||"")}/_apis/wit/workitems/${r}?api-version=6.0`,body:JSON.stringify(n),headers:{...w(this.config,a),"Content-Type":"application/json-patch+json"}})}async setIssueStatus(s,e={}){var l;if(!s.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let{namespace:r,project:n,issueId:a,status:o}=s,i=[{op:"add",path:"/fields/System.State",value:o}];if(!((l=(await this.updateIssue(r,n,a,i,e)).body.fields)!=null&&l["System.State"]))throw new Error("Could not set issue status")}async setIssueAssignee(s,e={}){var l;if(!s.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let{namespace:r,project:n,issueId:a,assigneeNameOrEmail:o}=s,i=[{op:"add",path:"/fields/System.AssignedTo",value:o??""}];if(!((l=(await this.updateIssue(r,n,a,i,e)).body.fields)!=null&&l["System.State"]))throw new Error("Could not set issue assignee")}async setIssueLabels(s,e={}){var l;let{namespace:r,project:n,issueId:a,tagNames:o}=s,i=[{op:"replace",path:"/fields/System.Tags",value:o.join(";")}];if(!((l=(await this.updateIssue(r,n,a,i,e)).body.fields)!=null&&l["System.Tags"]))throw new Error("Could not set issue tags")}async getIssueTypesForAzureProject(s,e={}){if(!s.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let{namespace:r,project:n}=s;return{data:(await this.config.request({url:`${e.baseUrl||E}/${encodeURIComponent(r)}/${encodeURIComponent(n||"")}/_apis/wit/workitemtypes?api-version=6.0`,headers:{...w(this.config,e)}})).body.value}}async getLabelsForProject(s,e={}){let{namespace:r,project:n}=s;return{data:(await this.config.request({url:`${e.baseUrl||E}/${encodeURIComponent(r)}/${encodeURIComponent(n||"")}/_apis/wit/tags?api-version=6.0`,headers:{...w(this.config,e)}})).body.value.map(o=>({color:null,description:null,id:o.id,name:o.name}))}}};var C=(t,s={})=>R(s.token||t.token,s.isPAT||t.isPAT);var v="https://api.bitbucket.org/2.0",_t={OPEN:"OPEN",MERGED:"MERGED",DECLINED:"CLOSED"},ft=t=>({id:t.uuid,name:t.display_name||t.nickname,username:t.nickname||t.display_name,email:null,avatarUrl:t.links.avatar.href,url:t.links.html.href}),ht=t=>{var s,e;return{id:t.uuid,namespace:t.workspace.slug,name:t.slug,webUrl:t.links.html.href,httpsUrl:((s=t.links.clone.find(r=>r.name==="https"))==null?void 0:s.href)??null,sshUrl:((e=t.links.clone.find(r=>r.name==="ssh"))==null?void 0:e.href)??null,defaultBranch:{name:t.mainbranch.name},permission:null}},Oe=t=>{let s=t.id;return{id:s.toString(),title:t.title,number:s,state:_t[t.state],isDraft:!1,commentCount:t.comment_count,upvoteCount:null,author:ft(t.author),createdDate:new Date(t.created_on),updatedDate:new Date(t.updated_on),closedDate:null,mergedDate:null,repository:{id:t.destination.repository.uuid,name:t.destination.repository.name,owner:{login:t.destination.repository.full_name.split("/")[0]},remoteInfo:null},headCommit:{buildStatuses:null},baseRef:{name:t.destination.branch.name,oid:t.destination.commit.hash},headRef:{name:t.source.branch.name,oid:t.source.commit.hash},url:t.links.html.href,assignees:null,reviews:null,reviewDecision:null,additions:null,deletions:null,fileCount:null,commitCount:null,headRepository:null,mergeableState:"UNKNOWN",permissions:null}},H=class extends U{async refreshToken(s){return{data:(await this.config.request({url:"https://bitbucket.org/site/oauth2/access_token",method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded",Authorization:`Basic ${s.base64ClientIDColonClientSecret}`},body:`grant_type=refresh_token&refresh_token=${s.refreshToken}`})).body}}async getCurrentUser(s={},e={}){let r=await this.config.request({url:`${v}/user`,headers:C(this.config,e)});return{data:ft(r.body)}}async getUserForCommit(s,e={}){var o;let n=(await this.config.request({url:`${v}/repositories/${s.repo.namespace}/${s.repo.name}/commit/${s.oid}`,headers:C(this.config,e)})).body.author,a=n.raw.match(/([^<]+)<(.+)>/);return{data:{name:a?a[1].trim():null,email:a?a[2]:null,avatarUrl:((o=n.user)==null?void 0:o.links.avatar.href)||null}}}async getRepo(s,e={}){let r=await this.config.request({url:`${v}/repositories/${s.namespace}/${s.name}`,headers:C(this.config,e)});return{data:ht(r.body)}}async getRepos(s,e={}){let r=[],n=[];return await Promise.all(s.map(async a=>{try{let o=await this.getRepo(a,e);r.push(o.data)}catch(o){n.push({input:a,error:o})}})),{data:r,errors:n}}async getReposForCurrentUser(s={},e={}){let r=new URL(`${v}/repositories`);r.searchParams.set("role","member"),r.searchParams.set("pagelen",q.toString()),s.cursor&&r.searchParams.set("after",s.cursor);let n=await this.config.request({url:r.toString(),headers:C(this.config,e)}),a=!!n.body.next,o=null;return n.body.next&&(o=new URL(n.body.next).searchParams.get("after")),{pageInfo:{hasNextPage:a,endCursor:o},data:n.body.values.map(ht)}}async getBranches(s,e={}){var o;let r=new URL(`${v}/repositories/${s.repo.namespace}/${s.repo.name}/refs/branches`);r.searchParams.set("page",((o=s.page)==null?void 0:o.toString())||"1"),r.searchParams.set("pagelen",q.toString());let n=await this.config.request({url:r.toString(),headers:C(this.config,e)}),a=!!n.body.next;return{pageInfo:{hasNextPage:a,nextPage:a?n.body.page+1:null},data:n.body.values.map(i=>{let u=new Date(i.target.date);return{name:i.name,commit:{oid:i.target.hash,authoredDate:u,committedDate:u}}})}}async getTags(s,e={}){let r=new URL(`${v}/repositories/${s.repo.namespace}/${s.repo.name}/refs/tags`);r.searchParams.set("pagelen",q.toString()),s.cursor&&r.searchParams.set("page",s.cursor);let n=await this.config.request({url:r.toString(),headers:C(this.config,e)}),a=!!n.body.next,o=null;return n.body.next&&(o=new URL(n.body.next).searchParams.get("page")),{pageInfo:{hasNextPage:a,endCursor:o},data:n.body.values.map(i=>{let u=new Date(i.target.date);return{name:i.name,commit:{oid:i.target.hash,authoredDate:u,committedDate:u}}})}}async getPullRequestsForUser(s,e={}){var o;let r=new URL(`${v}/pullrequests/${s.userId}`);r.searchParams.set("page",((o=s.page)==null?void 0:o.toString())||"1"),r.searchParams.set("pagelen","50");let n=await this.config.request({url:r.toString(),headers:C(this.config,e)}),a=!!n.body.next;return{pageInfo:{hasNextPage:a,nextPage:a?n.body.page+1:null},data:n.body.values.map(Oe)}}async getPullRequestsForRepoBase(s,e={}){var n;let r=new URL(`${v}/repositories/${encodeURI(s.repo.namespace)}/${encodeURI(s.repo.name)}/pullrequests?state=OPEN`);return r.searchParams.set("page",((n=s.page)==null?void 0:n.toString())||"1"),r.searchParams.set("pagelen","50"),await this.config.request({url:r.toString(),headers:C(this.config,e)})}async getPullRequestsForRepo(s,e={}){let r=[],n=await this.getPullRequestsForRepoBase(s,e);n.body.values.forEach(o=>{if(s.authorLogin&&o.author.uuid!==s.authorLogin)return null;r.push(Oe(o))});let a=!!n.body.next;return{pageInfo:{hasNextPage:a,nextPage:a?n.body.page+1:null},data:r}}async getPullRequestsForRepos(s,e={}){let r=[];return await Promise.all(s.repos.map(async n=>{try{(await this.getPullRequestsForRepoBase({repo:n,...s},e)).body.values.forEach(o=>{if(s.authorLogin&&o.author.uuid!==s.authorLogin)return null;r.push(Oe(o))})}catch(a){if(a.statusCode!==404&&a.statusCode!==401)throw a}})),{data:r}}async closePullRequest(s,e={}){let{repo:{namespace:r,name:n},pullRequestId:a}=s;if(!(await this.config.request({method:"POST",url:`${v}/repositories/${r}/${n}/pullrequests/${a}/decline`,headers:C(this.config,e)})).body.title)throw new Error("Could not close pull request")}async mergePullRequest(s,e={}){let{repo:{namespace:r,name:n},pullRequestId:a,mergeStrategy:o}=s,i;switch(o){case"MERGE_COMMIT":{i="merge_commit";break}case"FAST_FORWARD":{i="fast_forward";break}case"SQUASH":{i="squash";break}}let u={merge_strategy:i,type:"pullrequest"};if(!(await this.config.request({method:"POST",url:`${v}/repositories/${r}/${n}/pullrequests/${a}/merge`,body:JSON.stringify(u),headers:{...C(this.config,e),"Content-Type":"application/json"}})).body.title)throw new Error("Could not merge pull request")}async setPullRequestReviewers(s,e={}){let{repo:{namespace:r,name:n},pullRequestId:a,reviewerUsernames:o}=s,i={reviewers:o.map(l=>({username:l}))};if(!(await this.config.request({method:"PUT",url:`${v}/repositories/${r}/${n}/pullrequests/${a}`,body:JSON.stringify(i),headers:{...C(this.config,e),"Content-Type":"application/json"}})).body.title)throw new Error("Could not set pull request reviewers")}};var Rt=t=>({name:t.displayName,email:t.emailAddress,avatarUrl:null,id:t.id.toString(),username:t.name,url:t.links.self[0].href}),xe=t=>{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"},r=t.reviewers.map(m=>({reviewer:Rt(m.user),state:e[m.status]})),n=((u=t.toRef.repository.links.clone.find(m=>m.name==="ssh"))==null?void 0:u.href)??null,a=((l=t.toRef.repository.links.clone.find(m=>m.name==="https"))==null?void 0:l.href)??null;a||(a=((p=t.toRef.repository.links.clone.find(m=>m.name==="http"))==null?void 0:p.href)??null);let o=((d=t.fromRef.repository.links.clone.find(m=>m.name==="ssh"))==null?void 0:d.href)??null,i=((c=t.fromRef.repository.links.clone.find(m=>m.name==="https"))==null?void 0:c.href)??null;return i||(i=((g=t.fromRef.repository.links.clone.find(m=>m.name==="http"))==null?void 0:g.href)??null),{id:t.id.toString(),number:t.id,title:t.title,url:t.links.self[0].href,state:s[t.state],isDraft:!1,createdDate:new Date(t.createdDate),updatedDate:new Date(t.updatedDate),closedDate:t.closedDate?new Date(t.closedDate):null,mergedDate:t.state=="MERGED"&&t.closedDate?new Date(t.closedDate):null,baseRef:{name:t.toRef.displayId,oid:t.toRef.latestCommit},headRef:{name:t.fromRef.displayId,oid:t.fromRef.latestCommit},commentCount:t.properties.commentCount,upvoteCount:null,commitCount:null,fileCount:null,additions:null,deletions:null,author:Rt(t.author.user),assignees:null,reviews:r,reviewDecision:Q(r),repository:{id:t.toRef.repository.id.toString(),name:t.toRef.repository.name,owner:{login:t.toRef.repository.project.name},remoteInfo:a&&n?{cloneUrlHTTPS:a,cloneUrlSSH:n}:null},headRepository:{id:t.fromRef.repository.id.toString(),name:t.fromRef.repository.name,owner:{login:t.fromRef.repository.project.name},remoteInfo:i&&o?{cloneUrlHTTPS:i,cloneUrlSSH:o}:null},headCommit:null,mergeableState:"UNKNOWN",permissions:null}},J=class extends L{getBaseUrl(s){let e=s.baseUrl||this.config.baseUrl;if(!e)throw new Error('Bitbucket Server requires "baseUrl"');return e}getRequestHeaders(s){return R(s.token||this.config.token)}async getRepo(s,e={}){var n,a,o;let r=await this.config.request({url:`${this.getBaseUrl(e)}/projects/${s.namespace}/repos/${s.name}`,headers:this.getRequestHeaders(e)});return{data:{id:r.body.id.toString(),namespace:r.body.project.key,name:r.body.slug,webUrl:((n=r.body.links.self[0])==null?void 0:n.href)??null,httpsUrl:((a=r.body.links.clone.find(i=>i.name==="https"))==null?void 0:a.href)??null,sshUrl:((o=r.body.links.clone.find(i=>i.name==="ssh"))==null?void 0:o.href)??null,defaultBranch:null,permission:null}}}async getRepos(s,e={}){let r=[],n=[];return await Promise.all(s.map(async a=>{try{let o=await this.getRepo(a,e);r.push(o.data)}catch(o){n.push({input:a,error:o})}})),{data:r,errors:n}}async getPullRequestsForRepoBase(s,e={}){var n;let r=new URL(`${this.getBaseUrl(e)}/projects/${encodeURI(s.repo.namespace)}/repos/${encodeURI(s.repo.name)}/pull-requests?state=OPEN`);return r.searchParams.set("start",((n=s.page)==null?void 0:n.toString())||"0"),r.searchParams.set("limit","50"),await this.config.request({url:r.toString(),headers:this.getRequestHeaders(e)})}async getPullRequestsForRepo(s,e={}){let r=[],n=await this.getPullRequestsForRepoBase(s,e);n.body.values.forEach(o=>{if(s.authorLogin&&o.author.user.name!==s.authorLogin)return null;r.push(xe(o))});let a=n.body.values.length!==0;return{pageInfo:{hasNextPage:a,nextPage:a?n.body.start+n.body.values.length:null},data:r}}async getPullRequestsForRepos(s,e={}){let r=[];return await Promise.all(s.repos.map(async n=>{try{(await this.getPullRequestsForRepoBase({repo:n,...s},e)).body.values.forEach(o=>{if(s.authorLogin&&o.author.user.name!==s.authorLogin)return null;r.push(xe(o))})}catch(a){if(a.statusCode!==404&&a.statusCode!==401)throw a}})),{data:r}}async getPullRequestsForCurrentUser(s,e={}){var o;let r=new URL(`${this.getBaseUrl(e)}/dashboard/pull-requests`);r.searchParams.set("state","OPEN"),r.searchParams.set("start",((o=s.page)==null?void 0:o.toString())||"0"),r.searchParams.set("limit","50");let n=await this.config.request({url:r.toString(),headers:this.getRequestHeaders(e)}),a=n.body.values.length!==0;return{pageInfo:{hasNextPage:a,nextPage:a?n.body.start+n.body.values.length:null},data:n.body.values.map(xe)}}async closePullRequest(s,e){let{repo:{namespace:r,name:n},pullRequestId:a,version:o}=s;if(!(await this.config.request({method:"POST",url:`${this.getBaseUrl(e)}/projects/${r}/repos/${n}/pull-requests/${a}/decline`,body:JSON.stringify({version:o}),headers:{...this.getRequestHeaders(e),"Content-Type":"application/json"}})).body.title)throw new Error("Could not close pull request")}async mergePullRequest(s,e){let{repo:{namespace:r,name:n},pullRequestId:a,mergeStrategyId:o,version:i}=s;if(!(await this.config.request({method:"POST",url:`${this.getBaseUrl(e)}/projects/${r}/repos/${n}/pull-requests/${a}/merge`,body:JSON.stringify({strategyId:o,version:i}),headers:{...this.getRequestHeaders(e),"Content-Type":"application/json"}})).body.title)throw new Error("Could not merge pull request")}async getMergeStrategies(s){let e=await this.config.request({url:`${this.getBaseUrl(s)}/admin/pull-requests/git`,headers:{...this.getRequestHeaders(s),"Content-Type":"application/json"}});return{data:{defaultStrategy:e.body.mergeConfig.defaultStrategy,strategies:e.body.mergeConfig.strategies}}}async setPullRequestReviewers(s,e={}){let{repo:{namespace:r,name:n},pullRequestId:a,reviewerUsernames:o,version:i}=s,u={reviewers:o.map(p=>({user:{name:p}})),version:i};if(!(await this.config.request({method:"PUT",url:`${this.getBaseUrl(e)}/projects/${r}/repos/${n}/pull-requests/${a}`,body:JSON.stringify(u),headers:{...this.getRequestHeaders(e),"Content-Type":"application/json"}})).body.title)throw new Error("Could not set pull request reviewers")}};var Nt={AS_CODE_OWNER:[3,0,0],CHECK_RUN:[3,0,0],LATEST_REVIEWS:[3,0,0],VIEWER_CAN_MERGE_AS_ADMIN:[3,5,0]},ie=(t,s)=>{let e=Nt[s];for(let r=0;r<3;r++){if(t[r]>e[r])return!0;if(t[r]<e[r])return!1}return!0},le="https://api.github.com",Qt=`${le}/graphql`,pe=`
1
+ "use strict";var Lt=Object.create;var re=Object.defineProperty;var Ut=Object.getOwnPropertyDescriptor;var $t=Object.getOwnPropertyNames;var Gt=Object.getPrototypeOf,At=Object.prototype.hasOwnProperty;var O=(r,s)=>{for(var e in s)re(r,e,{get:s[e],enumerable:!0})},ut=(r,s,e,t)=>{if(s&&typeof s=="object"||typeof s=="function")for(let n of $t(s))!At.call(r,n)&&n!==e&&re(r,n,{get:()=>s[n],enumerable:!(t=Ut(s,n))||t.enumerable});return r};var Ot=(r,s,e)=>(e=r!=null?Lt(Gt(r)):{},ut(s||!r||!r.__esModule?re(e,"default",{value:r,enumerable:!0}):e,r)),Tt=r=>ut(re({},"__esModule",{value:!0}),r);var ur={};O(ur,{AzureDevOps:()=>H,AzureDevopsUtils:()=>Se,Bitbucket:()=>W,BitbucketServer:()=>J,BitbucketServerUtils:()=>ve,BitbucketUtils:()=>qe,GitHub:()=>K,GitHubUtils:()=>Ce,GitLab:()=>X,GitLabUtils:()=>De,GitProviderUtils:()=>Ee,Jira:()=>Z,JiraServer:()=>ee,JiraUtils:()=>Le,Trello:()=>te,TrelloUtils:()=>Ue,Utils:()=>ir,default:()=>ar});module.exports=Tt(ur);var v=100;var lt={APPROVED:0,COMMENTED:1,REVIEW_REQUESTED:2,CHANGES_REQUESTED:3},Q=r=>!r||r.length===0?null:r.reduce((s,e)=>lt[e.state]>lt[s]?e.state:s,"APPROVED");var pt=Ot(require("node-fetch")),dt=globalThis.fetch||pt.default;var xt=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 xt(t)};var Ge=(r,s=!1)=>r.name==="fetch"||s;var D=class{constructor(s){let e=(s==null?void 0:s.request)||dt;this.config={...s,request:Ge(e,s==null?void 0:s.forceIsFetch)?$e(e):e}}updateConfig(s){this.config={...this.config,...s,request:s.request&&Ge(s.request,(s==null?void 0:s.forceIsFetch)??this.config.forceIsFetch)?$e(s.request):this.config.request}}},$=class extends D{};var R=(r,s)=>{let e={};return r&&(e.Authorization=`${s?"Basic":"Bearer"} ${r}`),e},ct=r=>r?r.reduce((s,e)=>(s[e]=!0,s),{}):void 0,N=(r,s,e)=>!r||s.some(t=>r[t])?e:"";var P=(r,s={})=>R(s.token||r.token,s.isPAT||r.isPAT),gt=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 mt="https://app.vssps.visualstudio.com/_apis",S="https://dev.azure.com",kt={active:"OPEN",completed:"MERGED",abandoned:"CLOSED"},_t={10:"APPROVED",5:"APPROVED",0:"REVIEW_REQUESTED",[-5]:"CHANGES_REQUESTED",[-10]:"CHANGES_REQUESTED"},Ae=r=>({id:r.id,name:r.displayName,username:r.uniqueName||r.displayName,email:null,avatarUrl:r.imageUrl,url:null}),oe=r=>r.startsWith("refs/heads/")?r.replace("refs/heads/",""):r,ne=(r,s)=>{var t;let e=s.reviewers.filter(n=>n.vote!==0).map(n=>({reviewer:Ae(n),state:_t[n.vote]||"REVIEW_REQUESTED"}));return{id:s.pullRequestId.toString(),title:s.title,number:s.codeReviewId,state:kt[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:oe(s.targetRefName),oid:s.lastMergeTargetCommit.commitId},headRef:{name:oe(s.sourceRefName),oid:s.lastMergeSourceCommit.commitId},url:gt(s),assignees:s.reviewers.map(Ae),reviews:e,reviewDecision:Q(e),additions:null,deletions:null,fileCount:null,commitCount:null,headRepository:null,mergeableState:"UNKNOWN",labels:((t=s.labels)==null?void 0:t.map(n=>({color:null,description:null,id:n.id,name:n.name})))??[],permissions:null}},ht=(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:oe(s.defaultBranch)}:null,permission:null}),Qt=(r,s,e,t)=>{var l,p;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:n["System.CreatedBy"]._links.avatar.href,email:null,id:n["System.CreatedBy"].id,name:n["System.CreatedBy"].uniqueName,username:n["System.CreatedBy"].displayName,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:o._links.avatar.href,email:null,id:o.id,name:o.uniqueName,username:o.displayName,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},upvoteCount:0,labels:((p=e.fields["System.Tags"])==null?void 0:p.split(";").map(d=>({color:null,description:null,id:null,name:d.trim()})))??[]}},H=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:`${mt}/profile/profiles/me`,headers:P(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:`${S}/${encodeURIComponent(s.namespace)}/_apis/ConnectionData`,headers:P(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:`${S}/${encodeURIComponent(s.repo.namespace)}/${encodeURIComponent(s.repo.project)}/_apis/git/repositories/${encodeURIComponent(s.repo.name)}/commits/${s.oid}`,headers:P(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:`${mt}/accounts?memberId=${s.userId}&api-version=6.0`,headers:P(this.config,e)})).body.value.map(n=>({id:n.accountId,name:n.accountName}))}}async getAzureProjects(s,e={}){let t=new URL(`${S}/${encodeURIComponent(s.namespace)}/_apis/projects`);t.searchParams.set("$top",v.toString()),s.cursor&&t.searchParams.set("$skip",s.cursor);let n=await this.config.request({url:t.toString(),headers:P(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:P(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:P(this.config,e)}),u=i.headers["x-ms-continuationtoken"];return{pageInfo:{endCursor:u||null,hasNextPage:!!u},data:i.body.value.map(l=>{var p;return{avatarUrl:((p=l._links.avatar)==null?void 0:p.href)??null,descriptor:l.descriptor,email:l.mailAddress,name:l.displayName,storageKeyURL:l._links.storageKey.href,username:l.displayName}})}}async getAccountFromAzureGraphAccount(s,e={}){let{azureGraphAccount:t}=s,n=await this.config.request({url:t.storageKeyURL,headers:P(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:`${S}/${encodeURIComponent(s.namespace)}/${encodeURIComponent(s.project)}/_apis/git/repositories/${encodeURIComponent(s.name)}`,headers:P(this.config,e)});return{data:ht(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:`${S}/${encodeURIComponent(s.namespace)}/${encodeURIComponent(s.project)}/_apis/git/repositories`,headers:P(this.config,e)})).body.value.map(n=>ht(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(`${S}/${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",v.toString()),e.cursor&&n.searchParams.set("continuationToken",e.cursor);let o=await this.config.request({url:n.toString(),headers:P(this.config,t)}),a=o.headers["x-ms-continuationtoken"];return{pageInfo:{hasNextPage:!!a,endCursor:a||null},data:o.body.value.map(i=>({name:oe(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||S}/${encodeURIComponent(o.namespace)}/${encodeURIComponent(o.project||"")}/_apis/git/repositories/${encodeURIComponent(o.name)}/pullRequests?${l}&%24top=${t}&%24skip=${(u-1)*t}`,headers:P(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=>ne(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(ne(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||S}/${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:P(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=>ne(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(ne(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||S}/${encodeURIComponent(t)}/${encodeURIComponent(n||"")}/_apis/git/repositories/${o}/pullrequests/${a}?includeCommits=true?api-version=6.0`,headers:{...P(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||S}/${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:{...P(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||S}/${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:{...P(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||S}/${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:{...P(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||S}/${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:{...P(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||S}/${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:{...P(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,statusByWorkItemIdByStatusId:i}=s||{},u=t||1,l=200,p=["[Microsoft.VSTS.Common.ClosedDate] = ''","[System.TeamProject] = @project","[Microsoft.VSTS.Common.ResolvedDate] = ''"];o&&p.push(`[System.CreatedBy] = '${o.replace("'","''")}'`),n&&n[0]&&p.push(`[System.AssignedTo] = '${n[0].replace("'","''")}'`),a&&p.push("[System.Id] IN (@recentMentions)");let d=`Select [Microsoft.VSTS.Common.ClosedDate], [Microsoft.VSTS.Common.ResolvedDate] From WorkItems Where ${p.join(" AND ")} order by [System.CreatedDate] desc`,c=await this.config.request({url:`${e.baseUrl||S}/${encodeURIComponent(s.namespace)}/${encodeURIComponent(s.project)}/_apis/wit/wiql?api-version=6.0`,body:JSON.stringify({query:d}),method:"POST",headers:{...P(this.config,e),"Content-Type":"application/json"}}),g=c.body.workItems.slice((u-1)*l,l*u).map(f=>f.id);if(g.length==0)return{pageInfo:{hasNextPage:!1,nextPage:null},data:[]};let m=await this.config.request({url:`${e.baseUrl||S}/${encodeURIComponent(s.namespace)}/${encodeURIComponent(s.project)}/_apis/wit/workitemsbatch?api-version=6.0`,body:JSON.stringify({ids:g,$expand:"Links"}),method:"POST",headers:{...P(this.config,e),"Content-Type":"application/json"}});return{pageInfo:{hasNextPage:c.body.workItems.length>l*u,nextPage:u+1},data:m.body.value.map(f=>Qt(s.namespace,s.project,f,i||{}))}}async updateIssue(s,e,t={}){return await this.config.request({method:"PATCH",url:`${t.baseUrl||S}/${encodeURIComponent(s.project.namespace)}/${encodeURIComponent(s.project.name)}/_apis/wit/workitems/${s.id}?api-version=6.0`,body:JSON.stringify(e),headers:{...P(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||S}/${encodeURIComponent(t)}/${encodeURIComponent(n||"")}/_apis/wit/workitemtypes?api-version=6.0`,headers:{...P(this.config,e)}})).body.value}}async getLabelsForProject(s,e={}){let{namespace:t,project:n}=s;return{data:(await this.config.request({url:`${e.baseUrl||S}/${encodeURIComponent(t)}/${encodeURIComponent(n||"")}/_apis/wit/tags?api-version=6.0`,headers:{...P(this.config,e)}})).body.value.map(a=>({color:null,description:null,id:a.id,name:a.name,url:a.url}))}}};var C=(r,s={})=>R(s.token||r.token,s.isPAT||r.isPAT);var L="https://api.bitbucket.org/2.0",Nt={OPEN:"OPEN",MERGED:"MERGED",DECLINED:"CLOSED"},Rt=r=>({id:r.uuid,name:r.display_name||r.nickname,username:r.nickname||r.display_name,email:null,avatarUrl:r.links.avatar.href,url:r.links.html.href}),ft=r=>{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}},Te=r=>{let s=r.id;return{id:s.toString(),title:r.title,number:s,state:Nt[r.state],isDraft:!1,commentCount:r.comment_count,upvoteCount:null,author:Rt(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}},W=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:Rt(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: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=new URL(`${L}/repositories`);t.searchParams.set("role","member"),t.searchParams.set("pagelen",v.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(ft)}}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",v.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",v.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(Te)}}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(Te(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(Te(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 It=r=>({name:r.displayName,email:r.emailAddress,avatarUrl:null,id:r.id.toString(),username:r.name,url:r.links.self[0].href}),xe=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:It(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:It(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&&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}},bt=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"))==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}},J=class extends ${getBaseUrl(s){let e=s.baseUrl||this.config.baseUrl;if(!e)throw new Error('Bitbucket Server requires "baseUrl"');return e}getRequestHeaders(s){return R(s.token||this.config.token)}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:bt(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(bt)}}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(xe(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(xe(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(xe)}}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 qt=require("js-base64");var Ft={AS_CODE_OWNER:[3,0,0],CHECK_RUN:[3,0,0],LATEST_REVIEWS:[3,0,0],VIEWER_CAN_MERGE_AS_ADMIN:[3,5,0]},ie=(r,s)=>{let e=Ft[s];for(let t=0;t<3;t++){if(r[t]>e[t])return!0;if(r[t]<e[t])return!1}return!0},le="https://api.github.com",Bt=`${le}/graphql`,pe=`
2
2
  description
3
3
  dueOn
4
4
  id
@@ -6,7 +6,7 @@ number
6
6
  state
7
7
  title
8
8
  url
9
- `,Ft=`
9
+ `,jt=`
10
10
  ... on CheckRun {
11
11
  completedAt
12
12
  conclusion
@@ -20,34 +20,34 @@ color
20
20
  description
21
21
  id
22
22
  name
23
- `,It=t=>{if(t.endsWith("/api/graphql"))throw new Error("The graphql endpoint is being used as the baseUrl. This package uses both GraphQL and REST APIs, and the REST version cannot be assumed. Use the REST endpoint as the baseUrl instead.")},Bt=(t,s)=>{let e=s.baseUrl||t.baseUrl;return e?(e=e.replace(/\/$/,""),It(e),ue.test(e)&&(e=e.replace(ue,"")),`${e}/api/graphql`):Qt},ke=(t,s)=>{let e=s.baseUrl||t.baseUrl;return e?(e=e.replace(/\/$/,""),It(e),ue.test(e)&&(e=e.replace(ue,"")),`${e}/api/v3`):le},b=(t,s,e)=>{let r=R(e.token||t.token);return r["X-Github-Next-Global-ID"]="1",r["Content-Type"]="application/json",r.Accept="application/vnd.github.merge-info-preview+json",t.request({url:Bt(t,e),method:"POST",headers:r,body:JSON.stringify(s)})},jt={user:!0,"user:email":!0,"read:user":!0},O=t=>t.some(s=>jt[s]),$=(t=!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.")},Mt=(r,s)=>{let e=s.baseUrl||r.baseUrl;return e?(e=e.replace(/\/$/,""),yt(e),ue.test(e)&&(e=e.replace(ue,"")),`${e}/api/graphql`):Bt},ke=(r,s)=>{let e=s.baseUrl||r.baseUrl;return e?(e=e.replace(/\/$/,""),yt(e),ue.test(e)&&(e=e.replace(ue,"")),`${e}/api/v3`):le},I=(r,s,e)=>{let t=R(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:Mt(r,e),method:"POST",headers:t,body:JSON.stringify(s)})},zt={user:!0,"user:email":!0,"read:user":!0},T=r=>r.some(s=>zt[s]),U=(r=!1,s=!1,e)=>`
24
24
  __typename
25
25
  ${N(e,["graphQLId"],"id")}
26
26
  ${N(e,["id"],"databaseId")}
27
27
  ${N(e,["name"],"name")}
28
28
  ${N(e,["name","username"],"login")}
29
29
  ${s?N(e,["email"],"email"):""}
30
- ${N(e,["avatarUrl"],`avatarUrl${t?"(size: $avatarSize)":""}`)}
30
+ ${N(e,["avatarUrl"],`avatarUrl${r?"(size: $avatarSize)":""}`)}
31
31
  ${N(e,["url"],"url")}
32
- `,Mt=(t=!1)=>`
32
+ `,Ht=(r=!1)=>`
33
33
  latestReviews(first: 100) {
34
34
  nodes {
35
35
  author {
36
36
  ... on User {
37
- ${$(!1,t)}
37
+ ${U(!1,r)}
38
38
  }
39
39
  }
40
40
  state
41
41
  }
42
42
  }
43
- `,bt=(t=!1)=>`
43
+ `,wt=(r=!1)=>`
44
44
  __typename
45
45
  id
46
46
  databaseId
47
47
  login
48
- avatarUrl${t?"(size: $avatarSize)":""}
48
+ avatarUrl${r?"(size: $avatarSize)":""}
49
49
  url
50
- `,ce=(t,s=!1,e)=>`
50
+ `,ce=(r,s=!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
- ${$(!1,s)}
58
+ ${U(!1,s)}
59
59
  }
60
60
  ... on Bot {
61
- ${bt(!1)}
61
+ ${wt(!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||ie(e,"CHECK_RUN")?Ft:""}
74
+ ${!e||ie(e,"CHECK_RUN")?jt:""}
75
75
  ... on StatusContext {
76
76
  context
77
77
  createdAt
@@ -119,7 +119,7 @@ headRepository {
119
119
  url
120
120
  sshUrl
121
121
  }
122
- ${t?"isDraft":""}
122
+ ${r?"isDraft":""}
123
123
  url
124
124
  createdAt
125
125
  comments {
@@ -133,7 +133,7 @@ closedAt
133
133
  mergedAt
134
134
  assignees(first: 100) {
135
135
  nodes {
136
- ${$(!1,s)}
136
+ ${U(!1,s)}
137
137
  }
138
138
  }
139
139
  reviewRequests(first: 100) {
@@ -141,12 +141,12 @@ reviewRequests(first: 100) {
141
141
  ${!e||ie(e,"AS_CODE_OWNER")?"asCodeOwner":""}
142
142
  requestedReviewer {
143
143
  ... on User {
144
- ${$(!1,s)}
144
+ ${U(!1,s)}
145
145
  }
146
146
  }
147
147
  }
148
148
  }
149
- ${!e||ie(e,"LATEST_REVIEWS")?Mt(s):""}
149
+ ${!e||ie(e,"LATEST_REVIEWS")?Ht(s):""}
150
150
  additions
151
151
  deletions
152
152
  changedFiles
@@ -161,16 +161,16 @@ labels(first: 100) {
161
161
  }
162
162
  }
163
163
  ${!e||ie(e,"VIEWER_CAN_MERGE_AS_ADMIN")?"viewerCanMergeAsAdmin":""}
164
- `,zt=(t=!1)=>`
164
+ `,Wt=(r=!1)=>`
165
165
  id
166
166
  databaseId
167
167
  title
168
168
  author {
169
169
  ... on User {
170
- ${$(!1,t)}
170
+ ${U(!1,r)}
171
171
  }
172
172
  ... on Bot {
173
- ${bt(!1)}
173
+ ${wt(!1)}
174
174
  }
175
175
  }
176
176
  closedAt
@@ -194,7 +194,7 @@ comments {
194
194
  }
195
195
  assignees(first: 100) {
196
196
  nodes {
197
- ${$(!1,t)}
197
+ ${U(!1,r)}
198
198
  }
199
199
  }
200
200
  state
@@ -206,7 +206,7 @@ labels(first: 100) {
206
206
  ${de}
207
207
  }
208
208
  }
209
- `,Wt={"-linked":"-linked",archived:"archived",assignee:"assignee",author:"author",base:"base",closed:"closed",commenter:"commenter",comments:"comments",created:"created",draft:"draft",head:"head",label:"label",language:"language",linked:"linked",in:"in",interactions:"interactions",involves:"involves",is:"is",mentions:"mentions",merged:"merged",milestone:"milestone",no:"no",org:"org",project:"project",reactions:"reactions",repo:"repo",review:"review","reviewed-by":"reviewed-by","review-requested":"review-requested",state:"state",status:"status",team:"team","team-review-requested":"team-review-requested",type:"type",updated:"updated",user:"user","user-review-requested":"user-review-requested"},Ht=new RegExp('(([^\\s]+:)?\\"(?:[^\\"\\\\]|\\\\.)*\\"?)|([^\\"\\s]+)',"g"),_e=t=>{let s=[];return(t.match(Ht)??[]).forEach(r=>{if(r.includes(":")&&r!="is:closed"){let n=r.split(":")[0];Wt[n]&&s.push(r)}}),s},Ne=(t,s,e,r,n=!1,a=null)=>{let o=t==="issue";return{query:`
209
+ `,Jt={"-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"},Kt=new RegExp('(([^\\s]+:)?\\"(?:[^\\"\\\\]|\\\\.)*\\"?)|([^\\"\\s]+)',"g"),_e=r=>{let s=[];return(r.match(Kt)??[]).forEach(t=>{if(t.includes(":")&&t!="is:closed"){let n=t.split(":")[0];Jt[n]&&s.push(t)}}),s},Qe=(r,s,e,t,n=!1,o=null)=>{let a=r==="issue";return{query:`
210
210
  query SearchIssuesOrPullRequests($query: String! $after: String) {
211
211
  search(type:ISSUE query:$query first:100 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 ${o?"Issue":"PullRequest"} {
218
- ${o?zt(r):ce(n,r,a)}
217
+ ... on ${a?"Issue":"PullRequest"} {
218
+ ${a?Wt(t):ce(n,t,o)}
219
219
  }
220
220
  }
221
221
  }
222
- }`,variables:{query:`is:${t} is:open ${s}`,after:e}}},Jt="Field 'isDraft' doesn't exist on type 'PullRequest'",ge=(t=[])=>t.some(s=>(s==null?void 0:s.message)===Jt),Kt=/@@ -(\d+)(?:,\d+ | )\+(\d+)(?:,\d+ | )@@(?:\\n)?/,Vt=`
222
+ }`,variables:{query:`is:${r} is:open ${s}`,after:e}}},Vt="Field 'isDraft' doesn't exist on type 'PullRequest'",ge=(r=[])=>r.some(s=>(s==null?void 0:s.message)===Vt),Xt=/@@ -(\d+)(?:,\d+ | )\+(\d+)(?:,\d+ | )@@(?:\\n)?/,Yt=`
223
223
  \
224
- +`,yt=(t,s,e,r)=>{let n=Kt.exec(t);if(!n||!n[0]||!n[1])return[];let a=parseInt(n[1],10),o=parseInt(n[2],10),i=t.replace(Vt,`
224
+ +`,Pt=(r,s,e,t)=>{let n=Xt.exec(r);if(!n||!n[0]||!n[1])return[];let o=parseInt(n[1],10),a=parseInt(n[2],10),i=r.replace(Yt,`
225
225
  +`).split(`
226
- `).slice(1),u=a-1,l=o-1,p=i.map(g=>{let m,f;switch(g[0]){case"-":{m="DELETED",u+=1,f=`${g.slice(1)}
226
+ `).slice(1),u=o-1,l=a-1,p=i.map(g=>{let m,f;switch(g[0]){case"-":{m="DELETED",u+=1,f=`${g.slice(1)}
227
227
  `;break}case"+":{m="ADDED",l+=1,f=`${g.slice(1)}
228
228
  `;break}default:m="UNMODIFIED",l+=1,u+=1,f=`${g}
229
- `}return{line:f,oldLineNumber:m!=="ADDED"?u:null,newLineNumber:m!=="DELETED"?l:null,type:m}}),d=e,c=s;if(d!==null&&c!==null&&r!==null&&d<c){let g=0,m=p.length,f=r==="LEFT"?"oldLineNumber":"newLineNumber";for(let I=0;I<p.length;I++){let P=p[I][f];P===d?g=I:P===c&&(m=I)}p=p.slice(g,m+1)}return p};var Qe=`
229
+ `}return{line:f,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,f=t==="LEFT"?"oldLineNumber":"newLineNumber";for(let b=0;b<p.length;b++){let w=p[b][f];w===d?g=b:w===c&&(m=b)}p=p.slice(g,m+1)}return p};var Ne=`
230
230
  id
231
231
  databaseId
232
232
  owner {
@@ -239,18 +239,18 @@ defaultBranchRef {
239
239
  name
240
240
  }
241
241
  viewerPermission
242
- `,je={__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"},Xt={APPROVED:"APPROVED",CHANGES_REQUESTED:"CHANGES_REQUESTED",COMMENTED:"COMMENTED",REVIEW_REQUESTED:"REVIEW_REQUESTED"},Yt={MERGEABLE:"MERGEABLE",CONFLICTING:"CONFLICTS",UNKNOWN:"UNKNOWN"},Zt={BEHIND:"BEHIND",BLOCKED:"BLOCKED",UNKNOWN:"UNKNOWN_AND_BLOCKED",UNSTABLE:"UNSTABLE",CLEAN:null,DIRTY:null,DRAFT:null,HAS_HOOKS:null},es={OPEN:"OPEN",CLOSED:"CLOSED"},ts=["ADMIN","MAINTAIN","TRIAGE","WRITE"],Me=t=>({color:t.color,description:t.description,graphQLId:t.id,id:null,name:t.name}),Fe=t=>({id:t.databaseId.toString(),graphQLId:t.id,namespace:t.owner.login,name:t.name,webUrl:t.url,httpsUrl:t.url.endsWith(".git")?t.url:`${t.url}.git`,sshUrl:t.sshUrl,defaultBranch:t.defaultBranchRef,permission:t.viewerPermission}),ss={OPEN:"OPEN",CLOSED:"CLOSED",MERGED:"MERGED"},rs={id:!0,graphQLId:!0,name:!0,username:!0,email:!0,avatarUrl:!0,url:!0},G=(t,s=rs)=>{let e={};return s.id&&(e.id=t.databaseId.toString()),s.graphQLId&&(e.graphQLId=t.id),s.name&&(e.name=t.name??t.login),s.username&&(e.username=t.login),s.email&&(e.email=t.email??null),s.avatarUrl&&(e.avatarUrl=t.avatarUrl),s.url&&(e.url=t.url),e},ns=(t,s)=>{let e={IN_PROGRESS:"RUNNING",PENDING:"PENDING",QUEUED:"PENDING",REQUESTED:"PENDING",WAITING:"PENDING"};return t!=="COMPLETED"?e[t]:{ACTION_REQUIRED:"ACTION_REQUIRED",CANCELLED:"CANCELLED",FAILURE:"FAILED",NEUTRAL:null,SKIPPED:"SKIPPED",STALE:"FAILED",STARTUP_FAILURE:"FAILED",SUCCESS:"SUCCESS",TIMED_OUT:"ERROR"}[s]},as=t=>({ERROR:"ERROR",EXPECTED:"PENDING",FAILURE:"FAILED",PENDING:"PENDING",SUCCESS:"SUCCESS"})[t],Be=t=>{var o,i,u,l,p,d,c,g,m,f,I;let s=null;t.author?s=(t.author.__typename==="Bot",t.author):s=je;let e=(((o=t.reviewRequests)==null?void 0:o.nodes)||[]).filter(h=>!h.asCodeOwner),r=(i=t.headRepository)==null?void 0:i.url;r&&!r.endsWith(".git")&&(r=`${r}.git`);let n=(u=t.repository)==null?void 0:u.url;n&&!n.endsWith(".git")&&(n=`${n}.git`);let a=e.filter(h=>h.requestedReviewer&&"__typename"in h.requestedReviewer).map(h=>({reviewer:G(h.requestedReviewer),state:"REVIEW_REQUESTED"})).concat((((l=t.latestReviews)==null?void 0:l.nodes)||[]).map(h=>{let P=h.author||je;return{reviewer:G(P),state:Xt[h.state]}}));return{id:t.databaseId.toString(),graphQLId:t.id,title:t.title,number:t.number,state:ss[t.state],commentCount:t.comments.totalCount,upvoteCount:t.reactions.totalCount,author:s?G(s):null,createdDate:new Date(t.createdAt),isDraft:t.isDraft,repository:{id:t.repository.databaseId,graphQLId:t.repository.id,name:t.repository.name,owner:{login:t.repository.owner.login},remoteInfo:{cloneUrlHTTPS:n,cloneUrlSSH:t.repository.sshUrl}},headRepository:t.headRepository?{id:t.headRepository.databaseId,graphQLId:t.headRepository.id,name:t.headRepository.name,owner:{login:t.headRepository.owner.login},remoteInfo:{cloneUrlHTTPS:r,cloneUrlSSH:t.headRepository.sshUrl}}:null,headCommit:{buildStatuses:((c=(d=(p=t.commits.nodes)==null?void 0:p[0].commit.statusCheckRollup)==null?void 0:d.contexts.nodes)==null?void 0:c.map(h=>"context"in h?{completedAt:null,description:h.description,name:h.context,state:as(h.state),startedAt:new Date(h.createdAt),stage:null,url:h.targetUrl}:{completedAt:h.completedAt?new Date(h.completedAt):null,description:null,name:h.name,state:ns(h.status,h.conclusion),startedAt:h.startedAt?new Date(h.startedAt):null,stage:null,url:h.permalink}))??[]},headRef:t.headRef?{name:t.headRef.name,oid:((g=t.headRef.target)==null?void 0:g.oid)??null}:null,baseRef:t.baseRef?{name:t.baseRef.name,oid:((m=t.baseRef.target)==null?void 0:m.oid)??null}:null,url:t.url,updatedDate:new Date(t.updatedAt),closedDate:t.closedAt?new Date(t.closedAt):null,mergedDate:t.mergedAt?new Date(t.mergedAt):null,assignees:t.assignees.nodes?t.assignees.nodes.map(h=>G(h)):null,reviews:a,reviewDecision:Q(a),additions:t.additions,deletions:t.deletions,fileCount:t.changedFiles,commitCount:t.commits.totalCount,mergeableState:Zt[t.mergeStateStatus]??Yt[t.mergeable],milestone:t.milestone?ze(t.milestone):null,labels:((I=(f=t.labels)==null?void 0:f.nodes)==null?void 0:I.map(Me))??[],permissions:{canMerge:ts.includes(t.repository.viewerPermission),canMergeAndBypassProtections:t.viewerCanMergeAsAdmin??!1}}},os=t=>{let{comments:s,isOutdated:e,isResolved:r,originalLine:n,originalStartLine:a,startDiffSide:o}=t,{author:i,body:u,databaseId:l,id:p,path:d,publishedAt:c,url:g}=s.nodes[0];return{author:i?{avatarUrl:i.avatarUrl,email:null,name:i.login}:null,body:u,createdAt:c?new Date(c):null,diffLines:yt(s.nodes[0].diffHunk,n,a,o),id:l,isOutdated:e,isResolved:r,graphQLId:p,filename:d,replies:s.nodes.slice(1).map(is),url:g}},is=t=>({author:t.author?{avatarUrl:t.author.avatarUrl,email:null,name:t.author.login}:null,body:t.body,createdAt:t.publishedAt?new Date(t.publishedAt):null,graphQLId:t.id,id:t.databaseId,url:t.url}),us=t=>{var e,r;let s=null;return t.author?s=(t.author.__typename==="Bot",t.author):s=je,{id:t.databaseId.toString(),graphQLId:t.id,number:t.number,title:t.title,author:G(s),commentCount:t.comments.totalCount,closedDate:t.closedAt?new Date(t.closedAt):null,createdDate:new Date(t.createdAt),description:null,state:{name:es[t.state],color:null},type:null,repository:{id:t.repository.databaseId,graphQLId:t.repository.id,name:t.repository.name,owner:{login:t.repository.owner.login}},url:t.url,updatedDate:new Date(t.updatedAt),assignees:t.assignees.nodes?t.assignees.nodes.map(n=>G(n)):[],upvoteCount:t.reactions.totalCount,milestone:t.milestone?ze(t.milestone):null,labels:((r=(e=t.labels)==null?void 0:e.nodes)==null?void 0:r.map(Me))??[]}},ze=t=>({id:t.number.toString(),graphQLId:t.id.toString(),number:t.number,title:t.title,description:t.description,isOpen:t.state=="OPEN",url:t.url,startDate:null,dueDate:t.dueOn?new Date(t.dueOn):null}),K=class extends L{constructor(){super(...arguments);this._scopesCache={};this._enterpriseVersionsCache={}}async getScopes(e){let r=e.token||this.config.token;if(!r)return[];let n=this._scopesCache[r];if(!n){let o=(await b(this.config,{query:"query { rateLimit(dryRun: true) { __typename } }"},e)).headers["x-oauth-scopes"];n=o?o.split(", "):[],this._scopesCache[r]=n}return n}async getEnterpriseVersion(e){let r=e.baseUrl||this.config.baseUrl;if(!r)return null;let n=this._enterpriseVersionsCache[r];if(!n){let a=await this.config.request({url:`${ke(this.config,e)}/meta`,headers:R(e.token||this.config.token)});if(!a.body.installed_version)return null;n=a.body.installed_version.split(".").slice(0,3).map(o=>parseInt(o,10)),this._enterpriseVersionsCache[r]=n}return n}getEnterpriseAvatarUrlIfNeeded(e,r,n){let a=n.baseUrl||this.config.baseUrl;return!a||a.startsWith(le)?e:r?`https://avatars.githubusercontent.com/u/e?email=${encodeURIComponent(r)}`:""}async getCurrentUser(e={},r={}){var u;if(e.fields&&!e.fields.length)throw new Error('"fields" must contain at least one field or be omitted');let n=pt(e.fields),a=await this.getScopes(r),i=(u=(await b(this.config,{query:`
242
+ `,je={__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"},es={APPROVED:"APPROVED",CHANGES_REQUESTED:"CHANGES_REQUESTED",COMMENTED:"COMMENTED",REVIEW_REQUESTED:"REVIEW_REQUESTED"},ts={MERGEABLE:"MERGEABLE",CONFLICTING:"CONFLICTS",UNKNOWN:"UNKNOWN"},ss={BEHIND:"BEHIND",BLOCKED:"BLOCKED",UNKNOWN:"UNKNOWN_AND_BLOCKED",UNSTABLE:"UNSTABLE",CLEAN:null,DIRTY:null,DRAFT:null,HAS_HOOKS:null},rs={OPEN:"OPEN",CLOSED:"CLOSED"},ns=["ADMIN","MAINTAIN","TRIAGE","WRITE"],Me=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}),os={OPEN:"OPEN",CLOSED:"CLOSED",MERGED:"MERGED"},as={id:!0,graphQLId:!0,name:!0,username:!0,email:!0,avatarUrl:!0,url:!0},G=(r,s=as)=>{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},is=(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]},us=r=>({ERROR:"ERROR",EXPECTED:"PENDING",FAILURE:"FAILED",PENDING:"PENDING",SUCCESS:"SUCCESS"})[r],Be=r=>{var a,i,u,l,p,d,c,g,m,f,b;let s=null;r.author?s=(r.author.__typename==="Bot",r.author):s=je;let e=(((a=r.reviewRequests)==null?void 0:a.nodes)||[]).filter(h=>!h.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(h=>h.requestedReviewer&&"__typename"in h.requestedReviewer).map(h=>({reviewer:G(h.requestedReviewer),state:"REVIEW_REQUESTED"})).concat((((l=r.latestReviews)==null?void 0:l.nodes)||[]).map(h=>{let w=h.author||je;return{reviewer:G(w),state:es[h.state]}}));return{id:r.databaseId.toString(),graphQLId:r.id,title:r.title,number:r.number,state:os[r.state],commentCount:r.comments.totalCount,upvoteCount:r.reactions.totalCount,author:s?G(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:((c=(d=(p=r.commits.nodes)==null?void 0:p[0].commit.statusCheckRollup)==null?void 0:d.contexts.nodes)==null?void 0:c.map(h=>"context"in h?{completedAt:null,description:h.description,name:h.context,state:us(h.state),startedAt:new Date(h.createdAt),stage:null,url:h.targetUrl}:{completedAt:h.completedAt?new Date(h.completedAt):null,description:null,name:h.name,state:is(h.status,h.conclusion),startedAt:h.startedAt?new Date(h.startedAt):null,stage:null,url:h.permalink}))??[]},headRef:r.headRef?{name:r.headRef.name,oid:((g=r.headRef.target)==null?void 0:g.oid)??null}:null,baseRef:r.baseRef?{name:r.baseRef.name,oid:((m=r.baseRef.target)==null?void 0:m.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.map(h=>G(h)):null,reviews:o,reviewDecision:Q(o),additions:r.additions,deletions:r.deletions,fileCount:r.changedFiles,commitCount:r.commits.totalCount,mergeableState:ss[r.mergeStateStatus]??ts[r.mergeable],milestone:r.milestone?ze(r.milestone):null,labels:((b=(f=r.labels)==null?void 0:f.nodes)==null?void 0:b.map(Me))??[],permissions:{canMerge:ns.includes(r.repository.viewerPermission),canMergeAndBypassProtections:r.viewerCanMergeAsAdmin??!1}}},ls=r=>{let{comments:s,isOutdated:e,isResolved:t,originalLine:n,originalStartLine:o,startDiffSide:a}=r,{author:i,body:u,databaseId:l,id:p,path:d,publishedAt:c,url:g}=s.nodes[0];return{author:i?{avatarUrl:i.avatarUrl,email:null,name:i.login}:null,body:u,createdAt:c?new Date(c):null,diffLines:Pt(s.nodes[0].diffHunk,n,o,a),id:l,isOutdated:e,isResolved:t,graphQLId:p,filename:d,replies:s.nodes.slice(1).map(ps),url:g}},ps=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}),ds=r=>{var e,t;let s=null;return r.author?s=(r.author.__typename==="Bot",r.author):s=je,{id:r.databaseId.toString(),graphQLId:r.id,number:r.number,title:r.title,author:G(s),commentCount:r.comments.totalCount,closedDate:r.closedAt?new Date(r.closedAt):null,createdDate:new Date(r.createdAt),description:null,state:{name:rs[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:r.assignees.nodes?r.assignees.nodes.map(n=>G(n)):[],upvoteCount:r.reactions.totalCount,milestone:r.milestone?ze(r.milestone):null,labels:((t=(e=r.labels)==null?void 0:e.nodes)==null?void 0:t.map(Me))??[]}},ze=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}),K=class extends ${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 I(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:`${ke(this.config,e)}/meta`,headers:R(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(le)?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=ct(e.fields),o=await this.getScopes(t),i=(u=(await I(this.config,{query:`
243
243
  query getCurrentUser {
244
244
  viewer {
245
- ${$(!1,O(a),n)}
245
+ ${U(!1,T(o),n)}
246
246
  }
247
247
  }
248
- `},r)).body.data)==null?void 0:u.viewer;if(!i)throw new Error("Current user not found.");return{data:G(i,n)}}async getAccountsForRepo(e,r={}){var l,p,d,c,g,m;let n=await this.getScopes(r),{repo:{namespace:a,name:o},cursor:i}=e,u=await b(this.config,{query:`
248
+ `},t)).body.data)==null?void 0:u.viewer;if(!i)throw new Error("Current user not found.");return{data:G(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 I(this.config,{query:`
249
249
  query getAccountsForRepo($owner: String!, $name: String! $cursor: String, $first: Int!) {
250
250
  repository(owner: $owner, name: $name) {
251
251
  assignableUsers(first: $first, after: $cursor) {
252
252
  nodes {
253
- ${$(!1,O(n))}
253
+ ${U(!1,T(n))}
254
254
  }
255
255
  pageInfo {
256
256
  endCursor
@@ -259,7 +259,7 @@ query getAccountsForRepo($owner: String!, $name: String! $cursor: String, $first
259
259
  }
260
260
  }
261
261
  }
262
- `,variables:{owner:a,name:o,cursor:i,first:q}},r);if(!u.body.data)throw new Error(((l=u.body.errors)==null?void 0:l[0].message)||u.statusText||"Unknown error");return{pageInfo:((d=(p=u.body.data.repository)==null?void 0:p.assignableUsers)==null?void 0:d.pageInfo)??{endCursor:null,hasNextPage:!1},data:((m=(g=(c=u.body.data.repository)==null?void 0:c.assignableUsers)==null?void 0:g.nodes)==null?void 0:m.map(f=>G(f)))??[]}}async getUserForCommit(e,r={}){var i,u;let a=(i=(await b(this.config,{query:`
262
+ `,variables:{owner:o,name:a,cursor:i,first:v}},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(f=>G(f)))??[]}}async getUserForCommit(e,t={}){var i,u;let o=(i=(await I(this.config,{query:`
263
263
  query getUserForCommit(
264
264
  $owner: String!
265
265
  $name: String!
@@ -278,23 +278,50 @@ query getUserForCommit(
278
278
  }
279
279
  }
280
280
  }
281
- `,variables:{owner:e.repo.namespace,name:e.repo.name,oid:e.oid,avatarSize:e.avatarSize}},r)).body.data)==null?void 0:i.repository;if(!a)throw new Error("Repository not found.");let o=(u=a.object)==null?void 0:u.author;if(!o)throw new Error("Commit not found.");return{data:{name:o.name,email:o.email,avatarUrl:this.getEnterpriseAvatarUrlIfNeeded(o.avatarUrl,o.email,r)}}}async getAccountForEmail(e,r={}){var i,u,l;let n=await this.getScopes(r),o=(l=(u=(i=(await b(this.config,{query:`
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 I(this.config,{query:`
282
+ mutation createCommitOnBranch(
283
+ $branchName: String!,
284
+ $expectedHeadOid: GitObjectID!,
285
+ $fileChanges: FileChanges!,
286
+ $message: CommitMessage!,
287
+ $repositoryNameWithOwner: String!,
288
+ ) {
289
+ createCommitOnBranch(input: {
290
+ branch: {
291
+ branchName: $branchName,
292
+ repositoryNameWithOwner: $repositoryNameWithOwner,
293
+ },
294
+ expectedHeadOid: $expectedHeadOid,
295
+ fileChanges: $fileChanges,
296
+ message: $message
297
+ }) {
298
+ commit {
299
+ authoredDate
300
+ committedDate
301
+ oid
302
+ }
303
+ ref {
304
+ name
305
+ }
306
+ }
307
+ }
308
+ `,variables:{branchName:u.name,expectedHeadOid:u.oid,fileChanges:{additions:Object.entries(a).map(([d,c])=>({contents:qt.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 I(this.config,{query:`
282
309
  query getAccountForEmail($query: String! $avatarSize: Int) {
283
310
  search(query: $query, type: USER, first: 1) {
284
311
  nodes {
285
312
  ... on User {
286
- ${$(!0,O(n))}
313
+ ${U(!0,T(n))}
287
314
  }
288
315
  }
289
316
  }
290
317
  }
291
- `,variables:{query:`in:email ${e.email}`,avatarSize:e.avatarSize}},r)).body.data)==null?void 0:i.search)==null?void 0:u.nodes)==null?void 0:l[0];if(!o)throw new Error("User not found.");return{data:G({...o,avatarUrl:this.getEnterpriseAvatarUrlIfNeeded(o.avatarUrl,o.email,r)})}}async getAccountForUsername(e,r={}){var i;let n=await this.getScopes(r),o=(i=(await b(this.config,{query:`
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:G({...a,avatarUrl:this.getEnterpriseAvatarUrlIfNeeded(a.avatarUrl,a.email,t)})}}async getAccountForUsername(e,t={}){var i;let n=await this.getScopes(t),a=(i=(await I(this.config,{query:`
292
319
  query getUserForUsername($login: String! $avatarSize: Int) {
293
320
  user(login: $login) {
294
- ${$(!0,O(n))}
321
+ ${U(!0,T(n))}
295
322
  }
296
323
  }
297
- `,variables:{login:e.username,avatarSize:e.avatarSize}},r)).body.data)==null?void 0:i.user;if(!o)throw new Error("User not found.");return{data:G({...o,avatarUrl:this.getEnterpriseAvatarUrlIfNeeded(o.avatarUrl,o.email,r)})}}async getOrgsForCurrentUser(e={},r={}){var o,i;let n=await b(this.config,{query:`
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:G({...a,avatarUrl:this.getEnterpriseAvatarUrlIfNeeded(a.avatarUrl,a.email,t)})}}async getOrgsForCurrentUser(e={},t={}){var a,i;let n=await I(this.config,{query:`
298
325
  query getOrgsForCurrentUser($cursor: String, $first: Int!) {
299
326
  viewer {
300
327
  organizations(first: $first after: $cursor) {
@@ -313,22 +340,22 @@ query getOrgsForCurrentUser($cursor: String, $first: Int!) {
313
340
  }
314
341
  }
315
342
  }
316
- `,variables:{cursor:e.cursor,first:q}},r);if(!((o=n.body.data)!=null&&o.viewer.organizations))throw new Error(((i=n.body.errors)==null?void 0:i[0].message)||n.statusText||"Unknown error");let a=n.body.data.viewer.organizations.nodes||[];return{pageInfo:n.body.data.viewer.organizations.pageInfo,data:a.map(u=>({id:u.databaseId.toString(),graphQLId:u.id,username:u.login,name:u.name||null,email:u.email||null,avatarUrl:u.avatarUrl}))}}async getRepo(e,r={}){var a;let n=await b(this.config,{query:`
343
+ `,variables:{cursor:e.cursor,first:v}},t);if(!((a=n.body.data)!=null&&a.viewer.organizations))throw new Error(((i=n.body.errors)==null?void 0:i[0].message)||n.statusText||"Unknown error");let o=n.body.data.viewer.organizations.nodes||[];return{pageInfo:n.body.data.viewer.organizations.pageInfo,data:o.map(u=>({id:u.databaseId.toString(),graphQLId:u.id,username:u.login,name:u.name||null,email:u.email||null,avatarUrl:u.avatarUrl}))}}async getRepo(e,t={}){var o;let n=await I(this.config,{query:`
317
344
  query getRepo($owner: String!, $name: String!) {
318
345
  repository(owner: $owner, name: $name) {
319
- ${Qe}
346
+ ${Ne}
320
347
  }
321
348
  }
322
- `,variables:{owner:e.namespace,name:e.name}},r);if(!((a=n.body.data)!=null&&a.repository))throw new Error(`Repository ${e.namespace}/${e.name} not found`);return{data:Fe(n.body.data.repository)}}async getRepos(e,r={}){let n=e.map(({namespace:u,name:l},p)=>`
349
+ `,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)=>`
323
350
  getRepo_${p}: repository(owner: "${u}", name: "${l}") {
324
- ${Qe}
351
+ ${Ne}
325
352
  }
326
353
  `).join(`
327
- `),a=await b(this.config,{query:`
354
+ `),o=await I(this.config,{query:`
328
355
  query batchGetRepos {
329
356
  ${n}
330
357
  }
331
- `},r);if(!a.body.data)throw new Error(a.statusText||"Unknown error");let o=[],i=[];return e.forEach((u,l)=>{let p=a.body.data[`getRepo_${l}`];p?o.push(Fe(p)):i.push({input:u})}),{data:o,errors:i}}async getReposForUsernames(e,r={}){var o;if(!e.usernames.length)return{pageInfo:{endCursor:null,hasNextPage:!1},data:[]};let n=await b(this.config,{query:`
358
+ `},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 getReposForUsernames(e,t={}){var a;if(!e.usernames.length)return{pageInfo:{endCursor:null,hasNextPage:!1},data:[]};let n=await I(this.config,{query:`
332
359
  query getReposForUsernames($query: String!, $cursor: String, $first: Int!) {
333
360
  search(query: $query, type: REPOSITORY, first: $first, after: $cursor) {
334
361
  pageInfo {
@@ -337,12 +364,12 @@ query getReposForUsernames($query: String!, $cursor: String, $first: Int!) {
337
364
  }
338
365
  nodes {
339
366
  ... on Repository {
340
- ${Qe}
367
+ ${Ne}
341
368
  }
342
369
  }
343
370
  }
344
371
  }
345
- `,variables:{query:`fork:true ${e.usernames.map(i=>`user:${i}`).join(" ")}`,cursor:e.cursor,first:q}},r);if(!n.body.data)throw new Error(((o=n.body.errors)==null?void 0:o[0].message)||n.statusText||"Unknown error");let a=n.body.data.search.nodes||[];return{pageInfo:n.body.data.search.pageInfo,data:a.map(Fe)}}async getReposForOwners(e,r={}){return this.getReposForUsernames({usernames:e.owners.filter(n=>n.username).map(n=>n.username),cursor:e.cursor},r)}async getRefs(e,r,n={}){var u;let o=(u=(await b(this.config,{query:`
372
+ `,variables:{query:`fork:true ${e.usernames.map(i=>`user:${i}`).join(" ")}`,cursor:e.cursor,first:v}},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 I(this.config,{query:`
346
373
  query getRefs($owner: String!, $name: String!, $refPrefix: String!, $cursor: String, $first: Int!) {
347
374
  repository(owner: $owner, name: $name) {
348
375
  refs(refPrefix: $refPrefix first: $first after: $cursor) {
@@ -363,7 +390,7 @@ query getRefs($owner: String!, $name: String!, $refPrefix: String!, $cursor: Str
363
390
  }
364
391
  }
365
392
  }
366
- `,variables:{owner:r.repo.namespace,name:r.repo.name,refPrefix:e,cursor:r.cursor,first:q}},n)).body.data)==null?void 0:u.repository;if(!o)throw new Error("Repository not found.");let i=o.refs;return i?{pageInfo:i.pageInfo,data:(i.nodes||[]).map(l=>{var d;let p=(d=l.target)!=null&&d.oid?l.target:null;return{name:l.name,commit:p?{oid:p.oid,authoredDate:new Date(p.authoredDate),committedDate:new Date(p.committedDate)}:null}})}:{pageInfo:{endCursor:null,hasNextPage:!1},data:[]}}async getBranches(e,r={}){return this.getRefs("refs/heads/",e,r)}async getTags(e,r={}){return this.getRefs("refs/tags/",e,r)}async getBlame(e,r={}){var i;let a=(i=(await b(this.config,{query:`
393
+ `,variables:{owner:t.repo.namespace,name:t.repo.name,refPrefix:e,cursor:t.cursor,first:v}},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 I(this.config,{query:`
367
394
  query getBlame($owner: String!, $name: String!, $ref: String!, $path: String!) {
368
395
  repository(owner: $owner, name: $name) {
369
396
  object(expression: $ref) {
@@ -402,7 +429,7 @@ query getBlame($owner: String!, $name: String!, $ref: String!, $path: String!) {
402
429
  }
403
430
  }
404
431
  }
405
- `,variables:{owner:e.repo.namespace,name:e.repo.name,ref:e.ref,path:e.path}},r)).body.data)==null?void 0:i.repository;if(!a)throw new Error("Repository not found.");let o=a.object;if(!o||!("blame"in o))throw new Error("Ref not found.");if(o.blame.ranges.length===0)throw new Error("File not found.");return{data:{ranges:o.blame.ranges.map(u=>{var l;return{startingLine:u.startingLine,endingLine:u.endingLine,commit:{oid:u.commit.oid,parentOids:((l=u.commit.parents.nodes)==null?void 0:l.map(p=>p.oid))||[],authoredDate:new Date(u.commit.authoredDate),author:u.commit.author?{name:u.commit.author.name,email:u.commit.author.email,avatarUrl:u.commit.author.avatarUrl}:null,committedDate:new Date(u.commit.committedDate),committer:u.commit.committer?{name:u.commit.committer.name,email:u.commit.committer.email,avatarUrl:u.commit.committer.avatarUrl}:null,message:u.commit.message,fileCount:u.commit.changedFilesIfAvailable,additions:u.commit.additions,deletions:u.commit.deletions}}})}}}async getFileContents(e,r={}){let n=await this.config.request({url:`${ke(this.config,r)}/repos/${e.repo.namespace}/${e.repo.name}/contents/${encodeURIComponent(e.path)}?ref=${e.ref}`,headers:{...R(r.token||this.config.token),Accept:"application/vnd.github.raw+json"}});if(n.headers["content-type"].startsWith("application/json"))throw new Error(`GitHub: got directory when fetching "${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,r={}){var p,d;let n=await this.getEnterpriseVersion(r),a=await this.getScopes(r),o=O(a),i=c=>{let g=c&&typeof e.isDraft=="boolean"?`${e.query} draft:${e.isDraft}`:e.query;return Ne("pr",g,e.cursor,o,c,n)},u=await b(this.config,i(!0),r);u.body.errors&&ge(u.body.errors)&&(this.config.baseUrl||r.baseUrl)&&(u=await b(this.config,i(!1),r));let{data:l}=u.body;if(!l)throw new Error(((p=u.body.errors)==null?void 0:p[0].message)||u.statusText||"Unknown error");return{pageInfo:{hasNextPage:l.search.pageInfo.hasNextPage,endCursor:l.search.pageInfo.endCursor},data:((d=l.search.nodes)==null?void 0:d.map(Be))||[]}}async searchIssues(e,r={}){var u,l;let n=await this.getScopes(r),a=O(n),o=await b(this.config,Ne("issue",e.query,e.cursor,a),r),{data:i}=o.body;if(!i)throw new Error(((u=o.body.errors)==null?void 0:u[0].message)||o.statusText||"Unknown error");return{pageInfo:{hasNextPage:i.search.pageInfo.hasNextPage,endCursor:i.search.pageInfo.endCursor},data:((l=i.search.nodes)==null?void 0:l.map(us))||[]}}async getPullRequestsAssociatedWithUser(e,r={}){return this.searchPullRequests({query:`involves:${e.username}`,cursor:e.cursor},r)}async getPullRequestsForRepos(e,r={}){let{assigneeLogins:n,updatedBefore:a,authorLogin:o,repos:i,reviewRequestedLogin:u,startQuery:l,mentionLogin:p}=e,d=_e(l||"");return i.forEach(c=>{d.push(`repo:${c.namespace}/${c.name}`)}),n&&n.forEach(c=>{d.push(`assignee:${c}`)}),a&&d.push(`updated:<${a}`),o&&d.push(`author:${o}`),u&&d.push(`review-requested:${u}`),p&&d.push(`mentions:${p}`),this.searchPullRequests({query:`sort:updated ${d.join(" ")}`,isDraft:e.isDraft,cursor:e.cursor},r)}async getPullRequestForRepo(e,r={}){var d,c;let n=await this.getEnterpriseVersion(r),a=await this.getScopes(r),o=O(a),i=g=>({query:`query getPullRequest(
432
+ `,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:`${ke(this.config,t)}/repos/${e.repo.namespace}/${e.repo.name}/contents/${encodeURIComponent(e.path)}?ref=${e.ref}`,headers:{...R(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=T(o),i=c=>{let g=c&&typeof e.isDraft=="boolean"?`${e.query} draft:${e.isDraft}`:e.query;return Qe("pr",g,e.cursor,a,c,n)},u=await I(this.config,i(!0),t);u.body.errors&&ge(u.body.errors)&&(this.config.baseUrl||t.baseUrl)&&(u=await I(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.map(Be))||[]}}async searchIssues(e,t={}){var u,l;let n=await this.getScopes(t),o=T(n),a=await I(this.config,Qe("issue",e.query,e.cursor,o),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.map(ds))||[]}}async getPullRequestsAssociatedWithUser(e,t={}){return this.searchPullRequests({query:`involves:${e.username}`,cursor:e.cursor},t)}async getPullRequestsForRepos(e,t={}){let{assigneeLogins:n,updatedBefore:o,authorLogin:a,repos:i,reviewRequestedLogin:u,startQuery:l,mentionLogin:p}=e,d=_e(l||"");return i.forEach(c=>{d.push(`repo:${c.namespace}/${c.name}`)}),n&&n.forEach(c=>{d.push(`assignee:${c}`)}),o&&d.push(`updated:<${o}`),a&&d.push(`author:${a}`),u&&d.push(`review-requested:${u}`),p&&d.push(`mentions:${p}`),this.searchPullRequests({query:`sort:updated ${d.join(" ")}`,isDraft:e.isDraft,cursor:e.cursor},t)}async getPullRequestForRepo(e,t={}){var d,c;let n=await this.getEnterpriseVersion(t),o=await this.getScopes(t),a=T(o),i=g=>({query:`query getPullRequest(
406
433
  $owner: String!
407
434
  $name: String!
408
435
  $number: Int!
@@ -412,24 +439,24 @@ query getBlame($owner: String!, $name: String!, $ref: String!, $path: String!) {
412
439
  name: $name
413
440
  ) {
414
441
  pullRequest(number: $number) {
415
- ${ce(g,o,n)}
442
+ ${ce(g,a,n)}
416
443
  }
417
444
  }
418
- }`,variables:{owner:e.repo.namespace,name:e.repo.name,number:e.number}}),u=await b(this.config,i(!0),r);u.body.errors&&ge(u.body.errors)&&(this.config.baseUrl||r.baseUrl)&&(u=await b(this.config,i(!1),r));let{data:l}=u.body;if(!l)throw new Error(((d=u.body.errors)==null?void 0:d[0].message)||u.statusText||"Unknown error");let p=(c=u.body.data)==null?void 0:c.repository.pullRequest;return{data:p?Be(p):null}}async getPullRequestByGraphQLId(e,r={}){var d,c;let n=await this.getEnterpriseVersion(r),a=await this.getScopes(r),o=O(a),i=g=>({query:`query getPullRequest(
445
+ }`,variables:{owner:e.repo.namespace,name:e.repo.name,number:e.number}}),u=await I(this.config,i(!0),t);u.body.errors&&ge(u.body.errors)&&(this.config.baseUrl||t.baseUrl)&&(u=await I(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?Be(p):null}}async getPullRequestByGraphQLId(e,t={}){var d,c;let n=await this.getEnterpriseVersion(t),o=await this.getScopes(t),a=T(o),i=g=>({query:`query getPullRequest(
419
446
  $graphQLId: ID!
420
447
  ) {
421
448
  node(id: $graphQLId) {
422
449
  ... on PullRequest {
423
- ${ce(g,o,n)}
450
+ ${ce(g,a,n)}
424
451
  }
425
452
  }
426
- }`,variables:{graphQLId:e.graphQLId}}),u=await b(this.config,i(!0),r);u.body.errors&&ge(u.body.errors)&&(this.config.baseUrl||r.baseUrl)&&(u=await b(this.config,i(!1),r));let{data:l}=u.body;if(!l)throw new Error(((d=u.body.errors)==null?void 0:d[0].message)||u.statusText||"Unknown error");let p=(c=u.body.data)==null?void 0:c.node;return{data:p?Be(p):null}}async closePullRequest(e,r={}){var i,u,l;let{pullRequestGraphQLId:n}=e,a=`mutation ClosePullRequest($pullRequestGraphQLId: ID!) {
453
+ }`,variables:{graphQLId:e.graphQLId}}),u=await I(this.config,i(!0),t);u.body.errors&&ge(u.body.errors)&&(this.config.baseUrl||t.baseUrl)&&(u=await I(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?Be(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!) {
427
454
  closePullRequest(input: { pullRequestId: $pullRequestGraphQLId }) {
428
455
  pullRequest {
429
456
  id
430
457
  }
431
458
  }
432
- }`;if(!((l=(u=(i=(await b(this.config,{query:`${a}`,variables:{pullRequestGraphQLId:n}},r)).body.data)==null?void 0:i.closePullRequest)==null?void 0:u.pullRequest)!=null&&l.id))throw new Error("Could not close pull request")}async mergePullRequest(e,r={}){var p,d,c;let{pullRequestGraphQLId:n,expectedSourceSha:a,mergeStrategy:o}=e,i;switch(o){case"MERGE_COMMIT":{i="MERGE";break}case"REBASE":{i="REBASE";break}case"SQUASH":{i="SQUASH";break}}let u=`mutation MergePullRequest(
459
+ }`;if(!((l=(u=(i=(await I(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(
433
460
  $pullRequestGraphQLId: ID!,
434
461
  $expectedSourceSha: GitObjectID!,
435
462
  $mergeStrategy: PullRequestMergeMethod,
@@ -443,37 +470,43 @@ query getBlame($owner: String!, $name: String!, $ref: String!, $path: String!) {
443
470
  id
444
471
  }
445
472
  }
446
- }`;if(!((c=(d=(p=(await b(this.config,{query:`${u}`,variables:{pullRequestGraphQLId:n,expectedSourceSha:a,mergeStrategy:i}},r)).body.data)==null?void 0:p.mergePullRequest)==null?void 0:d.pullRequest)!=null&&c.id))throw new Error("Could not merge pull request")}async setPullRequestMilestone(e,r={}){var u,l,p;let{pullRequestGraphQLId:n,milestoneGraphQLId:a}=e,o=`mutation SetPullRequestMilestone($pullRequestGraphQLId: ID!, $milestoneGraphQLId: ID) {
473
+ }`;if(!((c=(d=(p=(await I(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) {
447
474
  updatePullRequest(input: { pullRequestId: $pullRequestGraphQLId, milestoneId: $milestoneGraphQLId }) {
448
475
  pullRequest {
449
476
  id
450
477
  }
451
478
  }
452
- }`;if(!((p=(l=(u=(await b(this.config,{query:`${o}`,variables:{pullRequestGraphQLId:n,milestoneGraphQLId:a}},r)).body.data)==null?void 0:u.updatePullRequest)==null?void 0:l.pullRequest)!=null&&p.id))throw new Error("Could not set milestone of pull request")}async markPullRequestReadyForReview(e,r){var o,i,u;let n=`mutation MarkReadyToReview($pullRequestGraphQLId: ID!) {
479
+ }`;if(!((p=(l=(u=(await I(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!) {
453
480
  markPullRequestReadyForReview(input: { pullRequestId: $pullRequestGraphQLId }) {
454
481
  pullRequest {
455
482
  id
456
483
  }
457
484
  }
458
- }`;if(!((u=(i=(o=(await b(this.config,{query:n,variables:{pullRequestGraphQLId:e}},r)).body.data)==null?void 0:o.markPullRequestReadyForReview)==null?void 0:i.pullRequest)!=null&&u.id))throw new Error("Could not mark pull request ready to review")}async convertPullRequestToDraft(e,r){var o,i,u;let n=`mutation ConvertToDraft($pullRequestGraphQLId: ID!) {
485
+ }`;if(!((u=(i=(a=(await I(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!) {
459
486
  convertPullRequestToDraft(input: { pullRequestId: $pullRequestGraphQLId }) {
460
487
  pullRequest {
461
488
  id
462
489
  }
463
490
  }
464
- }`;if(!((u=(i=(o=(await b(this.config,{query:n,variables:{pullRequestGraphQLId:e}},r)).body.data)==null?void 0:o.convertPullRequestToDraft)==null?void 0:i.pullRequest)!=null&&u.id))throw new Error("Could not convert pull request to draft")}async setPullRequestAsDraft(e,r={}){let{pullRequestGraphQLId:n,isDraft:a}=e;if(a){await this.convertPullRequestToDraft(n,r);return}await this.markPullRequestReadyForReview(n,r)}async setPullRequestReviewers(e,r={}){var u,l,p;let{pullRequestGraphQLId:n,reviewerGraphQLIds:a}=e,o=`mutation SetPullRequestReviewers($pullRequestGraphQLId: ID!, $reviewerGraphQLIds: [ID!]!) {
491
+ }`;if(!((u=(i=(a=(await I(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!]!) {
465
492
  requestReviews(input: { pullRequestId: $pullRequestGraphQLId, userIds: $reviewerGraphQLIds }) {
466
493
  pullRequest {
467
494
  id
468
495
  }
469
496
  }
470
- }`;if(!((p=(l=(u=(await b(this.config,{query:o,variables:{pullRequestGraphQLId:n,reviewerGraphQLIds:a}},r)).body.data)==null?void 0:u.requestReviews)==null?void 0:l.pullRequest)!=null&&p.id))throw new Error("Could not set pull request reviewers")}async setPullRequestAssignees(e,r={}){var u,l,p;let{pullRequestGraphQLId:n,assigneeGraphQLIds:a}=e,o=`mutation SetPullRequestAssignees($pullRequestGraphQLId: ID!, $assigneeGraphQLIds: [ID!]!) {
497
+ }`;if(!((g=(c=(d=(await I(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!]!) {
498
+ requestReviews(input: { pullRequestId: $pullRequestGraphQLId, userIds: $reviewerGraphQLIds, union: true }) {
499
+ pullRequest {
500
+ id
501
+ }
502
+ }
503
+ }`;if(!((c=(d=(p=(await I(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!]!) {
471
504
  updatePullRequest(input: { pullRequestId: $pullRequestGraphQLId, assigneeIds: $assigneeGraphQLIds }) {
472
505
  pullRequest {
473
506
  id
474
507
  }
475
508
  }
476
- }`;if(!((p=(l=(u=(await b(this.config,{query:o,variables:{pullRequestGraphQLId:n,assigneeGraphQLIds:a}},r)).body.data)==null?void 0:u.updatePullRequest)==null?void 0:l.pullRequest)!=null&&p.id))throw new Error("Could not set pull request assignees")}async getReviewsForPullRequest(e,r={}){var d,c;let{repo:{namespace:n,name:a},pullRequestId:o}=e,i=`query getPullRequests(
509
+ }`;if(!((d=(p=(l=(await I(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;let{repo:{namespace:n,name:o},pullRequestId:a}=e,i=`query getPullRequests(
477
510
  $namespace: String!
478
511
  $name: String!
479
512
  $pullRequestId: Int!
@@ -525,49 +558,49 @@ query getBlame($owner: String!, $name: String!, $ref: String!, $path: String!) {
525
558
  }
526
559
  }
527
560
  }
528
- }`,u=await b(this.config,{query:i,variables:{namespace:n,name:a,pullRequestId:o}},r),l=((d=u.body.data)==null?void 0:d.repository.pullRequest.reviewThreads.nodes.reduce((g,m)=>{let f=m.comments.nodes[0].pullRequestReview;return f&&(g[f.id]||(g[f.id]=[]),g[f.id].push(os(m))),g},{}))??{};return{data:((c=u.body.data)==null?void 0:c.repository.pullRequest.reviews.nodes.filter(g=>l[g.id]).map(g=>({author:g.author?{avatarUrl:g.author.avatarUrl,email:null,name:g.author.login}:null,body:g.body,createdAt:g.publishedAt?new Date(g.publishedAt):null,id:g.databaseId,graphQLId:g.id,reviewComments:l[g.id],url:g.url})))??[]}}async getIssuesAssociatedWithUser(e,r={}){var d;let[n,a]=((d=e.cursor)==null?void 0:d.split(";"))||[void 0,void 0],[o,i]=await Promise.all([n==="null"?null:this.searchIssues({query:`author:${e.username}`,cursor:n},r),a==="null"?null:this.searchIssues({query:`assignee:${e.username}`,cursor:a},r)]),u={},l=[],p=c=>{u[c.id]||(u[c.id]=!0,l.push(c))};return o==null||o.data.forEach(p),i==null||i.data.forEach(p),{pageInfo:{hasNextPage:(o==null?void 0:o.pageInfo.hasNextPage)||(i==null?void 0:i.pageInfo.hasNextPage)||!1,endCursor:`${(o==null?void 0:o.pageInfo.hasNextPage)&&(o==null?void 0:o.pageInfo.endCursor)||"null"};${(i==null?void 0:i.pageInfo.hasNextPage)&&(i==null?void 0:i.pageInfo.endCursor)||"null"}`},data:l}}async setPullRequestLabels(e,r={}){var u,l,p;let{pullRequestGraphQLId:n,labelGraphQLIds:a}=e,o=`mutation SetPullRequestLabels($pullRequestGraphQLId: ID!, $labelGraphQLIds: [ID!]) {
561
+ }`,u=await I(this.config,{query:i,variables:{namespace:n,name:o,pullRequestId:a}},t),l=((d=u.body.data)==null?void 0:d.repository.pullRequest.reviewThreads.nodes.reduce((g,m)=>{let f=m.comments.nodes[0].pullRequestReview;return f&&(g[f.id]||(g[f.id]=[]),g[f.id].push(ls(m))),g},{}))??{};return{data:((c=u.body.data)==null?void 0:c.repository.pullRequest.reviews.nodes.filter(g=>l[g.id]).map(g=>({author:g.author?{avatarUrl:g.author.avatarUrl,email:null,name:g.author.login}:null,body:g.body,createdAt:g.publishedAt?new Date(g.publishedAt):null,id:g.databaseId,graphQLId:g.id,reviewComments:l[g.id],url:g.url})))??[]}}async getIssuesAssociatedWithUser(e,t={}){var d;let[n,o]=((d=e.cursor)==null?void 0:d.split(";"))||[void 0,void 0],[a,i]=await Promise.all([n==="null"?null:this.searchIssues({query:`author:${e.username}`,cursor:n},t),o==="null"?null:this.searchIssues({query:`assignee:${e.username}`,cursor:o},t)]),u={},l=[],p=c=>{u[c.id]||(u[c.id]=!0,l.push(c))};return a==null||a.data.forEach(p),i==null||i.data.forEach(p),{pageInfo:{hasNextPage:(a==null?void 0:a.pageInfo.hasNextPage)||(i==null?void 0:i.pageInfo.hasNextPage)||!1,endCursor:`${(a==null?void 0:a.pageInfo.hasNextPage)&&(a==null?void 0:a.pageInfo.endCursor)||"null"};${(i==null?void 0:i.pageInfo.hasNextPage)&&(i==null?void 0:i.pageInfo.endCursor)||"null"}`},data:l}}async setPullRequestLabels(e,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!]) {
529
562
  updatePullRequest(input: { pullRequestId: $pullRequestGraphQLId, labelIds: $labelGraphQLIds }) {
530
563
  pullRequest {
531
564
  id
532
565
  }
533
566
  }
534
- }`;if(!((p=(l=(u=(await b(this.config,{query:o,variables:{pullRequestGraphQLId:n,labelGraphQLIds:a}},r)).body.data)==null?void 0:u.updatePullRequest)==null?void 0:l.pullRequest)!=null&&p.id))throw new Error("Could not set pull request labels")}async getIssuesForRepos(e,r={}){let n=_e(e.startQuery||""),{cursor:a,assigneeLogins:o,updatedBefore:i,authorLogin:u,mentionLogin:l}=e;return e.repos.forEach(p=>{n.push(`repo:${p.namespace}/${p.name}`)}),o&&o.forEach(p=>{n.push(`assignee:${p}`)}),i&&n.push(`updated:<${i}`),u&&n.push(`author:${u}`),l&&n.push(`mentions:${l}`),this.searchIssues({query:`sort:updated ${n.join(" ")}`,cursor:a},r)}async closeIssueWithReason(e,r,n){var i,u,l;let a=`mutation CloseIssueWithReason($issueGraphQLId: ID!, $closeReason: IssueClosedStateReason!) {
535
- closeIssue(input: { issueId: $issueGraphQLId, stateReason: $closeReason }) {
567
+ }`;if(!((p=(l=(u=(await I(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=_e(e.startQuery||""),{cursor:o,assigneeLogins:a,updatedBefore:i,authorLogin:u,mentionLogin:l}=e;return e.repos.forEach(p=>{n.push(`repo:${p.namespace}/${p.name}`)}),a&&a.forEach(p=>{n.push(`assignee:${p}`)}),i&&n.push(`updated:<${i}`),u&&n.push(`author:${u}`),l&&n.push(`mentions:${l}`),this.searchIssues({query:`sort:updated ${n.join(" ")}`,cursor:o},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!) {
568
+ closeIssue(input: { issueId: $issueGraphQLId, stateReason: $reason }) {
536
569
  issue {
537
570
  id
538
571
  }
539
572
  }
540
- }`;if(!((l=(u=(i=(await b(this.config,{query:a,variables:{issueGraphQLId:e,closeReason:r}},n)).body.data)==null?void 0:i.closeIssue)==null?void 0:u.issue)!=null&&l.id))throw new Error("Could not close issue with reason")}async closeIssueWithoutReason(e,r){var o,i,u;let n=`mutation SetIssueState($issueGraphQLId: ID!) {
573
+ }`;if(!((p=(l=(u=(await I(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!) {
541
574
  updateIssue(input: { id: $issueGraphQLId, state: CLOSED }) {
542
575
  issue {
543
576
  id
544
577
  }
545
578
  }
546
- }`;if(!((u=(i=(o=(await b(this.config,{query:n,variables:{issueGraphQLId:e}},r)).body.data)==null?void 0:o.updateIssue)==null?void 0:i.issue)!=null&&u.id))throw new Error("Could not close issue")}async reopenIssue(e,r){var o,i,u;let n=`mutation ReOpenIssue($issueGraphQLId: ID!) {
579
+ }`;if(!((l=(u=(i=(await I(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!) {
547
580
  reopenIssue(input: { issueId: $issueGraphQLId }) {
548
581
  issue {
549
582
  id
550
583
  }
551
584
  }
552
- }`;if(!((u=(i=(o=(await b(this.config,{query:n,variables:{issueGraphQLId:e}},r)).body.data)==null?void 0:o.reopenIssue)==null?void 0:i.issue)!=null&&u.id))throw new Error("Could not reopen issue")}async setIssueStatus(e,r={}){let{issueGraphQLId:n,status:a,closeReason:o}=e;if(o&&a=="OPEN")throw new Error("Did not expect closeReason to be set when trying to reopen issue");a=="OPEN"?await this.reopenIssue(n,r):a=="CLOSED"&&!o?await this.closeIssueWithoutReason(n,r):o&&await this.closeIssueWithReason(n,o,r)}async setIssueLabels(e,r={}){var u,l,p;let{issueGraphQLId:n,labelGraphQLIds:a}=e,o=`mutation SetIssueLabels($issueGraphQLId: ID!, $labelGraphQLIds: [ID!]) {
585
+ }`;if(!((l=(u=(i=(await I(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!]) {
553
586
  updateIssue(input: { id: $issueGraphQLId, labelIds: $labelGraphQLIds }) {
554
587
  issue {
555
588
  id
556
589
  }
557
590
  }
558
- }`;if(!((p=(l=(u=(await b(this.config,{query:o,variables:{issueGraphQLId:n,labelGraphQLIds:a}},r)).body.data)==null?void 0:u.updateIssue)==null?void 0:l.issue)!=null&&p.id))throw new Error("Could not set issue labels")}async setIssueMilestone(e,r={}){var u,l,p;let{issueGraphQLId:n,milestoneGraphQLId:a}=e,o=`mutation SetIssueMilestone($issueGraphQLId: ID!, $milestoneGraphQLId: ID) {
591
+ }`;if(!((d=(p=(l=(await I(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) {
559
592
  updateIssue(input: { id: $issueGraphQLId, milestoneId: $milestoneGraphQLId }) {
560
593
  issue {
561
594
  id
562
595
  }
563
596
  }
564
- }`;if(!((p=(l=(u=(await b(this.config,{query:`${o}`,variables:{issueGraphQLId:n,milestoneGraphQLId:a}},r)).body.data)==null?void 0:u.updateIssue)==null?void 0:l.issue)!=null&&p.id))throw new Error("Could not set milestone of issue")}async setIssueAssignees(e,r={}){var u,l,p;let{issueGraphQLId:n,assigneeGraphQLIds:a}=e,o=`mutation SetIssueAssignees($issueGraphQLId: ID!, $assigneeGraphQLIds: [ID!]!) {
597
+ }`;if(!((p=(l=(u=(await I(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!]!) {
565
598
  updateIssue(input: { id: $issueGraphQLId, assigneeIds: $assigneeGraphQLIds }) {
566
599
  issue {
567
600
  id
568
601
  }
569
602
  }
570
- }`;if(!((p=(l=(u=(await b(this.config,{query:o,variables:{issueGraphQLId:n,assigneeGraphQLIds:a}},r)).body.data)==null?void 0:u.updateIssue)==null?void 0:l.issue)!=null&&p.id))throw new Error("Could not set issue assignees")}async getMilestonesForRepo(e,r={}){var u,l,p,d;let{repo:{namespace:n,name:a},cursor:o}=e,i=await b(this.config,{query:`
603
+ }`;if(!((d=(p=(l=(await I(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 I(this.config,{query:`
571
604
  query getLabelsForRepo($owner: String!, $name: String! $cursor: String, $first: Int!) {
572
605
  repository(owner: $owner, name: $name) {
573
606
  milestones(first: $first, after: $cursor) {
@@ -581,7 +614,7 @@ query getLabelsForRepo($owner: String!, $name: String! $cursor: String, $first:
581
614
  }
582
615
  }
583
616
  }
584
- `,variables:{owner:n,name:a,cursor:o,first:q}},r);if(!i.body.data)throw new Error(((u=i.body.errors)==null?void 0:u[0].message)||i.statusText||"Unknown error");return{pageInfo:((l=i.body.data.repository.milestones)==null?void 0:l.pageInfo)??{endCursor:null,hasNextPage:!1},data:((d=(p=i.body.data.repository.milestones)==null?void 0:p.nodes)==null?void 0:d.map(ze))??[]}}async getLabelsForRepo(e,r={}){var u,l,p,d;let{repo:{namespace:n,name:a},cursor:o}=e,i=await b(this.config,{query:`
617
+ `,variables:{owner:n,name:o,cursor:a,first:v}},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(ze))??[]}}async getLabelsForRepo(e,t={}){var u,l,p,d;let{repo:{namespace:n,name:o},cursor:a}=e,i=await I(this.config,{query:`
585
618
  query getLabelsForRepo($owner: String!, $name: String! $cursor: String, $first: Int!) {
586
619
  repository(owner: $owner, name: $name) {
587
620
  labels(first: $first, after: $cursor) {
@@ -595,7 +628,7 @@ query getLabelsForRepo($owner: String!, $name: String! $cursor: String, $first:
595
628
  }
596
629
  }
597
630
  }
598
- `,variables:{owner:n,name:a,cursor:o,first:q}},r);if(!i.body.data)throw new Error(((u=i.body.errors)==null?void 0:u[0].message)||i.statusText||"Unknown error");return{pageInfo:((l=i.body.data.repository.labels)==null?void 0:l.pageInfo)??{endCursor:null,hasNextPage:!1},data:((d=(p=i.body.data.repository.labels)==null?void 0:p.nodes)==null?void 0:d.map(Me))??[]}}};var ls="https://gitlab.com/api/v4",ps="https://gitlab.com/api/graphql",wt=/\/api\/v\d+$/,Et=t=>{if(t.endsWith("/api/graphql"))throw new Error("The graphql endpoint is being used as the baseUrl. This package uses both GraphQL and REST APIs, and the REST version cannot be assumed. Use the REST endpoint as the baseUrl instead.")},We=(t,s)=>{let e=s.baseUrl||t.baseUrl;return e?(e=e.replace(/\/$/,""),Et(e),e):ls},ds=(t,s)=>{let e=s.baseUrl||t.baseUrl;return e?(e=e.replace(/\/$/,""),Et(e),wt.test(e)&&(e=e.replace(wt,"")),`${e}/api/graphql`):ps},y=(t,s,e)=>{let r=R(e.token||t.token);return t.request({url:ds(t,e),method:"POST",headers:{...r,"Content-Type":"application/json"},body:JSON.stringify(s)})};var Ze=t=>t.split("/").slice(0,-1).join("/"),et=t=>t.split("/").at(-1)??"",V=t=>({id:t.id.replace(F,""),graphQLId:t.id,namespace:Ze(t.fullPath),name:et(t.fullPath),webUrl:t.webUrl}),St=t=>({id:t.id.replace(F,""),graphQLId:t.id,httpsUrl:t.httpUrlToRepo,namespace:Ze(t.fullPath),name:et(t.fullPath),sshUrl:t.sshUrlToRepo,webUrl:t.webUrl}),cs={assigned:"assignedMergeRequests",authored:"authoredMergeRequests",reviewRequested:"reviewRequestedMergeRequests"},gs={CAN_BE_MERGED:"MERGEABLE",CANNOT_BE_MERGED:"CONFLICTS",CANNOT_BE_MERGED_RECHECK:"UNKNOWN",UNCHECKED:"UNKNOWN",CHECKING:"UNKNOWN"},ms="gid://gitlab/User/",F="gid://gitlab/Project/",hs="gid://gitlab/MergeRequest/",fs="gid://gitlab/Issue/",Rs="gid://gitlab/ProjectLabel/",qt="gid://gitlab/Milestone/",Is="gid://gitlab/Ci::Build/",tt=`
631
+ `,variables:{owner:n,name:o,cursor:a,first:v}},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(Me))??[]}}};var cs="https://gitlab.com/api/v4",gs="https://gitlab.com/api/graphql",vt=/\/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.")},He=(r,s)=>{let e=s.baseUrl||r.baseUrl;return e?(e=e.replace(/\/$/,""),Et(e),e):cs},ms=(r,s)=>{let e=s.baseUrl||r.baseUrl;return e?(e=e.replace(/\/$/,""),Et(e),vt.test(e)&&(e=e.replace(vt,"")),`${e}/api/graphql`):gs},y=(r,s,e)=>{let t=R(e.token||r.token);return r.request({url:ms(r,e),method:"POST",headers:{...t,"Content-Type":"application/json"},body:JSON.stringify(s)})};var Ze=r=>r.split("/").slice(0,-1).join("/"),et=r=>r.split("/").at(-1)??"",V=r=>({id:r.id.replace(F,""),graphQLId:r.id,namespace:Ze(r.fullPath),name:et(r.fullPath),webUrl:r.webUrl}),Ct=r=>({id:r.id.replace(F,""),graphQLId:r.id,httpsUrl:r.httpUrlToRepo,namespace:Ze(r.fullPath),name:et(r.fullPath),sshUrl:r.sshUrlToRepo,webUrl:r.webUrl}),hs={assigned:"assignedMergeRequests",authored:"authoredMergeRequests",reviewRequested:"reviewRequestedMergeRequests"},fs={CAN_BE_MERGED:"MERGEABLE",CANNOT_BE_MERGED:"CONFLICTS",CANNOT_BE_MERGED_RECHECK:"UNKNOWN",UNCHECKED:"UNKNOWN",CHECKING:"UNKNOWN"},Rs="gid://gitlab/User/",F="gid://gitlab/Project/",Is="gid://gitlab/MergeRequest/",bs="gid://gitlab/Issue/",ys="gid://gitlab/ProjectLabel/",ws="gid://gitlab/Milestone/",Ps="gid://gitlab/Ci::Build/",tt=`
599
632
  description
600
633
  dueDate
601
634
  id
@@ -604,7 +637,7 @@ startDate
604
637
  state
605
638
  title
606
639
  webPath
607
- `,He=`
640
+ `,We=`
608
641
  id
609
642
  fullPath
610
643
  webUrl
@@ -655,7 +688,7 @@ webUrl
655
688
  milestone {
656
689
  ${tt}
657
690
  }
658
- `,bs=`
691
+ `,Ss=`
659
692
  stages {
660
693
  nodes {
661
694
  jobs {
@@ -671,7 +704,7 @@ stages {
671
704
  name
672
705
  }
673
706
  }
674
- `,Ke=(t,s,e)=>`
707
+ `,Ke=(r,s,e)=>`
675
708
  id
676
709
  state
677
710
  approved
@@ -719,16 +752,16 @@ labels {
719
752
  ${st}
720
753
  }
721
754
  }
722
- ${t?"project { id httpUrlToRepo fullPath sshUrlToRepo webUrl } sourceProject { id httpUrlToRepo fullPath sshUrlToRepo webUrl }":""}
755
+ ${r?"project { id httpUrlToRepo fullPath sshUrlToRepo webUrl } sourceProject { id httpUrlToRepo fullPath sshUrlToRepo webUrl }":""}
723
756
  ${s?`milestone { ${tt} }`:""}
724
- ${e?`headPipeline { ${bs} }`:""}
725
- `,B=t=>`${t.namespace}/${t.name}`,ys=t=>`${t.namespace}/${t.name}`,Ve=t=>{var s;return{id:t.id.replace(F,""),graphQLId:t.id,namespace:Ze(t.fullPath),name:et(t.fullPath),webUrl:t.webUrl,httpsUrl:t.httpUrlToRepo,sshUrl:t.sshUrlToRepo,defaultBranch:(s=t.repository)!=null&&s.rootRef?{name:t.repository.rootRef}:null,permission:null}},Ps={opened:"OPEN",merged:"MERGED",closed:"CLOSED"},k=(t,s)=>{let e=t.avatarUrl;return!s&&(e!=null&&e.startsWith("/"))&&(e=`https://gitlab.com${e}`),{id:t.id.replace(ms,""),graphQLId:t.id,name:t.name,username:t.username,email:t.publicEmail??null,avatarUrl:e,url:t.webUrl}},rt=t=>({color:t.color,description:t.description,id:t.id.replace(Rs,""),graphQLId:t.id,name:t.title}),ws=(t,s)=>t?t==="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"}[t]:null,Xe=(t,s,e,r)=>{var a,o,i,u,l,p,d,c,g,m,f,I;let n=(a=t.reviewers)!=null&&a.nodes?t.reviewers.nodes.map(h=>{var P,S;return{reviewer:k(h,r),state:(P=h.mergeRequestInteraction)!=null&&P.approved?"APPROVED":((S=h.mergeRequestInteraction)==null?void 0:S.reviewState)==="REVIEWED"?"CHANGES_REQUESTED":"CHANGES_REQUESTED"}}):null;return{id:t.id.replace(hs,""),graphQLId:t.id,title:t.title,number:parseInt(t.iid,10),state:Ps[t.state],commentCount:t.userNotesCount||0,upvoteCount:t.upvotes,author:t.author?k(t.author,r):null,createdDate:new Date(t.createdAt),isDraft:t.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:((u=(i=(o=t.headPipeline)==null?void 0:o.stages)==null?void 0:i.nodes)==null?void 0:u.flatMap(h=>{var P,S;return((S=(P=h.jobs)==null?void 0:P.nodes)==null?void 0:S.map(D=>({completedAt:D.finishedAt?new Date(D.finishedAt):null,description:null,name:D.name??null,state:ws(D.status,D.allowFailure),stage:h.name??null,startedAt:new Date(D.createdAt),url:`${s.webUrl}/-/jobs/${D.id.replace(Is,"")}`})))??[]}))??[]},baseRef:{name:t.targetBranch,oid:((l=t.diffRefs)==null?void 0:l.baseSha)??null},headRef:{name:t.sourceBranch,oid:((p=t.diffRefs)==null?void 0:p.headSha)??null},url:t.webUrl,updatedDate:new Date(t.updatedAt),closedDate:t.mergedAt?new Date(t.mergedAt):null,mergedDate:t.mergedAt?new Date(t.mergedAt):null,assignees:(d=t.assignees)!=null&&d.nodes?t.assignees.nodes.map(h=>k(h,r)):null,reviews:n,reviewDecision:t.approved?"APPROVED":Q(n),additions:((c=t.diffStatsSummary)==null?void 0:c.additions)||0,deletions:((g=t.diffStatsSummary)==null?void 0:g.deletions)||0,fileCount:((m=t.diffStatsSummary)==null?void 0:m.fileCount)||0,commitCount:t.commitCount||0,mergeableState:gs[t.mergeStatusEnum],milestone:t.milestone?nt(t.milestone,s.webUrl):null,labels:((I=(f=t.labels)==null?void 0:f.nodes)==null?void 0:I.map(rt))??[],permissions:null}},Ye=(t,s,e)=>{var r,n;return{author:k(t.author,e),assignees:t.assignees.nodes.map(a=>k(a,e)),commentCount:t.userNotesCount,closedDate:t.closedAt?new Date(t.closedAt):null,createdDate:new Date(t.createdAt),description:t.description,graphQLId:t.id,id:t.id.replace(fs,""),labels:((n=(r=t.labels)==null?void 0:r.nodes)==null?void 0:n.map(rt))??[],number:t.iid,repository:{id:s.id.replace(F,""),graphQLId:s.id,name:s.name,owner:{login:s.namespace}},updatedDate:new Date(t.updatedAt),upvoteCount:t.upvotes,state:{name:t.state,color:null},type:t.type,title:t.title,url:t.webUrl,milestone:t.milestone?nt(t.milestone,s.webUrl):null}},nt=(t,s)=>({id:t.id.replace(qt,""),graphQLId:t.id,number:parseInt(t.iid,10),title:t.title,description:t.description,isOpen:t.state==="active",url:`${s}/-/${t.webPath.replace(/.+?\/-\//,"")}`,startDate:t.startDate?new Date(t.startDate):null,dueDate:t.dueDate?new Date(t.dueDate):null}),X=class extends L{getIsSelfHosted(s){return!!s.baseUrl||!!this.config.baseUrl}async getCurrentUser(s={},e={}){var a;let n=(a=(await y(this.config,{query:`
757
+ ${e?`headPipeline { ${Ss} }`:""}
758
+ `,B=r=>`${r.namespace}/${r.name}`,qs=r=>`${r.namespace}/${r.name}`,Ve=r=>{var s;return{id:r.id.replace(F,""),graphQLId:r.id,namespace:Ze(r.fullPath),name:et(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}},vs={opened:"OPEN",merged:"MERGED",closed:"CLOSED"},k=(r,s)=>{let e=r.avatarUrl;return!s&&(e!=null&&e.startsWith("/"))&&(e=`https://gitlab.com${e}`),{id:r.id.replace(Rs,""),graphQLId:r.id,name:r.name,username:r.username,email:r.publicEmail??null,avatarUrl:e,url:r.webUrl}},rt=r=>({color:r.color,description:r.description,id:r.id.replace(ys,""),graphQLId:r.id,name:r.title}),Es=(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,Xe=(r,s,e,t)=>{var o,a,i,u,l,p,d,c,g,m,f,b;let n=(o=r.reviewers)!=null&&o.nodes?r.reviewers.nodes.map(h=>{var w,q;return{reviewer:k(h,t),state:(w=h.mergeRequestInteraction)!=null&&w.approved?"APPROVED":((q=h.mergeRequestInteraction)==null?void 0:q.reviewState)==="REVIEWED"?"CHANGES_REQUESTED":"CHANGES_REQUESTED"}}):null;return{id:r.id.replace(Is,""),graphQLId:r.id,title:r.title,number:parseInt(r.iid,10),state:vs[r.state],commentCount:r.userNotesCount||0,upvoteCount:r.upvotes,author:r.author?k(r.author,t):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:((u=(i=(a=r.headPipeline)==null?void 0:a.stages)==null?void 0:i.nodes)==null?void 0:u.flatMap(h=>{var w,q;return((q=(w=h.jobs)==null?void 0:w.nodes)==null?void 0:q.map(E=>({completedAt:E.finishedAt?new Date(E.finishedAt):null,description:null,name:E.name??null,state:Es(E.status,E.allowFailure),stage:h.name??null,startedAt:new Date(E.createdAt),url:`${s.webUrl}/-/jobs/${E.id.replace(Ps,"")}`})))??[]}))??[]},baseRef:{name:r.targetBranch,oid:((l=r.diffRefs)==null?void 0:l.baseSha)??null},headRef:{name:r.sourceBranch,oid:((p=r.diffRefs)==null?void 0:p.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:(d=r.assignees)!=null&&d.nodes?r.assignees.nodes.map(h=>k(h,t)):null,reviews:n,reviewDecision:r.approved?"APPROVED":Q(n),additions:((c=r.diffStatsSummary)==null?void 0:c.additions)||0,deletions:((g=r.diffStatsSummary)==null?void 0:g.deletions)||0,fileCount:((m=r.diffStatsSummary)==null?void 0:m.fileCount)||0,commitCount:r.commitCount||0,mergeableState:fs[r.mergeStatusEnum],milestone:r.milestone?nt(r.milestone,s.webUrl):null,labels:((b=(f=r.labels)==null?void 0:f.nodes)==null?void 0:b.map(rt))??[],permissions:null}},Ye=(r,s,e)=>{var t,n;return{author:k(r.author,e),assignees:r.assignees.nodes.map(o=>k(o,e)),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(bs,""),labels:((n=(t=r.labels)==null?void 0:t.nodes)==null?void 0:n.map(rt))??[],number:r.iid,repository:{id:s.id.replace(F,""),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?nt(r.milestone,s.webUrl):null}},nt=(r,s)=>({id:r.id.replace(ws,""),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}),X=class extends ${getIsSelfHosted(s){return!!s.baseUrl||!!this.config.baseUrl}async getCurrentUser(s={},e={}){var o;let n=(o=(await y(this.config,{query:`
726
759
  query getCurrentUser {
727
760
  currentUser {
728
761
  ${x}
729
762
  }
730
763
  }
731
- `},e)).body.data)==null?void 0:a.currentUser;if(!n)throw new Error("Current user not found.");return{data:k(n,this.getIsSelfHosted(e))}}async getUserForCommit(s,e={}){var o,i,u,l;let r=B(s.repo),a=(l=(u=(i=(o=(await y(this.config,{query:`
764
+ `},e)).body.data)==null?void 0:o.currentUser;if(!n)throw new Error("Current user not found.");return{data:k(n,this.getIsSelfHosted(e))}}async getUserForCommit(s,e={}){var a,i,u,l;let t=B(s.repo),o=(l=(u=(i=(a=(await y(this.config,{query:`
732
765
  query getUserForCommit($fullPath: ID!, $oid: String!) {
733
766
  project(fullPath: $fullPath) {
734
767
  repository {
@@ -742,7 +775,7 @@ query getUserForCommit($fullPath: ID!, $oid: String!) {
742
775
  }
743
776
  }
744
777
  }
745
- `,variables:{fullPath:r,oid:s.oid}},e)).body.data)==null?void 0:o.project)==null?void 0:i.repository)==null?void 0:u.tree)==null?void 0:l.lastCommit;if(!a)throw new Error("Commit not found.");return{data:{name:a.authorName,email:a.authorEmail,avatarUrl:a.authorGravatar}}}async getAccountForEmail(s,e={}){var a,o,i;let n=(i=(o=(a=(await y(this.config,{query:`
778
+ `,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:`
746
779
  query getAccountForEmail($email: String!) {
747
780
  users(search: $email) {
748
781
  nodes {
@@ -750,13 +783,13 @@ query getAccountForEmail($email: String!) {
750
783
  }
751
784
  }
752
785
  }
753
- `,variables:{email:s.email}},e)).body.data)==null?void 0:a.users)==null?void 0:o.nodes)==null?void 0:i[0];if(!n)throw new Error("User not found.");return{data:k(n,this.getIsSelfHosted(e))}}async getAccountForUsername(s,e={}){var a;let n=(a=(await y(this.config,{query:`
786
+ `,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:k(n,this.getIsSelfHosted(e))}}async getAccountForUsername(s,e={}){var o;let n=(o=(await y(this.config,{query:`
754
787
  query getAccountForUsername($username: String!) {
755
788
  user(username: $username) {
756
789
  ${x}
757
790
  }
758
791
  }
759
- `,variables:{username:s.username}},e)).body.data)==null?void 0:a.user;if(!n)throw new Error("User not found.");return{data:k(n,this.getIsSelfHosted(e))}}async getAccountsForRepo(s,e={}){var u,l,p,d,c,g,m;let{repo:{namespace:r,name:n},cursor:a}=s,o=await y(this.config,{query:`
792
+ `,variables:{username:s.username}},e)).body.data)==null?void 0:o.user;if(!n)throw new Error("User not found.");return{data:k(n,this.getIsSelfHosted(e))}}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:`
760
793
  query getAccountsForRepo(
761
794
  $fullPath: ID!
762
795
  $after: String
@@ -777,22 +810,22 @@ query getAccountsForRepo(
777
810
  }
778
811
  }
779
812
  }
780
- `,variables:{fullPath:`${r}/${n}`,after:a}},e),i=(d=(p=(l=(u=o.body.data)==null?void 0:u.project)==null?void 0:l.projectMembers)==null?void 0:p.nodes)==null?void 0:d.map(f=>f.user).filter(f=>f!==null);return{pageInfo:((m=(g=(c=o.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(f=>k(f,this.getIsSelfHosted(e))))??[]}}async getRepo(s,e={}){var a;let r=B(s),n=await y(this.config,{query:`
813
+ `,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(f=>f.user).filter(f=>f!==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(f=>k(f,this.getIsSelfHosted(e))))??[]}}async getRepo(s,e={}){var o;let t=B(s),n=await y(this.config,{query:`
781
814
  query getRepo($fullPath: ID!) {
782
815
  project(fullPath: $fullPath) {
783
- ${He}
816
+ ${We}
784
817
  }
785
818
  }
786
- `,variables:{fullPath:r}},e);if(!((a=n.body.data)!=null&&a.project))throw new Error(`Repository ${r} not found`);return{data:Ve(n.body.data.project)}}async getRepos(s,e={}){let n=s.map(B).map((u,l)=>`
819
+ `,variables:{fullPath:t}},e);if(!((o=n.body.data)!=null&&o.project))throw new Error(`Repository ${t} not found`);return{data:Ve(n.body.data.project)}}async getRepos(s,e={}){let n=s.map(B).map((u,l)=>`
787
820
  getRepo_${l}: project(fullPath: "${u}") {
788
- ${He}
821
+ ${We}
789
822
  }
790
823
  `).join(`
791
- `),a=await y(this.config,{query:`
824
+ `),o=await y(this.config,{query:`
792
825
  query batchGetRepos {
793
826
  ${n}
794
827
  }
795
- `},e);if(!a.body.data)throw new Error(a.statusText||"Unknown error");let o=[],i=[];return s.forEach((u,l)=>{let p=a.body.data[`getRepo_${l}`];p?o.push(Ve(p)):i.push({input:u})}),{data:o,errors:i}}async getReposForCurrentUser(s={},e={}){var a,o,i,u,l,p;let r=await y(this.config,{query:`
828
+ `},e);if(!o.body.data)throw new Error(o.statusText||"Unknown error");let a=[],i=[];return s.forEach((u,l)=>{let p=o.body.data[`getRepo_${l}`];p?a.push(Ve(p)):i.push({input:u})}),{data:a,errors:i}}async getReposForCurrentUser(s,e={}){var o,a,i,u,l,p;let t=await y(this.config,{query:`
796
829
  query getReposForCurrentUser($after: String) {
797
830
  projects(membership: true first: 100 after: $after) {
798
831
  pageInfo {
@@ -800,14 +833,14 @@ query getReposForCurrentUser($after: String) {
800
833
  hasNextPage
801
834
  }
802
835
  nodes {
803
- ${He}
836
+ ${We}
804
837
  }
805
838
  }
806
839
  }
807
- `,variables:{after:s.cursor}},e);if(!((a=r.body.data)!=null&&a.projects))throw new Error(((o=r.body.errors)==null?void 0:o[0].message)||r.statusText||"Unknown error");let n=((u=(i=r.body.data)==null?void 0:i.projects)==null?void 0:u.nodes)||[];return{pageInfo:(p=(l=r.body.data)==null?void 0:l.projects)==null?void 0:p.pageInfo,data:n.map(Ve)}}async getRefs(s,e,r={}){var u;let n=B(e.repo),a=new URL(`${We(this.config,r)}/projects/${encodeURIComponent(n)}/repository/${s}`);a.searchParams.set("page",((u=e.page)==null?void 0:u.toString())||"1"),a.searchParams.set("per_page",q.toString());let o=await this.config.request({url:a.toString(),headers:R(r.token||this.config.token)}),i=o.headers["x-next-page"];return{pageInfo:{hasNextPage:!!i,nextPage:i?parseInt(i,10):null},data:o.body.map(l=>({name:l.name,commit:{oid:l.commit.id,authoredDate:new Date(l.commit.authored_date),committedDate:new Date(l.commit.committed_date)}}))}}async getBranches(s,e={}){return this.getRefs("branches",s,e)}async getTags(s,e={}){return this.getRefs("tags",s,e)}async getBlame(s,e={}){let r=B(s.repo),n=new URL(`${We(this.config,e)}/projects/${encodeURIComponent(r)}/repository/files/${encodeURIComponent(s.path)}/blame`);n.searchParams.set("ref",s.ref);let a=await this.config.request({url:n.toString(),headers:R(e.token||this.config.token)}),o=0;return{data:{ranges:a.body.map(i=>{let u=o+1;return o+=i.lines.length,{startingLine:u,endingLine:o,commit:{oid:i.commit.id,parentOids:i.commit.parent_ids,authoredDate:new Date(i.commit.authored_date),author:{name:i.commit.author_name,email:i.commit.author_email,avatarUrl:null},committedDate:new Date(i.commit.committed_date),committer:{name:i.commit.committer_name,email:i.commit.committer_email,avatarUrl:null},message:i.commit.message,fileCount:null,additions:null,deletions:null}}})}}}async getPullRequestsForUser(s,e={}){var o,i;let r=cs[s.association],n=await y(this.config,{query:`
840
+ `,variables:{after:s.cursor}},e);if(!((o=t.body.data)!=null&&o.projects))throw new Error(((a=t.body.errors)==null?void 0:a[0].message)||t.statusText||"Unknown error");let n=((u=(i=t.body.data)==null?void 0:i.projects)==null?void 0:u.nodes)||[];return{pageInfo:(p=(l=t.body.data)==null?void 0:l.projects)==null?void 0:p.pageInfo,data:n.map(Ve)}}async getRefs(s,e,t={}){var u;let n=B(e.repo),o=new URL(`${He(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",v.toString());let a=await this.config.request({url:o.toString(),headers:R(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=B(s.repo),n=new URL(`${He(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:R(e.token||this.config.token)}),a=0;return{data:{ranges:o.body.map(i=>{let u=a+1;return a+=i.lines.length,{startingLine:u,endingLine:a,commit:{oid:i.commit.id,parentOids:i.commit.parent_ids,authoredDate:new Date(i.commit.authored_date),author:{name:i.commit.author_name,email:i.commit.author_email,avatarUrl:null},committedDate:new Date(i.commit.committed_date),committer:{name:i.commit.committer_name,email:i.commit.committer_email,avatarUrl:null},message:i.commit.message,fileCount:null,additions:null,deletions:null}}})}}}async getPullRequestsForUser(s,e={}){var a,i;let t=hs[s.association],n=await y(this.config,{query:`
808
841
  query getPullRequestsForUser($username: String! $cursor: String) {
809
842
  user(username: $username) {
810
- ${r}(state:opened first:100 after:$cursor) {
843
+ ${t}(state:opened first:100 after:$cursor) {
811
844
  pageInfo {
812
845
  endCursor
813
846
  hasNextPage
@@ -818,7 +851,7 @@ query getPullRequestsForUser($username: String! $cursor: String) {
818
851
  }
819
852
  }
820
853
  }
821
- `,variables:{username:s.username,cursor:s.cursor}},e);if(!n.body.data)throw new Error(((o=n.body.errors)==null?void 0:o[0].message)||n.statusText||"Unknown error");if(!n.body.data.user)throw new Error("User not found");let a=n.body.data.user[r];if(!a)throw new Error("Unexpected response");return{pageInfo:a.pageInfo,data:((i=a.nodes)==null?void 0:i.map(u=>Xe(u,St(u.project),St(u.sourceProject),this.getIsSelfHosted(e))))||[]}}async getPullRequestsAssociatedWithUser(s,e={}){var c;let[r,n,a]=((c=s.cursor)==null?void 0:c.split(";"))||[void 0,void 0,void 0],[o,i,u]=await Promise.all([r==="null"?null:this.getPullRequestsForUser({username:s.username,association:"authored",cursor:r},e),n==="null"?null:this.getPullRequestsForUser({username:s.username,association:"assigned",cursor:n},e),a==="null"?null:this.getPullRequestsForUser({username:s.username,association:"reviewRequested",cursor:a},e)]),l={},p=[],d=g=>{l[g.id]||(l[g.id]=!0,p.push(g))};return o==null||o.data.forEach(d),i==null||i.data.forEach(d),u==null||u.data.forEach(d),{pageInfo:{hasNextPage:(o==null?void 0:o.pageInfo.hasNextPage)||(i==null?void 0:i.pageInfo.hasNextPage)||(u==null?void 0:u.pageInfo.hasNextPage)||!1,endCursor:`${(o==null?void 0:o.pageInfo.hasNextPage)&&(o==null?void 0:o.pageInfo.endCursor)||"null"};${(i==null?void 0:i.pageInfo.hasNextPage)&&(i==null?void 0:i.pageInfo.endCursor)||"null"};${(u==null?void 0:u.pageInfo.hasNextPage)&&(u==null?void 0:u.pageInfo.endCursor)||"null"}`},data:p}}getVariablesForPullRequests(s){let{updatedBefore:e,isDraft:r,authorLogin:n,assigneeLogins:a,reviewRequestedLogin:o}=s||{},i={},u=[],l=[],p=(d,c,g)=>{u.push(`$${d}: ${g}`),l.push(`${d}: $${d}`),i[d]=c};return e&&p("updatedBefore",e,"Time"),n&&p("authorUsername",n,"String"),a&&p("assigneeUsername",a[0],"String"),r!=null&&p("draft",r,"Boolean"),o&&p("reviewerUsername",o,"String"),{variables:i,variableTypes:u,mergeRequestArguments:l}}async getPullRequestsForRepo(s,e={}){var f,I,h;let{cursor:r,repo:n}=s||{},a=B(n),{variables:o,variableTypes:i,mergeRequestArguments:u}=this.getVariablesForPullRequests(s),l={fullPath:a,...o},p=await y(this.config,{query:`
854
+ `,variables:{username:s.username,cursor:s.cursor}},e);if(!n.body.data)throw new Error(((a=n.body.errors)==null?void 0:a[0].message)||n.statusText||"Unknown error");if(!n.body.data.user)throw new Error("User not found");let o=n.body.data.user[t];if(!o)throw new Error("Unexpected response");return{pageInfo:o.pageInfo,data:((i=o.nodes)==null?void 0:i.map(u=>Xe(u,Ct(u.project),Ct(u.sourceProject),this.getIsSelfHosted(e))))||[]}}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},e),n==="null"?null:this.getPullRequestsForUser({username:s.username,association:"assigned",cursor:n},e),o==="null"?null:this.getPullRequestsForUser({username:s.username,association:"reviewRequested",cursor:o},e)]),l={},p=[],d=g=>{l[g.id]||(l[g.id]=!0,p.push(g))};return a==null||a.data.forEach(d),i==null||i.data.forEach(d),u==null||u.data.forEach(d),{pageInfo:{hasNextPage:(a==null?void 0:a.pageInfo.hasNextPage)||(i==null?void 0:i.pageInfo.hasNextPage)||(u==null?void 0:u.pageInfo.hasNextPage)||!1,endCursor:`${(a==null?void 0:a.pageInfo.hasNextPage)&&(a==null?void 0:a.pageInfo.endCursor)||"null"};${(i==null?void 0:i.pageInfo.hasNextPage)&&(i==null?void 0:i.pageInfo.endCursor)||"null"};${(u==null?void 0:u.pageInfo.hasNextPage)&&(u==null?void 0:u.pageInfo.endCursor)||"null"}`},data:p}}getVariablesForPullRequests(s){let{updatedBefore:e,isDraft:t,authorLogin:n,assigneeLogins:o,reviewRequestedLogin:a}=s||{},i={},u=[],l=[],p=(d,c,g)=>{u.push(`$${d}: ${g}`),l.push(`${d}: $${d}`),i[d]=c};return e&&p("updatedBefore",e,"Time"),n&&p("authorUsername",n,"String"),o&&p("assigneeUsername",o[0],"String"),t!=null&&p("draft",t,"Boolean"),a&&p("reviewerUsername",a,"String"),{variables:i,variableTypes:u,mergeRequestArguments:l}}async getPullRequestsForRepo(s,e={}){var f,b,h;let{cursor:t,repo:n}=s||{},o=B(n),{variables:a,variableTypes:i,mergeRequestArguments:u}=this.getVariablesForPullRequests(s),l={fullPath:o,...a},p=await y(this.config,{query:`
822
855
  query getPullRequestsForRepo(
823
856
  $fullPath: ID!
824
857
  $after: String
@@ -847,11 +880,11 @@ query getPullRequestsForRepo(
847
880
  }
848
881
  }
849
882
  }
850
- `,variables:{...l,after:r}},e),d=[],c=(f=p.body.data)==null?void 0:f.project,g=V(c||{id:"",fullPath:"",webUrl:""});return(((I=c==null?void 0:c.mergeRequests)==null?void 0:I.nodes)||[]).forEach(P=>{d.push(Xe(P,g,null,this.getIsSelfHosted(e)))}),{pageInfo:(h=c==null?void 0:c.mergeRequests)==null?void 0:h.pageInfo,data:d}}async getPullRequestsForRepos(s,e={}){var c,g,m,f,I;let{cursor:r}=s||{},n=s.repoIds.map(h=>h.toString().startsWith(F)?h:`${F}${h}`),{variables:a,variableTypes:o,mergeRequestArguments:i}=this.getVariablesForPullRequests(s),u={projectIds:n,...a},l=await y(this.config,{query:`
883
+ `,variables:{...l,after:t}},e),d=[],c=(f=p.body.data)==null?void 0:f.project,g=V(c||{id:"",fullPath:"",webUrl:""});return(((b=c==null?void 0:c.mergeRequests)==null?void 0:b.nodes)||[]).forEach(w=>{d.push(Xe(w,g,null,this.getIsSelfHosted(e)))}),{pageInfo:(h=c==null?void 0:c.mergeRequests)==null?void 0:h.pageInfo,data:d}}async getPullRequestsForRepos(s,e={}){var c,g,m,f,b;let{cursor:t}=s||{},n=s.repoIds.map(h=>h.toString().startsWith(F)?h:`${F}${h}`),{variables:o,variableTypes:a,mergeRequestArguments:i}=this.getVariablesForPullRequests(s),u={projectIds:n,...o},l=await y(this.config,{query:`
851
884
  query getPullRequests(
852
885
  $projectIds: [ID!]
853
886
  $after: String
854
- ${o.length?o.join(" "):""}
887
+ ${a.length?a.join(" "):""}
855
888
  ) {
856
889
  projects(
857
890
  ids: $projectIds
@@ -878,14 +911,14 @@ query getPullRequests(
878
911
  }
879
912
  }
880
913
  }
881
- `,variables:{...u,after:r}},e),p=[];return(((g=(c=l.body.data)==null?void 0:c.projects)==null?void 0:g.nodes)||[]).forEach(h=>{var D;let P=V(h);(((D=h.mergeRequests)==null?void 0:D.nodes)||[]).forEach(se=>{p.push(Xe(se,P,null,this.getIsSelfHosted(e)))})}),{pageInfo:(I=(f=(m=l.body)==null?void 0:m.data)==null?void 0:f.projects)==null?void 0:I.pageInfo,data:p}}async closePullRequest(s,e={}){var l,p,d;let{repo:{namespace:r,name:n},pullRequestId:a}=s,o=`mutation ClosePullRequest($fullPath: ID!, $pullRequestId: String!) {
882
- mergeRequestUpdate(input: { projectPath: $fullPath, iid: $pullRequestId, state: CLOSED }) {
914
+ `,variables:{...u,after:t}},e),p=[];return(((g=(c=l.body.data)==null?void 0:c.projects)==null?void 0:g.nodes)||[]).forEach(h=>{var E;let w=V(h);(((E=h.mergeRequests)==null?void 0:E.nodes)||[]).forEach(se=>{p.push(Xe(se,w,null,this.getIsSelfHosted(e)))})}),{pageInfo:(b=(f=(m=l.body)==null?void 0:m.data)==null?void 0:f.projects)==null?void 0:b.pageInfo,data:p}}async closePullRequest(s,e={}){var i,u,l;let{pullRequest:t}=s,n=`mutation ClosePullRequest($fullPath: ID!, $pullRequestId: String!) {
915
+ mergeRequestUpdate(input: { projectPath: $fullPath, iid: $pullRequestId, state: CLOSED }) {
883
916
  errors,
884
- mergeRequest {
917
+ mergeRequest {
885
918
  id
886
919
  }
887
- }
888
- }`,u=(l=(await y(this.config,{query:o,variables:{fullPath:`${r}/${n}`,pullRequestId:a}},e)).body.data)==null?void 0:l.mergeRequestUpdate;if(!((p=u==null?void 0:u.mergeRequest)!=null&&p.id)||((d=u==null?void 0:u.errors)==null?void 0:d.length)!==0)throw new Error("Could not close pull request")}async mergePullRequest(s,e={}){var d,c,g;let{repo:{namespace:r,name:n},pullRequestId:a,expectedSourceSha:o,mergeStrategy:i}=s,u=`mutation MergePullRequest(
920
+ }
921
+ }`,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(
889
922
  $fullPath: ID!,
890
923
  $pullRequestId: String!,
891
924
  $expectedSourceSha: String!,
@@ -902,41 +935,48 @@ query getPullRequests(
902
935
  id
903
936
  }
904
937
  }
905
- }`,p=(d=(await y(this.config,{query:u,variables:{fullPath:`${r}/${n}`,pullRequestId:a,expectedSourceSha:o,squash:i==="SQUASH"}},e)).body.data)==null?void 0:d.mergeRequestAccept;if(!((c=p==null?void 0:p.mergeRequest)!=null&&c.id)||((g=p==null?void 0:p.errors)==null?void 0:g.length)!==0)throw new Error("Could not merge pull request")}async setPullRequestMilestone(s,e={}){var p,d,c;let{repo:{namespace:r,name:n},pullRequestId:a,milestoneGraphQLId:o}=s,i=`mutation SetPullRequestMilestone($fullPath: ID!, $pullRequestId: String!, $milestoneGraphQLId: MilestoneID) {
938
+ }`,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) {
906
939
  mergeRequestSetMilestone(input: { projectPath: $fullPath, iid: $pullRequestId, milestoneId: $milestoneGraphQLId }) {
907
940
  errors,
908
941
  mergeRequest {
909
942
  id
910
943
  }
911
944
  }
912
- }`,u=await y(this.config,{query:i,variables:{fullPath:`${r}/${n}`,pullRequestId:a,milestoneGraphQLId:o}},e),l=(p=u.body.data)==null?void 0:p.mergeRequestSetMilestone;if(!((d=l==null?void 0:l.mergeRequest)!=null&&d.id)||u.body.errors||((c=l==null?void 0:l.errors)==null?void 0:c.length)!==0)throw new Error("Could not set milestone of pull request")}async setPullRequestAsDraft(s,e={}){var p,d,c;let{repo:{namespace:r,name:n},pullRequestId:a,isDraft:o}=s,i=`mutation MergeRequestSetDraft($fullPath: ID!, $pullRequestId: String!, $isDraft: Boolean!) {
945
+ }`,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!) {
913
946
  mergeRequestSetDraft(input: { projectPath: $fullPath, iid: $pullRequestId, draft: $isDraft }) {
914
947
  errors,
915
948
  mergeRequest {
916
949
  id
917
950
  }
918
951
  }
919
- }`,l=(p=(await y(this.config,{query:i,variables:{fullPath:`${r}/${n}`,pullRequestId:a,isDraft:o}},e)).body.data)==null?void 0:p.mergeRequestSetDraft;if(!((d=l==null?void 0:l.mergeRequest)!=null&&d.id)||((c=l==null?void 0:l.errors)==null?void 0:c.length)!==0)throw new Error("Could not set pull request as draft")}async setPullRequestReviewers(s,e={}){var p,d,c;let{repo:{namespace:r,name:n},pullRequestId:a,reviewerUsernames:o}=s,i=`mutation MergeRequestSetReviewers($fullPath: ID!, $pullRequestId: String!, $reviewerUsernames: [String!]!) {
952
+ }`,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!]!) {
920
953
  mergeRequestSetReviewers(input: { projectPath: $fullPath, iid: $pullRequestId, reviewerUsernames: $reviewerUsernames }) {
921
954
  errors,
922
955
  mergeRequest {
923
956
  id
924
957
  }
925
958
  }
926
- }`,l=(p=(await y(this.config,{query:i,variables:{fullPath:`${r}/${n}`,pullRequestId:a,reviewerUsernames:o}},e)).body.data)==null?void 0:p.mergeRequestSetReviewers;if(!((d=l==null?void 0:l.mergeRequest)!=null&&d.id)||((c=l==null?void 0:l.errors)==null?void 0:c.length)!==0)throw new Error("Could not set pull request reviewers")}async setPullRequestAssignees(s,e={}){var p,d,c;let{repo:{namespace:r,name:n},pullRequestId:a,assigneeUsernames:o}=s,i=`mutation MergeRequestSetAssignees($fullPath: ID!, $pullRequestId: String!, $assigneeUsernames: [String!]!) {
959
+ }`,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!) {
960
+ mergeRequestReviewerRereview(input: { projectPath: $fullPath, iid: $pullRequestId, userId: $reviewerUserId }) {
961
+ errors,
962
+ mergeRequest {
963
+ id
964
+ }
965
+ }
966
+ }`,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!]!) {
927
967
  mergeRequestSetAssignees(input: { projectPath: $fullPath, iid: $pullRequestId, assigneeUsernames: $assigneeUsernames }) {
928
968
  errors,
929
969
  mergeRequest {
930
970
  id
931
971
  }
932
972
  }
933
- }`,l=(p=(await y(this.config,{query:i,variables:{fullPath:`${r}/${n}`,pullRequestId:a,assigneeUsernames:o}},e)).body.data)==null?void 0:p.mergeRequestSetAssignees;if(!((d=l==null?void 0:l.mergeRequest)!=null&&d.id)||((c=l==null?void 0:l.errors)==null?void 0:c.length)!==0)throw new Error("Could not set pull request assignees")}async setPullRequestLabels(s,e={}){var l,p,d;let{repo:{namespace:r,name:n},pullRequestId:a,labelGraphQLIds:o}=s,i=`mutation SetPullRequestLabels($fullPath: ID!, $pullRequestId: String!, $labelGraphQLIds: [LabelID!]!) {
973
+ }`,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!]!) {
934
974
  mergeRequestSetLabels(input: { projectPath: $fullPath, iid: $pullRequestId, labelIds: $labelGraphQLIds }) {
935
975
  mergeRequest {
936
976
  id
937
977
  }
938
978
  }
939
- }`;if(!((d=(p=(l=(await y(this.config,{query:i,variables:{fullPath:`${r}/${n}`,pullRequestId:a,labelGraphQLIds:o}},e)).body.data)==null?void 0:l.mergeRequestSetLabels)==null?void 0:p.mergeRequest)!=null&&d.id))throw new Error("Could not set pull request labels")}async getIssue(s,e={}){var a,o,i;let r=ys(s),n=await y(this.config,{query:`
979
+ }`;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=qs(s),n=await y(this.config,{query:`
940
980
  query GetSingleIssue($projectId: ID!, $issueNumber: String!) {
941
981
  project(fullPath: $projectId) {
942
982
  id
@@ -947,7 +987,7 @@ query GetSingleIssue($projectId: ID!, $issueNumber: String!) {
947
987
  }
948
988
  }
949
989
  }
950
- `,variables:{issueNumber:s.number,projectId:r}},e);if(!((a=n.body.data)!=null&&a.project))throw new Error(`Repository ${r} not found`);if(!((i=(o=n.body.data)==null?void 0:o.project)!=null&&i.issue))throw new Error(`Issue ${s.number} not found`);return{data:Ye(n.body.data.project.issue,V(n.body.data.project),this.getIsSelfHosted(e))}}getVariablesForIssues(s){let{updatedBefore:e,authorLogin:r,assigneeLogins:n}=s||{},a={},o=[],i=[],u=(l,p,d)=>{o.push(`$${l}: ${d}`),i.push(`${l}: $${l}`),a[l]=p};return e&&u("updatedBefore",e,"Time"),r&&u("authorUsername",r,"String"),n&&u("assigneeUsername",n[0],"String"),{variables:a,variableTypes:o,issueArguments:i}}async getIssuesForRepo(s,e={}){var I,h,P;let{cursor:r,repo:n}=s||{},a=B(n),{variables:o,variableTypes:i,issueArguments:u}=this.getVariablesForIssues(s),l={fullPath:a,...o},p=`
990
+ `,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:Ye(n.body.data.project.issue,V(n.body.data.project),this.getIsSelfHosted(e))}}getVariablesForIssues(s){let{updatedBefore:e,authorLogin:t,assigneeLogins:n}=s||{},o={},a=[],i=[],u=(l,p,d)=>{a.push(`$${l}: ${d}`),i.push(`${l}: $${l}`),o[l]=p};return e&&u("updatedBefore",e,"Time"),t&&u("authorUsername",t,"String"),n&&u("assigneeUsername",n[0],"String"),{variables:o,variableTypes:a,issueArguments:i}}async getIssuesForRepo(s,e={}){var b,h,w;let{cursor:t,repo:n}=s||{},o=B(n),{variables:a,variableTypes:i,issueArguments:u}=this.getVariablesForIssues(s),l={fullPath:o,...a},p=`
951
991
  query GetIssuesFromProject(
952
992
  $fullPath: ID!
953
993
  $after: String
@@ -975,11 +1015,11 @@ query GetSingleIssue($projectId: ID!, $issueNumber: String!) {
975
1015
  }
976
1016
  }
977
1017
  }
978
- }`,d=await y(this.config,{query:p,variables:{...l,after:r}},e),c=[],g=(I=d.body.data)==null?void 0:I.project,m=V(g||{id:"",fullPath:"",webUrl:""});return(((h=g==null?void 0:g.issues)==null?void 0:h.nodes)||[]).forEach(S=>{c.push(Ye(S,m,this.getIsSelfHosted(e)))}),{pageInfo:(P=g==null?void 0:g.issues)==null?void 0:P.pageInfo,data:c.sort((S,D)=>(S.updatedDate||S.createdDate).getTime()-(D.updatedDate||D.createdDate).getTime())}}async getIssuesForRepos(s,e={}){var g,m,f,I,h;let{cursor:r}=s||{},n=s.repoIds.map(P=>P.toString().startsWith(F)?P:`${F}${P}`),{variables:a,variableTypes:o,mergeRequestArguments:i}=this.getVariablesForPullRequests(s),u={projectIds:n,...a},l=`
1018
+ }`,d=await y(this.config,{query:p,variables:{...l,after:t}},e),c=[],g=(b=d.body.data)==null?void 0:b.project,m=V(g||{id:"",fullPath:"",webUrl:""});return(((h=g==null?void 0:g.issues)==null?void 0:h.nodes)||[]).forEach(q=>{c.push(Ye(q,m,this.getIsSelfHosted(e)))}),{pageInfo:((w=g==null?void 0:g.issues)==null?void 0:w.pageInfo)??{endCursor:null,hasNextPage:!1},data:c.sort((q,E)=>(q.updatedDate||q.createdDate).getTime()-(E.updatedDate||E.createdDate).getTime())}}async getIssuesForRepos(s,e={}){var g,m,f,b,h;let{cursor:t}=s||{},n=s.repoIds.map(w=>w.toString().startsWith(F)?w:`${F}${w}`),{variables:o,variableTypes:a,mergeRequestArguments:i}=this.getVariablesForPullRequests(s),u={projectIds:n,...o},l=`
979
1019
  query GetIssuesFromProject(
980
1020
  $projectIds: [ID!]
981
1021
  $after: String
982
- ${o.length?o.join(" "):""}
1022
+ ${a.length?a.join(" "):""}
983
1023
  ) {
984
1024
  projects(
985
1025
  ids: $projectIds
@@ -1005,20 +1045,20 @@ query GetSingleIssue($projectId: ID!, $issueNumber: String!) {
1005
1045
  }
1006
1046
  }
1007
1047
  }
1008
- }`,p=await y(this.config,{query:l,variables:{...u,after:r}},e),d=[];return(((m=(g=p.body.data)==null?void 0:g.projects)==null?void 0:m.nodes)||[]).forEach(P=>{var se;let S=V(P);(((se=P.issues)==null?void 0:se.nodes)||[]).forEach(Dt=>d.push(Ye(Dt,S,this.getIsSelfHosted(e))))}),{pageInfo:(h=(I=(f=p.body)==null?void 0:f.data)==null?void 0:I.projects)==null?void 0:h.pageInfo,data:d.sort((P,S)=>(P.updatedDate||P.createdDate).getTime()-(S.updatedDate||S.createdDate).getTime())}}async setIssueStatus(s,e={}){var l,p,d;let{repo:{namespace:r,name:n},issueId:a,status:o}=s,i=`mutation SetIssueState($fullPath: ID!, $issueId: String!, $status: IssueStateEvent!) {
1048
+ }`,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(w=>{var se;let q=V(w);(((se=w.issues)==null?void 0:se.nodes)||[]).forEach(Dt=>d.push(Ye(Dt,q,this.getIsSelfHosted(e))))}),{pageInfo:((h=(b=(f=p.body)==null?void 0:f.data)==null?void 0:b.projects)==null?void 0:h.pageInfo)??{endCursor:null,hasNextPage:!1},data:d.sort((w,q)=>(w.updatedDate||w.createdDate).getTime()-(q.updatedDate||q.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!) {
1009
1049
  updateIssue(input: { projectPath: $fullPath, iid: $issueId, stateEvent: $status }) {
1010
1050
  issue {
1011
1051
  id
1012
1052
  }
1013
1053
  }
1014
- }`;if(!((d=(p=(l=(await y(this.config,{query:i,variables:{fullPath:`${r}/${n}`,issueId:a,status:o}},e)).body.data)==null?void 0:l.updateIssue)==null?void 0:p.issue)!=null&&d.id))throw new Error("Could not set issue status")}async setIssueLabels(s,e={}){var l,p,d;let{repo:{namespace:r,name:n},issueId:a,labelGraphQLIds:o}=s,i=`mutation SetIssueLabels($fullPath: ID!, $issueId: String!, $labelGraphQLIds: [ID!]) {
1054
+ }`;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!]) {
1015
1055
  updateIssue(input: { projectPath: $fullPath, iid: $issueId, labelIds: $labelGraphQLIds }) {
1016
1056
  issue {
1017
1057
  id
1018
1058
  }
1019
1059
  }
1020
- }`;if(!((d=(p=(l=(await y(this.config,{query:i,variables:{fullPath:`${r}/${n}`,issueId:a,labelGraphQLIds:o}},e)).body.data)==null?void 0:l.updateIssue)==null?void 0:p.issue)!=null&&d.id))throw new Error("Could not set issue labels")}async setIssueMilestone(s,e={}){var p,d,c,g;let{repo:{namespace:r,name:n},issueId:a}=s,o=((p=s.milestoneGraphQLId)==null?void 0:p.replace(qt,""))??"",i=`mutation SetIssueMilestone($fullPath: ID!, $issueId: String!, $milestoneGraphQLId: ID) {
1021
- updateIssue(input: { projectPath: $fullPath, iid: $issueId, milestoneId: $milestoneGraphQLId }) {
1060
+ }`;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) {
1061
+ updateIssue(input: { projectPath: $fullPath, iid: $issueId, milestoneId: $milestoneId }) {
1022
1062
  errors
1023
1063
  issue {
1024
1064
  id
@@ -1027,14 +1067,14 @@ query GetSingleIssue($projectId: ID!, $issueNumber: String!) {
1027
1067
  }
1028
1068
  }
1029
1069
  }
1030
- }`,u=await y(this.config,{query:i,variables:{fullPath:`${r}/${n}`,issueId:a,milestoneGraphQLId:o}},e),l=(d=u.body.data)==null?void 0:d.updateIssue;if(!((c=l==null?void 0:l.issue)!=null&&c.id)||u.body.errors||((g=l==null?void 0:l.errors)==null?void 0:g.length)!==0)throw new Error("Could not set milestone of issue")}async setIssueAssignees(s,e={}){var p,d,c;let{repo:{namespace:r,name:n},issueId:a,assigneeUsernames:o}=s,i=`mutation SetIssueAssignees($fullPath: ID!, $issueId: String!, $assigneeUsernames: [String!]!) {
1070
+ }`,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!]!) {
1031
1071
  issueSetAssignees(input: { projectPath: $fullPath, iid: $issueId, assigneeUsernames: $assigneeUsernames }) {
1032
1072
  errors,
1033
1073
  issue {
1034
1074
  id
1035
1075
  }
1036
1076
  }
1037
- }`,l=(p=(await y(this.config,{query:i,variables:{fullPath:`${r}/${n}`,issueId:a,assigneeUsernames:o}},e)).body.data)==null?void 0:p.issueSetAssignees;if(!((d=l==null?void 0:l.issue)!=null&&d.id)||((c=l==null?void 0:l.errors)==null?void 0:c.length)!==0)throw new Error("Could not set issue assignees")}async getMilestonesForRepo(s,e={}){var i,u,l,p,d,c,g;let{repo:{namespace:r,name:n},cursor:a}=s,o=await y(this.config,{query:`
1077
+ }`,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:`
1038
1078
  query getLabelsForRepo(
1039
1079
  $fullPath: ID!
1040
1080
  $after: String
@@ -1054,7 +1094,7 @@ query getLabelsForRepo(
1054
1094
  }
1055
1095
  }
1056
1096
  }
1057
- `,variables:{fullPath:`${r}/${n}`,after:a}},e);return{pageInfo:((l=(u=(i=o.body.data)==null?void 0:i.project)==null?void 0:u.milestones)==null?void 0:l.pageInfo)??{endCursor:null,hasNextPage:!1},data:((g=(c=(d=(p=o.body.data)==null?void 0:p.project)==null?void 0:d.milestones)==null?void 0:c.nodes)==null?void 0:g.map(m=>{var f,I;return nt(m,((I=(f=o.body.data)==null?void 0:f.project)==null?void 0:I.webUrl)||"")}))??[]}}async getLabelsForRepo(s,e={}){var i,u,l,p,d,c,g;let{repo:{namespace:r,name:n},cursor:a}=s,o=await y(this.config,{query:`
1097
+ `,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 f,b;return nt(m,((b=(f=a.body.data)==null?void 0:f.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:`
1058
1098
  query getLabelsForRepo(
1059
1099
  $fullPath: ID!
1060
1100
  $after: String
@@ -1073,5 +1113,5 @@ query getLabelsForRepo(
1073
1113
  }
1074
1114
  }
1075
1115
  }
1076
- `,variables:{fullPath:`${r}/${n}`,after:a}},e);return{pageInfo:((l=(u=(i=o.body.data)==null?void 0:i.project)==null?void 0:u.labels)==null?void 0:l.pageInfo)??{endCursor:null,hasNextPage:!1},data:((g=(c=(d=(p=o.body.data)==null?void 0:p.project)==null?void 0:d.labels)==null?void 0:c.nodes)==null?void 0:g.map(rt))??[]}}};var Es="https://api.atlassian.com/ex/jira",me=100,at=(t,s,e)=>{var n,a,o,i;let r=t.fields.assignee;return{id:t.id,commentCount:t.fields.comment.comments.length,number:t.key,title:t.fields.summary,url:s?`${s}/browse/${t.key}`:null,closedDate:null,createdDate:new Date(t.fields.created),author:he(t.fields.creator,s,e),updatedDate:new Date(t.fields.updated),assignees:r?[he(r,s,e)]:[],description:null,repository:null,state:Cs(t.fields.status),statusTransitions:((n=t.transitions)==null?void 0:n.map(Ss))??[],components:((a=t.fields.components)==null?void 0:a.map(qs))??[],type:t.fields.issuetype.name,upvoteCount:((o=t.fields.votes)==null?void 0:o.votes)||0,labels:((i=t.fields.labels)==null?void 0:i.map(u=>({color:null,description:null,id:null,name:u})))??[]}},Ss=t=>{let s;switch(t.to.statusCategory.name){case"To Do":s="TO_DO";break;case"In Progress":s="IN_PROGRESS";break;default:s="DONE";break}return{name:t.name,id:t.id,to:{id:t.to.id,name:t.to.name,color:t.to.statusCategory.colorName,category:s}}},qs=t=>({description:t.description??null,id:t.id,name:t.name}),Ds=(t,s,e)=>e&&t.name?`${s}/secure/ViewProfile.jspa?name=${encodeURIComponent(t.name)}`:`${s}/jira/people/${t.accountId}`,he=(t,s,e)=>({id:(e?t.key:t.accountId)??"",name:t.displayName,email:t.emailAddress,avatarUrl:t.avatarUrls["48x48"],username:t.displayName,url:Ds(t,s,e)}),Cs=t=>{let s;switch(t.statusCategory.name){case"To Do":s="TO_DO";break;case"In Progress":s="IN_PROGRESS";break;default:s="DONE";break}return{id:t.id,name:t.name,color:t.statusCategory.colorName,category:s}},j=(t,s,e)=>e?`${s.baseUrl||Es}/${e}`:`${(s==null?void 0:s.baseUrl)||t.baseUrl}`,fe=async(t,s,e,r={})=>{let{number:n,resourceId:a}=s||{},o=await t.request({url:`${j(t,r,a)}/rest/api/2/issue/${n}?fields=${["assignee","comment","summary","created","creator","updated","votes","issuetype","status","labels","components"].join(",")}&expand=transitions`,headers:R(r.token||t.token)});return{data:at(o.body,e,!a)}},Re=async(t,s,e,r={})=>{let{page:n,resourceId:a}=s||{},o=n??0,i=`statusCategory != Done AND (creator = currentUser() OR assignee = currentUser()
1077
- OR comment ~ currentUser() OR summary ~ currentUser() OR description ~ currentUser())`,l=(await t.request({url:`${j(t,r,a)}/rest/api/2/search?jql=${i}&startAt=${o}&maxResults=${me}&fields=${["assignee","comment","summary","created","creator","updated","votes","issuetype","status","labels","components"].join(",")}&expand=transitions`,headers:R(r.token||t.token)})).body.issues.map(d=>at(d,e,!a)),p=l.length==me;return{data:l,pageInfo:{hasNextPage:p,nextPage:p?o+l.length:null}}},Ie=async(t,s,e,r={})=>{let{assigneeLogins:n,authorLogin:a,mentionLogin:o,page:i,project:u,resourceId:l}=s||{},p=i??0,d=[`project = "${u}"`,"statusCategory != Done"];a&&d.push(`creator in ("${a}")`),n&&n.length!==0&&d.push(`assignee in ("${n.join('", "')}")`),o&&d.push(`comment ~ "${o}"`);let g=(await t.request({url:`${j(t,r,l)}/rest/api/2/search?jql=${d.join(" AND ")}&startAt=${p}&maxResults=${me}&fields=${["assignee","comment","summary","created","creator","updated","votes","issuetype","status","labels","components"].join(",")}&expand=transitions`,headers:R(r.token||t.token)})).body.issues.map(f=>at(f,e,!l)),m=g.length==me;return{data:g,pageInfo:{hasNextPage:m,nextPage:m?p+g.length:null}}},be=async(t,s,e={})=>{let{resourceId:r,issueId:n,labelNames:a}=s,o={fields:{labels:a}};await t.request({method:"PUT",url:`${j(t,e,r)}/rest/api/2/issue/${n}`,body:JSON.stringify(o),headers:{...R(e.token||t.token),"Content-Type":"application/json"}})},ye=async(t,s,e={})=>{let{resourceId:r,issueId:n,componentIds:a}=s,o={fields:{components:a.map(i=>({id:i}))}};await t.request({method:"PUT",url:`${j(t,e,r)}/rest/api/2/issue/${n}`,body:JSON.stringify(o),headers:{...R(e.token||t.token),"Content-Type":"application/json"}})},Pe=async(t,s,e={})=>{let{resourceId:r,issueId:n,status:a}=s,o={transition:{id:a}};await t.request({method:"POST",url:`${j(t,e,r)}/rest/api/2/issue/${n}/transitions`,body:JSON.stringify(o),headers:{...R(e.token||t.token),"Content-Type":"application/json"}})},we=async(t,s,e={})=>{let{resourceId:r,projectIdOrKey:n}=s,a=new URL(`${j(t,e,r)}/rest/api/2/project/${n}/components`);return{data:(await t.request({url:a.toString(),headers:R(e.token||t.token)})).body}};var Y="https://api.atlassian.com/ex/jira",ot=100,Z=class extends U{constructor(){super(...arguments);this._resourceUrlCache={}}async getResourceUrl(e,r={}){var o;let n=r.token||this.config.token;if(!n)return null;let a=this._resourceUrlCache[n];return a?a[e.resourceId]??null:(await this.getJiraResourcesForCurrentUser(r),((o=this._resourceUrlCache[n])==null?void 0:o[e.resourceId])??null)}async getCurrentUserForResource(e,r={}){let n=await this.getResourceUrl({resourceId:e.resourceId},r),a=await this.config.request({url:`${r.baseUrl||Y}/${e.resourceId}/rest/api/2/myself`,headers:R(r.token||this.config.token)});return{data:{name:a.body.displayName,email:a.body.emailAddress,avatarUrl:a.body.avatarUrls["48x48"],id:a.body.accountId,username:a.body.displayName,url:n?`${n}/jira/people/${a.body.accountId}`:null}}}async getJiraResourcesForCurrentUser(e={}){let r=await this.config.request({url:`${e.baseUrl||"https://api.atlassian.com/"}/oauth/token/accessible-resources`,headers:R(e.token||this.config.token)}),n=e.token||this.config.token,a=n?this._resourceUrlCache[n]||{}:void 0,o=r.body.map(i=>(a&&(a[i.id]=i.url),{avatarUrl:i.avatarUrl,id:i.id,name:i.name,url:i.url}));return n&&(this._resourceUrlCache[n]=a),{data:o}}async getJiraProjectsForResource(e,r={}){let n=new URL(`${r.baseUrl||Y}/${e.resourceId}/rest/api/2/project/search`);n.searchParams.set("maxResults",ot.toString()),e.cursor&&n.searchParams.set("startAt",e.cursor);let a=await this.config.request({url:n.toString(),headers:R(r.token||this.config.token)});return{pageInfo:{hasNextPage:a.body.values.length!==0,endCursor:(a.body.startAt+a.body.values.length).toString()},data:a.body.values.map(o=>({id:o.id,key:o.key,name:o.name,resourceId:e.resourceId}))}}async getJiraProjectsForResources(e,r={}){let n=[];return await Promise.all(e.resourceIds.map(async a=>{let o=await this.getJiraProjectsForResource({resourceId:a},r);n.push(...o.data)})),{data:n}}async getAccountsForJiraProject(e,r={}){let{resourceId:n,projectKey:a,cursor:o}=e,i=await this.getResourceUrl({resourceId:n},r),u=new URL(`${r.baseUrl||Y}/${n}/rest/api/2/user/assignable/search`);u.searchParams.set("maxResults",ot.toString()),o&&u.searchParams.set("startAt",o),u.searchParams.set("project",a);let l=await this.config.request({url:u.toString(),headers:R(r.token||this.config.token)});return{pageInfo:{hasNextPage:l.body.length!==0,endCursor:((o?parseInt(o):0)+l.body.length).toString()},data:l.body.filter(p=>p.accountType!=="app"&&p.active).map(p=>he(p,i,!1))}}async getComponentsForJiraProject(e,r={}){return await we(this.config,e,r)}async getIssue(e,r={}){let n=await this.getResourceUrl({resourceId:e.resourceId},r);return await fe(this.config,e,n,r)}async getIssuesForProject(e,r={}){let n=await this.getResourceUrl({resourceId:e.resourceId},r);return await Ie(this.config,e,n,r)}async getIssuesForResourceForCurrentUser(e,r={}){let n=await this.getResourceUrl({resourceId:e.resourceId},r);return await Re(this.config,e,n,r)}async setIssueStatus(e,r={}){await Pe(this.config,e,r)}async setIssueAssignee(e,r={}){let{resourceId:n,issueId:a,assigneeId:o}=e,i={accountId:o};await this.config.request({method:"PUT",url:`${r.baseUrl||Y}/${n}/rest/api/2/issue/${a}/assignee`,body:JSON.stringify(i),headers:{...R(r.token||this.config.token),"Content-Type":"application/json"}})}async setIssueComponents(e,r={}){await ye(this.config,e,r)}async setIssueLabels(e,r={}){await be(this.config,e,r)}async getLabelsForResource(e,r={}){let{resourceId:n,cursor:a}=e,o=new URL(`${r.baseUrl||Y}/${n}/rest/api/2/label`);o.searchParams.set("maxResults",ot.toString()),a&&o.searchParams.set("startAt",a);let i=await this.config.request({url:o.toString(),headers:R(r.token||this.config.token)});return{pageInfo:{hasNextPage:!i.body.isLast,endCursor:(i.body.startAt+i.body.values.length).toString()},data:i.body.values.map(u=>({color:null,description:null,id:null,name:u}))}}};var ee=class extends L{async getCurrentUser(s={}){let e=await this.config.request({url:`${(s==null?void 0:s.baseUrl)||this.config.baseUrl}/rest/api/2/myself`,headers:R((s==null?void 0:s.token)||this.config.token)});return{data:{name:e.body.displayName,email:e.body.emailAddress,avatarUrl:e.body.avatarUrls["48x48"],id:e.body.key,username:e.body.displayName,url:null}}}async getJiraProjects(s={}){return{data:(await this.config.request({url:`${(s==null?void 0:s.baseUrl)||this.config.baseUrl}/rest/api/2/project`,headers:R((s==null?void 0:s.token)||this.config.token)})).body.map(r=>({id:r.id,name:r.name}))}}async getIssue(s,e={}){if(!e.baseUrl)throw new Error('Jira Server requires a "baseUrl" for this function.');return await fe(this.config,s,e.baseUrl,e)}async getIssuesForProject(s,e={}){if(!e.baseUrl)throw new Error('Jira Server requires a "baseUrl" for this function.');return await Ie(this.config,s,e.baseUrl,e)}async getIssuesForResourceForCurrentUser(s,e={}){if(!e.baseUrl)throw new Error('Jira Server requires a "baseUrl" for this function.');return await Re(this.config,s,e.baseUrl,e)}async setIssueStatus(s,e={}){await Pe(this.config,s,e)}async setIssueLabels(s,e={}){await be(this.config,s,e)}async setIssueComponents(s,e={}){await ye(this.config,s,e)}async getLabels(s={}){return{data:(await this.config.request({url:`${(s==null?void 0:s.baseUrl)||this.config.baseUrl}/rest/api/2/jql/autocompletedata/suggestions?fieldName=labels`,headers:R(s.token||this.config.token)})).body.results.map(({displayName:r})=>({color:null,description:null,id:null,name:r}))}}async getComponentsForJiraProject(s,e={}){return await we(this.config,s,e)}};var _="https://api.trello.com",Us=1e3,vs=(t,s)=>{let e=new Date(1e3*parseInt(t.id.substring(0,8),16));return{id:t.id,commentCount:t.badges.comments,number:t.idShort.toString(),title:t.name,url:t.url,closedDate:null,createdDate:new Date(e.toISOString()),author:null,updatedDate:new Date(t.dateLastActivity),assignees:t.idMembers.map(r=>({id:r,username:null,name:null,email:null,avatarUrl:null,url:null})),description:null,state:s[t.idList??""]?{id:t.idList,name:s[t.idList].name,color:null}:null,type:null,repository:null,upvoteCount:t.badges.votes,labels:t.labels.map(r=>({color:r.color,description:null,id:r.id,name:r.name}))}},te=class extends U{async getCurrentUser(s,e={}){let r=await this.config.request({url:`${e.baseUrl||_}/1/members/me?key=${s.appKey}&token=${e.token||this.config.token}`,headers:R(e.token||this.config.token)});return{data:{name:r.body.fullName,email:r.body.email,avatarUrl:r.body.avatarHash?`https://trello-members.s3.amazonaws.com/${r.body.id}/${r.body.avatarHash}/50.png`:null,id:r.body.id,username:r.body.username,url:r.body.url}}}async getBoardsForCurrentUser(s,e={}){return{data:(await this.config.request({url:`${e.baseUrl||_}/1/members/me/boards?fields=name&key=${s.appKey}&token=${e.token||this.config.token}&filter=open`,headers:R(e.token||this.config.token)})).body.map(n=>({id:n.id,name:n.name}))}}async getListsForTrelloBoard(s,e={}){let{appKey:r,boardId:n}=s;return{data:(await this.config.request({url:`${e.baseUrl||_}/1/boards/${n}/lists?key=${r}&token=${e.token||this.config.token}`,headers:R(e.token||this.config.token)})).body}}async getAccountsForTrelloBoard(s,e={}){let{appKey:r,boardId:n}=s;return{data:(await this.config.request({url:`${e.baseUrl||_}/1/boards/${n}/members?key=${r}&token=${e.token||this.config.token}`,headers:R(e.token||this.config.token)})).body.map(o=>({id:o.id,name:o.fullName,username:o.username,email:null,avatarUrl:null,url:null}))}}async getIssuesForBoard(s,e={}){let r=["-is:archived","sort:edited"],{appKey:n,boardId:a,filterText:o,assigneeLogins:i,trelloBoardListsById:u}=s||{};i&&r.push("@me");let l=`${o?`${o}`:""}${r.join(" ")} board:${a}`;return{data:(await this.config.request({url:`${e.baseUrl||_}/1/search?key=${n}&query=${l}&cards_limit=${Us}&token=${e.token||this.config.token}`,headers:R(e.token||this.config.token)})).body.cards.map(d=>vs(d,u||{}))}}async updateIssue(s,e,r,n){return await this.config.request({method:"PUT",url:`${n.baseUrl||_}/1/cards/${e}?key=${s}&token=${n.token||this.config.token}&${r}`,headers:R(n.token||this.config.token)})}async setIssueStatus(s,e={}){let{appKey:r,cardId:n,status:a}=s,o=`idList=${a}`;if(!(await this.updateIssue(r,n,o,e)).body.id)throw new Error("Could not set issue status")}async setIssueAssignees(s,e={}){let{appKey:r,cardId:n,assigneeIds:a}=s,o=`idMembers=${encodeURIComponent(a.join(","))}`;if(!(await this.updateIssue(r,n,o,e)).body.id)throw new Error("Could not set issue status")}async setIssueLabels(s,e={}){let{appKey:r,cardId:n,labelIds:a}=s;if(!(await this.config.request({method:"PUT",url:`${e.baseUrl||_}/1/cards/${n}?key=${r}&token=${e.token||this.config.token}&idLabels=${encodeURIComponent(a.join(","))}`,headers:R(e.token||this.config.token)})).body.id)throw new Error("Could not set issue status")}async setIssueArchived(s,e={}){let{appKey:r,cardId:n,archived:a}=s;if(!(await this.config.request({method:"PUT",url:`${e.baseUrl||_}/1/cards/${n}?key=${r}&token=${e.token||this.config.token}&closed=${a}`,headers:R(e.token||this.config.token)})).body.id)throw new Error("Could not update issue archived status")}async getLabelsForBoard(s,e={}){let{appKey:r,boardId:n}=s;return{data:(await this.config.request({url:`${e.baseUrl||_}/1/boards/${n}/labels?key=${r}&token=${e.token||this.config.token}`,headers:R(e.token||this.config.token)})).body.map(o=>({color:o.color,description:null,id:o.id,name:o.name}))}}};var Ee={};T(Ee,{getIssueUniqueId:()=>$s,getPullRequestUniqueId:()=>Ls});var $s=(t,s,e,r="")=>{let n=[];return n.push(r),n.push(t),n.push(s),n.push(e),JSON.stringify(n)},Ls=(t,s,e,r,n="")=>{let a=[];return a.push(n),a.push(t),a.push(s),a.push(e),a.push(r),JSON.stringify(a)};var Se={};T(Se,{getIssueUniqueId:()=>Gs,getPullRequestUniqueId:()=>As});var Gs=(t,s)=>JSON.stringify(["",t,s]),As=(t,s)=>JSON.stringify(["",t,s]);var qe={};T(qe,{getIssueUniqueId:()=>Ts,getPullRequestUniqueId:()=>Os});var Ts=(t,s,e)=>JSON.stringify([e,t,s]),Os=(t,s,e)=>JSON.stringify([e,t,s]);var De={};T(De,{CHANGES_REQUESTED_BUCKET_ID:()=>Fs,CONFLICTS_BUCKET_ID:()=>Ns,DRAFT_BUCKET_ID:()=>Ms,FAILING_CI_BUCKET_ID:()=>_s,NEEDS_MY_REVIEW_BUCKET_ID:()=>Qs,OTHER_BUCKET_ID:()=>zs,READY_TO_MERGE_BUCKET_ID:()=>xs,REVIEWER_COMMENTED_BUCKET_ID:()=>Bs,UNASSIGNED_REVIEWERS_BUCKET_ID:()=>ks,WAITING_FOR_REVIEW_BUCKET_ID:()=>js,groupPullRequestsIntoBuckets:()=>Ws});var A=(t,s,e,r)=>({id:t,faIconName:e,name:s,priority:r,pullRequests:[]}),xs="readyToMerge",ks="unassignedReviewers",_s="failingCI",Ns="conflicts",Qs="needsMyReview",Fs="changesRequested",Bs="reviewerCommented",js="waitingForReview",Ms="draft",zs="other",Ws=(t,s)=>{let e={readyToMerge:A("readyToMerge","Ready to Merge","code-merge",0),unassignedReviewers:A("unassignedReviewers","Unassigned Reviewers","user-plus",1),failingCI:A("failingCI","Failing CI","circle-x",2),conflicts:A("conflicts","Resolve Conflicts","triangle-exclamation",3),needsMyReview:A("needsMyReview","Needs My Review","eye",4),changesRequested:A("changesRequested","Suggested Changes","file-plus",5),reviewerCommented:A("reviewerCommented","Reviewer Commented","comment",6),waitingForReview:A("waitingForReview","Waiting for Review","circle-pause",7),draft:A("draft","Draft","compass-drafting",8),other:A("other","Other","ellipsis",9)};return t.forEach(r=>{var u,l,p,d,c,g,m,f;let n=!0,a=((u=r.author)==null?void 0:u.id)===s.id,o=((l=r.assignees)==null?void 0:l.some(I=>I.id===s.id))??!1,i=((p=r.reviews)==null?void 0:p.some(I=>I.reviewer.id===s.id))??!1;(a||o&&!i)&&r.mergeableState==="MERGEABLE"&&(!r.reviewDecision||r.reviewDecision==="APPROVED")&&(((d=r.permissions)==null?void 0:d.canMerge)??!0)&&(e.readyToMerge.pullRequests.push(r),n=!1),a&&!((c=r.reviews)!=null&&c.length)&&(e.unassignedReviewers.pullRequests.push(r),n=!1),a&&((m=(g=r.headCommit)==null?void 0:g.buildStatuses)!=null&&m.some(I=>I.state==="ERROR"||I.state==="FAILED"))&&(e.failingCI.pullRequests.push(r),n=!1),a&&r.mergeableState==="CONFLICTS"&&(e.conflicts.pullRequests.push(r),n=!1),(f=r.reviews)!=null&&f.some(I=>I.reviewer.id===s.id&&I.state==="REVIEW_REQUESTED")&&(e.needsMyReview.pullRequests.push(r),n=!1),a&&r.reviewDecision==="CHANGES_REQUESTED"&&(e.changesRequested.pullRequests.push(r),n=!1),a&&r.reviewDecision==="COMMENTED"&&(e.reviewerCommented.pullRequests.push(r),n=!1),a&&r.reviewDecision==="REVIEW_REQUESTED"&&(e.waitingForReview.pullRequests.push(r),n=!1),a&&r.isDraft&&(e.draft.pullRequests.push(r),n=!1),n&&e.other.pullRequests.push(r)}),e};var Ce={};T(Ce,{getIssueUniqueId:()=>Hs,getPullRequestRank:()=>Ks,getPullRequestUniqueId:()=>Js});var Hs=(t,s="")=>{let e=[];return e.push(s),e.push(t),JSON.stringify(e)},Js=(t,s="")=>{let e=[];return e.push(s),e.push(t),JSON.stringify(e)},Ks=(t,s,e)=>{var o,i,u;let r=0,n,a;return(o=t.reviews)==null||o.forEach(l=>{l.reviewer.id===s&&(n=l.state),l.state==="CHANGES_REQUESTED"?a="CHANGES_REQUESTED":l.state==="APPROVED"&&a!=="CHANGES_REQUESTED"&&(a="APPROVED")}),a||(a="REVIEW_REQUESTED"),((i=t.author)==null?void 0:i.id)===s?r+=1e3:(u=t.assignees)!=null&&u.find(l=>l.id===s)?r+=900:n==="REVIEW_REQUESTED"?r+=800:e&&(r+=700),a==="APPROVED"?t.mergeableState==="MERGEABLE"?r+=100:t.mergeableState==="CONFLICTS"?r+=90:r+=80:a=="CHANGES_REQUESTED"&&(r+=70),r};var Ue={};T(Ue,{getIssueUniqueId:()=>Vs,getPullRequestUniqueId:()=>Xs});var Vs=(t,s="")=>{let e=[];return e.push(s),e.push(t),JSON.stringify(e)},Xs=(t,s="")=>{let e=[];return e.push(s),e.push(t),JSON.stringify(e)};var ve={};T(ve,{getIssueUniqueId:()=>Ys,getJiraServerIssueUniqueId:()=>Zs});var Ys=(t,s,e)=>{let r=[];return r.push(""),r.push(t),r.push(s),r.push(e),JSON.stringify(r)},Zs=(t,s,e)=>{let r=[];return r.push(e),r.push(""),r.push(t),r.push(s),JSON.stringify(r)};var $e={};T($e,{getIssueUniqueId:()=>er});var er=(t,s,e,r="")=>{let n=[];return n.push(r),n.push(t),n.push(s),n.push(e),JSON.stringify(n)};var tr=t=>{let s={request:t==null?void 0:t.request};return{azureDevOps:new W({...s,...t==null?void 0:t.azureDevOps}),bitbucket:new H({...s,...t==null?void 0:t.bitbucket}),bitbucketServer:new J({...s,...t==null?void 0:t.bitbucketServer}),github:new K({...s,...t==null?void 0:t.github}),gitlab:new X({...s,...t==null?void 0:t.gitlab}),jira:new Z({...s,...t==null?void 0:t.jira}),jiraServer:new ee({...s,...t==null?void 0:t.jiraServer}),trello:new te({...s,...t==null?void 0:t.trello})}},sr=tr;var rr={azureDevOps:Ee,bitbucket:Se,bitbucketServer:qe,github:Ce,gitlab:Ue,gitProvider:De,jira:ve,trello:$e};
1116
+ `,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(rt))??[]}}};var Cs="https://api.atlassian.com/ex/jira",me=10,ot=["assignee","comment","summary","created","creator","updated","votes","issuetype","status","labels","components","project"],at=(r,s,e)=>{var o,a,i,u;let t=r.fields.assignee,n=!e;return{id:r.id,commentCount:r.fields.comment.comments.length,number:r.key,title:r.fields.summary,url:s?`${s}/browse/${r.key}`:null,closedDate:null,createdDate:new Date(r.fields.created),author:he(r.fields.creator,s,n),updatedDate:new Date(r.fields.updated),assignees:t?[he(t,s,n)]:[],description:null,repository:null,project:{name:r.fields.project.name,resourceId:e??null,namespace:null},state:$s(r.fields.status),statusTransitions:((o=r.transitions)==null?void 0:o.map(Ds))??[],components:((a=r.fields.components)==null?void 0:a.map(Ls))??[],type:r.fields.issuetype.name,upvoteCount:((i=r.fields.votes)==null?void 0:i.votes)||0,labels:((u=r.fields.labels)==null?void 0:u.map(l=>({color:null,description:null,id:null,name:l})))??[]}},Ds=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}}},Ls=r=>({description:r.description??null,id:r.id,name:r.name}),Us=(r,s,e)=>e&&r.name?`${s}/secure/ViewProfile.jspa?name=${encodeURIComponent(r.name)}`:`${s}/jira/people/${r.accountId}`,he=(r,s,e)=>({id:(e?r.key:r.accountId)??"",name:r.displayName,email:r.emailAddress,avatarUrl:r.avatarUrls["48x48"],username:r.displayName,url:Us(r,s,e)}),$s=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}},j=(r,s,e)=>e?`${s.baseUrl||Cs}/${e}`:`${(s==null?void 0:s.baseUrl)||r.baseUrl}`,fe=async(r,s,e,t={})=>{let{number:n,resourceId:o}=s||{},a=await r.request({url:`${j(r,t,o)}/rest/api/2/issue/${n}?fields=${ot.join(",")}&expand=transitions`,headers:R(t.token||r.token)});return{data:at(a.body,e,o)}},Re=async(r,s,e,t={})=>{let{page:n,resourceId:o}=s||{},a=n??0,i=`statusCategory != Done AND (creator = currentUser() OR assignee = currentUser()
1117
+ OR comment ~ currentUser() OR summary ~ currentUser() OR description ~ currentUser())`,l=(await r.request({url:`${j(r,t,o)}/rest/api/2/search?jql=${i}&startAt=${a}&maxResults=${me}&fields=${ot.join(",")}&expand=transitions`,headers:R(t.token||r.token)})).body.issues.map(d=>at(d,e,o)),p=l.length==me;return{data:l,pageInfo:{hasNextPage:p,nextPage:p?a+l.length:null}}},Ie=async(r,s,e,t={})=>{let{assigneeLogins:n,authorLogin:o,mentionLogin:a,page:i,project:u,resourceId:l}=s||{},p=i??0,d=[`project = "${u}"`,"statusCategory != Done"];o&&d.push(`creator in ("${o}")`),n&&n.length!==0&&d.push(`assignee in ("${n.join('", "')}")`),a&&d.push(`comment ~ "${a}"`);let g=(await r.request({url:`${j(r,t,l)}/rest/api/2/search?jql=${d.join(" AND ")}&startAt=${p}&maxResults=${me}&fields=${ot.join(",")}&expand=transitions`,headers:R(t.token||r.token)})).body.issues.map(f=>at(f,e,l)),m=g.length==me;return{data:g,pageInfo:{hasNextPage:m,nextPage:m?p+g.length:null}}},be=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:`${j(r,e,t.project.resourceId??void 0)}/rest/api/2/issue/${t.id}`,body:JSON.stringify(o),headers:{...R(e.token||r.token),"Content-Type":"application/json"}})},ye=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:`${j(r,e,t.project.resourceId??void 0)}/rest/api/2/issue/${t.id}`,body:JSON.stringify(o),headers:{...R(e.token||r.token),"Content-Type":"application/json"}})},we=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:`${j(r,e,t.project.resourceId??void 0)}/rest/api/2/issue/${t.id}/transitions`,body:JSON.stringify(o),headers:{...R(e.token||r.token),"Content-Type":"application/json"}})},Pe=async(r,s,e={})=>{let{resourceId:t,projectIdOrKey:n}=s,o=new URL(`${j(r,e,t)}/rest/api/2/project/${n}/components`);return{data:(await r.request({url:o.toString(),headers:R(e.token||r.token)})).body}};var Y="https://api.atlassian.com/ex/jira",it=100,Z=class extends D{constructor(){super(...arguments);this._resourceUrlCache={}}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||Y}/${e.resourceId}/rest/api/2/myself`,headers:R(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:R(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||Y}/${e.resourceId}/rest/api/2/project/search`);n.searchParams.set("maxResults",it.toString()),e.cursor&&n.searchParams.set("startAt",e.cursor);let o=await this.config.request({url:n.toString(),headers:R(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=>{let a=await this.getJiraProjectsForResource({resourceId:o},t);n.push(...a.data)})),{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||Y}/${n}/rest/api/2/user/assignable/search`);u.searchParams.set("maxResults",it.toString()),a&&u.searchParams.set("startAt",a),u.searchParams.set("project",o);let l=await this.config.request({url:u.toString(),headers:R(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=>he(p,i,!1))}}async getComponentsForJiraProject(e,t={}){return await Pe(this.config,e,t)}async getIssue(e,t={}){let n=await this.getResourceUrl({resourceId:e.resourceId},t);return await fe(this.config,e,n,t)}async getIssuesForProject(e,t={}){let n=await this.getResourceUrl({resourceId:e.resourceId},t);return await Ie(this.config,e,n,t)}async getIssuesForResourceForCurrentUser(e,t={}){let n=await this.getResourceUrl({resourceId:e.resourceId},t);return await Re(this.config,e,n,t)}async setIssueStatus(e,t={}){await we(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||Y}/${n.project.resourceId}/rest/api/2/issue/${n.id}/assignee`,body:JSON.stringify(a),headers:{...R(t.token||this.config.token),"Content-Type":"application/json"}})}async setIssueComponents(e,t={}){await ye(this.config,e,t)}async setIssueLabels(e,t={}){await be(this.config,e,t)}async getLabelsForResource(e,t={}){let{resourceId:n,cursor:o}=e,a=new URL(`${t.baseUrl||Y}/${n}/rest/api/2/label`);a.searchParams.set("maxResults",it.toString()),o&&a.searchParams.set("startAt",o);let i=await this.config.request({url:a.toString(),headers:R(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 ${async getCurrentUser(s={}){let e=await this.config.request({url:`${(s==null?void 0:s.baseUrl)||this.config.baseUrl}/rest/api/2/myself`,headers:R((s==null?void 0:s.token)||this.config.token)});return{data:{name:e.body.displayName,email:e.body.emailAddress,avatarUrl:e.body.avatarUrls["48x48"],id:e.body.key,username:e.body.displayName,url:null}}}async getJiraProjects(s={}){return{data:(await this.config.request({url:`${(s==null?void 0:s.baseUrl)||this.config.baseUrl}/rest/api/2/project`,headers:R((s==null?void 0:s.token)||this.config.token)})).body.map(t=>({id:t.id,name:t.name}))}}async getIssue(s,e={}){if(!e.baseUrl)throw new Error('Jira Server requires a "baseUrl" for this function.');return await fe(this.config,s,e.baseUrl,e)}async getIssuesForProject(s,e={}){if(!e.baseUrl)throw new Error('Jira Server requires a "baseUrl" for this function.');return await Ie(this.config,s,e.baseUrl,e)}async getIssuesForResourceForCurrentUser(s,e={}){if(!e.baseUrl)throw new Error('Jira Server requires a "baseUrl" for this function.');return await Re(this.config,s,e.baseUrl,e)}async setIssueStatus(s,e={}){await we(this.config,s,e)}async setIssueLabels(s,e={}){await be(this.config,s,e)}async setIssueComponents(s,e={}){await ye(this.config,s,e)}async getLabels(s={}){return{data:(await this.config.request({url:`${(s==null?void 0:s.baseUrl)||this.config.baseUrl}/rest/api/2/jql/autocompletedata/suggestions?fieldName=labels`,headers:R(s.token||this.config.token)})).body.results.map(({displayName:t})=>({color:null,description:null,id:null,name:t}))}}async getComponentsForJiraProject(s,e={}){return await Pe(this.config,s,e)}};var _="https://api.trello.com",Gs=1e3,As=(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.idMembers.map(t=>({id:t,username:null,name:null,email:null,avatarUrl:null,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||_}/1/members/me?key=${s.appKey}&token=${e.token||this.config.token}`,headers:R(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||_}/1/members/me/boards?fields=name&key=${s.appKey}&token=${e.token||this.config.token}&filter=open`,headers:R(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||_}/1/boards/${n}/lists?key=${t}&token=${e.token||this.config.token}`,headers:R(e.token||this.config.token)})).body}}async getAccountsForTrelloBoard(s,e={}){let{appKey:t,boardId:n}=s;return{data:(await this.config.request({url:`${e.baseUrl||_}/1/boards/${n}/members?key=${t}&token=${e.token||this.config.token}`,headers:R(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,trelloBoardListsById:u}=s||{};i&&t.push("@me");let l=`${a?`${a}`:""}${t.join(" ")} board:${o}`;return{data:(await this.config.request({url:`${e.baseUrl||_}/1/search?key=${n}&query=${l}&cards_limit=${Gs}&token=${e.token||this.config.token}`,headers:R(e.token||this.config.token)})).body.cards.map(d=>As(d,u||{}))}}async updateIssue(s,e,t,n){return await this.config.request({method:"PUT",url:`${n.baseUrl||_}/1/cards/${e.id}?key=${s}&token=${n.token||this.config.token}&${t}`,headers:R(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||_}/1/cards/${n.id}?key=${t}&token=${e.token||this.config.token}&idLabels=${encodeURIComponent(a)}`,headers:R(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||_}/1/cards/${n.id}?key=${t}&token=${e.token||this.config.token}&closed=${o}`,headers:R(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||_}/1/boards/${n}/labels?key=${t}&token=${e.token||this.config.token}`,headers:R(e.token||this.config.token)})).body.map(a=>({color:a.color,description:null,id:a.id,name:a.name}))}}};var Se={};O(Se,{getIssueUniqueId:()=>Os,getPullRequestUniqueId:()=>Ts});var Os=(r,s,e,t="")=>{let n=[];return n.push(t),n.push(r),n.push(s),n.push(e),JSON.stringify(n)},Ts=(r,s,e,t,n="")=>{let o=[];return o.push(n),o.push(r),o.push(s),o.push(e),o.push(t),JSON.stringify(o)};var qe={};O(qe,{getIssueUniqueId:()=>xs,getPullRequestUniqueId:()=>ks});var xs=(r,s)=>JSON.stringify(["",r,s]),ks=(r,s)=>JSON.stringify(["",r,s]);var ve={};O(ve,{getIssueUniqueId:()=>_s,getPullRequestUniqueId:()=>Qs});var _s=(r,s,e)=>JSON.stringify([e,r,s]),Qs=(r,s,e)=>JSON.stringify([e,r,s]);var Ee={};O(Ee,{CHANGES_REQUESTED_BUCKET_ID:()=>zs,CONFLICTS_BUCKET_ID:()=>js,DRAFT_BUCKET_ID:()=>Js,FAILING_CI_BUCKET_ID:()=>Bs,NEEDS_MY_REVIEW_BUCKET_ID:()=>Ms,OTHER_BUCKET_ID:()=>Ks,READY_TO_MERGE_BUCKET_ID:()=>Ns,REVIEWER_COMMENTED_BUCKET_ID:()=>Hs,UNASSIGNED_REVIEWERS_BUCKET_ID:()=>Fs,WAITING_FOR_REVIEW_BUCKET_ID:()=>Ws,groupPullRequestsIntoBuckets:()=>Vs});var A=(r,s,e,t)=>({id:r,faIconName:e,name:s,priority:t,pullRequests:[]}),Ns="readyToMerge",Fs="unassignedReviewers",Bs="failingCI",js="conflicts",Ms="needsMyReview",zs="changesRequested",Hs="reviewerCommented",Ws="waitingForReview",Js="draft",Ks="other",Vs=(r,s)=>{let e={readyToMerge:A("readyToMerge","Ready to Merge","code-merge",0),unassignedReviewers:A("unassignedReviewers","Unassigned Reviewers","user-plus",1),failingCI:A("failingCI","Failing CI","circle-x",2),conflicts:A("conflicts","Resolve Conflicts","triangle-exclamation",3),needsMyReview:A("needsMyReview","Needs My Review","eye",4),changesRequested:A("changesRequested","Suggested Changes","file-plus",5),reviewerCommented:A("reviewerCommented","Reviewer Commented","comment",6),waitingForReview:A("waitingForReview","Waiting for Review","circle-pause",7),draft:A("draft","Draft","compass-drafting",8),other:A("other","Other","ellipsis",9)};return r.forEach(t=>{var u,l,p,d,c,g,m,f;let n=!0,o=((u=t.author)==null?void 0:u.id)===s.id,a=((l=t.assignees)==null?void 0:l.some(b=>b.id===s.id))??!1,i=((p=t.reviews)==null?void 0:p.some(b=>b.reviewer.id===s.id))??!1;(o||a&&!i)&&t.mergeableState==="MERGEABLE"&&(!t.reviewDecision||t.reviewDecision==="APPROVED")&&(((d=t.permissions)==null?void 0:d.canMerge)??!0)&&(e.readyToMerge.pullRequests.push(t),n=!1),o&&!((c=t.reviews)!=null&&c.length)&&(e.unassignedReviewers.pullRequests.push(t),n=!1),o&&((m=(g=t.headCommit)==null?void 0:g.buildStatuses)!=null&&m.some(b=>b.state==="ERROR"||b.state==="FAILED"))&&(e.failingCI.pullRequests.push(t),n=!1),o&&t.mergeableState==="CONFLICTS"&&(e.conflicts.pullRequests.push(t),n=!1),(f=t.reviews)!=null&&f.some(b=>b.reviewer.id===s.id&&b.state==="REVIEW_REQUESTED")&&(e.needsMyReview.pullRequests.push(t),n=!1),o&&t.reviewDecision==="CHANGES_REQUESTED"&&(e.changesRequested.pullRequests.push(t),n=!1),o&&t.reviewDecision==="COMMENTED"&&(e.reviewerCommented.pullRequests.push(t),n=!1),o&&t.reviewDecision==="REVIEW_REQUESTED"&&(e.waitingForReview.pullRequests.push(t),n=!1),o&&t.isDraft&&(e.draft.pullRequests.push(t),n=!1),n&&e.other.pullRequests.push(t)}),e};var Ce={};O(Ce,{getIssueUniqueId:()=>Xs,getPullRequestRank:()=>Zs,getPullRequestUniqueId:()=>Ys});var Xs=(r,s="")=>{let e=[];return e.push(s),e.push(r),JSON.stringify(e)},Ys=(r,s="")=>{let e=[];return e.push(s),e.push(r),JSON.stringify(e)},Zs=(r,s,e)=>{var a,i,u;let t=0,n,o;return(a=r.reviews)==null||a.forEach(l=>{l.reviewer.id===s&&(n=l.state),l.state==="CHANGES_REQUESTED"?o="CHANGES_REQUESTED":l.state==="APPROVED"&&o!=="CHANGES_REQUESTED"&&(o="APPROVED")}),o||(o="REVIEW_REQUESTED"),((i=r.author)==null?void 0:i.id)===s?t+=1e3:(u=r.assignees)!=null&&u.find(l=>l.id===s)?t+=900:n==="REVIEW_REQUESTED"?t+=800:e&&(t+=700),o==="APPROVED"?r.mergeableState==="MERGEABLE"?t+=100:r.mergeableState==="CONFLICTS"?t+=90:t+=80:o=="CHANGES_REQUESTED"&&(t+=70),t};var De={};O(De,{getIssueUniqueId:()=>er,getPullRequestUniqueId:()=>tr});var er=(r,s="")=>{let e=[];return e.push(s),e.push(r),JSON.stringify(e)},tr=(r,s="")=>{let e=[];return e.push(s),e.push(r),JSON.stringify(e)};var Le={};O(Le,{getIssueUniqueId:()=>sr,getJiraServerIssueUniqueId:()=>rr});var sr=(r,s,e)=>{let t=[];return t.push(""),t.push(r),t.push(s),t.push(e),JSON.stringify(t)},rr=(r,s,e)=>{let t=[];return t.push(e),t.push(""),t.push(r),t.push(s),JSON.stringify(t)};var Ue={};O(Ue,{getIssueUniqueId:()=>nr});var nr=(r,s,e,t="")=>{let n=[];return n.push(t),n.push(r),n.push(s),n.push(e),JSON.stringify(n)};var or=r=>{let s={request:r==null?void 0:r.request};return{azureDevOps:new H({...s,...r==null?void 0:r.azureDevOps}),bitbucket:new W({...s,...r==null?void 0:r.bitbucket}),bitbucketServer:new J({...s,...r==null?void 0:r.bitbucketServer}),github:new K({...s,...r==null?void 0:r.github}),gitlab:new X({...s,...r==null?void 0:r.gitlab}),jira:new Z({...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})}},ar=or;var ir={azureDevOps:Se,bitbucket:qe,bitbucketServer:ve,github:Ce,gitlab:De,gitProvider:Ee,jira:Le,trello:Ue};