@gitkraken/provider-apis 0.26.0 → 0.26.1

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/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.26.1
4
+
5
+ - add support for `GitPullRequest.headRepository` (Azure DevOps)
6
+
3
7
  ## 0.26.0
4
8
 
5
9
  - Added `getWorkspacesForUser` (BitBucket)
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- "use strict";var $r=Object.create;var me=Object.defineProperty;var Gr=Object.getOwnPropertyDescriptor;var Tr=Object.getOwnPropertyNames;var Or=Object.getPrototypeOf,xr=Object.prototype.hasOwnProperty;var B=(s,t)=>{for(var e in t)me(s,e,{get:t[e],enumerable:!0})},Wt=(s,t,e,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of Tr(t))!xr.call(s,n)&&n!==e&&me(s,n,{get:()=>t[n],enumerable:!(r=Gr(t,n))||r.enumerable});return s};var kr=(s,t,e)=>(e=s!=null?$r(Or(s)):{},Wt(t||!s||!s.__esModule?me(e,"default",{value:s,enumerable:!0}):e,s)),Nr=s=>Wt(me({},"__esModule",{value:!0}),s);var ln={};B(ln,{AzureDevOps:()=>te,AzureDevopsUtils:()=>Be,Bitbucket:()=>re,BitbucketServer:()=>se,BitbucketServerUtils:()=>je,BitbucketUtils:()=>Qe,EntityIdentifierProviderType:()=>A,EntityIdentifierUtils:()=>et,EntityType:()=>T,EntityVersion:()=>G,GitBuildStatusStage:()=>Ht,GitBuildStatusState:()=>de,GitDiffLineType:()=>it,GitHub:()=>oe,GitHubIssueCloseReason:()=>Lr,GitHubUtils:()=>rt,GitIssueState:()=>ye,GitLab:()=>ae,GitLabUtils:()=>st,GitMergeStrategy:()=>ee,GitProviderUtils:()=>tt,GitPullRequestMergeableState:()=>M,GitPullRequestReviewState:()=>F,GitPullRequestState:()=>X,GraphQLErrors:()=>b,Jira:()=>ue,JiraServer:()=>le,JiraUtils:()=>nt,PullRequestAsyncStatus:()=>Ar,Trello:()=>pe,TrelloUtils:()=>ot,Utils:()=>un,default:()=>an,isFetch:()=>fe});module.exports=Nr(ln);var Ht=(n=>(n.Build="build",n.Production="production",n.Staging="staging",n.Test="test",n))(Ht||{}),de=(p=>(p.ActionRequired="ACTION_REQUIRED",p.Cancelled="CANCELLED",p.Error="ERROR",p.Failed="FAILED",p.Pending="PENDING",p.Running="RUNNING",p.Skipped="SKIPPED",p.Success="SUCCESS",p.Warning="WARNING",p.OptionalActionRequired="OPTIONAL_ACTION_REQUIRED",p))(de||{}),ee=(o=>(o.MergeCommit="MERGE_COMMIT",o.Rebase="REBASE",o.RebaseThenMergeCommit="REBASE_THEN_MERGE_COMMIT",o.FastForward="FAST_FORWARD",o.Squash="SQUASH",o))(ee||{}),X=(r=>(r.Open="OPEN",r.Closed="CLOSED",r.Merged="MERGED",r))(X||{}),F=(n=>(n.Approved="APPROVED",n.ChangesRequested="CHANGES_REQUESTED",n.Commented="COMMENTED",n.ReviewRequested="REVIEW_REQUESTED",n))(F||{}),M=(a=>(a.Behind="BEHIND",a.Blocked="BLOCKED",a.Conflicts="CONFLICTS",a.Mergeable="MERGEABLE",a.Unknown="UNKNOWN",a.UnknownAndBlocked="UNKNOWN_AND_BLOCKED",a.Unstable="UNSTABLE",a))(M||{}),it=(r=>(r.ADDED="ADDED",r.DELETED="DELETED",r.UNMODIFIED="UNMODIFIED",r))(it||{});var Jt={APPROVED:0,COMMENTED:1,REVIEW_REQUESTED:2,CHANGES_REQUESTED:3},J=s=>!s||s.length===0?null:s.reduce((t,e)=>Jt[e.state]>Jt[t]?e.state:t,"APPROVED"),he=(s,t)=>s.name||s.username||s.email||t,Y=s=>{let t=Object.values(s).map(e=>e.name).sort((e,r)=>e.localeCompare(r));return Object.values(s).forEach(e=>{e.priority!==-1&&(e.priority=t.indexOf(e.name))}),s};var D=100;var Vt=kr(require("node-fetch")),Kt=globalThis.fetch||Vt.default;var _r=async s=>{let t=s.headers.get("content-type")||"",e=null;if(t.startsWith("application/json")){let n=await s.text();e=n.trim().length>0?JSON.parse(n):null}else if(t.startsWith("text/")||t==="")e=await s.text();else if(t.startsWith("application/vnd.github.raw+json"))e=await s.arrayBuffer();else throw new Error(`Unsupported content-type: ${t}`);let r={body:e,headers:Object.fromEntries(s.headers.entries()),status:s.status,statusText:s.statusText};if(!s.ok){let n=new Error(s.statusText);throw Object.assign(n,{response:r}),n}return r},at=s=>async({url:t,...e})=>{let r=await s(t,e);return _r(r)};var fe=(s,t=!1)=>s.name==="fetch"||t;var N=class{constructor(t){let e=(t==null?void 0:t.request)||Kt;this.config={...t,request:fe(e,t==null?void 0:t.forceIsFetch)?at(e):e}}updateConfig(t){this.config={...this.config,...t,request:t.request&&fe(t.request,(t==null?void 0:t.forceIsFetch)??this.config.forceIsFetch)?at(t.request):this.config.request}}},Q=class extends N{};var R=(s,t)=>{let e={};return s&&(e.Authorization=`${t?"Basic":"Bearer"} ${s}`),e},Xt=s=>s?s.reduce((t,e)=>(t[e]=!0,t),{}):void 0,V=(s,t,e)=>!s||t.some(r=>s[r])?e:"",Yt=async s=>{var n,o,i;let t=[],e=!0,r;for(;e;){let a=await s(r);t=t.concat(a.data),e=!!((n=a==null?void 0:a.pageInfo)!=null&&n.hasNextPage),r=((o=a==null?void 0:a.pageInfo)==null?void 0:o.endCursor)||((i=a==null?void 0:a.pageInfo)==null?void 0:i.nextPage)}return t};var q=(s,t={})=>R(t.token||s.token,t.isPAT||s.isPAT),Zt=s=>s.url.replace("/_apis/git/repositories/","/_git/").replace(`/${s.repository.project.id}/`,`/${encodeURIComponent(s.repository.project.name)}/`).replace(`/${s.repository.id}/`,`/${encodeURIComponent(s.repository.name)}/`).replace("/pullRequests/","/pullrequest/");var er="https://app.vssps.visualstudio.com/_apis",C="https://dev.azure.com",Br={active:"OPEN",completed:"MERGED",abandoned:"CLOSED"},Qr={10:"APPROVED",5:"APPROVED",0:"REVIEW_REQUESTED",[-5]:"CHANGES_REQUESTED",[-10]:"CHANGES_REQUESTED"},ut=s=>({id:s.id,name:s.displayName??null,username:(s.uniqueName||s.displayName)??null,email:null,avatarUrl:s.imageUrl??null,url:null}),Re=s=>s.startsWith("refs/heads/")?s.replace("refs/heads/",""):s,Ie=(s,t)=>{var n;let e=[],r=[];return t.reviewers.forEach(o=>{let i={reviewer:ut(o),state:Qr[o.vote??0]||"REVIEW_REQUESTED"};o.isRequired&&e.push(i),r.push(i)}),{id:t.pullRequestId.toString(),title:t.title,number:t.codeReviewId,state:Br[t.status],isDraft:t.isDraft,commentCount:null,upvoteCount:null,author:ut(t.createdBy),createdDate:new Date(t.creationDate),updatedDate:new Date(t.closedDate||t.creationDate),closedDate:t.closedDate?new Date(t.closedDate):null,mergedDate:t.closedDate&&t.status==="completed"?new Date(t.closedDate):null,repository:{id:t.repository.id,name:t.repository.name,project:t.repository.project.name,owner:{login:s},remoteInfo:null},headCommit:{buildStatuses:null},baseRef:{name:Re(t.targetRefName),oid:t.lastMergeTargetCommit.commitId},headRef:{name:Re(t.sourceRefName),oid:t.lastMergeSourceCommit.commitId},url:Zt(t),assignees:t.reviewers.map(ut),reviews:r,reviewDecision:J(e),additions:null,deletions:null,fileCount:null,commitCount:null,headRepository:null,mergeableState:"UNKNOWN",labels:((n=t.labels)==null?void 0:n.map(o=>({color:null,description:null,id:o.id,name:o.name})))??[],permissions:null}},tr=(s,t)=>({id:t.id,name:t.name,namespace:s,project:t.project.name,webUrl:t.webUrl,httpsUrl:t.remoteUrl,sshUrl:t.sshUrl,defaultBranch:t.defaultBranch?{name:Re(t.defaultBranch)}:null,permission:null}),jr=(s,t,e,r)=>{var l,p,d,c,g,m;let n=e.fields,o=n["System.AssignedTo"],i=n["System.State"],a=n["System.WorkItemType"],u;return i&&a&&(u=(l=r[a])==null?void 0:l[i]),{id:e.id.toString(),number:e.id.toString(),title:n["System.Title"],commentCount:n["System.CommentCount"],author:{avatarUrl:((d=(p=n["System.CreatedBy"]._links)==null?void 0:p.avatar)==null?void 0:d.href)??null,email:null,id:n["System.CreatedBy"].id,name:n["System.CreatedBy"].uniqueName??null,username:n["System.CreatedBy"].displayName??null,url:null},closedDate:n["Microsoft.VSTS.Common.ClosedDate"]?new Date(n["Microsoft.VSTS.Common.ClosedDate"]):null,createdDate:new Date(n["System.CreatedDate"]),updatedDate:new Date(n["System.ChangedDate"]),url:e._links.html.href,assignees:o?[{avatarUrl:((g=(c=o._links)==null?void 0:c.avatar)==null?void 0:g.href)??null,email:null,id:o.id,name:o.uniqueName??null,username:o.displayName??null,url:null}]:[],description:null,state:{name:(u==null?void 0:u.title)||i,color:null},type:n["System.WorkItemType"],repository:null,project:{namespace:s,name:t,resourceId:null,key:null,id:null},upvoteCount:0,labels:((m=e.fields["System.Tags"])==null?void 0:m.split(";").map(f=>({color:null,description:null,id:null,name:f.trim()})))??[]}},te=class extends N{async getCurrentUser(t={},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:`${er}/profile/profiles/me`,headers:q(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(t,e={}){let n=(await this.config.request({url:`${C}/${encodeURIComponent(t.namespace)}/_apis/ConnectionData`,headers:q(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(t,e={}){if(!t.repo.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let n=(await this.config.request({url:`${C}/${encodeURIComponent(t.repo.namespace)}/${encodeURIComponent(t.repo.project)}/_apis/git/repositories/${encodeURIComponent(t.repo.name)}/commits/${t.oid}`,headers:q(this.config,e)})).body.author;return{data:{name:n.name,email:n.email,avatarUrl:n.imageUrl}}}async getOrgsForUser(t,e={}){return{data:(await this.config.request({url:`${er}/accounts?memberId=${t.userId}&api-version=6.0`,headers:q(this.config,e)})).body.value.map(n=>({id:n.accountId,name:n.accountName}))}}async getAzureProjects(t,e={}){let r=new URL(`${C}/${encodeURIComponent(t.namespace)}/_apis/projects`);r.searchParams.set("$top",D.toString()),t.cursor&&r.searchParams.set("$skip",t.cursor);let n=await this.config.request({url:r.toString(),headers:q(this.config,e)}),o=n.headers["x-ms-continuationtoken"];return{pageInfo:{hasNextPage:!!o,endCursor:o||null},data:n.body.value.map(i=>({id:i.id,name:i.name,namespace:t.namespace}))}}async getAzureProjectScopeDescriptor(t,e={}){let{namespace:r,projectId:n}=t;return{data:{scope:(await this.config.request({url:`https://vssps.dev.azure.com/${encodeURIComponent(r)}/_apis/graph/descriptors/${n}?api-version=6.0`,headers:q(this.config,e)})).body.value}}}async getAzureGraphAccountsForAzureProject(t,e={}){let{namespace:r,projectScopeDescriptor:n,cursor:o}=t,i=new URL(`https://vssps.dev.azure.com/${encodeURIComponent(r)}/_apis/graph/users`);n&&i.searchParams.set("scopeDescriptor",n),o&&i.searchParams.set("continuationToken",o);let a=await this.config.request({url:i.toString(),headers:q(this.config,e)}),u=a.headers["x-ms-continuationtoken"];return{pageInfo:{endCursor:u||null,hasNextPage:!!u},data:a.body.value.map(l=>{var p,d,c,g;return{avatarUrl:((d=(p=l._links)==null?void 0:p.avatar)==null?void 0:d.href)??null,descriptor:l.descriptor??null,email:l.mailAddress??null,name:l.displayName??null,storageKeyURL:((g=(c=l._links)==null?void 0:c.storageKey)==null?void 0:g.href)??null,username:l.displayName??null}})}}async getAccountFromAzureGraphAccount(t,e={}){let{azureGraphAccount:r}=t;if(!r.storageKeyURL)throw new Error("Expected 'storageKeyURL' to not be null for 'azureGraphAccount'");let n=await this.config.request({url:r.storageKeyURL,headers:q(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(t,e={}){let r=[];for(let n of t.azureGraphAccounts){let o=await this.getAccountFromAzureGraphAccount({azureGraphAccount:n},e);r.push(o.data)}return{data:r}}async getRepo(t,e={}){if(!t.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let r=await this.config.request({url:`${C}/${encodeURIComponent(t.namespace)}/${encodeURIComponent(t.project)}/_apis/git/repositories/${encodeURIComponent(t.name)}`,headers:q(this.config,e)});return{data:tr(t.namespace,r.body)}}async getRepos(t,e={}){let r=[],n=[];return await Promise.all(t.map(async o=>{try{let i=await this.getRepo(o,e);r.push(i.data)}catch(i){n.push({input:o,error:i})}})),{data:r,errors:n}}async getReposForAzureProject(t,e={}){if(!t.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');return{data:(await this.config.request({url:`${C}/${encodeURIComponent(t.namespace)}/${encodeURIComponent(t.project)}/_apis/git/repositories`,headers:q(this.config,e)})).body.value.map(n=>tr(t.namespace,n))}}async getRefs(t,e,r={}){if(!e.repo.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let n=new URL(`${C}/${encodeURIComponent(e.repo.namespace)}/${encodeURIComponent(e.repo.project)}/_apis/git/repositories/${encodeURIComponent(e.repo.name)}/refs`);n.searchParams.set("filter",t),n.searchParams.set("$top",D.toString()),e.cursor&&n.searchParams.set("continuationToken",e.cursor);let o=await this.config.request({url:n.toString(),headers:q(this.config,r)}),i=o.headers["x-ms-continuationtoken"];return{pageInfo:{hasNextPage:!!i,endCursor:i||null},data:o.body.value.map(a=>({name:Re(a.name),commit:{oid:a.objectId,authoredDate:null,committedDate:null}}))}}async getBranches(t,e={}){return this.getRefs("heads",t,e)}async getTags(t,e={}){return this.getRefs("tags",t,e)}async getPullRequestsForRepoBase(t,e={},r=100){let{page:n,repo:o,assigneeLogins:i,authorLogin:a}=t||{},u=n||1;if(!o.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let l="searchCriteria.status=1";return i&&i.length&&(l+=`&searchCriteria.reviewerId=${i[0]}`),a&&(l+=`&searchCriteria.creatorId=${a}`),await this.config.request({url:`${e.baseUrl||C}/${encodeURIComponent(o.namespace)}/${encodeURIComponent(o.project||"")}/_apis/git/repositories/${encodeURIComponent(o.name)}/pullRequests?${l}&%24top=${r}&%24skip=${(u-1)*r}`,headers:q(this.config,e)})}async getPullRequestsForRepo(t,e={}){let n=t.page||1,o=await this.getPullRequestsForRepoBase(t,e,100);return{pageInfo:{hasNextPage:o.body.value.length===100,nextPage:n+1},data:o.body.value.map(i=>Ie(t.repo.namespace,i))}}async getPullRequestsForRepos(t,e={}){if(!t.repos.every(o=>o.project))throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let{repos:r}=t||{},n=[];return await Promise.all(r.map(async o=>{try{(await this.getPullRequestsForRepoBase({repo:o,...t},e)).body.value.forEach(a=>{n.push(Ie(o.namespace,a))})}catch(i){if(i.statusCode!==404&&i.statusCode!==401)throw i}})),{data:n}}async getPullRequestsForProjectBase(t,e={},r=100){let{namespace:n,project:o,page:i,assigneeLogins:a,authorLogin:u}=t,l=i||1,p=new URL(`${e.baseUrl||C}/${encodeURIComponent(n)}/${encodeURIComponent(o)}/_apis/git/pullRequests`);return p.searchParams.set("searchCriteria.status","1"),p.searchParams.set("$top",r.toString()),p.searchParams.set("$skip",((l-1)*r).toString()),a&&a.length&&p.searchParams.set("searchCriteria.reviewerId",a[0]),u&&p.searchParams.set("searchCriteria.creatorId",u),await this.config.request({url:p.toString(),headers:q(this.config,e)})}async getPullRequestsForProject(t,e={}){let n=t.page||1,o=await this.getPullRequestsForProjectBase(t,e,100);return{pageInfo:{hasNextPage:o.body.value.length===100,nextPage:n+1},data:o.body.value.map(i=>Ie(t.namespace,i))}}async getPullRequestsForProjects(t,e={}){let{projects:r}=t||{},n=[];return await Promise.all(r.map(async o=>{try{(await this.getPullRequestsForProjectBase({...o,...t},e)).body.value.forEach(a=>{n.push(Ie(o.namespace,a))})}catch(i){if(i.statusCode!==404&&i.statusCode!==401)throw i}})),{data:n}}async getAzurePullRequestLastMergeStatus(t,e={}){if(!t.repo.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let{repo:{namespace:r,project:n,name:o},pullRequestId:i}=t,a=await this.config.request({url:`${e.baseUrl||C}/${encodeURIComponent(r)}/${encodeURIComponent(n||"")}/_apis/git/repositories/${o}/pullrequests/${i}?includeCommits=true?api-version=6.0`,headers:{...q(this.config,e)}});if(!a.body.mergeStatus)throw new Error("Could not fetch pull request");return{data:a.body.mergeStatus}}async updatePullRequest(t,e,r){return await this.config.request({method:"PATCH",url:`${r.baseUrl||C}/${encodeURIComponent(t.repository.owner.login)}/${encodeURIComponent(t.repository.project)}/_apis/git/repositories/${t.repository.name}/pullrequests/${t.id}?api-version=6.0`,body:e,headers:{...q(this.config,r),"Content-Type":"application/json"}})}async closePullRequest(t,e={}){let{pullRequest:r}=t,n={status:"abandoned"};if(!(await this.updatePullRequest(r,JSON.stringify(n),e)).body.status)throw new Error("Could not close pull request")}async mergePullRequest(t,e={}){var u;let{pullRequest:r,mergeStrategy:n}=t,o;switch(n){case"MERGE_COMMIT":{o="noFastForward";break}case"REBASE":{o="rebase";break}case"REBASE_THEN_MERGE_COMMIT":{o="rebaseMerge";break}case"SQUASH":{o="squash";break}}let i={completionOptions:{mergeStrategy:o},lastMergeSourceCommit:{commitId:(u=r.headRef)==null?void 0:u.oid},status:"completed"};if(!(await this.updatePullRequest(r,JSON.stringify(i),e)).body.status)throw new Error("Could not merge pull request")}async addPullRequestLabel(t,e={}){let{pullRequest:r,label:n}=t;if(!r.repository.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let o={name:n.name};if(!(await this.config.request({method:"POST",url:`${e.baseUrl||C}/${encodeURIComponent(r.repository.owner.login)}/${encodeURIComponent(r.repository.project)}/_apis/git/repositories/${r.repository.name}/pullrequests/${r.id}/labels?api-version=6.0`,body:JSON.stringify(o),headers:{...q(this.config,e),"Content-Type":"application/json"}})).body.id)throw new Error("Could not add pull request label")}async removePullRequestLabel(t,e={}){let{pullRequest:r,label:n}=t;if(!r.repository.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');await this.config.request({method:"DELETE",url:`${e.baseUrl||C}/${encodeURIComponent(r.repository.owner.login)}/${encodeURIComponent(r.repository.project)}/_apis/git/repositories/${r.repository.name}/pullrequests/${r.id}/labels/${encodeURIComponent(n.name)}?api-version=6.0`,headers:{...q(this.config,e)}})}async setPullRequestLabels(t,e={}){let{pullRequest:r,labels:n}=t;if(!r.repository.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let o=r.labels;if(!o)throw new Error('Azure DevOps requires "labels" for this function.');for(let i of n)o.find(a=>a.id===i.id)||await this.addPullRequestLabel({pullRequest:r,label:i},e);for(let i of o)n.find(a=>i.id===a.id)||await this.removePullRequestLabel({pullRequest:r,label:i},e)}async setPullRequestAsDraft(t,e={}){let{pullRequest:r,isDraft:n}=t,o={isDraft:n};if(!(await this.updatePullRequest(r,JSON.stringify(o),e)).body.status)throw new Error("Could not set the pull request as draft")}async addPullRequestReviewer(t,e={}){let{pullRequest:r,reviewer:n,isRequired:o}=t,i={id:n.id,isRequired:o};if(!(await this.config.request({method:"PUT",url:`${e.baseUrl||C}/${encodeURIComponent(r.repository.owner.login)}/${encodeURIComponent(r.repository.project)}/_apis/git/repositories/${r.repository.name}/pullrequests/${r.id}/reviewers/${n.id}?api-version=6.0`,body:JSON.stringify(i),headers:{...q(this.config,e),"Content-Type":"application/json"}})).body.id)throw new Error("Could not add pull request reviewer")}async removePullRequestReviewer(t,e={}){let{pullRequest:r,reviewer:n}=t;await this.config.request({method:"DELETE",url:`${e.baseUrl||C}/${encodeURIComponent(r.repository.owner.login)}/${encodeURIComponent(r.repository.project)}/_apis/git/repositories/${r.repository.name}/pullrequests/${r.id}/reviewers/${n.id}?api-version=6.0`,headers:{...q(this.config,e),Accept:"application/json"}})}async setPullRequestReviewers(t,e={}){let{pullRequest:r,reviewers:n}=t;for(let o of n)r.assignees.find(i=>i.id===o.id)||await this.addPullRequestReviewer({pullRequest:r,reviewer:o,isRequired:!0},e);for(let o of r.assignees)n.find(i=>o.id===i.id)||await this.removePullRequestReviewer({pullRequest:r,reviewer:o},e)}async getIssuesForAzureProject(t,e={}){let{page:r,assigneeLogins:n,authorLogin:o,mentionLogin:i,labelNames:a,statusByWorkItemIdByStatusId:u}=t||{},l=r||1,p=200,d=["[Microsoft.VSTS.Common.ClosedDate] = ''","[System.TeamProject] = @project","[Microsoft.VSTS.Common.ResolvedDate] = ''"];o&&d.push(`[System.CreatedBy] = '${o.replace("'","''")}'`),n&&n[0]&&d.push(`[System.AssignedTo] = '${n[0].replace("'","''")}'`),i&&d.push("[System.Id] IN (@recentMentions)"),a&&a.forEach(y=>d.push(`[System.Tags] Contains '${y}'`));let c=`Select [Microsoft.VSTS.Common.ClosedDate], [Microsoft.VSTS.Common.ResolvedDate] From WorkItems Where ${d.join(" AND ")} order by [System.CreatedDate] desc`,g=await this.config.request({url:`${e.baseUrl||C}/${encodeURIComponent(t.namespace)}/${encodeURIComponent(t.project)}/_apis/wit/wiql?api-version=6.0`,body:JSON.stringify({query:c}),method:"POST",headers:{...q(this.config,e),"Content-Type":"application/json"}}),m=g.body.workItems.slice((l-1)*p,p*l).map(y=>y.id);if(m.length==0)return{pageInfo:{hasNextPage:!1,nextPage:null},data:[]};let f=await this.config.request({url:`${e.baseUrl||C}/${encodeURIComponent(t.namespace)}/${encodeURIComponent(t.project)}/_apis/wit/workitemsbatch?api-version=6.0`,body:JSON.stringify({ids:m,$expand:"Links"}),method:"POST",headers:{...q(this.config,e),"Content-Type":"application/json"}});return{pageInfo:{hasNextPage:g.body.workItems.length>p*l,nextPage:l+1},data:f.body.value.map(y=>jr(t.namespace,t.project,y,u||{}))}}async updateIssue(t,e,r={}){return await this.config.request({method:"PATCH",url:`${r.baseUrl||C}/${encodeURIComponent(t.project.namespace)}/${encodeURIComponent(t.project.name)}/_apis/wit/workitems/${t.id}?api-version=6.0`,body:JSON.stringify(e),headers:{...q(this.config,r),"Content-Type":"application/json-patch+json"}})}async setIssueStatus(t,e={}){var a;let{issue:r,status:n}=t,o=[{op:"add",path:"/fields/System.State",value:n.name}];if(!((a=(await this.updateIssue(r,o,e)).body.fields)!=null&&a["System.State"]))throw new Error("Could not set issue status")}async setIssueAssignee(t,e={}){var a;let{issue:r,assignee:n}=t,o=[{op:"add",path:"/fields/System.AssignedTo",value:(n==null?void 0:n.name)??""}];if(!((a=(await this.updateIssue(r,o,e)).body.fields)!=null&&a["System.State"]))throw new Error("Could not set issue assignee")}async setIssueLabels(t,e={}){var u;let{issue:r,labels:n}=t,i=[{op:"replace",path:"/fields/System.Tags",value:n.map(l=>l.name).join(";")}];if(!((u=(await this.updateIssue(r,i,e)).body.fields)!=null&&u["System.Tags"]))throw new Error("Could not set issue tags")}async getIssueTypesForAzureProject(t,e={}){if(!t.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let{namespace:r,project:n}=t;return{data:(await this.config.request({url:`${e.baseUrl||C}/${encodeURIComponent(r)}/${encodeURIComponent(n||"")}/_apis/wit/workitemtypes?api-version=6.0`,headers:{...q(this.config,e)}})).body.value}}async getLabelsForProject(t,e={}){let{namespace:r,project:n}=t;return{data:(await this.config.request({url:`${e.baseUrl||C}/${encodeURIComponent(r)}/${encodeURIComponent(n||"")}/_apis/wit/tags?api-version=6.0`,headers:{...q(this.config,e)}})).body.value.map(i=>({color:null,description:null,id:i.id,name:i.name,url:i.url}))}}};var $=(s,t={})=>R(t.token||s.token,t.isPAT||s.isPAT);var O="https://api.bitbucket.org/2.0",Fr={OPEN:"OPEN",MERGED:"MERGED",DECLINED:"CLOSED"},sr=s=>({id:s.uuid,name:s.display_name||s.nickname,username:s.nickname||s.display_name,email:null,avatarUrl:s.links.avatar.href,url:s.links.html.href}),rr=s=>{var t,e;return{id:s.uuid,namespace:s.workspace.slug,name:s.slug,webUrl:s.links.html.href,httpsUrl:((t=s.links.clone.find(r=>r.name==="https"))==null?void 0:t.href)??null,sshUrl:((e=s.links.clone.find(r=>r.name==="ssh"))==null?void 0:e.href)??null,defaultBranch:{name:s.mainbranch.name},permission:null}},lt=s=>{let t=s.id;return{id:t.toString(),title:s.title,number:t,state:Fr[s.state],isDraft:!1,commentCount:s.comment_count,upvoteCount:null,author:sr(s.author),createdDate:new Date(s.created_on),updatedDate:new Date(s.updated_on),closedDate:null,mergedDate:null,repository:{id:s.destination.repository.uuid,name:s.destination.repository.name,owner:{login:s.destination.repository.full_name.split("/")[0]},remoteInfo:null},headCommit:{buildStatuses:null},baseRef:{name:s.destination.branch.name,oid:s.destination.commit.hash},headRef:{name:s.source.branch.name,oid:s.source.commit.hash},url:s.links.html.href,assignees:null,reviews:null,reviewDecision:null,additions:null,deletions:null,fileCount:null,commitCount:null,headRepository:null,mergeableState:"UNKNOWN",permissions:null}},re=class extends N{async refreshToken(t){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 ${t.base64ClientIDColonClientSecret}`},body:`grant_type=refresh_token&refresh_token=${t.refreshToken}`})).body}}async getCurrentUser(t={},e={}){let r=await this.config.request({url:`${O}/user`,headers:$(this.config,e)});return{data:sr(r.body)}}async getUserForCommit(t,e={}){var i;let n=(await this.config.request({url:`${O}/repositories/${t.repo.namespace}/${t.repo.name}/commit/${t.oid}`,headers:$(this.config,e)})).body.author,o=n.raw.match(/([^<]+)<(.+)>/);return{data:{name:o?o[1].trim():null,email:o?o[2]:null,avatarUrl:((i=n.user)==null?void 0:i.links.avatar.href)||null}}}async getRepo(t,e={}){let r=await this.config.request({url:`${O}/repositories/${t.namespace}/${t.name}`,headers:$(this.config,e)});return{data:rr(r.body)}}async getRepos(t,e={}){let r=[],n=[];return await Promise.all(t.map(async o=>{try{let i=await this.getRepo(o,e);r.push(i.data)}catch(i){n.push({input:o,error:i})}})),{data:r,errors:n}}async getReposForCurrentUser(t,e={}){let r=new URL(`${O}/repositories`);r.searchParams.set("role","member"),r.searchParams.set("pagelen",D.toString()),t.cursor&&r.searchParams.set("after",t.cursor);let n=await this.config.request({url:r.toString(),headers:$(this.config,e)}),o=!!n.body.next,i=null;return n.body.next&&(i=new URL(n.body.next).searchParams.get("after")),{pageInfo:{hasNextPage:o,endCursor:i},data:n.body.values.map(rr)}}async getBranches(t,e={}){var i;let r=new URL(`${O}/repositories/${t.repo.namespace}/${t.repo.name}/refs/branches`);r.searchParams.set("page",((i=t.page)==null?void 0:i.toString())||"1"),r.searchParams.set("pagelen",D.toString());let n=await this.config.request({url:r.toString(),headers:$(this.config,e)}),o=!!n.body.next;return{pageInfo:{hasNextPage:o,nextPage:o?n.body.page+1:null},data:n.body.values.map(a=>{let u=new Date(a.target.date);return{name:a.name,commit:{oid:a.target.hash,authoredDate:u,committedDate:u}}})}}async getTags(t,e={}){let r=new URL(`${O}/repositories/${t.repo.namespace}/${t.repo.name}/refs/tags`);r.searchParams.set("pagelen",D.toString()),t.cursor&&r.searchParams.set("page",t.cursor);let n=await this.config.request({url:r.toString(),headers:$(this.config,e)}),o=!!n.body.next,i=null;return n.body.next&&(i=new URL(n.body.next).searchParams.get("page")),{pageInfo:{hasNextPage:o,endCursor:i},data:n.body.values.map(a=>{let u=new Date(a.target.date);return{name:a.name,commit:{oid:a.target.hash,authoredDate:u,committedDate:u}}})}}async getWorkspacesForUser(t,e={}){var i;let r=new URL(`${O}/user/permissions/workspaces`);r.searchParams.set("page",((i=t.page)==null?void 0:i.toString())||"1"),r.searchParams.set("pagelen","50");let n=await this.config.request({url:r.toString(),headers:$(this.config,e)}),o=!!n.body.next;return{pageInfo:{hasNextPage:o,nextPage:o?n.body.page+1:null},data:n.body.values.map(a=>({id:a.workspace.uuid,slug:a.workspace.slug,name:a.workspace.name}))}}async getPullRequestsForUserAndWorkspace(t,e={}){var i;let r=new URL(`${O}/workspaces/${t.workspaceSlug}/pullrequests/${t.userId}`);r.searchParams.set("page",((i=t.page)==null?void 0:i.toString())||"1"),r.searchParams.set("pagelen","50");let n=await this.config.request({url:r.toString(),headers:$(this.config,e)}),o=!!n.body.next;return{pageInfo:{hasNextPage:o,nextPage:o?n.body.page+1:null},data:n.body.values.map(lt)}}async getPullRequestsForRepoBase(t,e={}){var n;let r=new URL(`${O}/repositories/${encodeURI(t.repo.namespace)}/${encodeURI(t.repo.name)}/pullrequests?state=OPEN`);return r.searchParams.set("page",((n=t.page)==null?void 0:n.toString())||"1"),r.searchParams.set("pagelen","50"),await this.config.request({url:r.toString(),headers:$(this.config,e)})}async getPullRequestsForRepo(t,e={}){let r=[],n=await this.getPullRequestsForRepoBase(t,e);n.body.values.forEach(i=>{if(t.authorLogin&&i.author.uuid!==t.authorLogin)return null;r.push(lt(i))});let o=!!n.body.next;return{pageInfo:{hasNextPage:o,nextPage:o?n.body.page+1:null},data:r}}async getPullRequestsForRepos(t,e={}){let r=[];return await Promise.all(t.repos.map(async n=>{try{(await this.getPullRequestsForRepoBase({repo:n,...t},e)).body.values.forEach(i=>{if(t.authorLogin&&i.author.uuid!==t.authorLogin)return null;r.push(lt(i))})}catch(o){if(o.statusCode!==404&&o.statusCode!==401)throw o}})),{data:r}}async closePullRequest(t,e={}){let{pullRequest:r}=t;if(!(await this.config.request({method:"POST",url:`${O}/repositories/${r.repository.owner.login}/${r.repository.name}/pullrequests/${r.id}/decline`,headers:$(this.config,e)})).body.title)throw new Error("Could not close pull request")}async mergePullRequest(t,e={}){let{pullRequest:r,mergeStrategy:n}=t,o;switch(n){case"MERGE_COMMIT":{o="merge_commit";break}case"FAST_FORWARD":{o="fast_forward";break}case"SQUASH":{o="squash";break}}let i={merge_strategy:o,type:"pullrequest"};if(!(await this.config.request({method:"POST",url:`${O}/repositories/${r.repository.owner.login}/${r.repository.name}/pullrequests/${r.id}/merge`,body:JSON.stringify(i),headers:{...$(this.config,e),"Content-Type":"application/json"}})).body.title)throw new Error("Could not merge pull request")}async setPullRequestReviewers(t,e={}){let{pullRequest:r,reviewers:n}=t,o={reviewers:n.map(a=>{if(a.username)throw new Error('Bitbucket reviewer requires "username" for this function.');return{username:a.username}})};if(!(await this.config.request({method:"PUT",url:`${O}/repositories/${r.repository.owner.login}/${r.repository.name}/pullrequests/${r.id}`,body:JSON.stringify(o),headers:{...$(this.config,e),"Content-Type":"application/json"}})).body.title)throw new Error("Could not set pull request reviewers")}};var pt=s=>({name:s.displayName,email:s.emailAddress,avatarUrl:s.avatarUrl??null,id:s.id.toString(),username:s.name,url:s.links.self[0].href}),ce=s=>{var u,l,p,d,c,g;let t={OPEN:"OPEN",MERGED:"MERGED",DECLINED:"CLOSED"},e={UNAPPROVED:"REVIEW_REQUESTED",NEEDS_WORK:"CHANGES_REQUESTED",APPROVED:"APPROVED"},r=s.reviewers.map(m=>({reviewer:pt(m.user),state:e[m.status]})),n=((u=s.toRef.repository.links.clone.find(m=>m.name==="ssh"))==null?void 0:u.href)??null,o=((l=s.toRef.repository.links.clone.find(m=>m.name==="https"))==null?void 0:l.href)??null;o||(o=((p=s.toRef.repository.links.clone.find(m=>m.name==="http"))==null?void 0:p.href)??null);let i=((d=s.fromRef.repository.links.clone.find(m=>m.name==="ssh"))==null?void 0:d.href)??null,a=((c=s.fromRef.repository.links.clone.find(m=>m.name==="https"))==null?void 0:c.href)??null;return a||(a=((g=s.fromRef.repository.links.clone.find(m=>m.name==="http"))==null?void 0:g.href)??null),{id:s.id.toString(),number:s.id,title:s.title,url:s.links.self[0].href,state:t[s.state],isDraft:!1,createdDate:new Date(s.createdDate),updatedDate:new Date(s.updatedDate),closedDate:s.closedDate?new Date(s.closedDate):null,mergedDate:s.state=="MERGED"&&s.closedDate?new Date(s.closedDate):null,baseRef:{name:s.toRef.displayId,oid:s.toRef.latestCommit},headRef:{name:s.fromRef.displayId,oid:s.fromRef.latestCommit},commentCount:s.properties.commentCount,upvoteCount:null,commitCount:null,fileCount:null,additions:null,deletions:null,author:pt(s.author.user),assignees:null,reviews:r,reviewDecision:J(r),repository:{id:s.toRef.repository.id.toString(),name:s.toRef.repository.name,owner:{login:s.toRef.repository.project.key},remoteInfo:o&&n?{cloneUrlHTTPS:o,cloneUrlSSH:n}:null},headRepository:{id:s.fromRef.repository.id.toString(),name:s.fromRef.repository.name,owner:{login:s.fromRef.repository.project.key},remoteInfo:a&&i?{cloneUrlHTTPS:a,cloneUrlSSH:i}:null},headCommit:null,mergeableState:"UNKNOWN",permissions:null,version:s.version}},nr=s=>{var t,e,r;return{id:s.id.toString(),namespace:s.project.key,name:s.slug,webUrl:((t=s.links.self[0])==null?void 0:t.href)??null,httpsUrl:((e=s.links.clone.find(n=>n.name==="https"||n.name==="http"))==null?void 0:e.href)??null,sshUrl:((r=s.links.clone.find(n=>n.name==="ssh"))==null?void 0:r.href)??null,defaultBranch:null,permission:null}},se=class extends Q{getBaseUrl(t){let e=t.baseUrl||this.config.baseUrl;if(!e)throw new Error('Bitbucket Server requires "baseUrl"');return e}getRequestHeaders(t){return R(t.token||this.config.token)}async getCurrentUser(t={},e={}){let r=await this.config.request({url:`${this.getBaseUrl(e)}/users?limit=2`,headers:this.getRequestHeaders(e)}),{headers:{"x-auserid":n,"x-ausername":o}}=r,i=n?parseInt(n,10):null,a=decodeURIComponent(o),l=(await this.config.request({url:`${this.getBaseUrl(e)}/users?filter=${o}&avatarSize=64`,headers:this.getRequestHeaders(e)})).body.values.find(({emailAddress:p,id:d,name:c,slug:g})=>i?i===d:a===c||a===p||a===g);if(!l)throw new Error("Could not find current Bitbucket Server user");return{data:pt(l)}}async getRepo(t,e={}){let r=await this.config.request({url:`${this.getBaseUrl(e)}/projects/${t.namespace}/repos/${t.name}`,headers:this.getRequestHeaders(e)});return{data:nr(r.body)}}async getRepos(t,e={}){let r=[],n=[];return await Promise.all(t.map(async o=>{try{let i=await this.getRepo(o,e);r.push(i.data)}catch(i){n.push({input:o,error:i})}})),{data:r,errors:n}}async getReposForCurrentUser(t,e={}){let r=t.page??0,n=await this.config.request({url:`${this.getBaseUrl(e)}/repos?start=${r}`,headers:this.getRequestHeaders(e)});return{pageInfo:{hasNextPage:!n.body.isLastPage,nextPage:n.body.nextPageStart},data:n.body.values.map(nr)}}async getPullRequestsForRepoBase(t,e={}){var n;let r=new URL(`${this.getBaseUrl(e)}/projects/${encodeURI(t.repo.namespace)}/repos/${encodeURI(t.repo.name)}/pull-requests?state=OPEN`);return r.searchParams.set("start",((n=t.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(t,e={}){let r=[],n=await this.getPullRequestsForRepoBase(t,e);n.body.values.forEach(i=>{if(t.authorLogin&&i.author.user.name!==t.authorLogin)return null;r.push(ce(i))});let o=n.body.values.length!==0;return{pageInfo:{hasNextPage:o,nextPage:o?n.body.start+n.body.values.length:null},data:r}}async getPullRequestsForRepos(t,e={}){let r=[];return await Promise.all(t.repos.map(async n=>{try{(await this.getPullRequestsForRepoBase({repo:n,...t},e)).body.values.forEach(i=>{if(t.authorLogin&&i.author.user.name!==t.authorLogin)return null;r.push(ce(i))})}catch(o){if(o.statusCode!==404&&o.statusCode!==401)throw o}})),{data:r}}async getPullRequestsForCurrentUser(t,e={}){var i;let r=new URL(`${this.getBaseUrl(e)}/dashboard/pull-requests`);r.searchParams.set("state","OPEN"),r.searchParams.set("start",((i=t.page)==null?void 0:i.toString())||"0"),r.searchParams.set("limit","50");let n=await this.config.request({url:r.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(ce)}}async closePullRequest(t,e={}){let{pullRequest:r}=t;if(r.version===void 0)throw new Error('Bitbucket Server requires "version" for this function.');if(!(await this.config.request({method:"POST",url:`${this.getBaseUrl(e)}/projects/${r.repository.owner.login}/repos/${r.repository.name}/pull-requests/${r.id}/decline`,body:JSON.stringify({version:r.version}),headers:{...this.getRequestHeaders(e),"Content-Type":"application/json"}})).body.title)throw new Error("Could not close pull request")}async mergePullRequest(t,e={}){let{pullRequest:r,mergeStrategyId:n}=t;if(t.mergeStrategy)throw new Error('Bitbucket Server uses "mergeStrategyId" instead of "mergeStrategy".');if(r.version===void 0)throw new Error('Bitbucket Server requires "version" for this function.');if(!(await this.config.request({method:"POST",url:`${this.getBaseUrl(e)}/projects/${r.repository.owner.login}/repos/${r.repository.name}/pull-requests/${r.id}/merge`,body:JSON.stringify({strategyId:n,version:r.version}),headers:{...this.getRequestHeaders(e),"Content-Type":"application/json"}})).body.title)throw new Error("Could not merge pull request")}async getMergeStrategies(t={}){let e=await this.config.request({url:`${this.getBaseUrl(t)}/admin/pull-requests/git`,headers:{...this.getRequestHeaders(t),"Content-Type":"application/json"}});return{data:{defaultStrategy:e.body.mergeConfig.defaultStrategy,strategies:e.body.mergeConfig.strategies}}}async setPullRequestReviewers(t,e={}){let{pullRequest:r,reviewers:n}=t;if(r.version===void 0)throw new Error('Bitbucket Server requires "version" for this function.');let o={reviewers:n.map(a=>{if(a.username)throw new Error('Bitbucket Server reviewer requires "username" for this function.');return{user:{name:a.username}}}),version:r.version};if(!(await this.config.request({method:"PUT",url:`${this.getBaseUrl(e)}/projects/${r.repository.owner.login}/repos/${r.repository.name}/pull-requests/${r.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 dr=require("js-base64");var ye=(e=>(e.Open="OPEN",e.Closed="CLOSED",e))(ye||{});var b=class extends Error{constructor(e,r){let n=r==null?void 0:r.map(i=>`'${i.message}'`).join(", "),o=n?`${e}: ${n}`:e;super(o);this.graphQLErrors=r??[]}};var Mr={AS_CODE_OWNER:[3,0,0],CHECK_RUN:[3,0,0],LATEST_REVIEWS:[3,0,0],VIEWER_CAN_MERGE_AS_ADMIN:[3,5,0]},or=15,ir=100,U=s=>!!s,be=(s,t)=>{let e=Mr[t];for(let r=0;r<3;r++){if(s[r]>e[r])return!0;if(s[r]<e[r])return!1}return!0},Pe="https://api.github.com",zr=`${Pe}/graphql`,ve=`
1
+ "use strict";var $r=Object.create;var me=Object.defineProperty;var Gr=Object.getOwnPropertyDescriptor;var Tr=Object.getOwnPropertyNames;var Or=Object.getPrototypeOf,xr=Object.prototype.hasOwnProperty;var B=(s,t)=>{for(var e in t)me(s,e,{get:t[e],enumerable:!0})},Wt=(s,t,e,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of Tr(t))!xr.call(s,n)&&n!==e&&me(s,n,{get:()=>t[n],enumerable:!(r=Gr(t,n))||r.enumerable});return s};var kr=(s,t,e)=>(e=s!=null?$r(Or(s)):{},Wt(t||!s||!s.__esModule?me(e,"default",{value:s,enumerable:!0}):e,s)),Nr=s=>Wt(me({},"__esModule",{value:!0}),s);var ln={};B(ln,{AzureDevOps:()=>te,AzureDevopsUtils:()=>Be,Bitbucket:()=>re,BitbucketServer:()=>se,BitbucketServerUtils:()=>je,BitbucketUtils:()=>Qe,EntityIdentifierProviderType:()=>A,EntityIdentifierUtils:()=>et,EntityType:()=>T,EntityVersion:()=>G,GitBuildStatusStage:()=>Ht,GitBuildStatusState:()=>de,GitDiffLineType:()=>it,GitHub:()=>oe,GitHubIssueCloseReason:()=>Lr,GitHubUtils:()=>rt,GitIssueState:()=>ye,GitLab:()=>ae,GitLabUtils:()=>st,GitMergeStrategy:()=>ee,GitProviderUtils:()=>tt,GitPullRequestMergeableState:()=>M,GitPullRequestReviewState:()=>F,GitPullRequestState:()=>X,GraphQLErrors:()=>b,Jira:()=>ue,JiraServer:()=>le,JiraUtils:()=>nt,PullRequestAsyncStatus:()=>Ar,Trello:()=>pe,TrelloUtils:()=>ot,Utils:()=>un,default:()=>an,isFetch:()=>fe});module.exports=Nr(ln);var Ht=(n=>(n.Build="build",n.Production="production",n.Staging="staging",n.Test="test",n))(Ht||{}),de=(p=>(p.ActionRequired="ACTION_REQUIRED",p.Cancelled="CANCELLED",p.Error="ERROR",p.Failed="FAILED",p.Pending="PENDING",p.Running="RUNNING",p.Skipped="SKIPPED",p.Success="SUCCESS",p.Warning="WARNING",p.OptionalActionRequired="OPTIONAL_ACTION_REQUIRED",p))(de||{}),ee=(o=>(o.MergeCommit="MERGE_COMMIT",o.Rebase="REBASE",o.RebaseThenMergeCommit="REBASE_THEN_MERGE_COMMIT",o.FastForward="FAST_FORWARD",o.Squash="SQUASH",o))(ee||{}),X=(r=>(r.Open="OPEN",r.Closed="CLOSED",r.Merged="MERGED",r))(X||{}),F=(n=>(n.Approved="APPROVED",n.ChangesRequested="CHANGES_REQUESTED",n.Commented="COMMENTED",n.ReviewRequested="REVIEW_REQUESTED",n))(F||{}),M=(a=>(a.Behind="BEHIND",a.Blocked="BLOCKED",a.Conflicts="CONFLICTS",a.Mergeable="MERGEABLE",a.Unknown="UNKNOWN",a.UnknownAndBlocked="UNKNOWN_AND_BLOCKED",a.Unstable="UNSTABLE",a))(M||{}),it=(r=>(r.ADDED="ADDED",r.DELETED="DELETED",r.UNMODIFIED="UNMODIFIED",r))(it||{});var Jt={APPROVED:0,COMMENTED:1,REVIEW_REQUESTED:2,CHANGES_REQUESTED:3},J=s=>!s||s.length===0?null:s.reduce((t,e)=>Jt[e.state]>Jt[t]?e.state:t,"APPROVED"),he=(s,t)=>s.name||s.username||s.email||t,Y=s=>{let t=Object.values(s).map(e=>e.name).sort((e,r)=>e.localeCompare(r));return Object.values(s).forEach(e=>{e.priority!==-1&&(e.priority=t.indexOf(e.name))}),s};var D=100;var Vt=kr(require("node-fetch")),Kt=globalThis.fetch||Vt.default;var _r=async s=>{let t=s.headers.get("content-type")||"",e=null;if(t.startsWith("application/json")){let n=await s.text();e=n.trim().length>0?JSON.parse(n):null}else if(t.startsWith("text/")||t==="")e=await s.text();else if(t.startsWith("application/vnd.github.raw+json"))e=await s.arrayBuffer();else throw new Error(`Unsupported content-type: ${t}`);let r={body:e,headers:Object.fromEntries(s.headers.entries()),status:s.status,statusText:s.statusText};if(!s.ok){let n=new Error(s.statusText);throw Object.assign(n,{response:r}),n}return r},at=s=>async({url:t,...e})=>{let r=await s(t,e);return _r(r)};var fe=(s,t=!1)=>s.name==="fetch"||t;var N=class{constructor(t){let e=(t==null?void 0:t.request)||Kt;this.config={...t,request:fe(e,t==null?void 0:t.forceIsFetch)?at(e):e}}updateConfig(t){this.config={...this.config,...t,request:t.request&&fe(t.request,(t==null?void 0:t.forceIsFetch)??this.config.forceIsFetch)?at(t.request):this.config.request}}},Q=class extends N{};var R=(s,t)=>{let e={};return s&&(e.Authorization=`${t?"Basic":"Bearer"} ${s}`),e},Xt=s=>s?s.reduce((t,e)=>(t[e]=!0,t),{}):void 0,V=(s,t,e)=>!s||t.some(r=>s[r])?e:"",Yt=async s=>{var n,o,i;let t=[],e=!0,r;for(;e;){let a=await s(r);t=t.concat(a.data),e=!!((n=a==null?void 0:a.pageInfo)!=null&&n.hasNextPage),r=((o=a==null?void 0:a.pageInfo)==null?void 0:o.endCursor)||((i=a==null?void 0:a.pageInfo)==null?void 0:i.nextPage)}return t};var q=(s,t={})=>R(t.token||s.token,t.isPAT||s.isPAT),Zt=s=>s.url.replace("/_apis/git/repositories/","/_git/").replace(`/${s.repository.project.id}/`,`/${encodeURIComponent(s.repository.project.name)}/`).replace(`/${s.repository.id}/`,`/${encodeURIComponent(s.repository.name)}/`).replace("/pullRequests/","/pullrequest/");var er="https://app.vssps.visualstudio.com/_apis",C="https://dev.azure.com",Br={active:"OPEN",completed:"MERGED",abandoned:"CLOSED"},Qr={10:"APPROVED",5:"APPROVED",0:"REVIEW_REQUESTED",[-5]:"CHANGES_REQUESTED",[-10]:"CHANGES_REQUESTED"},ut=s=>({id:s.id,name:s.displayName??null,username:(s.uniqueName||s.displayName)??null,email:null,avatarUrl:s.imageUrl??null,url:null}),Re=s=>s.startsWith("refs/heads/")?s.replace("refs/heads/",""):s,Ie=(s,t)=>{var n;let e=[],r=[];return t.reviewers.forEach(o=>{let i={reviewer:ut(o),state:Qr[o.vote??0]||"REVIEW_REQUESTED"};o.isRequired&&e.push(i),r.push(i)}),{id:t.pullRequestId.toString(),title:t.title,number:t.codeReviewId,state:Br[t.status],isDraft:t.isDraft,commentCount:null,upvoteCount:null,author:ut(t.createdBy),createdDate:new Date(t.creationDate),updatedDate:new Date(t.closedDate||t.creationDate),closedDate:t.closedDate?new Date(t.closedDate):null,mergedDate:t.closedDate&&t.status==="completed"?new Date(t.closedDate):null,repository:{id:t.repository.id,name:t.repository.name,project:t.repository.project.name,owner:{login:s},remoteInfo:null},headCommit:{buildStatuses:null},baseRef:{name:Re(t.targetRefName),oid:t.lastMergeTargetCommit.commitId},headRef:{name:Re(t.sourceRefName),oid:t.lastMergeSourceCommit.commitId},url:Zt(t),assignees:t.reviewers.map(ut),reviews:r,reviewDecision:J(e),additions:null,deletions:null,fileCount:null,commitCount:null,headRepository:t.forkSource?{id:t.forkSource.repository.id,name:t.forkSource.repository.name,project:void 0,owner:{login:s},remoteInfo:null}:{id:t.repository.id,name:t.repository.name,project:t.repository.project.name,owner:{login:s},remoteInfo:null},mergeableState:"UNKNOWN",labels:((n=t.labels)==null?void 0:n.map(o=>({color:null,description:null,id:o.id,name:o.name})))??[],permissions:null}},tr=(s,t)=>({id:t.id,name:t.name,namespace:s,project:t.project.name,webUrl:t.webUrl,httpsUrl:t.remoteUrl,sshUrl:t.sshUrl,defaultBranch:t.defaultBranch?{name:Re(t.defaultBranch)}:null,permission:null}),jr=(s,t,e,r)=>{var l,p,d,c,g,m;let n=e.fields,o=n["System.AssignedTo"],i=n["System.State"],a=n["System.WorkItemType"],u;return i&&a&&(u=(l=r[a])==null?void 0:l[i]),{id:e.id.toString(),number:e.id.toString(),title:n["System.Title"],commentCount:n["System.CommentCount"],author:{avatarUrl:((d=(p=n["System.CreatedBy"]._links)==null?void 0:p.avatar)==null?void 0:d.href)??null,email:null,id:n["System.CreatedBy"].id,name:n["System.CreatedBy"].uniqueName??null,username:n["System.CreatedBy"].displayName??null,url:null},closedDate:n["Microsoft.VSTS.Common.ClosedDate"]?new Date(n["Microsoft.VSTS.Common.ClosedDate"]):null,createdDate:new Date(n["System.CreatedDate"]),updatedDate:new Date(n["System.ChangedDate"]),url:e._links.html.href,assignees:o?[{avatarUrl:((g=(c=o._links)==null?void 0:c.avatar)==null?void 0:g.href)??null,email:null,id:o.id,name:o.uniqueName??null,username:o.displayName??null,url:null}]:[],description:null,state:{name:(u==null?void 0:u.title)||i,color:null},type:n["System.WorkItemType"],repository:null,project:{namespace:s,name:t,resourceId:null,key:null,id:null},upvoteCount:0,labels:((m=e.fields["System.Tags"])==null?void 0:m.split(";").map(f=>({color:null,description:null,id:null,name:f.trim()})))??[]}},te=class extends N{async getCurrentUser(t={},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:`${er}/profile/profiles/me`,headers:q(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(t,e={}){let n=(await this.config.request({url:`${C}/${encodeURIComponent(t.namespace)}/_apis/ConnectionData`,headers:q(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(t,e={}){if(!t.repo.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let n=(await this.config.request({url:`${C}/${encodeURIComponent(t.repo.namespace)}/${encodeURIComponent(t.repo.project)}/_apis/git/repositories/${encodeURIComponent(t.repo.name)}/commits/${t.oid}`,headers:q(this.config,e)})).body.author;return{data:{name:n.name,email:n.email,avatarUrl:n.imageUrl}}}async getOrgsForUser(t,e={}){return{data:(await this.config.request({url:`${er}/accounts?memberId=${t.userId}&api-version=6.0`,headers:q(this.config,e)})).body.value.map(n=>({id:n.accountId,name:n.accountName}))}}async getAzureProjects(t,e={}){let r=new URL(`${C}/${encodeURIComponent(t.namespace)}/_apis/projects`);r.searchParams.set("$top",D.toString()),t.cursor&&r.searchParams.set("$skip",t.cursor);let n=await this.config.request({url:r.toString(),headers:q(this.config,e)}),o=n.headers["x-ms-continuationtoken"];return{pageInfo:{hasNextPage:!!o,endCursor:o||null},data:n.body.value.map(i=>({id:i.id,name:i.name,namespace:t.namespace}))}}async getAzureProjectScopeDescriptor(t,e={}){let{namespace:r,projectId:n}=t;return{data:{scope:(await this.config.request({url:`https://vssps.dev.azure.com/${encodeURIComponent(r)}/_apis/graph/descriptors/${n}?api-version=6.0`,headers:q(this.config,e)})).body.value}}}async getAzureGraphAccountsForAzureProject(t,e={}){let{namespace:r,projectScopeDescriptor:n,cursor:o}=t,i=new URL(`https://vssps.dev.azure.com/${encodeURIComponent(r)}/_apis/graph/users`);n&&i.searchParams.set("scopeDescriptor",n),o&&i.searchParams.set("continuationToken",o);let a=await this.config.request({url:i.toString(),headers:q(this.config,e)}),u=a.headers["x-ms-continuationtoken"];return{pageInfo:{endCursor:u||null,hasNextPage:!!u},data:a.body.value.map(l=>{var p,d,c,g;return{avatarUrl:((d=(p=l._links)==null?void 0:p.avatar)==null?void 0:d.href)??null,descriptor:l.descriptor??null,email:l.mailAddress??null,name:l.displayName??null,storageKeyURL:((g=(c=l._links)==null?void 0:c.storageKey)==null?void 0:g.href)??null,username:l.displayName??null}})}}async getAccountFromAzureGraphAccount(t,e={}){let{azureGraphAccount:r}=t;if(!r.storageKeyURL)throw new Error("Expected 'storageKeyURL' to not be null for 'azureGraphAccount'");let n=await this.config.request({url:r.storageKeyURL,headers:q(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(t,e={}){let r=[];for(let n of t.azureGraphAccounts){let o=await this.getAccountFromAzureGraphAccount({azureGraphAccount:n},e);r.push(o.data)}return{data:r}}async getRepo(t,e={}){if(!t.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let r=await this.config.request({url:`${C}/${encodeURIComponent(t.namespace)}/${encodeURIComponent(t.project)}/_apis/git/repositories/${encodeURIComponent(t.name)}`,headers:q(this.config,e)});return{data:tr(t.namespace,r.body)}}async getRepos(t,e={}){let r=[],n=[];return await Promise.all(t.map(async o=>{try{let i=await this.getRepo(o,e);r.push(i.data)}catch(i){n.push({input:o,error:i})}})),{data:r,errors:n}}async getReposForAzureProject(t,e={}){if(!t.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');return{data:(await this.config.request({url:`${C}/${encodeURIComponent(t.namespace)}/${encodeURIComponent(t.project)}/_apis/git/repositories`,headers:q(this.config,e)})).body.value.map(n=>tr(t.namespace,n))}}async getRefs(t,e,r={}){if(!e.repo.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let n=new URL(`${C}/${encodeURIComponent(e.repo.namespace)}/${encodeURIComponent(e.repo.project)}/_apis/git/repositories/${encodeURIComponent(e.repo.name)}/refs`);n.searchParams.set("filter",t),n.searchParams.set("$top",D.toString()),e.cursor&&n.searchParams.set("continuationToken",e.cursor);let o=await this.config.request({url:n.toString(),headers:q(this.config,r)}),i=o.headers["x-ms-continuationtoken"];return{pageInfo:{hasNextPage:!!i,endCursor:i||null},data:o.body.value.map(a=>({name:Re(a.name),commit:{oid:a.objectId,authoredDate:null,committedDate:null}}))}}async getBranches(t,e={}){return this.getRefs("heads",t,e)}async getTags(t,e={}){return this.getRefs("tags",t,e)}async getPullRequestsForRepoBase(t,e={},r=100){let{page:n,repo:o,assigneeLogins:i,authorLogin:a}=t||{},u=n||1;if(!o.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let l="searchCriteria.status=1";return i&&i.length&&(l+=`&searchCriteria.reviewerId=${i[0]}`),a&&(l+=`&searchCriteria.creatorId=${a}`),await this.config.request({url:`${e.baseUrl||C}/${encodeURIComponent(o.namespace)}/${encodeURIComponent(o.project||"")}/_apis/git/repositories/${encodeURIComponent(o.name)}/pullRequests?${l}&%24top=${r}&%24skip=${(u-1)*r}`,headers:q(this.config,e)})}async getPullRequestsForRepo(t,e={}){let n=t.page||1,o=await this.getPullRequestsForRepoBase(t,e,100);return{pageInfo:{hasNextPage:o.body.value.length===100,nextPage:n+1},data:o.body.value.map(i=>Ie(t.repo.namespace,i))}}async getPullRequestsForRepos(t,e={}){if(!t.repos.every(o=>o.project))throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let{repos:r}=t||{},n=[];return await Promise.all(r.map(async o=>{try{(await this.getPullRequestsForRepoBase({repo:o,...t},e)).body.value.forEach(a=>{n.push(Ie(o.namespace,a))})}catch(i){if(i.statusCode!==404&&i.statusCode!==401)throw i}})),{data:n}}async getPullRequestsForProjectBase(t,e={},r=100){let{namespace:n,project:o,page:i,assigneeLogins:a,authorLogin:u}=t,l=i||1,p=new URL(`${e.baseUrl||C}/${encodeURIComponent(n)}/${encodeURIComponent(o)}/_apis/git/pullRequests`);return p.searchParams.set("searchCriteria.status","1"),p.searchParams.set("$top",r.toString()),p.searchParams.set("$skip",((l-1)*r).toString()),a&&a.length&&p.searchParams.set("searchCriteria.reviewerId",a[0]),u&&p.searchParams.set("searchCriteria.creatorId",u),await this.config.request({url:p.toString(),headers:q(this.config,e)})}async getPullRequestsForProject(t,e={}){let n=t.page||1,o=await this.getPullRequestsForProjectBase(t,e,100);return{pageInfo:{hasNextPage:o.body.value.length===100,nextPage:n+1},data:o.body.value.map(i=>Ie(t.namespace,i))}}async getPullRequestsForProjects(t,e={}){let{projects:r}=t||{},n=[];return await Promise.all(r.map(async o=>{try{(await this.getPullRequestsForProjectBase({...o,...t},e)).body.value.forEach(a=>{n.push(Ie(o.namespace,a))})}catch(i){if(i.statusCode!==404&&i.statusCode!==401)throw i}})),{data:n}}async getAzurePullRequestLastMergeStatus(t,e={}){if(!t.repo.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let{repo:{namespace:r,project:n,name:o},pullRequestId:i}=t,a=await this.config.request({url:`${e.baseUrl||C}/${encodeURIComponent(r)}/${encodeURIComponent(n||"")}/_apis/git/repositories/${o}/pullrequests/${i}?includeCommits=true?api-version=6.0`,headers:{...q(this.config,e)}});if(!a.body.mergeStatus)throw new Error("Could not fetch pull request");return{data:a.body.mergeStatus}}async updatePullRequest(t,e,r){return await this.config.request({method:"PATCH",url:`${r.baseUrl||C}/${encodeURIComponent(t.repository.owner.login)}/${encodeURIComponent(t.repository.project)}/_apis/git/repositories/${t.repository.name}/pullrequests/${t.id}?api-version=6.0`,body:e,headers:{...q(this.config,r),"Content-Type":"application/json"}})}async closePullRequest(t,e={}){let{pullRequest:r}=t,n={status:"abandoned"};if(!(await this.updatePullRequest(r,JSON.stringify(n),e)).body.status)throw new Error("Could not close pull request")}async mergePullRequest(t,e={}){var u;let{pullRequest:r,mergeStrategy:n}=t,o;switch(n){case"MERGE_COMMIT":{o="noFastForward";break}case"REBASE":{o="rebase";break}case"REBASE_THEN_MERGE_COMMIT":{o="rebaseMerge";break}case"SQUASH":{o="squash";break}}let i={completionOptions:{mergeStrategy:o},lastMergeSourceCommit:{commitId:(u=r.headRef)==null?void 0:u.oid},status:"completed"};if(!(await this.updatePullRequest(r,JSON.stringify(i),e)).body.status)throw new Error("Could not merge pull request")}async addPullRequestLabel(t,e={}){let{pullRequest:r,label:n}=t;if(!r.repository.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let o={name:n.name};if(!(await this.config.request({method:"POST",url:`${e.baseUrl||C}/${encodeURIComponent(r.repository.owner.login)}/${encodeURIComponent(r.repository.project)}/_apis/git/repositories/${r.repository.name}/pullrequests/${r.id}/labels?api-version=6.0`,body:JSON.stringify(o),headers:{...q(this.config,e),"Content-Type":"application/json"}})).body.id)throw new Error("Could not add pull request label")}async removePullRequestLabel(t,e={}){let{pullRequest:r,label:n}=t;if(!r.repository.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');await this.config.request({method:"DELETE",url:`${e.baseUrl||C}/${encodeURIComponent(r.repository.owner.login)}/${encodeURIComponent(r.repository.project)}/_apis/git/repositories/${r.repository.name}/pullrequests/${r.id}/labels/${encodeURIComponent(n.name)}?api-version=6.0`,headers:{...q(this.config,e)}})}async setPullRequestLabels(t,e={}){let{pullRequest:r,labels:n}=t;if(!r.repository.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let o=r.labels;if(!o)throw new Error('Azure DevOps requires "labels" for this function.');for(let i of n)o.find(a=>a.id===i.id)||await this.addPullRequestLabel({pullRequest:r,label:i},e);for(let i of o)n.find(a=>i.id===a.id)||await this.removePullRequestLabel({pullRequest:r,label:i},e)}async setPullRequestAsDraft(t,e={}){let{pullRequest:r,isDraft:n}=t,o={isDraft:n};if(!(await this.updatePullRequest(r,JSON.stringify(o),e)).body.status)throw new Error("Could not set the pull request as draft")}async addPullRequestReviewer(t,e={}){let{pullRequest:r,reviewer:n,isRequired:o}=t,i={id:n.id,isRequired:o};if(!(await this.config.request({method:"PUT",url:`${e.baseUrl||C}/${encodeURIComponent(r.repository.owner.login)}/${encodeURIComponent(r.repository.project)}/_apis/git/repositories/${r.repository.name}/pullrequests/${r.id}/reviewers/${n.id}?api-version=6.0`,body:JSON.stringify(i),headers:{...q(this.config,e),"Content-Type":"application/json"}})).body.id)throw new Error("Could not add pull request reviewer")}async removePullRequestReviewer(t,e={}){let{pullRequest:r,reviewer:n}=t;await this.config.request({method:"DELETE",url:`${e.baseUrl||C}/${encodeURIComponent(r.repository.owner.login)}/${encodeURIComponent(r.repository.project)}/_apis/git/repositories/${r.repository.name}/pullrequests/${r.id}/reviewers/${n.id}?api-version=6.0`,headers:{...q(this.config,e),Accept:"application/json"}})}async setPullRequestReviewers(t,e={}){let{pullRequest:r,reviewers:n}=t;for(let o of n)r.assignees.find(i=>i.id===o.id)||await this.addPullRequestReviewer({pullRequest:r,reviewer:o,isRequired:!0},e);for(let o of r.assignees)n.find(i=>o.id===i.id)||await this.removePullRequestReviewer({pullRequest:r,reviewer:o},e)}async getIssuesForAzureProject(t,e={}){let{page:r,assigneeLogins:n,authorLogin:o,mentionLogin:i,labelNames:a,statusByWorkItemIdByStatusId:u}=t||{},l=r||1,p=200,d=["[Microsoft.VSTS.Common.ClosedDate] = ''","[System.TeamProject] = @project","[Microsoft.VSTS.Common.ResolvedDate] = ''"];o&&d.push(`[System.CreatedBy] = '${o.replace("'","''")}'`),n&&n[0]&&d.push(`[System.AssignedTo] = '${n[0].replace("'","''")}'`),i&&d.push("[System.Id] IN (@recentMentions)"),a&&a.forEach(y=>d.push(`[System.Tags] Contains '${y}'`));let c=`Select [Microsoft.VSTS.Common.ClosedDate], [Microsoft.VSTS.Common.ResolvedDate] From WorkItems Where ${d.join(" AND ")} order by [System.CreatedDate] desc`,g=await this.config.request({url:`${e.baseUrl||C}/${encodeURIComponent(t.namespace)}/${encodeURIComponent(t.project)}/_apis/wit/wiql?api-version=6.0`,body:JSON.stringify({query:c}),method:"POST",headers:{...q(this.config,e),"Content-Type":"application/json"}}),m=g.body.workItems.slice((l-1)*p,p*l).map(y=>y.id);if(m.length==0)return{pageInfo:{hasNextPage:!1,nextPage:null},data:[]};let f=await this.config.request({url:`${e.baseUrl||C}/${encodeURIComponent(t.namespace)}/${encodeURIComponent(t.project)}/_apis/wit/workitemsbatch?api-version=6.0`,body:JSON.stringify({ids:m,$expand:"Links"}),method:"POST",headers:{...q(this.config,e),"Content-Type":"application/json"}});return{pageInfo:{hasNextPage:g.body.workItems.length>p*l,nextPage:l+1},data:f.body.value.map(y=>jr(t.namespace,t.project,y,u||{}))}}async updateIssue(t,e,r={}){return await this.config.request({method:"PATCH",url:`${r.baseUrl||C}/${encodeURIComponent(t.project.namespace)}/${encodeURIComponent(t.project.name)}/_apis/wit/workitems/${t.id}?api-version=6.0`,body:JSON.stringify(e),headers:{...q(this.config,r),"Content-Type":"application/json-patch+json"}})}async setIssueStatus(t,e={}){var a;let{issue:r,status:n}=t,o=[{op:"add",path:"/fields/System.State",value:n.name}];if(!((a=(await this.updateIssue(r,o,e)).body.fields)!=null&&a["System.State"]))throw new Error("Could not set issue status")}async setIssueAssignee(t,e={}){var a;let{issue:r,assignee:n}=t,o=[{op:"add",path:"/fields/System.AssignedTo",value:(n==null?void 0:n.name)??""}];if(!((a=(await this.updateIssue(r,o,e)).body.fields)!=null&&a["System.State"]))throw new Error("Could not set issue assignee")}async setIssueLabels(t,e={}){var u;let{issue:r,labels:n}=t,i=[{op:"replace",path:"/fields/System.Tags",value:n.map(l=>l.name).join(";")}];if(!((u=(await this.updateIssue(r,i,e)).body.fields)!=null&&u["System.Tags"]))throw new Error("Could not set issue tags")}async getIssueTypesForAzureProject(t,e={}){if(!t.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let{namespace:r,project:n}=t;return{data:(await this.config.request({url:`${e.baseUrl||C}/${encodeURIComponent(r)}/${encodeURIComponent(n||"")}/_apis/wit/workitemtypes?api-version=6.0`,headers:{...q(this.config,e)}})).body.value}}async getLabelsForProject(t,e={}){let{namespace:r,project:n}=t;return{data:(await this.config.request({url:`${e.baseUrl||C}/${encodeURIComponent(r)}/${encodeURIComponent(n||"")}/_apis/wit/tags?api-version=6.0`,headers:{...q(this.config,e)}})).body.value.map(i=>({color:null,description:null,id:i.id,name:i.name,url:i.url}))}}};var $=(s,t={})=>R(t.token||s.token,t.isPAT||s.isPAT);var O="https://api.bitbucket.org/2.0",Fr={OPEN:"OPEN",MERGED:"MERGED",DECLINED:"CLOSED"},sr=s=>({id:s.uuid,name:s.display_name||s.nickname,username:s.nickname||s.display_name,email:null,avatarUrl:s.links.avatar.href,url:s.links.html.href}),rr=s=>{var t,e;return{id:s.uuid,namespace:s.workspace.slug,name:s.slug,webUrl:s.links.html.href,httpsUrl:((t=s.links.clone.find(r=>r.name==="https"))==null?void 0:t.href)??null,sshUrl:((e=s.links.clone.find(r=>r.name==="ssh"))==null?void 0:e.href)??null,defaultBranch:{name:s.mainbranch.name},permission:null}},lt=s=>{let t=s.id;return{id:t.toString(),title:s.title,number:t,state:Fr[s.state],isDraft:!1,commentCount:s.comment_count,upvoteCount:null,author:sr(s.author),createdDate:new Date(s.created_on),updatedDate:new Date(s.updated_on),closedDate:null,mergedDate:null,repository:{id:s.destination.repository.uuid,name:s.destination.repository.name,owner:{login:s.destination.repository.full_name.split("/")[0]},remoteInfo:null},headCommit:{buildStatuses:null},baseRef:{name:s.destination.branch.name,oid:s.destination.commit.hash},headRef:{name:s.source.branch.name,oid:s.source.commit.hash},url:s.links.html.href,assignees:null,reviews:null,reviewDecision:null,additions:null,deletions:null,fileCount:null,commitCount:null,headRepository:null,mergeableState:"UNKNOWN",permissions:null}},re=class extends N{async refreshToken(t){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 ${t.base64ClientIDColonClientSecret}`},body:`grant_type=refresh_token&refresh_token=${t.refreshToken}`})).body}}async getCurrentUser(t={},e={}){let r=await this.config.request({url:`${O}/user`,headers:$(this.config,e)});return{data:sr(r.body)}}async getUserForCommit(t,e={}){var i;let n=(await this.config.request({url:`${O}/repositories/${t.repo.namespace}/${t.repo.name}/commit/${t.oid}`,headers:$(this.config,e)})).body.author,o=n.raw.match(/([^<]+)<(.+)>/);return{data:{name:o?o[1].trim():null,email:o?o[2]:null,avatarUrl:((i=n.user)==null?void 0:i.links.avatar.href)||null}}}async getRepo(t,e={}){let r=await this.config.request({url:`${O}/repositories/${t.namespace}/${t.name}`,headers:$(this.config,e)});return{data:rr(r.body)}}async getRepos(t,e={}){let r=[],n=[];return await Promise.all(t.map(async o=>{try{let i=await this.getRepo(o,e);r.push(i.data)}catch(i){n.push({input:o,error:i})}})),{data:r,errors:n}}async getReposForCurrentUser(t,e={}){let r=new URL(`${O}/repositories`);r.searchParams.set("role","member"),r.searchParams.set("pagelen",D.toString()),t.cursor&&r.searchParams.set("after",t.cursor);let n=await this.config.request({url:r.toString(),headers:$(this.config,e)}),o=!!n.body.next,i=null;return n.body.next&&(i=new URL(n.body.next).searchParams.get("after")),{pageInfo:{hasNextPage:o,endCursor:i},data:n.body.values.map(rr)}}async getBranches(t,e={}){var i;let r=new URL(`${O}/repositories/${t.repo.namespace}/${t.repo.name}/refs/branches`);r.searchParams.set("page",((i=t.page)==null?void 0:i.toString())||"1"),r.searchParams.set("pagelen",D.toString());let n=await this.config.request({url:r.toString(),headers:$(this.config,e)}),o=!!n.body.next;return{pageInfo:{hasNextPage:o,nextPage:o?n.body.page+1:null},data:n.body.values.map(a=>{let u=new Date(a.target.date);return{name:a.name,commit:{oid:a.target.hash,authoredDate:u,committedDate:u}}})}}async getTags(t,e={}){let r=new URL(`${O}/repositories/${t.repo.namespace}/${t.repo.name}/refs/tags`);r.searchParams.set("pagelen",D.toString()),t.cursor&&r.searchParams.set("page",t.cursor);let n=await this.config.request({url:r.toString(),headers:$(this.config,e)}),o=!!n.body.next,i=null;return n.body.next&&(i=new URL(n.body.next).searchParams.get("page")),{pageInfo:{hasNextPage:o,endCursor:i},data:n.body.values.map(a=>{let u=new Date(a.target.date);return{name:a.name,commit:{oid:a.target.hash,authoredDate:u,committedDate:u}}})}}async getWorkspacesForUser(t,e={}){var i;let r=new URL(`${O}/user/permissions/workspaces`);r.searchParams.set("page",((i=t.page)==null?void 0:i.toString())||"1"),r.searchParams.set("pagelen","50");let n=await this.config.request({url:r.toString(),headers:$(this.config,e)}),o=!!n.body.next;return{pageInfo:{hasNextPage:o,nextPage:o?n.body.page+1:null},data:n.body.values.map(a=>({id:a.workspace.uuid,slug:a.workspace.slug,name:a.workspace.name}))}}async getPullRequestsForUserAndWorkspace(t,e={}){var i;let r=new URL(`${O}/workspaces/${t.workspaceSlug}/pullrequests/${t.userId}`);r.searchParams.set("page",((i=t.page)==null?void 0:i.toString())||"1"),r.searchParams.set("pagelen","50");let n=await this.config.request({url:r.toString(),headers:$(this.config,e)}),o=!!n.body.next;return{pageInfo:{hasNextPage:o,nextPage:o?n.body.page+1:null},data:n.body.values.map(lt)}}async getPullRequestsForRepoBase(t,e={}){var n;let r=new URL(`${O}/repositories/${encodeURI(t.repo.namespace)}/${encodeURI(t.repo.name)}/pullrequests?state=OPEN`);return r.searchParams.set("page",((n=t.page)==null?void 0:n.toString())||"1"),r.searchParams.set("pagelen","50"),await this.config.request({url:r.toString(),headers:$(this.config,e)})}async getPullRequestsForRepo(t,e={}){let r=[],n=await this.getPullRequestsForRepoBase(t,e);n.body.values.forEach(i=>{if(t.authorLogin&&i.author.uuid!==t.authorLogin)return null;r.push(lt(i))});let o=!!n.body.next;return{pageInfo:{hasNextPage:o,nextPage:o?n.body.page+1:null},data:r}}async getPullRequestsForRepos(t,e={}){let r=[];return await Promise.all(t.repos.map(async n=>{try{(await this.getPullRequestsForRepoBase({repo:n,...t},e)).body.values.forEach(i=>{if(t.authorLogin&&i.author.uuid!==t.authorLogin)return null;r.push(lt(i))})}catch(o){if(o.statusCode!==404&&o.statusCode!==401)throw o}})),{data:r}}async closePullRequest(t,e={}){let{pullRequest:r}=t;if(!(await this.config.request({method:"POST",url:`${O}/repositories/${r.repository.owner.login}/${r.repository.name}/pullrequests/${r.id}/decline`,headers:$(this.config,e)})).body.title)throw new Error("Could not close pull request")}async mergePullRequest(t,e={}){let{pullRequest:r,mergeStrategy:n}=t,o;switch(n){case"MERGE_COMMIT":{o="merge_commit";break}case"FAST_FORWARD":{o="fast_forward";break}case"SQUASH":{o="squash";break}}let i={merge_strategy:o,type:"pullrequest"};if(!(await this.config.request({method:"POST",url:`${O}/repositories/${r.repository.owner.login}/${r.repository.name}/pullrequests/${r.id}/merge`,body:JSON.stringify(i),headers:{...$(this.config,e),"Content-Type":"application/json"}})).body.title)throw new Error("Could not merge pull request")}async setPullRequestReviewers(t,e={}){let{pullRequest:r,reviewers:n}=t,o={reviewers:n.map(a=>{if(a.username)throw new Error('Bitbucket reviewer requires "username" for this function.');return{username:a.username}})};if(!(await this.config.request({method:"PUT",url:`${O}/repositories/${r.repository.owner.login}/${r.repository.name}/pullrequests/${r.id}`,body:JSON.stringify(o),headers:{...$(this.config,e),"Content-Type":"application/json"}})).body.title)throw new Error("Could not set pull request reviewers")}};var pt=s=>({name:s.displayName,email:s.emailAddress,avatarUrl:s.avatarUrl??null,id:s.id.toString(),username:s.name,url:s.links.self[0].href}),ce=s=>{var u,l,p,d,c,g;let t={OPEN:"OPEN",MERGED:"MERGED",DECLINED:"CLOSED"},e={UNAPPROVED:"REVIEW_REQUESTED",NEEDS_WORK:"CHANGES_REQUESTED",APPROVED:"APPROVED"},r=s.reviewers.map(m=>({reviewer:pt(m.user),state:e[m.status]})),n=((u=s.toRef.repository.links.clone.find(m=>m.name==="ssh"))==null?void 0:u.href)??null,o=((l=s.toRef.repository.links.clone.find(m=>m.name==="https"))==null?void 0:l.href)??null;o||(o=((p=s.toRef.repository.links.clone.find(m=>m.name==="http"))==null?void 0:p.href)??null);let i=((d=s.fromRef.repository.links.clone.find(m=>m.name==="ssh"))==null?void 0:d.href)??null,a=((c=s.fromRef.repository.links.clone.find(m=>m.name==="https"))==null?void 0:c.href)??null;return a||(a=((g=s.fromRef.repository.links.clone.find(m=>m.name==="http"))==null?void 0:g.href)??null),{id:s.id.toString(),number:s.id,title:s.title,url:s.links.self[0].href,state:t[s.state],isDraft:!1,createdDate:new Date(s.createdDate),updatedDate:new Date(s.updatedDate),closedDate:s.closedDate?new Date(s.closedDate):null,mergedDate:s.state=="MERGED"&&s.closedDate?new Date(s.closedDate):null,baseRef:{name:s.toRef.displayId,oid:s.toRef.latestCommit},headRef:{name:s.fromRef.displayId,oid:s.fromRef.latestCommit},commentCount:s.properties.commentCount,upvoteCount:null,commitCount:null,fileCount:null,additions:null,deletions:null,author:pt(s.author.user),assignees:null,reviews:r,reviewDecision:J(r),repository:{id:s.toRef.repository.id.toString(),name:s.toRef.repository.name,owner:{login:s.toRef.repository.project.key},remoteInfo:o&&n?{cloneUrlHTTPS:o,cloneUrlSSH:n}:null},headRepository:{id:s.fromRef.repository.id.toString(),name:s.fromRef.repository.name,owner:{login:s.fromRef.repository.project.key},remoteInfo:a&&i?{cloneUrlHTTPS:a,cloneUrlSSH:i}:null},headCommit:null,mergeableState:"UNKNOWN",permissions:null,version:s.version}},nr=s=>{var t,e,r;return{id:s.id.toString(),namespace:s.project.key,name:s.slug,webUrl:((t=s.links.self[0])==null?void 0:t.href)??null,httpsUrl:((e=s.links.clone.find(n=>n.name==="https"||n.name==="http"))==null?void 0:e.href)??null,sshUrl:((r=s.links.clone.find(n=>n.name==="ssh"))==null?void 0:r.href)??null,defaultBranch:null,permission:null}},se=class extends Q{getBaseUrl(t){let e=t.baseUrl||this.config.baseUrl;if(!e)throw new Error('Bitbucket Server requires "baseUrl"');return e}getRequestHeaders(t){return R(t.token||this.config.token)}async getCurrentUser(t={},e={}){let r=await this.config.request({url:`${this.getBaseUrl(e)}/users?limit=2`,headers:this.getRequestHeaders(e)}),{headers:{"x-auserid":n,"x-ausername":o}}=r,i=n?parseInt(n,10):null,a=decodeURIComponent(o),l=(await this.config.request({url:`${this.getBaseUrl(e)}/users?filter=${o}&avatarSize=64`,headers:this.getRequestHeaders(e)})).body.values.find(({emailAddress:p,id:d,name:c,slug:g})=>i?i===d:a===c||a===p||a===g);if(!l)throw new Error("Could not find current Bitbucket Server user");return{data:pt(l)}}async getRepo(t,e={}){let r=await this.config.request({url:`${this.getBaseUrl(e)}/projects/${t.namespace}/repos/${t.name}`,headers:this.getRequestHeaders(e)});return{data:nr(r.body)}}async getRepos(t,e={}){let r=[],n=[];return await Promise.all(t.map(async o=>{try{let i=await this.getRepo(o,e);r.push(i.data)}catch(i){n.push({input:o,error:i})}})),{data:r,errors:n}}async getReposForCurrentUser(t,e={}){let r=t.page??0,n=await this.config.request({url:`${this.getBaseUrl(e)}/repos?start=${r}`,headers:this.getRequestHeaders(e)});return{pageInfo:{hasNextPage:!n.body.isLastPage,nextPage:n.body.nextPageStart},data:n.body.values.map(nr)}}async getPullRequestsForRepoBase(t,e={}){var n;let r=new URL(`${this.getBaseUrl(e)}/projects/${encodeURI(t.repo.namespace)}/repos/${encodeURI(t.repo.name)}/pull-requests?state=OPEN`);return r.searchParams.set("start",((n=t.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(t,e={}){let r=[],n=await this.getPullRequestsForRepoBase(t,e);n.body.values.forEach(i=>{if(t.authorLogin&&i.author.user.name!==t.authorLogin)return null;r.push(ce(i))});let o=n.body.values.length!==0;return{pageInfo:{hasNextPage:o,nextPage:o?n.body.start+n.body.values.length:null},data:r}}async getPullRequestsForRepos(t,e={}){let r=[];return await Promise.all(t.repos.map(async n=>{try{(await this.getPullRequestsForRepoBase({repo:n,...t},e)).body.values.forEach(i=>{if(t.authorLogin&&i.author.user.name!==t.authorLogin)return null;r.push(ce(i))})}catch(o){if(o.statusCode!==404&&o.statusCode!==401)throw o}})),{data:r}}async getPullRequestsForCurrentUser(t,e={}){var i;let r=new URL(`${this.getBaseUrl(e)}/dashboard/pull-requests`);r.searchParams.set("state","OPEN"),r.searchParams.set("start",((i=t.page)==null?void 0:i.toString())||"0"),r.searchParams.set("limit","50");let n=await this.config.request({url:r.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(ce)}}async closePullRequest(t,e={}){let{pullRequest:r}=t;if(r.version===void 0)throw new Error('Bitbucket Server requires "version" for this function.');if(!(await this.config.request({method:"POST",url:`${this.getBaseUrl(e)}/projects/${r.repository.owner.login}/repos/${r.repository.name}/pull-requests/${r.id}/decline`,body:JSON.stringify({version:r.version}),headers:{...this.getRequestHeaders(e),"Content-Type":"application/json"}})).body.title)throw new Error("Could not close pull request")}async mergePullRequest(t,e={}){let{pullRequest:r,mergeStrategyId:n}=t;if(t.mergeStrategy)throw new Error('Bitbucket Server uses "mergeStrategyId" instead of "mergeStrategy".');if(r.version===void 0)throw new Error('Bitbucket Server requires "version" for this function.');if(!(await this.config.request({method:"POST",url:`${this.getBaseUrl(e)}/projects/${r.repository.owner.login}/repos/${r.repository.name}/pull-requests/${r.id}/merge`,body:JSON.stringify({strategyId:n,version:r.version}),headers:{...this.getRequestHeaders(e),"Content-Type":"application/json"}})).body.title)throw new Error("Could not merge pull request")}async getMergeStrategies(t={}){let e=await this.config.request({url:`${this.getBaseUrl(t)}/admin/pull-requests/git`,headers:{...this.getRequestHeaders(t),"Content-Type":"application/json"}});return{data:{defaultStrategy:e.body.mergeConfig.defaultStrategy,strategies:e.body.mergeConfig.strategies}}}async setPullRequestReviewers(t,e={}){let{pullRequest:r,reviewers:n}=t;if(r.version===void 0)throw new Error('Bitbucket Server requires "version" for this function.');let o={reviewers:n.map(a=>{if(a.username)throw new Error('Bitbucket Server reviewer requires "username" for this function.');return{user:{name:a.username}}}),version:r.version};if(!(await this.config.request({method:"PUT",url:`${this.getBaseUrl(e)}/projects/${r.repository.owner.login}/repos/${r.repository.name}/pull-requests/${r.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 dr=require("js-base64");var ye=(e=>(e.Open="OPEN",e.Closed="CLOSED",e))(ye||{});var b=class extends Error{constructor(e,r){let n=r==null?void 0:r.map(i=>`'${i.message}'`).join(", "),o=n?`${e}: ${n}`:e;super(o);this.graphQLErrors=r??[]}};var Mr={AS_CODE_OWNER:[3,0,0],CHECK_RUN:[3,0,0],LATEST_REVIEWS:[3,0,0],VIEWER_CAN_MERGE_AS_ADMIN:[3,5,0]},or=15,ir=100,U=s=>!!s,be=(s,t)=>{let e=Mr[t];for(let r=0;r<3;r++){if(s[r]>e[r])return!0;if(s[r]<e[r])return!1}return!0},Pe="https://api.github.com",zr=`${Pe}/graphql`,ve=`
2
2
  description
3
3
  dueOn
4
4
  id
@@ -1,4 +1,4 @@
1
- "use strict";var Nt=Object.create;var oe=Object.defineProperty;var Ft=Object.getOwnPropertyDescriptor;var Qt=Object.getOwnPropertyNames;var _t=Object.getPrototypeOf,Bt=Object.prototype.hasOwnProperty;var jt=(r,n)=>{for(var e in n)oe(r,e,{get:n[e],enumerable:!0})},ot=(r,n,e,t)=>{if(n&&typeof n=="object"||typeof n=="function")for(let s of Qt(n))!Bt.call(r,s)&&s!==e&&oe(r,s,{get:()=>n[s],enumerable:!(t=Ft(n,s))||t.enumerable});return r};var Mt=(r,n,e)=>(e=r!=null?Nt(_t(r)):{},ot(n||!r||!r.__esModule?oe(e,"default",{value:r,enumerable:!0}):e,r)),zt=r=>ot(oe({},"__esModule",{value:!0}),r);var Kr={};jt(Kr,{AzureDevOps:()=>J,Bitbucket:()=>K,BitbucketServer:()=>V,EntityIdentifierProviderType:()=>Ot,EntityType:()=>Tt,EntityVersion:()=>Gt,GitBuildStatusStage:()=>at,GitBuildStatusState:()=>ae,GitDiffLineType:()=>$e,GitHub:()=>Z,GitHubIssueCloseReason:()=>xt,GitIssueState:()=>pe,GitLab:()=>ee,GitMergeStrategy:()=>W,GitPullRequestMergeableState:()=>z,GitPullRequestReviewState:()=>M,GitPullRequestState:()=>j,GraphQLErrors:()=>R,Jira:()=>te,JiraServer:()=>re,PullRequestAsyncStatus:()=>At,Trello:()=>se,default:()=>Jr,isFetch:()=>ie});module.exports=zt(Kr);var at=(s=>(s.Build="build",s.Production="production",s.Staging="staging",s.Test="test",s))(at||{}),ae=(p=>(p.ActionRequired="ACTION_REQUIRED",p.Cancelled="CANCELLED",p.Error="ERROR",p.Failed="FAILED",p.Pending="PENDING",p.Running="RUNNING",p.Skipped="SKIPPED",p.Success="SUCCESS",p.Warning="WARNING",p.OptionalActionRequired="OPTIONAL_ACTION_REQUIRED",p))(ae||{}),W=(o=>(o.MergeCommit="MERGE_COMMIT",o.Rebase="REBASE",o.RebaseThenMergeCommit="REBASE_THEN_MERGE_COMMIT",o.FastForward="FAST_FORWARD",o.Squash="SQUASH",o))(W||{}),j=(t=>(t.Open="OPEN",t.Closed="CLOSED",t.Merged="MERGED",t))(j||{}),M=(s=>(s.Approved="APPROVED",s.ChangesRequested="CHANGES_REQUESTED",s.Commented="COMMENTED",s.ReviewRequested="REVIEW_REQUESTED",s))(M||{}),z=(i=>(i.Behind="BEHIND",i.Blocked="BLOCKED",i.Conflicts="CONFLICTS",i.Mergeable="MERGEABLE",i.Unknown="UNKNOWN",i.UnknownAndBlocked="UNKNOWN_AND_BLOCKED",i.Unstable="UNSTABLE",i))(z||{}),$e=(t=>(t.ADDED="ADDED",t.DELETED="DELETED",t.UNMODIFIED="UNMODIFIED",t))($e||{});var it={APPROVED:0,COMMENTED:1,REVIEW_REQUESTED:2,CHANGES_REQUESTED:3},Q=r=>!r||r.length===0?null:r.reduce((n,e)=>it[e.state]>it[n]?e.state:n,"APPROVED");var E=100;var ut=Mt(require("node-fetch")),lt=globalThis.fetch||ut.default;var Ht=async r=>{let n=r.headers.get("content-type")||"",e=null;if(n.startsWith("application/json")){let s=await r.text();e=s.trim().length>0?JSON.parse(s):null}else if(n.startsWith("text/")||n==="")e=await r.text();else if(n.startsWith("application/vnd.github.raw+json"))e=await r.arrayBuffer();else throw new Error(`Unsupported content-type: ${n}`);let t={body:e,headers:Object.fromEntries(r.headers.entries()),status:r.status,statusText:r.statusText};if(!r.ok){let s=new Error(r.statusText);throw Object.assign(s,{response:t}),s}return t},Ae=r=>async({url:n,...e})=>{let t=await r(n,e);return Ht(t)};var ie=(r,n=!1)=>r.name==="fetch"||n;var $=class{constructor(n){let e=(n==null?void 0:n.request)||lt;this.config={...n,request:ie(e,n==null?void 0:n.forceIsFetch)?Ae(e):e}}updateConfig(n){this.config={...this.config,...n,request:n.request&&ie(n.request,(n==null?void 0:n.forceIsFetch)??this.config.forceIsFetch)?Ae(n.request):this.config.request}}},T=class extends ${};var I=(r,n)=>{let e={};return r&&(e.Authorization=`${n?"Basic":"Bearer"} ${r}`),e},pt=r=>r?r.reduce((n,e)=>(n[e]=!0,n),{}):void 0,_=(r,n,e)=>!r||n.some(t=>r[t])?e:"",dt=async r=>{var s,o,a;let n=[],e=!0,t;for(;e;){let i=await r(t);n=n.concat(i.data),e=!!((s=i==null?void 0:i.pageInfo)!=null&&s.hasNextPage),t=((o=i==null?void 0:i.pageInfo)==null?void 0:o.endCursor)||((a=i==null?void 0:i.pageInfo)==null?void 0:a.nextPage)}return n};var P=(r,n={})=>I(n.token||r.token,n.isPAT||r.isPAT),ct=r=>r.url.replace("/_apis/git/repositories/","/_git/").replace(`/${r.repository.project.id}/`,`/${encodeURIComponent(r.repository.project.name)}/`).replace(`/${r.repository.id}/`,`/${encodeURIComponent(r.repository.name)}/`).replace("/pullRequests/","/pullrequest/");var gt="https://app.vssps.visualstudio.com/_apis",q="https://dev.azure.com",Wt={active:"OPEN",completed:"MERGED",abandoned:"CLOSED"},Jt={10:"APPROVED",5:"APPROVED",0:"REVIEW_REQUESTED",[-5]:"CHANGES_REQUESTED",[-10]:"CHANGES_REQUESTED"},Ge=r=>({id:r.id,name:r.displayName??null,username:(r.uniqueName||r.displayName)??null,email:null,avatarUrl:r.imageUrl??null,url:null}),le=r=>r.startsWith("refs/heads/")?r.replace("refs/heads/",""):r,ue=(r,n)=>{var s;let e=[],t=[];return n.reviewers.forEach(o=>{let a={reviewer:Ge(o),state:Jt[o.vote??0]||"REVIEW_REQUESTED"};o.isRequired&&e.push(a),t.push(a)}),{id:n.pullRequestId.toString(),title:n.title,number:n.codeReviewId,state:Wt[n.status],isDraft:n.isDraft,commentCount:null,upvoteCount:null,author:Ge(n.createdBy),createdDate:new Date(n.creationDate),updatedDate:new Date(n.closedDate||n.creationDate),closedDate:n.closedDate?new Date(n.closedDate):null,mergedDate:n.closedDate&&n.status==="completed"?new Date(n.closedDate):null,repository:{id:n.repository.id,name:n.repository.name,project:n.repository.project.name,owner:{login:r},remoteInfo:null},headCommit:{buildStatuses:null},baseRef:{name:le(n.targetRefName),oid:n.lastMergeTargetCommit.commitId},headRef:{name:le(n.sourceRefName),oid:n.lastMergeSourceCommit.commitId},url:ct(n),assignees:n.reviewers.map(Ge),reviews:t,reviewDecision:Q(e),additions:null,deletions:null,fileCount:null,commitCount:null,headRepository:null,mergeableState:"UNKNOWN",labels:((s=n.labels)==null?void 0:s.map(o=>({color:null,description:null,id:o.id,name:o.name})))??[],permissions:null}},mt=(r,n)=>({id:n.id,name:n.name,namespace:r,project:n.project.name,webUrl:n.webUrl,httpsUrl:n.remoteUrl,sshUrl:n.sshUrl,defaultBranch:n.defaultBranch?{name:le(n.defaultBranch)}:null,permission:null}),Kt=(r,n,e,t)=>{var l,p,d,c,g,m;let s=e.fields,o=s["System.AssignedTo"],a=s["System.State"],i=s["System.WorkItemType"],u;return a&&i&&(u=(l=t[i])==null?void 0:l[a]),{id:e.id.toString(),number:e.id.toString(),title:s["System.Title"],commentCount:s["System.CommentCount"],author:{avatarUrl:((d=(p=s["System.CreatedBy"]._links)==null?void 0:p.avatar)==null?void 0:d.href)??null,email:null,id:s["System.CreatedBy"].id,name:s["System.CreatedBy"].uniqueName??null,username:s["System.CreatedBy"].displayName??null,url:null},closedDate:s["Microsoft.VSTS.Common.ClosedDate"]?new Date(s["Microsoft.VSTS.Common.ClosedDate"]):null,createdDate:new Date(s["System.CreatedDate"]),updatedDate:new Date(s["System.ChangedDate"]),url:e._links.html.href,assignees:o?[{avatarUrl:((g=(c=o._links)==null?void 0:c.avatar)==null?void 0:g.href)??null,email:null,id:o.id,name:o.uniqueName??null,username:o.displayName??null,url:null}]:[],description:null,state:{name:(u==null?void 0:u.title)||a,color:null},type:s["System.WorkItemType"],repository:null,project:{namespace:r,name:n,resourceId:null,key:null,id:null},upvoteCount:0,labels:((m=e.fields["System.Tags"])==null?void 0:m.split(";").map(h=>({color:null,description:null,id:null,name:h.trim()})))??[]}},J=class extends ${async getCurrentUser(n={},e={}){if(e.isPAT||this.config.isPAT)throw new Error("Azure DevOps does not support PATs for this function.");let t=await this.config.request({url:`${gt}/profile/profiles/me`,headers: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(n,e={}){let s=(await this.config.request({url:`${q}/${encodeURIComponent(n.namespace)}/_apis/ConnectionData`,headers:P(this.config,e)})).body.authorizedUser;if(s.providerDisplayName==="Anonymous")throw new Error("Current user not found.");return{data:{id:s.id,name:s.providerDisplayName,username:s.providerDisplayName,email:s.properties.Account.$value,avatarUrl:null}}}async getUserForCommit(n,e={}){if(!n.repo.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let s=(await this.config.request({url:`${q}/${encodeURIComponent(n.repo.namespace)}/${encodeURIComponent(n.repo.project)}/_apis/git/repositories/${encodeURIComponent(n.repo.name)}/commits/${n.oid}`,headers:P(this.config,e)})).body.author;return{data:{name:s.name,email:s.email,avatarUrl:s.imageUrl}}}async getOrgsForUser(n,e={}){return{data:(await this.config.request({url:`${gt}/accounts?memberId=${n.userId}&api-version=6.0`,headers:P(this.config,e)})).body.value.map(s=>({id:s.accountId,name:s.accountName}))}}async getAzureProjects(n,e={}){let t=new URL(`${q}/${encodeURIComponent(n.namespace)}/_apis/projects`);t.searchParams.set("$top",E.toString()),n.cursor&&t.searchParams.set("$skip",n.cursor);let s=await this.config.request({url:t.toString(),headers:P(this.config,e)}),o=s.headers["x-ms-continuationtoken"];return{pageInfo:{hasNextPage:!!o,endCursor:o||null},data:s.body.value.map(a=>({id:a.id,name:a.name,namespace:n.namespace}))}}async getAzureProjectScopeDescriptor(n,e={}){let{namespace:t,projectId:s}=n;return{data:{scope:(await this.config.request({url:`https://vssps.dev.azure.com/${encodeURIComponent(t)}/_apis/graph/descriptors/${s}?api-version=6.0`,headers:P(this.config,e)})).body.value}}}async getAzureGraphAccountsForAzureProject(n,e={}){let{namespace:t,projectScopeDescriptor:s,cursor:o}=n,a=new URL(`https://vssps.dev.azure.com/${encodeURIComponent(t)}/_apis/graph/users`);s&&a.searchParams.set("scopeDescriptor",s),o&&a.searchParams.set("continuationToken",o);let i=await this.config.request({url:a.toString(),headers: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,d,c,g;return{avatarUrl:((d=(p=l._links)==null?void 0:p.avatar)==null?void 0:d.href)??null,descriptor:l.descriptor??null,email:l.mailAddress??null,name:l.displayName??null,storageKeyURL:((g=(c=l._links)==null?void 0:c.storageKey)==null?void 0:g.href)??null,username:l.displayName??null}})}}async getAccountFromAzureGraphAccount(n,e={}){let{azureGraphAccount:t}=n;if(!t.storageKeyURL)throw new Error("Expected 'storageKeyURL' to not be null for 'azureGraphAccount'");let s=await this.config.request({url:t.storageKeyURL,headers:P(this.config,e)});return{data:{avatarUrl:t.avatarUrl,email:t.email,id:s.body.value,name:t.name,username:t.username,url:null}}}async getAccountsFromAzureGraphAccounts(n,e={}){let t=[];for(let s of n.azureGraphAccounts){let o=await this.getAccountFromAzureGraphAccount({azureGraphAccount:s},e);t.push(o.data)}return{data:t}}async getRepo(n,e={}){if(!n.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let t=await this.config.request({url:`${q}/${encodeURIComponent(n.namespace)}/${encodeURIComponent(n.project)}/_apis/git/repositories/${encodeURIComponent(n.name)}`,headers:P(this.config,e)});return{data:mt(n.namespace,t.body)}}async getRepos(n,e={}){let t=[],s=[];return await Promise.all(n.map(async o=>{try{let a=await this.getRepo(o,e);t.push(a.data)}catch(a){s.push({input:o,error:a})}})),{data:t,errors:s}}async getReposForAzureProject(n,e={}){if(!n.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');return{data:(await this.config.request({url:`${q}/${encodeURIComponent(n.namespace)}/${encodeURIComponent(n.project)}/_apis/git/repositories`,headers:P(this.config,e)})).body.value.map(s=>mt(n.namespace,s))}}async getRefs(n,e,t={}){if(!e.repo.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let s=new URL(`${q}/${encodeURIComponent(e.repo.namespace)}/${encodeURIComponent(e.repo.project)}/_apis/git/repositories/${encodeURIComponent(e.repo.name)}/refs`);s.searchParams.set("filter",n),s.searchParams.set("$top",E.toString()),e.cursor&&s.searchParams.set("continuationToken",e.cursor);let o=await this.config.request({url:s.toString(),headers:P(this.config,t)}),a=o.headers["x-ms-continuationtoken"];return{pageInfo:{hasNextPage:!!a,endCursor:a||null},data:o.body.value.map(i=>({name:le(i.name),commit:{oid:i.objectId,authoredDate:null,committedDate:null}}))}}async getBranches(n,e={}){return this.getRefs("heads",n,e)}async getTags(n,e={}){return this.getRefs("tags",n,e)}async getPullRequestsForRepoBase(n,e={},t=100){let{page:s,repo:o,assigneeLogins:a,authorLogin:i}=n||{},u=s||1;if(!o.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let l="searchCriteria.status=1";return a&&a.length&&(l+=`&searchCriteria.reviewerId=${a[0]}`),i&&(l+=`&searchCriteria.creatorId=${i}`),await this.config.request({url:`${e.baseUrl||q}/${encodeURIComponent(o.namespace)}/${encodeURIComponent(o.project||"")}/_apis/git/repositories/${encodeURIComponent(o.name)}/pullRequests?${l}&%24top=${t}&%24skip=${(u-1)*t}`,headers:P(this.config,e)})}async getPullRequestsForRepo(n,e={}){let s=n.page||1,o=await this.getPullRequestsForRepoBase(n,e,100);return{pageInfo:{hasNextPage:o.body.value.length===100,nextPage:s+1},data:o.body.value.map(a=>ue(n.repo.namespace,a))}}async getPullRequestsForRepos(n,e={}){if(!n.repos.every(o=>o.project))throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let{repos:t}=n||{},s=[];return await Promise.all(t.map(async o=>{try{(await this.getPullRequestsForRepoBase({repo:o,...n},e)).body.value.forEach(i=>{s.push(ue(o.namespace,i))})}catch(a){if(a.statusCode!==404&&a.statusCode!==401)throw a}})),{data:s}}async getPullRequestsForProjectBase(n,e={},t=100){let{namespace:s,project:o,page:a,assigneeLogins:i,authorLogin:u}=n,l=a||1,p=new URL(`${e.baseUrl||q}/${encodeURIComponent(s)}/${encodeURIComponent(o)}/_apis/git/pullRequests`);return p.searchParams.set("searchCriteria.status","1"),p.searchParams.set("$top",t.toString()),p.searchParams.set("$skip",((l-1)*t).toString()),i&&i.length&&p.searchParams.set("searchCriteria.reviewerId",i[0]),u&&p.searchParams.set("searchCriteria.creatorId",u),await this.config.request({url:p.toString(),headers:P(this.config,e)})}async getPullRequestsForProject(n,e={}){let s=n.page||1,o=await this.getPullRequestsForProjectBase(n,e,100);return{pageInfo:{hasNextPage:o.body.value.length===100,nextPage:s+1},data:o.body.value.map(a=>ue(n.namespace,a))}}async getPullRequestsForProjects(n,e={}){let{projects:t}=n||{},s=[];return await Promise.all(t.map(async o=>{try{(await this.getPullRequestsForProjectBase({...o,...n},e)).body.value.forEach(i=>{s.push(ue(o.namespace,i))})}catch(a){if(a.statusCode!==404&&a.statusCode!==401)throw a}})),{data:s}}async getAzurePullRequestLastMergeStatus(n,e={}){if(!n.repo.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let{repo:{namespace:t,project:s,name:o},pullRequestId:a}=n,i=await this.config.request({url:`${e.baseUrl||q}/${encodeURIComponent(t)}/${encodeURIComponent(s||"")}/_apis/git/repositories/${o}/pullrequests/${a}?includeCommits=true?api-version=6.0`,headers:{...P(this.config,e)}});if(!i.body.mergeStatus)throw new Error("Could not fetch pull request");return{data:i.body.mergeStatus}}async updatePullRequest(n,e,t){return await this.config.request({method:"PATCH",url:`${t.baseUrl||q}/${encodeURIComponent(n.repository.owner.login)}/${encodeURIComponent(n.repository.project)}/_apis/git/repositories/${n.repository.name}/pullrequests/${n.id}?api-version=6.0`,body:e,headers:{...P(this.config,t),"Content-Type":"application/json"}})}async closePullRequest(n,e={}){let{pullRequest:t}=n,s={status:"abandoned"};if(!(await this.updatePullRequest(t,JSON.stringify(s),e)).body.status)throw new Error("Could not close pull request")}async mergePullRequest(n,e={}){var u;let{pullRequest:t,mergeStrategy:s}=n,o;switch(s){case"MERGE_COMMIT":{o="noFastForward";break}case"REBASE":{o="rebase";break}case"REBASE_THEN_MERGE_COMMIT":{o="rebaseMerge";break}case"SQUASH":{o="squash";break}}let a={completionOptions:{mergeStrategy:o},lastMergeSourceCommit:{commitId:(u=t.headRef)==null?void 0:u.oid},status:"completed"};if(!(await this.updatePullRequest(t,JSON.stringify(a),e)).body.status)throw new Error("Could not merge pull request")}async addPullRequestLabel(n,e={}){let{pullRequest:t,label:s}=n;if(!t.repository.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let o={name:s.name};if(!(await this.config.request({method:"POST",url:`${e.baseUrl||q}/${encodeURIComponent(t.repository.owner.login)}/${encodeURIComponent(t.repository.project)}/_apis/git/repositories/${t.repository.name}/pullrequests/${t.id}/labels?api-version=6.0`,body:JSON.stringify(o),headers:{...P(this.config,e),"Content-Type":"application/json"}})).body.id)throw new Error("Could not add pull request label")}async removePullRequestLabel(n,e={}){let{pullRequest:t,label:s}=n;if(!t.repository.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');await this.config.request({method:"DELETE",url:`${e.baseUrl||q}/${encodeURIComponent(t.repository.owner.login)}/${encodeURIComponent(t.repository.project)}/_apis/git/repositories/${t.repository.name}/pullrequests/${t.id}/labels/${encodeURIComponent(s.name)}?api-version=6.0`,headers:{...P(this.config,e)}})}async setPullRequestLabels(n,e={}){let{pullRequest:t,labels:s}=n;if(!t.repository.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let o=t.labels;if(!o)throw new Error('Azure DevOps requires "labels" for this function.');for(let a of s)o.find(i=>i.id===a.id)||await this.addPullRequestLabel({pullRequest:t,label:a},e);for(let a of o)s.find(i=>a.id===i.id)||await this.removePullRequestLabel({pullRequest:t,label:a},e)}async setPullRequestAsDraft(n,e={}){let{pullRequest:t,isDraft:s}=n,o={isDraft:s};if(!(await this.updatePullRequest(t,JSON.stringify(o),e)).body.status)throw new Error("Could not set the pull request as draft")}async addPullRequestReviewer(n,e={}){let{pullRequest:t,reviewer:s,isRequired:o}=n,a={id:s.id,isRequired:o};if(!(await this.config.request({method:"PUT",url:`${e.baseUrl||q}/${encodeURIComponent(t.repository.owner.login)}/${encodeURIComponent(t.repository.project)}/_apis/git/repositories/${t.repository.name}/pullrequests/${t.id}/reviewers/${s.id}?api-version=6.0`,body:JSON.stringify(a),headers:{...P(this.config,e),"Content-Type":"application/json"}})).body.id)throw new Error("Could not add pull request reviewer")}async removePullRequestReviewer(n,e={}){let{pullRequest:t,reviewer:s}=n;await this.config.request({method:"DELETE",url:`${e.baseUrl||q}/${encodeURIComponent(t.repository.owner.login)}/${encodeURIComponent(t.repository.project)}/_apis/git/repositories/${t.repository.name}/pullrequests/${t.id}/reviewers/${s.id}?api-version=6.0`,headers:{...P(this.config,e),Accept:"application/json"}})}async setPullRequestReviewers(n,e={}){let{pullRequest:t,reviewers:s}=n;for(let o of s)t.assignees.find(a=>a.id===o.id)||await this.addPullRequestReviewer({pullRequest:t,reviewer:o,isRequired:!0},e);for(let o of t.assignees)s.find(a=>o.id===a.id)||await this.removePullRequestReviewer({pullRequest:t,reviewer:o},e)}async getIssuesForAzureProject(n,e={}){let{page:t,assigneeLogins:s,authorLogin:o,mentionLogin:a,labelNames:i,statusByWorkItemIdByStatusId:u}=n||{},l=t||1,p=200,d=["[Microsoft.VSTS.Common.ClosedDate] = ''","[System.TeamProject] = @project","[Microsoft.VSTS.Common.ResolvedDate] = ''"];o&&d.push(`[System.CreatedBy] = '${o.replace("'","''")}'`),s&&s[0]&&d.push(`[System.AssignedTo] = '${s[0].replace("'","''")}'`),a&&d.push("[System.Id] IN (@recentMentions)"),i&&i.forEach(y=>d.push(`[System.Tags] Contains '${y}'`));let c=`Select [Microsoft.VSTS.Common.ClosedDate], [Microsoft.VSTS.Common.ResolvedDate] From WorkItems Where ${d.join(" AND ")} order by [System.CreatedDate] desc`,g=await this.config.request({url:`${e.baseUrl||q}/${encodeURIComponent(n.namespace)}/${encodeURIComponent(n.project)}/_apis/wit/wiql?api-version=6.0`,body:JSON.stringify({query:c}),method:"POST",headers:{...P(this.config,e),"Content-Type":"application/json"}}),m=g.body.workItems.slice((l-1)*p,p*l).map(y=>y.id);if(m.length==0)return{pageInfo:{hasNextPage:!1,nextPage:null},data:[]};let h=await this.config.request({url:`${e.baseUrl||q}/${encodeURIComponent(n.namespace)}/${encodeURIComponent(n.project)}/_apis/wit/workitemsbatch?api-version=6.0`,body:JSON.stringify({ids:m,$expand:"Links"}),method:"POST",headers:{...P(this.config,e),"Content-Type":"application/json"}});return{pageInfo:{hasNextPage:g.body.workItems.length>p*l,nextPage:l+1},data:h.body.value.map(y=>Kt(n.namespace,n.project,y,u||{}))}}async updateIssue(n,e,t={}){return await this.config.request({method:"PATCH",url:`${t.baseUrl||q}/${encodeURIComponent(n.project.namespace)}/${encodeURIComponent(n.project.name)}/_apis/wit/workitems/${n.id}?api-version=6.0`,body:JSON.stringify(e),headers:{...P(this.config,t),"Content-Type":"application/json-patch+json"}})}async setIssueStatus(n,e={}){var i;let{issue:t,status:s}=n,o=[{op:"add",path:"/fields/System.State",value:s.name}];if(!((i=(await this.updateIssue(t,o,e)).body.fields)!=null&&i["System.State"]))throw new Error("Could not set issue status")}async setIssueAssignee(n,e={}){var i;let{issue:t,assignee:s}=n,o=[{op:"add",path:"/fields/System.AssignedTo",value:(s==null?void 0:s.name)??""}];if(!((i=(await this.updateIssue(t,o,e)).body.fields)!=null&&i["System.State"]))throw new Error("Could not set issue assignee")}async setIssueLabels(n,e={}){var u;let{issue:t,labels:s}=n,a=[{op:"replace",path:"/fields/System.Tags",value:s.map(l=>l.name).join(";")}];if(!((u=(await this.updateIssue(t,a,e)).body.fields)!=null&&u["System.Tags"]))throw new Error("Could not set issue tags")}async getIssueTypesForAzureProject(n,e={}){if(!n.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let{namespace:t,project:s}=n;return{data:(await this.config.request({url:`${e.baseUrl||q}/${encodeURIComponent(t)}/${encodeURIComponent(s||"")}/_apis/wit/workitemtypes?api-version=6.0`,headers:{...P(this.config,e)}})).body.value}}async getLabelsForProject(n,e={}){let{namespace:t,project:s}=n;return{data:(await this.config.request({url:`${e.baseUrl||q}/${encodeURIComponent(t)}/${encodeURIComponent(s||"")}/_apis/wit/tags?api-version=6.0`,headers:{...P(this.config,e)}})).body.value.map(a=>({color:null,description:null,id:a.id,name:a.name,url:a.url}))}}};var D=(r,n={})=>I(n.token||r.token,n.isPAT||r.isPAT);var U="https://api.bitbucket.org/2.0",Vt={OPEN:"OPEN",MERGED:"MERGED",DECLINED:"CLOSED"},ft=r=>({id:r.uuid,name:r.display_name||r.nickname,username:r.nickname||r.display_name,email:null,avatarUrl:r.links.avatar.href,url:r.links.html.href}),ht=r=>{var n,e;return{id:r.uuid,namespace:r.workspace.slug,name:r.slug,webUrl:r.links.html.href,httpsUrl:((n=r.links.clone.find(t=>t.name==="https"))==null?void 0:n.href)??null,sshUrl:((e=r.links.clone.find(t=>t.name==="ssh"))==null?void 0:e.href)??null,defaultBranch:{name:r.mainbranch.name},permission:null}},Te=r=>{let n=r.id;return{id:n.toString(),title:r.title,number:n,state:Vt[r.state],isDraft:!1,commentCount:r.comment_count,upvoteCount:null,author:ft(r.author),createdDate:new Date(r.created_on),updatedDate:new Date(r.updated_on),closedDate:null,mergedDate:null,repository:{id:r.destination.repository.uuid,name:r.destination.repository.name,owner:{login:r.destination.repository.full_name.split("/")[0]},remoteInfo:null},headCommit:{buildStatuses:null},baseRef:{name:r.destination.branch.name,oid:r.destination.commit.hash},headRef:{name:r.source.branch.name,oid:r.source.commit.hash},url:r.links.html.href,assignees:null,reviews:null,reviewDecision:null,additions:null,deletions:null,fileCount:null,commitCount:null,headRepository:null,mergeableState:"UNKNOWN",permissions:null}},K=class extends ${async refreshToken(n){return{data:(await this.config.request({url:"https://bitbucket.org/site/oauth2/access_token",method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded",Authorization:`Basic ${n.base64ClientIDColonClientSecret}`},body:`grant_type=refresh_token&refresh_token=${n.refreshToken}`})).body}}async getCurrentUser(n={},e={}){let t=await this.config.request({url:`${U}/user`,headers:D(this.config,e)});return{data:ft(t.body)}}async getUserForCommit(n,e={}){var a;let s=(await this.config.request({url:`${U}/repositories/${n.repo.namespace}/${n.repo.name}/commit/${n.oid}`,headers:D(this.config,e)})).body.author,o=s.raw.match(/([^<]+)<(.+)>/);return{data:{name:o?o[1].trim():null,email:o?o[2]:null,avatarUrl:((a=s.user)==null?void 0:a.links.avatar.href)||null}}}async getRepo(n,e={}){let t=await this.config.request({url:`${U}/repositories/${n.namespace}/${n.name}`,headers:D(this.config,e)});return{data:ht(t.body)}}async getRepos(n,e={}){let t=[],s=[];return await Promise.all(n.map(async o=>{try{let a=await this.getRepo(o,e);t.push(a.data)}catch(a){s.push({input:o,error:a})}})),{data:t,errors:s}}async getReposForCurrentUser(n,e={}){let t=new URL(`${U}/repositories`);t.searchParams.set("role","member"),t.searchParams.set("pagelen",E.toString()),n.cursor&&t.searchParams.set("after",n.cursor);let s=await this.config.request({url:t.toString(),headers:D(this.config,e)}),o=!!s.body.next,a=null;return s.body.next&&(a=new URL(s.body.next).searchParams.get("after")),{pageInfo:{hasNextPage:o,endCursor:a},data:s.body.values.map(ht)}}async getBranches(n,e={}){var a;let t=new URL(`${U}/repositories/${n.repo.namespace}/${n.repo.name}/refs/branches`);t.searchParams.set("page",((a=n.page)==null?void 0:a.toString())||"1"),t.searchParams.set("pagelen",E.toString());let s=await this.config.request({url:t.toString(),headers:D(this.config,e)}),o=!!s.body.next;return{pageInfo:{hasNextPage:o,nextPage:o?s.body.page+1:null},data:s.body.values.map(i=>{let u=new Date(i.target.date);return{name:i.name,commit:{oid:i.target.hash,authoredDate:u,committedDate:u}}})}}async getTags(n,e={}){let t=new URL(`${U}/repositories/${n.repo.namespace}/${n.repo.name}/refs/tags`);t.searchParams.set("pagelen",E.toString()),n.cursor&&t.searchParams.set("page",n.cursor);let s=await this.config.request({url:t.toString(),headers:D(this.config,e)}),o=!!s.body.next,a=null;return s.body.next&&(a=new URL(s.body.next).searchParams.get("page")),{pageInfo:{hasNextPage:o,endCursor:a},data:s.body.values.map(i=>{let u=new Date(i.target.date);return{name:i.name,commit:{oid:i.target.hash,authoredDate:u,committedDate:u}}})}}async getWorkspacesForUser(n,e={}){var a;let t=new URL(`${U}/user/permissions/workspaces`);t.searchParams.set("page",((a=n.page)==null?void 0:a.toString())||"1"),t.searchParams.set("pagelen","50");let s=await this.config.request({url:t.toString(),headers:D(this.config,e)}),o=!!s.body.next;return{pageInfo:{hasNextPage:o,nextPage:o?s.body.page+1:null},data:s.body.values.map(i=>({id:i.workspace.uuid,slug:i.workspace.slug,name:i.workspace.name}))}}async getPullRequestsForUserAndWorkspace(n,e={}){var a;let t=new URL(`${U}/workspaces/${n.workspaceSlug}/pullrequests/${n.userId}`);t.searchParams.set("page",((a=n.page)==null?void 0:a.toString())||"1"),t.searchParams.set("pagelen","50");let s=await this.config.request({url:t.toString(),headers:D(this.config,e)}),o=!!s.body.next;return{pageInfo:{hasNextPage:o,nextPage:o?s.body.page+1:null},data:s.body.values.map(Te)}}async getPullRequestsForRepoBase(n,e={}){var s;let t=new URL(`${U}/repositories/${encodeURI(n.repo.namespace)}/${encodeURI(n.repo.name)}/pullrequests?state=OPEN`);return t.searchParams.set("page",((s=n.page)==null?void 0:s.toString())||"1"),t.searchParams.set("pagelen","50"),await this.config.request({url:t.toString(),headers:D(this.config,e)})}async getPullRequestsForRepo(n,e={}){let t=[],s=await this.getPullRequestsForRepoBase(n,e);s.body.values.forEach(a=>{if(n.authorLogin&&a.author.uuid!==n.authorLogin)return null;t.push(Te(a))});let o=!!s.body.next;return{pageInfo:{hasNextPage:o,nextPage:o?s.body.page+1:null},data:t}}async getPullRequestsForRepos(n,e={}){let t=[];return await Promise.all(n.repos.map(async s=>{try{(await this.getPullRequestsForRepoBase({repo:s,...n},e)).body.values.forEach(a=>{if(n.authorLogin&&a.author.uuid!==n.authorLogin)return null;t.push(Te(a))})}catch(o){if(o.statusCode!==404&&o.statusCode!==401)throw o}})),{data:t}}async closePullRequest(n,e={}){let{pullRequest:t}=n;if(!(await this.config.request({method:"POST",url:`${U}/repositories/${t.repository.owner.login}/${t.repository.name}/pullrequests/${t.id}/decline`,headers:D(this.config,e)})).body.title)throw new Error("Could not close pull request")}async mergePullRequest(n,e={}){let{pullRequest:t,mergeStrategy:s}=n,o;switch(s){case"MERGE_COMMIT":{o="merge_commit";break}case"FAST_FORWARD":{o="fast_forward";break}case"SQUASH":{o="squash";break}}let a={merge_strategy:o,type:"pullrequest"};if(!(await this.config.request({method:"POST",url:`${U}/repositories/${t.repository.owner.login}/${t.repository.name}/pullrequests/${t.id}/merge`,body:JSON.stringify(a),headers:{...D(this.config,e),"Content-Type":"application/json"}})).body.title)throw new Error("Could not merge pull request")}async setPullRequestReviewers(n,e={}){let{pullRequest:t,reviewers:s}=n,o={reviewers:s.map(i=>{if(i.username)throw new Error('Bitbucket reviewer requires "username" for this function.');return{username:i.username}})};if(!(await this.config.request({method:"PUT",url:`${U}/repositories/${t.repository.owner.login}/${t.repository.name}/pullrequests/${t.id}`,body:JSON.stringify(o),headers:{...D(this.config,e),"Content-Type":"application/json"}})).body.title)throw new Error("Could not set pull request reviewers")}};var xe=r=>({name:r.displayName,email:r.emailAddress,avatarUrl:r.avatarUrl??null,id:r.id.toString(),username:r.name,url:r.links.self[0].href}),Oe=r=>{var u,l,p,d,c,g;let n={OPEN:"OPEN",MERGED:"MERGED",DECLINED:"CLOSED"},e={UNAPPROVED:"REVIEW_REQUESTED",NEEDS_WORK:"CHANGES_REQUESTED",APPROVED:"APPROVED"},t=r.reviewers.map(m=>({reviewer:xe(m.user),state:e[m.status]})),s=((u=r.toRef.repository.links.clone.find(m=>m.name==="ssh"))==null?void 0:u.href)??null,o=((l=r.toRef.repository.links.clone.find(m=>m.name==="https"))==null?void 0:l.href)??null;o||(o=((p=r.toRef.repository.links.clone.find(m=>m.name==="http"))==null?void 0:p.href)??null);let a=((d=r.fromRef.repository.links.clone.find(m=>m.name==="ssh"))==null?void 0:d.href)??null,i=((c=r.fromRef.repository.links.clone.find(m=>m.name==="https"))==null?void 0:c.href)??null;return i||(i=((g=r.fromRef.repository.links.clone.find(m=>m.name==="http"))==null?void 0:g.href)??null),{id:r.id.toString(),number:r.id,title:r.title,url:r.links.self[0].href,state:n[r.state],isDraft:!1,createdDate:new Date(r.createdDate),updatedDate:new Date(r.updatedDate),closedDate:r.closedDate?new Date(r.closedDate):null,mergedDate:r.state=="MERGED"&&r.closedDate?new Date(r.closedDate):null,baseRef:{name:r.toRef.displayId,oid:r.toRef.latestCommit},headRef:{name:r.fromRef.displayId,oid:r.fromRef.latestCommit},commentCount:r.properties.commentCount,upvoteCount:null,commitCount:null,fileCount:null,additions:null,deletions:null,author:xe(r.author.user),assignees:null,reviews:t,reviewDecision:Q(t),repository:{id:r.toRef.repository.id.toString(),name:r.toRef.repository.name,owner:{login:r.toRef.repository.project.key},remoteInfo:o&&s?{cloneUrlHTTPS:o,cloneUrlSSH:s}:null},headRepository:{id:r.fromRef.repository.id.toString(),name:r.fromRef.repository.name,owner:{login:r.fromRef.repository.project.key},remoteInfo:i&&a?{cloneUrlHTTPS:i,cloneUrlSSH:a}:null},headCommit:null,mergeableState:"UNKNOWN",permissions:null,version:r.version}},It=r=>{var n,e,t;return{id:r.id.toString(),namespace:r.project.key,name:r.slug,webUrl:((n=r.links.self[0])==null?void 0:n.href)??null,httpsUrl:((e=r.links.clone.find(s=>s.name==="https"||s.name==="http"))==null?void 0:e.href)??null,sshUrl:((t=r.links.clone.find(s=>s.name==="ssh"))==null?void 0:t.href)??null,defaultBranch:null,permission:null}},V=class extends T{getBaseUrl(n){let e=n.baseUrl||this.config.baseUrl;if(!e)throw new Error('Bitbucket Server requires "baseUrl"');return e}getRequestHeaders(n){return I(n.token||this.config.token)}async getCurrentUser(n={},e={}){let t=await this.config.request({url:`${this.getBaseUrl(e)}/users?limit=2`,headers:this.getRequestHeaders(e)}),{headers:{"x-auserid":s,"x-ausername":o}}=t,a=s?parseInt(s,10):null,i=decodeURIComponent(o),l=(await this.config.request({url:`${this.getBaseUrl(e)}/users?filter=${o}&avatarSize=64`,headers:this.getRequestHeaders(e)})).body.values.find(({emailAddress:p,id:d,name:c,slug:g})=>a?a===d:i===c||i===p||i===g);if(!l)throw new Error("Could not find current Bitbucket Server user");return{data:xe(l)}}async getRepo(n,e={}){let t=await this.config.request({url:`${this.getBaseUrl(e)}/projects/${n.namespace}/repos/${n.name}`,headers:this.getRequestHeaders(e)});return{data:It(t.body)}}async getRepos(n,e={}){let t=[],s=[];return await Promise.all(n.map(async o=>{try{let a=await this.getRepo(o,e);t.push(a.data)}catch(a){s.push({input:o,error:a})}})),{data:t,errors:s}}async getReposForCurrentUser(n,e={}){let t=n.page??0,s=await this.config.request({url:`${this.getBaseUrl(e)}/repos?start=${t}`,headers:this.getRequestHeaders(e)});return{pageInfo:{hasNextPage:!s.body.isLastPage,nextPage:s.body.nextPageStart},data:s.body.values.map(It)}}async getPullRequestsForRepoBase(n,e={}){var s;let t=new URL(`${this.getBaseUrl(e)}/projects/${encodeURI(n.repo.namespace)}/repos/${encodeURI(n.repo.name)}/pull-requests?state=OPEN`);return t.searchParams.set("start",((s=n.page)==null?void 0:s.toString())||"0"),t.searchParams.set("limit","50"),await this.config.request({url:t.toString(),headers:this.getRequestHeaders(e)})}async getPullRequestsForRepo(n,e={}){let t=[],s=await this.getPullRequestsForRepoBase(n,e);s.body.values.forEach(a=>{if(n.authorLogin&&a.author.user.name!==n.authorLogin)return null;t.push(Oe(a))});let o=s.body.values.length!==0;return{pageInfo:{hasNextPage:o,nextPage:o?s.body.start+s.body.values.length:null},data:t}}async getPullRequestsForRepos(n,e={}){let t=[];return await Promise.all(n.repos.map(async s=>{try{(await this.getPullRequestsForRepoBase({repo:s,...n},e)).body.values.forEach(a=>{if(n.authorLogin&&a.author.user.name!==n.authorLogin)return null;t.push(Oe(a))})}catch(o){if(o.statusCode!==404&&o.statusCode!==401)throw o}})),{data:t}}async getPullRequestsForCurrentUser(n,e={}){var a;let t=new URL(`${this.getBaseUrl(e)}/dashboard/pull-requests`);t.searchParams.set("state","OPEN"),t.searchParams.set("start",((a=n.page)==null?void 0:a.toString())||"0"),t.searchParams.set("limit","50");let s=await this.config.request({url:t.toString(),headers:this.getRequestHeaders(e)}),o=s.body.values.length!==0;return{pageInfo:{hasNextPage:o,nextPage:o?s.body.start+s.body.values.length:null},data:s.body.values.map(Oe)}}async closePullRequest(n,e={}){let{pullRequest:t}=n;if(t.version===void 0)throw new Error('Bitbucket Server requires "version" for this function.');if(!(await this.config.request({method:"POST",url:`${this.getBaseUrl(e)}/projects/${t.repository.owner.login}/repos/${t.repository.name}/pull-requests/${t.id}/decline`,body:JSON.stringify({version:t.version}),headers:{...this.getRequestHeaders(e),"Content-Type":"application/json"}})).body.title)throw new Error("Could not close pull request")}async mergePullRequest(n,e={}){let{pullRequest:t,mergeStrategyId:s}=n;if(n.mergeStrategy)throw new Error('Bitbucket Server uses "mergeStrategyId" instead of "mergeStrategy".');if(t.version===void 0)throw new Error('Bitbucket Server requires "version" for this function.');if(!(await this.config.request({method:"POST",url:`${this.getBaseUrl(e)}/projects/${t.repository.owner.login}/repos/${t.repository.name}/pull-requests/${t.id}/merge`,body:JSON.stringify({strategyId:s,version:t.version}),headers:{...this.getRequestHeaders(e),"Content-Type":"application/json"}})).body.title)throw new Error("Could not merge pull request")}async getMergeStrategies(n={}){let e=await this.config.request({url:`${this.getBaseUrl(n)}/admin/pull-requests/git`,headers:{...this.getRequestHeaders(n),"Content-Type":"application/json"}});return{data:{defaultStrategy:e.body.mergeConfig.defaultStrategy,strategies:e.body.mergeConfig.strategies}}}async setPullRequestReviewers(n,e={}){let{pullRequest:t,reviewers:s}=n;if(t.version===void 0)throw new Error('Bitbucket Server requires "version" for this function.');let o={reviewers:s.map(i=>{if(i.username)throw new Error('Bitbucket Server reviewer requires "username" for this function.');return{user:{name:i.username}}}),version:t.version};if(!(await this.config.request({method:"PUT",url:`${this.getBaseUrl(e)}/projects/${t.repository.owner.login}/repos/${t.repository.name}/pull-requests/${t.id}`,body:JSON.stringify(o),headers:{...this.getRequestHeaders(e),"Content-Type":"application/json"}})).body.title)throw new Error("Could not set pull request reviewers")}};var vt=require("js-base64");var pe=(e=>(e.Open="OPEN",e.Closed="CLOSED",e))(pe||{});var R=class extends Error{constructor(e,t){let s=t==null?void 0:t.map(a=>`'${a.message}'`).join(", "),o=s?`${e}: ${s}`:e;super(o);this.graphQLErrors=t??[]}};var Xt={AS_CODE_OWNER:[3,0,0],CHECK_RUN:[3,0,0],LATEST_REVIEWS:[3,0,0],VIEWER_CAN_MERGE_AS_ADMIN:[3,5,0]},Rt=15,bt=100,C=r=>!!r,de=(r,n)=>{let e=Xt[n];for(let t=0;t<3;t++){if(r[t]>e[t])return!0;if(r[t]<e[t])return!1}return!0},ge="https://api.github.com",Zt=`${ge}/graphql`,me=`
1
+ "use strict";var Nt=Object.create;var oe=Object.defineProperty;var Ft=Object.getOwnPropertyDescriptor;var Qt=Object.getOwnPropertyNames;var _t=Object.getPrototypeOf,Bt=Object.prototype.hasOwnProperty;var jt=(r,n)=>{for(var e in n)oe(r,e,{get:n[e],enumerable:!0})},ot=(r,n,e,t)=>{if(n&&typeof n=="object"||typeof n=="function")for(let s of Qt(n))!Bt.call(r,s)&&s!==e&&oe(r,s,{get:()=>n[s],enumerable:!(t=Ft(n,s))||t.enumerable});return r};var Mt=(r,n,e)=>(e=r!=null?Nt(_t(r)):{},ot(n||!r||!r.__esModule?oe(e,"default",{value:r,enumerable:!0}):e,r)),zt=r=>ot(oe({},"__esModule",{value:!0}),r);var Kr={};jt(Kr,{AzureDevOps:()=>J,Bitbucket:()=>K,BitbucketServer:()=>V,EntityIdentifierProviderType:()=>Ot,EntityType:()=>Tt,EntityVersion:()=>Gt,GitBuildStatusStage:()=>at,GitBuildStatusState:()=>ae,GitDiffLineType:()=>$e,GitHub:()=>Z,GitHubIssueCloseReason:()=>xt,GitIssueState:()=>pe,GitLab:()=>ee,GitMergeStrategy:()=>W,GitPullRequestMergeableState:()=>z,GitPullRequestReviewState:()=>M,GitPullRequestState:()=>j,GraphQLErrors:()=>R,Jira:()=>te,JiraServer:()=>re,PullRequestAsyncStatus:()=>At,Trello:()=>se,default:()=>Jr,isFetch:()=>ie});module.exports=zt(Kr);var at=(s=>(s.Build="build",s.Production="production",s.Staging="staging",s.Test="test",s))(at||{}),ae=(p=>(p.ActionRequired="ACTION_REQUIRED",p.Cancelled="CANCELLED",p.Error="ERROR",p.Failed="FAILED",p.Pending="PENDING",p.Running="RUNNING",p.Skipped="SKIPPED",p.Success="SUCCESS",p.Warning="WARNING",p.OptionalActionRequired="OPTIONAL_ACTION_REQUIRED",p))(ae||{}),W=(o=>(o.MergeCommit="MERGE_COMMIT",o.Rebase="REBASE",o.RebaseThenMergeCommit="REBASE_THEN_MERGE_COMMIT",o.FastForward="FAST_FORWARD",o.Squash="SQUASH",o))(W||{}),j=(t=>(t.Open="OPEN",t.Closed="CLOSED",t.Merged="MERGED",t))(j||{}),M=(s=>(s.Approved="APPROVED",s.ChangesRequested="CHANGES_REQUESTED",s.Commented="COMMENTED",s.ReviewRequested="REVIEW_REQUESTED",s))(M||{}),z=(i=>(i.Behind="BEHIND",i.Blocked="BLOCKED",i.Conflicts="CONFLICTS",i.Mergeable="MERGEABLE",i.Unknown="UNKNOWN",i.UnknownAndBlocked="UNKNOWN_AND_BLOCKED",i.Unstable="UNSTABLE",i))(z||{}),$e=(t=>(t.ADDED="ADDED",t.DELETED="DELETED",t.UNMODIFIED="UNMODIFIED",t))($e||{});var it={APPROVED:0,COMMENTED:1,REVIEW_REQUESTED:2,CHANGES_REQUESTED:3},Q=r=>!r||r.length===0?null:r.reduce((n,e)=>it[e.state]>it[n]?e.state:n,"APPROVED");var E=100;var ut=Mt(require("node-fetch")),lt=globalThis.fetch||ut.default;var Ht=async r=>{let n=r.headers.get("content-type")||"",e=null;if(n.startsWith("application/json")){let s=await r.text();e=s.trim().length>0?JSON.parse(s):null}else if(n.startsWith("text/")||n==="")e=await r.text();else if(n.startsWith("application/vnd.github.raw+json"))e=await r.arrayBuffer();else throw new Error(`Unsupported content-type: ${n}`);let t={body:e,headers:Object.fromEntries(r.headers.entries()),status:r.status,statusText:r.statusText};if(!r.ok){let s=new Error(r.statusText);throw Object.assign(s,{response:t}),s}return t},Ae=r=>async({url:n,...e})=>{let t=await r(n,e);return Ht(t)};var ie=(r,n=!1)=>r.name==="fetch"||n;var $=class{constructor(n){let e=(n==null?void 0:n.request)||lt;this.config={...n,request:ie(e,n==null?void 0:n.forceIsFetch)?Ae(e):e}}updateConfig(n){this.config={...this.config,...n,request:n.request&&ie(n.request,(n==null?void 0:n.forceIsFetch)??this.config.forceIsFetch)?Ae(n.request):this.config.request}}},T=class extends ${};var I=(r,n)=>{let e={};return r&&(e.Authorization=`${n?"Basic":"Bearer"} ${r}`),e},pt=r=>r?r.reduce((n,e)=>(n[e]=!0,n),{}):void 0,_=(r,n,e)=>!r||n.some(t=>r[t])?e:"",dt=async r=>{var s,o,a;let n=[],e=!0,t;for(;e;){let i=await r(t);n=n.concat(i.data),e=!!((s=i==null?void 0:i.pageInfo)!=null&&s.hasNextPage),t=((o=i==null?void 0:i.pageInfo)==null?void 0:o.endCursor)||((a=i==null?void 0:i.pageInfo)==null?void 0:a.nextPage)}return n};var P=(r,n={})=>I(n.token||r.token,n.isPAT||r.isPAT),ct=r=>r.url.replace("/_apis/git/repositories/","/_git/").replace(`/${r.repository.project.id}/`,`/${encodeURIComponent(r.repository.project.name)}/`).replace(`/${r.repository.id}/`,`/${encodeURIComponent(r.repository.name)}/`).replace("/pullRequests/","/pullrequest/");var gt="https://app.vssps.visualstudio.com/_apis",q="https://dev.azure.com",Wt={active:"OPEN",completed:"MERGED",abandoned:"CLOSED"},Jt={10:"APPROVED",5:"APPROVED",0:"REVIEW_REQUESTED",[-5]:"CHANGES_REQUESTED",[-10]:"CHANGES_REQUESTED"},Ge=r=>({id:r.id,name:r.displayName??null,username:(r.uniqueName||r.displayName)??null,email:null,avatarUrl:r.imageUrl??null,url:null}),le=r=>r.startsWith("refs/heads/")?r.replace("refs/heads/",""):r,ue=(r,n)=>{var s;let e=[],t=[];return n.reviewers.forEach(o=>{let a={reviewer:Ge(o),state:Jt[o.vote??0]||"REVIEW_REQUESTED"};o.isRequired&&e.push(a),t.push(a)}),{id:n.pullRequestId.toString(),title:n.title,number:n.codeReviewId,state:Wt[n.status],isDraft:n.isDraft,commentCount:null,upvoteCount:null,author:Ge(n.createdBy),createdDate:new Date(n.creationDate),updatedDate:new Date(n.closedDate||n.creationDate),closedDate:n.closedDate?new Date(n.closedDate):null,mergedDate:n.closedDate&&n.status==="completed"?new Date(n.closedDate):null,repository:{id:n.repository.id,name:n.repository.name,project:n.repository.project.name,owner:{login:r},remoteInfo:null},headCommit:{buildStatuses:null},baseRef:{name:le(n.targetRefName),oid:n.lastMergeTargetCommit.commitId},headRef:{name:le(n.sourceRefName),oid:n.lastMergeSourceCommit.commitId},url:ct(n),assignees:n.reviewers.map(Ge),reviews:t,reviewDecision:Q(e),additions:null,deletions:null,fileCount:null,commitCount:null,headRepository:n.forkSource?{id:n.forkSource.repository.id,name:n.forkSource.repository.name,project:void 0,owner:{login:r},remoteInfo:null}:{id:n.repository.id,name:n.repository.name,project:n.repository.project.name,owner:{login:r},remoteInfo:null},mergeableState:"UNKNOWN",labels:((s=n.labels)==null?void 0:s.map(o=>({color:null,description:null,id:o.id,name:o.name})))??[],permissions:null}},mt=(r,n)=>({id:n.id,name:n.name,namespace:r,project:n.project.name,webUrl:n.webUrl,httpsUrl:n.remoteUrl,sshUrl:n.sshUrl,defaultBranch:n.defaultBranch?{name:le(n.defaultBranch)}:null,permission:null}),Kt=(r,n,e,t)=>{var l,p,d,c,g,m;let s=e.fields,o=s["System.AssignedTo"],a=s["System.State"],i=s["System.WorkItemType"],u;return a&&i&&(u=(l=t[i])==null?void 0:l[a]),{id:e.id.toString(),number:e.id.toString(),title:s["System.Title"],commentCount:s["System.CommentCount"],author:{avatarUrl:((d=(p=s["System.CreatedBy"]._links)==null?void 0:p.avatar)==null?void 0:d.href)??null,email:null,id:s["System.CreatedBy"].id,name:s["System.CreatedBy"].uniqueName??null,username:s["System.CreatedBy"].displayName??null,url:null},closedDate:s["Microsoft.VSTS.Common.ClosedDate"]?new Date(s["Microsoft.VSTS.Common.ClosedDate"]):null,createdDate:new Date(s["System.CreatedDate"]),updatedDate:new Date(s["System.ChangedDate"]),url:e._links.html.href,assignees:o?[{avatarUrl:((g=(c=o._links)==null?void 0:c.avatar)==null?void 0:g.href)??null,email:null,id:o.id,name:o.uniqueName??null,username:o.displayName??null,url:null}]:[],description:null,state:{name:(u==null?void 0:u.title)||a,color:null},type:s["System.WorkItemType"],repository:null,project:{namespace:r,name:n,resourceId:null,key:null,id:null},upvoteCount:0,labels:((m=e.fields["System.Tags"])==null?void 0:m.split(";").map(h=>({color:null,description:null,id:null,name:h.trim()})))??[]}},J=class extends ${async getCurrentUser(n={},e={}){if(e.isPAT||this.config.isPAT)throw new Error("Azure DevOps does not support PATs for this function.");let t=await this.config.request({url:`${gt}/profile/profiles/me`,headers: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(n,e={}){let s=(await this.config.request({url:`${q}/${encodeURIComponent(n.namespace)}/_apis/ConnectionData`,headers:P(this.config,e)})).body.authorizedUser;if(s.providerDisplayName==="Anonymous")throw new Error("Current user not found.");return{data:{id:s.id,name:s.providerDisplayName,username:s.providerDisplayName,email:s.properties.Account.$value,avatarUrl:null}}}async getUserForCommit(n,e={}){if(!n.repo.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let s=(await this.config.request({url:`${q}/${encodeURIComponent(n.repo.namespace)}/${encodeURIComponent(n.repo.project)}/_apis/git/repositories/${encodeURIComponent(n.repo.name)}/commits/${n.oid}`,headers:P(this.config,e)})).body.author;return{data:{name:s.name,email:s.email,avatarUrl:s.imageUrl}}}async getOrgsForUser(n,e={}){return{data:(await this.config.request({url:`${gt}/accounts?memberId=${n.userId}&api-version=6.0`,headers:P(this.config,e)})).body.value.map(s=>({id:s.accountId,name:s.accountName}))}}async getAzureProjects(n,e={}){let t=new URL(`${q}/${encodeURIComponent(n.namespace)}/_apis/projects`);t.searchParams.set("$top",E.toString()),n.cursor&&t.searchParams.set("$skip",n.cursor);let s=await this.config.request({url:t.toString(),headers:P(this.config,e)}),o=s.headers["x-ms-continuationtoken"];return{pageInfo:{hasNextPage:!!o,endCursor:o||null},data:s.body.value.map(a=>({id:a.id,name:a.name,namespace:n.namespace}))}}async getAzureProjectScopeDescriptor(n,e={}){let{namespace:t,projectId:s}=n;return{data:{scope:(await this.config.request({url:`https://vssps.dev.azure.com/${encodeURIComponent(t)}/_apis/graph/descriptors/${s}?api-version=6.0`,headers:P(this.config,e)})).body.value}}}async getAzureGraphAccountsForAzureProject(n,e={}){let{namespace:t,projectScopeDescriptor:s,cursor:o}=n,a=new URL(`https://vssps.dev.azure.com/${encodeURIComponent(t)}/_apis/graph/users`);s&&a.searchParams.set("scopeDescriptor",s),o&&a.searchParams.set("continuationToken",o);let i=await this.config.request({url:a.toString(),headers: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,d,c,g;return{avatarUrl:((d=(p=l._links)==null?void 0:p.avatar)==null?void 0:d.href)??null,descriptor:l.descriptor??null,email:l.mailAddress??null,name:l.displayName??null,storageKeyURL:((g=(c=l._links)==null?void 0:c.storageKey)==null?void 0:g.href)??null,username:l.displayName??null}})}}async getAccountFromAzureGraphAccount(n,e={}){let{azureGraphAccount:t}=n;if(!t.storageKeyURL)throw new Error("Expected 'storageKeyURL' to not be null for 'azureGraphAccount'");let s=await this.config.request({url:t.storageKeyURL,headers:P(this.config,e)});return{data:{avatarUrl:t.avatarUrl,email:t.email,id:s.body.value,name:t.name,username:t.username,url:null}}}async getAccountsFromAzureGraphAccounts(n,e={}){let t=[];for(let s of n.azureGraphAccounts){let o=await this.getAccountFromAzureGraphAccount({azureGraphAccount:s},e);t.push(o.data)}return{data:t}}async getRepo(n,e={}){if(!n.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let t=await this.config.request({url:`${q}/${encodeURIComponent(n.namespace)}/${encodeURIComponent(n.project)}/_apis/git/repositories/${encodeURIComponent(n.name)}`,headers:P(this.config,e)});return{data:mt(n.namespace,t.body)}}async getRepos(n,e={}){let t=[],s=[];return await Promise.all(n.map(async o=>{try{let a=await this.getRepo(o,e);t.push(a.data)}catch(a){s.push({input:o,error:a})}})),{data:t,errors:s}}async getReposForAzureProject(n,e={}){if(!n.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');return{data:(await this.config.request({url:`${q}/${encodeURIComponent(n.namespace)}/${encodeURIComponent(n.project)}/_apis/git/repositories`,headers:P(this.config,e)})).body.value.map(s=>mt(n.namespace,s))}}async getRefs(n,e,t={}){if(!e.repo.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let s=new URL(`${q}/${encodeURIComponent(e.repo.namespace)}/${encodeURIComponent(e.repo.project)}/_apis/git/repositories/${encodeURIComponent(e.repo.name)}/refs`);s.searchParams.set("filter",n),s.searchParams.set("$top",E.toString()),e.cursor&&s.searchParams.set("continuationToken",e.cursor);let o=await this.config.request({url:s.toString(),headers:P(this.config,t)}),a=o.headers["x-ms-continuationtoken"];return{pageInfo:{hasNextPage:!!a,endCursor:a||null},data:o.body.value.map(i=>({name:le(i.name),commit:{oid:i.objectId,authoredDate:null,committedDate:null}}))}}async getBranches(n,e={}){return this.getRefs("heads",n,e)}async getTags(n,e={}){return this.getRefs("tags",n,e)}async getPullRequestsForRepoBase(n,e={},t=100){let{page:s,repo:o,assigneeLogins:a,authorLogin:i}=n||{},u=s||1;if(!o.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let l="searchCriteria.status=1";return a&&a.length&&(l+=`&searchCriteria.reviewerId=${a[0]}`),i&&(l+=`&searchCriteria.creatorId=${i}`),await this.config.request({url:`${e.baseUrl||q}/${encodeURIComponent(o.namespace)}/${encodeURIComponent(o.project||"")}/_apis/git/repositories/${encodeURIComponent(o.name)}/pullRequests?${l}&%24top=${t}&%24skip=${(u-1)*t}`,headers:P(this.config,e)})}async getPullRequestsForRepo(n,e={}){let s=n.page||1,o=await this.getPullRequestsForRepoBase(n,e,100);return{pageInfo:{hasNextPage:o.body.value.length===100,nextPage:s+1},data:o.body.value.map(a=>ue(n.repo.namespace,a))}}async getPullRequestsForRepos(n,e={}){if(!n.repos.every(o=>o.project))throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let{repos:t}=n||{},s=[];return await Promise.all(t.map(async o=>{try{(await this.getPullRequestsForRepoBase({repo:o,...n},e)).body.value.forEach(i=>{s.push(ue(o.namespace,i))})}catch(a){if(a.statusCode!==404&&a.statusCode!==401)throw a}})),{data:s}}async getPullRequestsForProjectBase(n,e={},t=100){let{namespace:s,project:o,page:a,assigneeLogins:i,authorLogin:u}=n,l=a||1,p=new URL(`${e.baseUrl||q}/${encodeURIComponent(s)}/${encodeURIComponent(o)}/_apis/git/pullRequests`);return p.searchParams.set("searchCriteria.status","1"),p.searchParams.set("$top",t.toString()),p.searchParams.set("$skip",((l-1)*t).toString()),i&&i.length&&p.searchParams.set("searchCriteria.reviewerId",i[0]),u&&p.searchParams.set("searchCriteria.creatorId",u),await this.config.request({url:p.toString(),headers:P(this.config,e)})}async getPullRequestsForProject(n,e={}){let s=n.page||1,o=await this.getPullRequestsForProjectBase(n,e,100);return{pageInfo:{hasNextPage:o.body.value.length===100,nextPage:s+1},data:o.body.value.map(a=>ue(n.namespace,a))}}async getPullRequestsForProjects(n,e={}){let{projects:t}=n||{},s=[];return await Promise.all(t.map(async o=>{try{(await this.getPullRequestsForProjectBase({...o,...n},e)).body.value.forEach(i=>{s.push(ue(o.namespace,i))})}catch(a){if(a.statusCode!==404&&a.statusCode!==401)throw a}})),{data:s}}async getAzurePullRequestLastMergeStatus(n,e={}){if(!n.repo.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let{repo:{namespace:t,project:s,name:o},pullRequestId:a}=n,i=await this.config.request({url:`${e.baseUrl||q}/${encodeURIComponent(t)}/${encodeURIComponent(s||"")}/_apis/git/repositories/${o}/pullrequests/${a}?includeCommits=true?api-version=6.0`,headers:{...P(this.config,e)}});if(!i.body.mergeStatus)throw new Error("Could not fetch pull request");return{data:i.body.mergeStatus}}async updatePullRequest(n,e,t){return await this.config.request({method:"PATCH",url:`${t.baseUrl||q}/${encodeURIComponent(n.repository.owner.login)}/${encodeURIComponent(n.repository.project)}/_apis/git/repositories/${n.repository.name}/pullrequests/${n.id}?api-version=6.0`,body:e,headers:{...P(this.config,t),"Content-Type":"application/json"}})}async closePullRequest(n,e={}){let{pullRequest:t}=n,s={status:"abandoned"};if(!(await this.updatePullRequest(t,JSON.stringify(s),e)).body.status)throw new Error("Could not close pull request")}async mergePullRequest(n,e={}){var u;let{pullRequest:t,mergeStrategy:s}=n,o;switch(s){case"MERGE_COMMIT":{o="noFastForward";break}case"REBASE":{o="rebase";break}case"REBASE_THEN_MERGE_COMMIT":{o="rebaseMerge";break}case"SQUASH":{o="squash";break}}let a={completionOptions:{mergeStrategy:o},lastMergeSourceCommit:{commitId:(u=t.headRef)==null?void 0:u.oid},status:"completed"};if(!(await this.updatePullRequest(t,JSON.stringify(a),e)).body.status)throw new Error("Could not merge pull request")}async addPullRequestLabel(n,e={}){let{pullRequest:t,label:s}=n;if(!t.repository.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let o={name:s.name};if(!(await this.config.request({method:"POST",url:`${e.baseUrl||q}/${encodeURIComponent(t.repository.owner.login)}/${encodeURIComponent(t.repository.project)}/_apis/git/repositories/${t.repository.name}/pullrequests/${t.id}/labels?api-version=6.0`,body:JSON.stringify(o),headers:{...P(this.config,e),"Content-Type":"application/json"}})).body.id)throw new Error("Could not add pull request label")}async removePullRequestLabel(n,e={}){let{pullRequest:t,label:s}=n;if(!t.repository.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');await this.config.request({method:"DELETE",url:`${e.baseUrl||q}/${encodeURIComponent(t.repository.owner.login)}/${encodeURIComponent(t.repository.project)}/_apis/git/repositories/${t.repository.name}/pullrequests/${t.id}/labels/${encodeURIComponent(s.name)}?api-version=6.0`,headers:{...P(this.config,e)}})}async setPullRequestLabels(n,e={}){let{pullRequest:t,labels:s}=n;if(!t.repository.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let o=t.labels;if(!o)throw new Error('Azure DevOps requires "labels" for this function.');for(let a of s)o.find(i=>i.id===a.id)||await this.addPullRequestLabel({pullRequest:t,label:a},e);for(let a of o)s.find(i=>a.id===i.id)||await this.removePullRequestLabel({pullRequest:t,label:a},e)}async setPullRequestAsDraft(n,e={}){let{pullRequest:t,isDraft:s}=n,o={isDraft:s};if(!(await this.updatePullRequest(t,JSON.stringify(o),e)).body.status)throw new Error("Could not set the pull request as draft")}async addPullRequestReviewer(n,e={}){let{pullRequest:t,reviewer:s,isRequired:o}=n,a={id:s.id,isRequired:o};if(!(await this.config.request({method:"PUT",url:`${e.baseUrl||q}/${encodeURIComponent(t.repository.owner.login)}/${encodeURIComponent(t.repository.project)}/_apis/git/repositories/${t.repository.name}/pullrequests/${t.id}/reviewers/${s.id}?api-version=6.0`,body:JSON.stringify(a),headers:{...P(this.config,e),"Content-Type":"application/json"}})).body.id)throw new Error("Could not add pull request reviewer")}async removePullRequestReviewer(n,e={}){let{pullRequest:t,reviewer:s}=n;await this.config.request({method:"DELETE",url:`${e.baseUrl||q}/${encodeURIComponent(t.repository.owner.login)}/${encodeURIComponent(t.repository.project)}/_apis/git/repositories/${t.repository.name}/pullrequests/${t.id}/reviewers/${s.id}?api-version=6.0`,headers:{...P(this.config,e),Accept:"application/json"}})}async setPullRequestReviewers(n,e={}){let{pullRequest:t,reviewers:s}=n;for(let o of s)t.assignees.find(a=>a.id===o.id)||await this.addPullRequestReviewer({pullRequest:t,reviewer:o,isRequired:!0},e);for(let o of t.assignees)s.find(a=>o.id===a.id)||await this.removePullRequestReviewer({pullRequest:t,reviewer:o},e)}async getIssuesForAzureProject(n,e={}){let{page:t,assigneeLogins:s,authorLogin:o,mentionLogin:a,labelNames:i,statusByWorkItemIdByStatusId:u}=n||{},l=t||1,p=200,d=["[Microsoft.VSTS.Common.ClosedDate] = ''","[System.TeamProject] = @project","[Microsoft.VSTS.Common.ResolvedDate] = ''"];o&&d.push(`[System.CreatedBy] = '${o.replace("'","''")}'`),s&&s[0]&&d.push(`[System.AssignedTo] = '${s[0].replace("'","''")}'`),a&&d.push("[System.Id] IN (@recentMentions)"),i&&i.forEach(y=>d.push(`[System.Tags] Contains '${y}'`));let c=`Select [Microsoft.VSTS.Common.ClosedDate], [Microsoft.VSTS.Common.ResolvedDate] From WorkItems Where ${d.join(" AND ")} order by [System.CreatedDate] desc`,g=await this.config.request({url:`${e.baseUrl||q}/${encodeURIComponent(n.namespace)}/${encodeURIComponent(n.project)}/_apis/wit/wiql?api-version=6.0`,body:JSON.stringify({query:c}),method:"POST",headers:{...P(this.config,e),"Content-Type":"application/json"}}),m=g.body.workItems.slice((l-1)*p,p*l).map(y=>y.id);if(m.length==0)return{pageInfo:{hasNextPage:!1,nextPage:null},data:[]};let h=await this.config.request({url:`${e.baseUrl||q}/${encodeURIComponent(n.namespace)}/${encodeURIComponent(n.project)}/_apis/wit/workitemsbatch?api-version=6.0`,body:JSON.stringify({ids:m,$expand:"Links"}),method:"POST",headers:{...P(this.config,e),"Content-Type":"application/json"}});return{pageInfo:{hasNextPage:g.body.workItems.length>p*l,nextPage:l+1},data:h.body.value.map(y=>Kt(n.namespace,n.project,y,u||{}))}}async updateIssue(n,e,t={}){return await this.config.request({method:"PATCH",url:`${t.baseUrl||q}/${encodeURIComponent(n.project.namespace)}/${encodeURIComponent(n.project.name)}/_apis/wit/workitems/${n.id}?api-version=6.0`,body:JSON.stringify(e),headers:{...P(this.config,t),"Content-Type":"application/json-patch+json"}})}async setIssueStatus(n,e={}){var i;let{issue:t,status:s}=n,o=[{op:"add",path:"/fields/System.State",value:s.name}];if(!((i=(await this.updateIssue(t,o,e)).body.fields)!=null&&i["System.State"]))throw new Error("Could not set issue status")}async setIssueAssignee(n,e={}){var i;let{issue:t,assignee:s}=n,o=[{op:"add",path:"/fields/System.AssignedTo",value:(s==null?void 0:s.name)??""}];if(!((i=(await this.updateIssue(t,o,e)).body.fields)!=null&&i["System.State"]))throw new Error("Could not set issue assignee")}async setIssueLabels(n,e={}){var u;let{issue:t,labels:s}=n,a=[{op:"replace",path:"/fields/System.Tags",value:s.map(l=>l.name).join(";")}];if(!((u=(await this.updateIssue(t,a,e)).body.fields)!=null&&u["System.Tags"]))throw new Error("Could not set issue tags")}async getIssueTypesForAzureProject(n,e={}){if(!n.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let{namespace:t,project:s}=n;return{data:(await this.config.request({url:`${e.baseUrl||q}/${encodeURIComponent(t)}/${encodeURIComponent(s||"")}/_apis/wit/workitemtypes?api-version=6.0`,headers:{...P(this.config,e)}})).body.value}}async getLabelsForProject(n,e={}){let{namespace:t,project:s}=n;return{data:(await this.config.request({url:`${e.baseUrl||q}/${encodeURIComponent(t)}/${encodeURIComponent(s||"")}/_apis/wit/tags?api-version=6.0`,headers:{...P(this.config,e)}})).body.value.map(a=>({color:null,description:null,id:a.id,name:a.name,url:a.url}))}}};var D=(r,n={})=>I(n.token||r.token,n.isPAT||r.isPAT);var U="https://api.bitbucket.org/2.0",Vt={OPEN:"OPEN",MERGED:"MERGED",DECLINED:"CLOSED"},ft=r=>({id:r.uuid,name:r.display_name||r.nickname,username:r.nickname||r.display_name,email:null,avatarUrl:r.links.avatar.href,url:r.links.html.href}),ht=r=>{var n,e;return{id:r.uuid,namespace:r.workspace.slug,name:r.slug,webUrl:r.links.html.href,httpsUrl:((n=r.links.clone.find(t=>t.name==="https"))==null?void 0:n.href)??null,sshUrl:((e=r.links.clone.find(t=>t.name==="ssh"))==null?void 0:e.href)??null,defaultBranch:{name:r.mainbranch.name},permission:null}},Te=r=>{let n=r.id;return{id:n.toString(),title:r.title,number:n,state:Vt[r.state],isDraft:!1,commentCount:r.comment_count,upvoteCount:null,author:ft(r.author),createdDate:new Date(r.created_on),updatedDate:new Date(r.updated_on),closedDate:null,mergedDate:null,repository:{id:r.destination.repository.uuid,name:r.destination.repository.name,owner:{login:r.destination.repository.full_name.split("/")[0]},remoteInfo:null},headCommit:{buildStatuses:null},baseRef:{name:r.destination.branch.name,oid:r.destination.commit.hash},headRef:{name:r.source.branch.name,oid:r.source.commit.hash},url:r.links.html.href,assignees:null,reviews:null,reviewDecision:null,additions:null,deletions:null,fileCount:null,commitCount:null,headRepository:null,mergeableState:"UNKNOWN",permissions:null}},K=class extends ${async refreshToken(n){return{data:(await this.config.request({url:"https://bitbucket.org/site/oauth2/access_token",method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded",Authorization:`Basic ${n.base64ClientIDColonClientSecret}`},body:`grant_type=refresh_token&refresh_token=${n.refreshToken}`})).body}}async getCurrentUser(n={},e={}){let t=await this.config.request({url:`${U}/user`,headers:D(this.config,e)});return{data:ft(t.body)}}async getUserForCommit(n,e={}){var a;let s=(await this.config.request({url:`${U}/repositories/${n.repo.namespace}/${n.repo.name}/commit/${n.oid}`,headers:D(this.config,e)})).body.author,o=s.raw.match(/([^<]+)<(.+)>/);return{data:{name:o?o[1].trim():null,email:o?o[2]:null,avatarUrl:((a=s.user)==null?void 0:a.links.avatar.href)||null}}}async getRepo(n,e={}){let t=await this.config.request({url:`${U}/repositories/${n.namespace}/${n.name}`,headers:D(this.config,e)});return{data:ht(t.body)}}async getRepos(n,e={}){let t=[],s=[];return await Promise.all(n.map(async o=>{try{let a=await this.getRepo(o,e);t.push(a.data)}catch(a){s.push({input:o,error:a})}})),{data:t,errors:s}}async getReposForCurrentUser(n,e={}){let t=new URL(`${U}/repositories`);t.searchParams.set("role","member"),t.searchParams.set("pagelen",E.toString()),n.cursor&&t.searchParams.set("after",n.cursor);let s=await this.config.request({url:t.toString(),headers:D(this.config,e)}),o=!!s.body.next,a=null;return s.body.next&&(a=new URL(s.body.next).searchParams.get("after")),{pageInfo:{hasNextPage:o,endCursor:a},data:s.body.values.map(ht)}}async getBranches(n,e={}){var a;let t=new URL(`${U}/repositories/${n.repo.namespace}/${n.repo.name}/refs/branches`);t.searchParams.set("page",((a=n.page)==null?void 0:a.toString())||"1"),t.searchParams.set("pagelen",E.toString());let s=await this.config.request({url:t.toString(),headers:D(this.config,e)}),o=!!s.body.next;return{pageInfo:{hasNextPage:o,nextPage:o?s.body.page+1:null},data:s.body.values.map(i=>{let u=new Date(i.target.date);return{name:i.name,commit:{oid:i.target.hash,authoredDate:u,committedDate:u}}})}}async getTags(n,e={}){let t=new URL(`${U}/repositories/${n.repo.namespace}/${n.repo.name}/refs/tags`);t.searchParams.set("pagelen",E.toString()),n.cursor&&t.searchParams.set("page",n.cursor);let s=await this.config.request({url:t.toString(),headers:D(this.config,e)}),o=!!s.body.next,a=null;return s.body.next&&(a=new URL(s.body.next).searchParams.get("page")),{pageInfo:{hasNextPage:o,endCursor:a},data:s.body.values.map(i=>{let u=new Date(i.target.date);return{name:i.name,commit:{oid:i.target.hash,authoredDate:u,committedDate:u}}})}}async getWorkspacesForUser(n,e={}){var a;let t=new URL(`${U}/user/permissions/workspaces`);t.searchParams.set("page",((a=n.page)==null?void 0:a.toString())||"1"),t.searchParams.set("pagelen","50");let s=await this.config.request({url:t.toString(),headers:D(this.config,e)}),o=!!s.body.next;return{pageInfo:{hasNextPage:o,nextPage:o?s.body.page+1:null},data:s.body.values.map(i=>({id:i.workspace.uuid,slug:i.workspace.slug,name:i.workspace.name}))}}async getPullRequestsForUserAndWorkspace(n,e={}){var a;let t=new URL(`${U}/workspaces/${n.workspaceSlug}/pullrequests/${n.userId}`);t.searchParams.set("page",((a=n.page)==null?void 0:a.toString())||"1"),t.searchParams.set("pagelen","50");let s=await this.config.request({url:t.toString(),headers:D(this.config,e)}),o=!!s.body.next;return{pageInfo:{hasNextPage:o,nextPage:o?s.body.page+1:null},data:s.body.values.map(Te)}}async getPullRequestsForRepoBase(n,e={}){var s;let t=new URL(`${U}/repositories/${encodeURI(n.repo.namespace)}/${encodeURI(n.repo.name)}/pullrequests?state=OPEN`);return t.searchParams.set("page",((s=n.page)==null?void 0:s.toString())||"1"),t.searchParams.set("pagelen","50"),await this.config.request({url:t.toString(),headers:D(this.config,e)})}async getPullRequestsForRepo(n,e={}){let t=[],s=await this.getPullRequestsForRepoBase(n,e);s.body.values.forEach(a=>{if(n.authorLogin&&a.author.uuid!==n.authorLogin)return null;t.push(Te(a))});let o=!!s.body.next;return{pageInfo:{hasNextPage:o,nextPage:o?s.body.page+1:null},data:t}}async getPullRequestsForRepos(n,e={}){let t=[];return await Promise.all(n.repos.map(async s=>{try{(await this.getPullRequestsForRepoBase({repo:s,...n},e)).body.values.forEach(a=>{if(n.authorLogin&&a.author.uuid!==n.authorLogin)return null;t.push(Te(a))})}catch(o){if(o.statusCode!==404&&o.statusCode!==401)throw o}})),{data:t}}async closePullRequest(n,e={}){let{pullRequest:t}=n;if(!(await this.config.request({method:"POST",url:`${U}/repositories/${t.repository.owner.login}/${t.repository.name}/pullrequests/${t.id}/decline`,headers:D(this.config,e)})).body.title)throw new Error("Could not close pull request")}async mergePullRequest(n,e={}){let{pullRequest:t,mergeStrategy:s}=n,o;switch(s){case"MERGE_COMMIT":{o="merge_commit";break}case"FAST_FORWARD":{o="fast_forward";break}case"SQUASH":{o="squash";break}}let a={merge_strategy:o,type:"pullrequest"};if(!(await this.config.request({method:"POST",url:`${U}/repositories/${t.repository.owner.login}/${t.repository.name}/pullrequests/${t.id}/merge`,body:JSON.stringify(a),headers:{...D(this.config,e),"Content-Type":"application/json"}})).body.title)throw new Error("Could not merge pull request")}async setPullRequestReviewers(n,e={}){let{pullRequest:t,reviewers:s}=n,o={reviewers:s.map(i=>{if(i.username)throw new Error('Bitbucket reviewer requires "username" for this function.');return{username:i.username}})};if(!(await this.config.request({method:"PUT",url:`${U}/repositories/${t.repository.owner.login}/${t.repository.name}/pullrequests/${t.id}`,body:JSON.stringify(o),headers:{...D(this.config,e),"Content-Type":"application/json"}})).body.title)throw new Error("Could not set pull request reviewers")}};var xe=r=>({name:r.displayName,email:r.emailAddress,avatarUrl:r.avatarUrl??null,id:r.id.toString(),username:r.name,url:r.links.self[0].href}),Oe=r=>{var u,l,p,d,c,g;let n={OPEN:"OPEN",MERGED:"MERGED",DECLINED:"CLOSED"},e={UNAPPROVED:"REVIEW_REQUESTED",NEEDS_WORK:"CHANGES_REQUESTED",APPROVED:"APPROVED"},t=r.reviewers.map(m=>({reviewer:xe(m.user),state:e[m.status]})),s=((u=r.toRef.repository.links.clone.find(m=>m.name==="ssh"))==null?void 0:u.href)??null,o=((l=r.toRef.repository.links.clone.find(m=>m.name==="https"))==null?void 0:l.href)??null;o||(o=((p=r.toRef.repository.links.clone.find(m=>m.name==="http"))==null?void 0:p.href)??null);let a=((d=r.fromRef.repository.links.clone.find(m=>m.name==="ssh"))==null?void 0:d.href)??null,i=((c=r.fromRef.repository.links.clone.find(m=>m.name==="https"))==null?void 0:c.href)??null;return i||(i=((g=r.fromRef.repository.links.clone.find(m=>m.name==="http"))==null?void 0:g.href)??null),{id:r.id.toString(),number:r.id,title:r.title,url:r.links.self[0].href,state:n[r.state],isDraft:!1,createdDate:new Date(r.createdDate),updatedDate:new Date(r.updatedDate),closedDate:r.closedDate?new Date(r.closedDate):null,mergedDate:r.state=="MERGED"&&r.closedDate?new Date(r.closedDate):null,baseRef:{name:r.toRef.displayId,oid:r.toRef.latestCommit},headRef:{name:r.fromRef.displayId,oid:r.fromRef.latestCommit},commentCount:r.properties.commentCount,upvoteCount:null,commitCount:null,fileCount:null,additions:null,deletions:null,author:xe(r.author.user),assignees:null,reviews:t,reviewDecision:Q(t),repository:{id:r.toRef.repository.id.toString(),name:r.toRef.repository.name,owner:{login:r.toRef.repository.project.key},remoteInfo:o&&s?{cloneUrlHTTPS:o,cloneUrlSSH:s}:null},headRepository:{id:r.fromRef.repository.id.toString(),name:r.fromRef.repository.name,owner:{login:r.fromRef.repository.project.key},remoteInfo:i&&a?{cloneUrlHTTPS:i,cloneUrlSSH:a}:null},headCommit:null,mergeableState:"UNKNOWN",permissions:null,version:r.version}},It=r=>{var n,e,t;return{id:r.id.toString(),namespace:r.project.key,name:r.slug,webUrl:((n=r.links.self[0])==null?void 0:n.href)??null,httpsUrl:((e=r.links.clone.find(s=>s.name==="https"||s.name==="http"))==null?void 0:e.href)??null,sshUrl:((t=r.links.clone.find(s=>s.name==="ssh"))==null?void 0:t.href)??null,defaultBranch:null,permission:null}},V=class extends T{getBaseUrl(n){let e=n.baseUrl||this.config.baseUrl;if(!e)throw new Error('Bitbucket Server requires "baseUrl"');return e}getRequestHeaders(n){return I(n.token||this.config.token)}async getCurrentUser(n={},e={}){let t=await this.config.request({url:`${this.getBaseUrl(e)}/users?limit=2`,headers:this.getRequestHeaders(e)}),{headers:{"x-auserid":s,"x-ausername":o}}=t,a=s?parseInt(s,10):null,i=decodeURIComponent(o),l=(await this.config.request({url:`${this.getBaseUrl(e)}/users?filter=${o}&avatarSize=64`,headers:this.getRequestHeaders(e)})).body.values.find(({emailAddress:p,id:d,name:c,slug:g})=>a?a===d:i===c||i===p||i===g);if(!l)throw new Error("Could not find current Bitbucket Server user");return{data:xe(l)}}async getRepo(n,e={}){let t=await this.config.request({url:`${this.getBaseUrl(e)}/projects/${n.namespace}/repos/${n.name}`,headers:this.getRequestHeaders(e)});return{data:It(t.body)}}async getRepos(n,e={}){let t=[],s=[];return await Promise.all(n.map(async o=>{try{let a=await this.getRepo(o,e);t.push(a.data)}catch(a){s.push({input:o,error:a})}})),{data:t,errors:s}}async getReposForCurrentUser(n,e={}){let t=n.page??0,s=await this.config.request({url:`${this.getBaseUrl(e)}/repos?start=${t}`,headers:this.getRequestHeaders(e)});return{pageInfo:{hasNextPage:!s.body.isLastPage,nextPage:s.body.nextPageStart},data:s.body.values.map(It)}}async getPullRequestsForRepoBase(n,e={}){var s;let t=new URL(`${this.getBaseUrl(e)}/projects/${encodeURI(n.repo.namespace)}/repos/${encodeURI(n.repo.name)}/pull-requests?state=OPEN`);return t.searchParams.set("start",((s=n.page)==null?void 0:s.toString())||"0"),t.searchParams.set("limit","50"),await this.config.request({url:t.toString(),headers:this.getRequestHeaders(e)})}async getPullRequestsForRepo(n,e={}){let t=[],s=await this.getPullRequestsForRepoBase(n,e);s.body.values.forEach(a=>{if(n.authorLogin&&a.author.user.name!==n.authorLogin)return null;t.push(Oe(a))});let o=s.body.values.length!==0;return{pageInfo:{hasNextPage:o,nextPage:o?s.body.start+s.body.values.length:null},data:t}}async getPullRequestsForRepos(n,e={}){let t=[];return await Promise.all(n.repos.map(async s=>{try{(await this.getPullRequestsForRepoBase({repo:s,...n},e)).body.values.forEach(a=>{if(n.authorLogin&&a.author.user.name!==n.authorLogin)return null;t.push(Oe(a))})}catch(o){if(o.statusCode!==404&&o.statusCode!==401)throw o}})),{data:t}}async getPullRequestsForCurrentUser(n,e={}){var a;let t=new URL(`${this.getBaseUrl(e)}/dashboard/pull-requests`);t.searchParams.set("state","OPEN"),t.searchParams.set("start",((a=n.page)==null?void 0:a.toString())||"0"),t.searchParams.set("limit","50");let s=await this.config.request({url:t.toString(),headers:this.getRequestHeaders(e)}),o=s.body.values.length!==0;return{pageInfo:{hasNextPage:o,nextPage:o?s.body.start+s.body.values.length:null},data:s.body.values.map(Oe)}}async closePullRequest(n,e={}){let{pullRequest:t}=n;if(t.version===void 0)throw new Error('Bitbucket Server requires "version" for this function.');if(!(await this.config.request({method:"POST",url:`${this.getBaseUrl(e)}/projects/${t.repository.owner.login}/repos/${t.repository.name}/pull-requests/${t.id}/decline`,body:JSON.stringify({version:t.version}),headers:{...this.getRequestHeaders(e),"Content-Type":"application/json"}})).body.title)throw new Error("Could not close pull request")}async mergePullRequest(n,e={}){let{pullRequest:t,mergeStrategyId:s}=n;if(n.mergeStrategy)throw new Error('Bitbucket Server uses "mergeStrategyId" instead of "mergeStrategy".');if(t.version===void 0)throw new Error('Bitbucket Server requires "version" for this function.');if(!(await this.config.request({method:"POST",url:`${this.getBaseUrl(e)}/projects/${t.repository.owner.login}/repos/${t.repository.name}/pull-requests/${t.id}/merge`,body:JSON.stringify({strategyId:s,version:t.version}),headers:{...this.getRequestHeaders(e),"Content-Type":"application/json"}})).body.title)throw new Error("Could not merge pull request")}async getMergeStrategies(n={}){let e=await this.config.request({url:`${this.getBaseUrl(n)}/admin/pull-requests/git`,headers:{...this.getRequestHeaders(n),"Content-Type":"application/json"}});return{data:{defaultStrategy:e.body.mergeConfig.defaultStrategy,strategies:e.body.mergeConfig.strategies}}}async setPullRequestReviewers(n,e={}){let{pullRequest:t,reviewers:s}=n;if(t.version===void 0)throw new Error('Bitbucket Server requires "version" for this function.');let o={reviewers:s.map(i=>{if(i.username)throw new Error('Bitbucket Server reviewer requires "username" for this function.');return{user:{name:i.username}}}),version:t.version};if(!(await this.config.request({method:"PUT",url:`${this.getBaseUrl(e)}/projects/${t.repository.owner.login}/repos/${t.repository.name}/pull-requests/${t.id}`,body:JSON.stringify(o),headers:{...this.getRequestHeaders(e),"Content-Type":"application/json"}})).body.title)throw new Error("Could not set pull request reviewers")}};var vt=require("js-base64");var pe=(e=>(e.Open="OPEN",e.Closed="CLOSED",e))(pe||{});var R=class extends Error{constructor(e,t){let s=t==null?void 0:t.map(a=>`'${a.message}'`).join(", "),o=s?`${e}: ${s}`:e;super(o);this.graphQLErrors=t??[]}};var Xt={AS_CODE_OWNER:[3,0,0],CHECK_RUN:[3,0,0],LATEST_REVIEWS:[3,0,0],VIEWER_CAN_MERGE_AS_ADMIN:[3,5,0]},Rt=15,bt=100,C=r=>!!r,de=(r,n)=>{let e=Xt[n];for(let t=0;t<3;t++){if(r[t]>e[t])return!0;if(r[t]<e[t])return!1}return!0},ge="https://api.github.com",Zt=`${ge}/graphql`,me=`
2
2
  description
3
3
  dueOn
4
4
  id
@@ -103,6 +103,9 @@ export interface AzurePullRequest {
103
103
  repository: RepositoryBase & {
104
104
  project: ProjectBase;
105
105
  };
106
+ forkSource?: {
107
+ repository: RepositoryBase;
108
+ };
106
109
  pullRequestId: number;
107
110
  codeReviewId: number;
108
111
  status: PullRequestState;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gitkraken/provider-apis",
3
- "version": "0.26.0",
3
+ "version": "0.26.1",
4
4
  "description": "An SDK around different third-party APIs that accepts and returns data in a common format.",
5
5
  "author": "Axosoft, LLC dba GitKraken",
6
6
  "license": "SEE LICENSE IN LICENSE",