@gitkraken/provider-apis 0.23.0 → 0.24.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,42 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.24.0
4
+
5
+ ### ⚠️ Breaking Changes
6
+
7
+ Changed some fields on the `AzureGraphAccount` to be nullish to better reflect what the Azure DevOps REST API is sending us.
8
+
9
+ Old version of the type:
10
+ ```ts
11
+ interface AzureGraphAccount {
12
+ descriptor: string;
13
+ name: string;
14
+ storageKeyURL: string;
15
+ username: string;
16
+
17
+ // these fields were already nullish in the old version of the type
18
+ avatarUrl: string | null;
19
+ email: string | null;
20
+ }
21
+ ```
22
+
23
+ New version of the type:
24
+ ```ts
25
+ interface AzureGraphAccount {
26
+ descriptor: string | null;
27
+ name: string | null;
28
+ storageKeyURL: string | null;
29
+ username: string | null;
30
+
31
+ avatarUrl: string | null;
32
+ email: string | null;
33
+ }
34
+ ```
35
+
36
+ ## 0.23.1
37
+
38
+ - added the `project.id` field to the `Issue` type (Jira, Jira Server)
39
+
3
40
  ## 0.23.0
4
41
 
5
42
  - added `getIssuesForProjects` function (Jira, Jira Server)
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- "use strict";var Pr=Object.create;var pe=Object.defineProperty;var Er=Object.getOwnPropertyDescriptor;var vr=Object.getOwnPropertyNames;var qr=Object.getPrototypeOf,Sr=Object.prototype.hasOwnProperty;var x=(s,e)=>{for(var t in e)pe(s,t,{get:e[t],enumerable:!0})},Qt=(s,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of vr(e))!Sr.call(s,n)&&n!==t&&pe(s,n,{get:()=>e[n],enumerable:!(r=Er(e,n))||r.enumerable});return s};var Cr=(s,e,t)=>(t=s!=null?Pr(qr(s)):{},Qt(e||!s||!s.__esModule?pe(t,"default",{value:s,enumerable:!0}):t,s)),Dr=s=>Qt(pe({},"__esModule",{value:!0}),s);var Fs={};x(Fs,{AzureDevOps:()=>ee,AzureDevopsUtils:()=>Te,Bitbucket:()=>te,BitbucketServer:()=>se,BitbucketServerUtils:()=>xe,BitbucketUtils:()=>Oe,EntityIdentifierProviderType:()=>U,EntityIdentifierUtils:()=>Je,EntityType:()=>L,EntityVersion:()=>D,GitBuildStatusStage:()=>Bt,GitBuildStatusState:()=>Z,GitDiffLineType:()=>et,GitHub:()=>ne,GitHubIssueCloseReason:()=>wr,GitHubUtils:()=>Ke,GitIssueState:()=>me,GitLab:()=>oe,GitLabUtils:()=>Xe,GitMergeStrategy:()=>K,GitProviderUtils:()=>Ve,GitPullRequestMergeableState:()=>Q,GitPullRequestReviewState:()=>_,GitPullRequestState:()=>W,Jira:()=>ae,JiraServer:()=>ue,JiraUtils:()=>Ye,PullRequestAsyncStatus:()=>br,Trello:()=>le,TrelloUtils:()=>Ze,Utils:()=>js,default:()=>Bs,isFetch:()=>de});module.exports=Dr(Fs);var Bt=(n=>(n.Build="build",n.Production="production",n.Staging="staging",n.Test="test",n))(Bt||{}),Z=(p=>(p.ActionRequired="ACTION_REQUIRED",p.Cancelled="CANCELLED",p.Error="ERROR",p.Failed="FAILED",p.Pending="PENDING",p.Running="RUNNING",p.Skipped="SKIPPED",p.Success="SUCCESS",p.Warning="WARNING",p.OptionalActionRequired="OPTIONAL_ACTION_REQUIRED",p))(Z||{}),K=(o=>(o.MergeCommit="MERGE_COMMIT",o.Rebase="REBASE",o.RebaseThenMergeCommit="REBASE_THEN_MERGE_COMMIT",o.FastForward="FAST_FORWARD",o.Squash="SQUASH",o))(K||{}),W=(r=>(r.Open="OPEN",r.Closed="CLOSED",r.Merged="MERGED",r))(W||{}),_=(n=>(n.Approved="APPROVED",n.ChangesRequested="CHANGES_REQUESTED",n.Commented="COMMENTED",n.ReviewRequested="REVIEW_REQUESTED",n))(_||{}),Q=(a=>(a.Behind="BEHIND",a.Blocked="BLOCKED",a.Conflicts="CONFLICTS",a.Mergeable="MERGEABLE",a.Unknown="UNKNOWN",a.UnknownAndBlocked="UNKNOWN_AND_BLOCKED",a.Unstable="UNSTABLE",a))(Q||{}),et=(r=>(r.ADDED="ADDED",r.DELETED="DELETED",r.UNMODIFIED="UNMODIFIED",r))(et||{});var jt={APPROVED:0,COMMENTED:1,REVIEW_REQUESTED:2,CHANGES_REQUESTED:3},z=s=>!s||s.length===0?null:s.reduce((e,t)=>jt[t.state]>jt[e]?t.state:e,"APPROVED");var S=100;var Ft=Cr(require("node-fetch")),Mt=globalThis.fetch||Ft.default;var Lr=async s=>{let e=s.headers.get("content-type")||"",t=null;if(e.startsWith("application/json")){let n=await s.text();t=n.trim().length>0?JSON.parse(n):null}else if(e.startsWith("text/")||e==="")t=await s.text();else if(e.startsWith("application/vnd.github.raw+json"))t=await s.arrayBuffer();else throw new Error(`Unsupported content-type: ${e}`);let r={body:t,headers:Object.fromEntries(s.headers.entries()),status:s.status,statusText:s.statusText};if(!s.ok){let n=new Error(s.statusText);throw Object.assign(n,{response:r}),n}return r},tt=s=>async({url:e,...t})=>{let r=await s(e,t);return Lr(r)};var de=(s,e=!1)=>s.name==="fetch"||e;var G=class{constructor(e){let t=(e==null?void 0:e.request)||Mt;this.config={...e,request:de(t,e==null?void 0:e.forceIsFetch)?tt(t):t}}updateConfig(e){this.config={...this.config,...e,request:e.request&&de(e.request,(e==null?void 0:e.forceIsFetch)??this.config.forceIsFetch)?tt(e.request):this.config.request}}},k=class extends G{};var f=(s,e)=>{let t={};return s&&(t.Authorization=`${e?"Basic":"Bearer"} ${s}`),t},zt=s=>s?s.reduce((e,t)=>(e[t]=!0,e),{}):void 0,H=(s,e,t)=>!s||e.some(r=>s[r])?t:"",Ht=async s=>{var n,o,i;let e=[],t=!0,r;for(;t;){let a=await s(r);e=e.concat(a.data),t=!!((n=a==null?void 0:a.pageInfo)!=null&&n.hasNextPage),r=((o=a==null?void 0:a.pageInfo)==null?void 0:o.endCursor)||((i=a==null?void 0:a.pageInfo)==null?void 0:i.nextPage)}return e};var P=(s,e={})=>f(e.token||s.token,e.isPAT||s.isPAT),Wt=s=>s.url.replace("/_apis/git/repositories/","/_git/").replace(`/${s.repository.project.id}/`,`/${encodeURIComponent(s.repository.project.name)}/`).replace(`/${s.repository.id}/`,`/${encodeURIComponent(s.repository.name)}/`).replace("/pullRequests/","/pullrequest/");var Jt="https://app.vssps.visualstudio.com/_apis",v="https://dev.azure.com",Ur={active:"OPEN",completed:"MERGED",abandoned:"CLOSED"},Ar={10:"APPROVED",5:"APPROVED",0:"REVIEW_REQUESTED",[-5]:"CHANGES_REQUESTED",[-10]:"CHANGES_REQUESTED"},rt=s=>({id:s.id,name:s.displayName,username:s.uniqueName||s.displayName,email:null,avatarUrl:s.imageUrl,url:null}),ge=s=>s.startsWith("refs/heads/")?s.replace("refs/heads/",""):s,ce=(s,e)=>{var n;let t=[],r=[];return e.reviewers.forEach(o=>{let i={reviewer:rt(o),state:Ar[o.vote]||"REVIEW_REQUESTED"};o.isRequired&&t.push(i),r.push(i)}),{id:e.pullRequestId.toString(),title:e.title,number:e.codeReviewId,state:Ur[e.status],isDraft:e.isDraft,commentCount:null,upvoteCount:null,author:rt(e.createdBy),createdDate:new Date(e.creationDate),updatedDate:new Date(e.closedDate||e.creationDate),closedDate:e.closedDate?new Date(e.closedDate):null,mergedDate:e.closedDate&&e.status==="completed"?new Date(e.closedDate):null,repository:{id:e.repository.id,name:e.repository.name,project:e.repository.project.name,owner:{login:s},remoteInfo:null},headCommit:{buildStatuses:null},baseRef:{name:ge(e.targetRefName),oid:e.lastMergeTargetCommit.commitId},headRef:{name:ge(e.sourceRefName),oid:e.lastMergeSourceCommit.commitId},url:Wt(e),assignees:e.reviewers.map(rt),reviews:r,reviewDecision:z(t),additions:null,deletions:null,fileCount:null,commitCount:null,headRepository:null,mergeableState:"UNKNOWN",labels:((n=e.labels)==null?void 0:n.map(o=>({color:null,description:null,id:o.id,name:o.name})))??[],permissions:null}},Vt=(s,e)=>({id:e.id,name:e.name,namespace:s,project:e.project.name,webUrl:e.webUrl,httpsUrl:e.remoteUrl,sshUrl:e.sshUrl,defaultBranch:e.defaultBranch?{name:ge(e.defaultBranch)}:null,permission:null}),$r=(s,e,t,r)=>{var l,p;let n=t.fields,o=n["System.AssignedTo"],i=n["System.State"],a=n["System.WorkItemType"],u;return i&&a&&(u=(l=r[a])==null?void 0:l[i]),{id:t.id.toString(),number:t.id.toString(),title:n["System.Title"],commentCount:n["System.CommentCount"],author:{avatarUrl:n["System.CreatedBy"]._links.avatar.href,email:null,id:n["System.CreatedBy"].id,name:n["System.CreatedBy"].uniqueName,username:n["System.CreatedBy"].displayName,url:null},closedDate:n["Microsoft.VSTS.Common.ClosedDate"]?new Date(n["Microsoft.VSTS.Common.ClosedDate"]):null,createdDate:new Date(n["System.CreatedDate"]),updatedDate:new Date(n["System.ChangedDate"]),url:t._links.html.href,assignees:o?[{avatarUrl:o._links.avatar.href,email:null,id:o.id,name:o.uniqueName,username:o.displayName,url:null}]:[],description:null,state:{name:(u==null?void 0:u.title)||i,color:null},type:n["System.WorkItemType"],repository:null,project:{namespace:s,name:e,resourceId:null,key:null},upvoteCount:0,labels:((p=t.fields["System.Tags"])==null?void 0:p.split(";").map(d=>({color:null,description:null,id:null,name:d.trim()})))??[]}},ee=class extends G{async getCurrentUser(e={},t={}){if(t.isPAT||this.config.isPAT)throw new Error("Azure DevOps does not support PATs for this function.");let r=await this.config.request({url:`${Jt}/profile/profiles/me`,headers:P(this.config,t)});return{data:{id:r.body.id,name:r.body.displayName,username:r.body.displayName,email:r.body.emailAddress,avatarUrl:null,url:null}}}async getCurrentUserForInstance(e,t={}){let n=(await this.config.request({url:`${v}/${encodeURIComponent(e.namespace)}/_apis/ConnectionData`,headers:P(this.config,t)})).body.authorizedUser;if(n.providerDisplayName==="Anonymous")throw new Error("Current user not found.");return{data:{id:n.id,name:n.providerDisplayName,username:n.providerDisplayName,email:n.properties.Account.$value,avatarUrl:null}}}async getUserForCommit(e,t={}){if(!e.repo.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let n=(await this.config.request({url:`${v}/${encodeURIComponent(e.repo.namespace)}/${encodeURIComponent(e.repo.project)}/_apis/git/repositories/${encodeURIComponent(e.repo.name)}/commits/${e.oid}`,headers:P(this.config,t)})).body.author;return{data:{name:n.name,email:n.email,avatarUrl:n.imageUrl}}}async getOrgsForUser(e,t={}){return{data:(await this.config.request({url:`${Jt}/accounts?memberId=${e.userId}&api-version=6.0`,headers:P(this.config,t)})).body.value.map(n=>({id:n.accountId,name:n.accountName}))}}async getAzureProjects(e,t={}){let r=new URL(`${v}/${encodeURIComponent(e.namespace)}/_apis/projects`);r.searchParams.set("$top",S.toString()),e.cursor&&r.searchParams.set("$skip",e.cursor);let n=await this.config.request({url:r.toString(),headers:P(this.config,t)}),o=n.headers["x-ms-continuationtoken"];return{pageInfo:{hasNextPage:!!o,endCursor:o||null},data:n.body.value.map(i=>({id:i.id,name:i.name,namespace:e.namespace}))}}async getAzureProjectScopeDescriptor(e,t={}){let{namespace:r,projectId:n}=e;return{data:{scope:(await this.config.request({url:`https://vssps.dev.azure.com/${encodeURIComponent(r)}/_apis/graph/descriptors/${n}?api-version=6.0`,headers:P(this.config,t)})).body.value}}}async getAzureGraphAccountsForAzureProject(e,t={}){let{namespace:r,projectScopeDescriptor:n,cursor:o}=e,i=new URL(`https://vssps.dev.azure.com/${encodeURIComponent(r)}/_apis/graph/users`);n&&i.searchParams.set("scopeDescriptor",n),o&&i.searchParams.set("continuationToken",o);let a=await this.config.request({url:i.toString(),headers:P(this.config,t)}),u=a.headers["x-ms-continuationtoken"];return{pageInfo:{endCursor:u||null,hasNextPage:!!u},data:a.body.value.map(l=>{var p;return{avatarUrl:((p=l._links.avatar)==null?void 0:p.href)??null,descriptor:l.descriptor,email:l.mailAddress,name:l.displayName,storageKeyURL:l._links.storageKey.href,username:l.displayName}})}}async getAccountFromAzureGraphAccount(e,t={}){let{azureGraphAccount:r}=e,n=await this.config.request({url:r.storageKeyURL,headers:P(this.config,t)});return{data:{avatarUrl:r.avatarUrl,email:r.email,id:n.body.value,name:r.name,username:r.username,url:null}}}async getAccountsFromAzureGraphAccounts(e,t={}){let r=[];for(let n of e.azureGraphAccounts){let o=await this.getAccountFromAzureGraphAccount({azureGraphAccount:n},t);r.push(o.data)}return{data:r}}async getRepo(e,t={}){if(!e.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let r=await this.config.request({url:`${v}/${encodeURIComponent(e.namespace)}/${encodeURIComponent(e.project)}/_apis/git/repositories/${encodeURIComponent(e.name)}`,headers:P(this.config,t)});return{data:Vt(e.namespace,r.body)}}async getRepos(e,t={}){let r=[],n=[];return await Promise.all(e.map(async o=>{try{let i=await this.getRepo(o,t);r.push(i.data)}catch(i){n.push({input:o,error:i})}})),{data:r,errors:n}}async getReposForAzureProject(e,t={}){if(!e.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');return{data:(await this.config.request({url:`${v}/${encodeURIComponent(e.namespace)}/${encodeURIComponent(e.project)}/_apis/git/repositories`,headers:P(this.config,t)})).body.value.map(n=>Vt(e.namespace,n))}}async getRefs(e,t,r={}){if(!t.repo.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let n=new URL(`${v}/${encodeURIComponent(t.repo.namespace)}/${encodeURIComponent(t.repo.project)}/_apis/git/repositories/${encodeURIComponent(t.repo.name)}/refs`);n.searchParams.set("filter",e),n.searchParams.set("$top",S.toString()),t.cursor&&n.searchParams.set("continuationToken",t.cursor);let o=await this.config.request({url:n.toString(),headers:P(this.config,r)}),i=o.headers["x-ms-continuationtoken"];return{pageInfo:{hasNextPage:!!i,endCursor:i||null},data:o.body.value.map(a=>({name:ge(a.name),commit:{oid:a.objectId,authoredDate:null,committedDate:null}}))}}async getBranches(e,t={}){return this.getRefs("heads",e,t)}async getTags(e,t={}){return this.getRefs("tags",e,t)}async getPullRequestsForRepoBase(e,t={},r=100){let{page:n,repo:o,assigneeLogins:i,authorLogin:a}=e||{},u=n||1;if(!o.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let l="searchCriteria.status=1";return i&&i.length&&(l+=`&searchCriteria.reviewerId=${i[0]}`),a&&(l+=`&searchCriteria.creatorId=${a}`),await this.config.request({url:`${t.baseUrl||v}/${encodeURIComponent(o.namespace)}/${encodeURIComponent(o.project||"")}/_apis/git/repositories/${encodeURIComponent(o.name)}/pullRequests?${l}&%24top=${r}&%24skip=${(u-1)*r}`,headers:P(this.config,t)})}async getPullRequestsForRepo(e,t={}){let n=e.page||1,o=await this.getPullRequestsForRepoBase(e,t,100);return{pageInfo:{hasNextPage:o.body.value.length===100,nextPage:n+1},data:o.body.value.map(i=>ce(e.repo.namespace,i))}}async getPullRequestsForRepos(e,t={}){if(!e.repos.every(o=>o.project))throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let{repos:r}=e||{},n=[];return await Promise.all(r.map(async o=>{try{(await this.getPullRequestsForRepoBase({repo:o,...e},t)).body.value.forEach(a=>{n.push(ce(o.namespace,a))})}catch(i){if(i.statusCode!==404&&i.statusCode!==401)throw i}})),{data:n}}async getPullRequestsForProjectBase(e,t={},r=100){let{namespace:n,project:o,page:i,assigneeLogins:a,authorLogin:u}=e,l=i||1,p=new URL(`${t.baseUrl||v}/${encodeURIComponent(n)}/${encodeURIComponent(o)}/_apis/git/pullRequests`);return p.searchParams.set("searchCriteria.status","1"),p.searchParams.set("$top",r.toString()),p.searchParams.set("$skip",((l-1)*r).toString()),a&&a.length&&p.searchParams.set("searchCriteria.reviewerId",a[0]),u&&p.searchParams.set("searchCriteria.creatorId",u),await this.config.request({url:p.toString(),headers:P(this.config,t)})}async getPullRequestsForProject(e,t={}){let n=e.page||1,o=await this.getPullRequestsForProjectBase(e,t,100);return{pageInfo:{hasNextPage:o.body.value.length===100,nextPage:n+1},data:o.body.value.map(i=>ce(e.namespace,i))}}async getPullRequestsForProjects(e,t={}){let{projects:r}=e||{},n=[];return await Promise.all(r.map(async o=>{try{(await this.getPullRequestsForProjectBase({...o,...e},t)).body.value.forEach(a=>{n.push(ce(o.namespace,a))})}catch(i){if(i.statusCode!==404&&i.statusCode!==401)throw i}})),{data:n}}async getAzurePullRequestLastMergeStatus(e,t={}){if(!e.repo.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let{repo:{namespace:r,project:n,name:o},pullRequestId:i}=e,a=await this.config.request({url:`${t.baseUrl||v}/${encodeURIComponent(r)}/${encodeURIComponent(n||"")}/_apis/git/repositories/${o}/pullrequests/${i}?includeCommits=true?api-version=6.0`,headers:{...P(this.config,t)}});if(!a.body.mergeStatus)throw new Error("Could not fetch pull request");return{data:a.body.mergeStatus}}async updatePullRequest(e,t,r){return await this.config.request({method:"PATCH",url:`${r.baseUrl||v}/${encodeURIComponent(e.repository.owner.login)}/${encodeURIComponent(e.repository.project)}/_apis/git/repositories/${e.repository.name}/pullrequests/${e.id}?api-version=6.0`,body:t,headers:{...P(this.config,r),"Content-Type":"application/json"}})}async closePullRequest(e,t={}){let{pullRequest:r}=e,n={status:"abandoned"};if(!(await this.updatePullRequest(r,JSON.stringify(n),t)).body.status)throw new Error("Could not close pull request")}async mergePullRequest(e,t={}){var u;let{pullRequest:r,mergeStrategy:n}=e,o;switch(n){case"MERGE_COMMIT":{o="noFastForward";break}case"REBASE":{o="rebase";break}case"REBASE_THEN_MERGE_COMMIT":{o="rebaseMerge";break}case"SQUASH":{o="squash";break}}let i={completionOptions:{mergeStrategy:o},lastMergeSourceCommit:{commitId:(u=r.headRef)==null?void 0:u.oid},status:"completed"};if(!(await this.updatePullRequest(r,JSON.stringify(i),t)).body.status)throw new Error("Could not merge pull request")}async addPullRequestLabel(e,t={}){let{pullRequest:r,label:n}=e;if(!r.repository.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let o={name:n.name};if(!(await this.config.request({method:"POST",url:`${t.baseUrl||v}/${encodeURIComponent(r.repository.owner.login)}/${encodeURIComponent(r.repository.project)}/_apis/git/repositories/${r.repository.name}/pullrequests/${r.id}/labels?api-version=6.0`,body:JSON.stringify(o),headers:{...P(this.config,t),"Content-Type":"application/json"}})).body.id)throw new Error("Could not add pull request label")}async removePullRequestLabel(e,t={}){let{pullRequest:r,label:n}=e;if(!r.repository.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');await this.config.request({method:"DELETE",url:`${t.baseUrl||v}/${encodeURIComponent(r.repository.owner.login)}/${encodeURIComponent(r.repository.project)}/_apis/git/repositories/${r.repository.name}/pullrequests/${r.id}/labels/${encodeURIComponent(n.name)}?api-version=6.0`,headers:{...P(this.config,t)}})}async setPullRequestLabels(e,t={}){let{pullRequest:r,labels:n}=e;if(!r.repository.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let o=r.labels;if(!o)throw new Error('Azure DevOps requires "labels" for this function.');for(let i of n)o.find(a=>a.id===i.id)||await this.addPullRequestLabel({pullRequest:r,label:i},t);for(let i of o)n.find(a=>i.id===a.id)||await this.removePullRequestLabel({pullRequest:r,label:i},t)}async setPullRequestAsDraft(e,t={}){let{pullRequest:r,isDraft:n}=e,o={isDraft:n};if(!(await this.updatePullRequest(r,JSON.stringify(o),t)).body.status)throw new Error("Could not set the pull request as draft")}async addPullRequestReviewer(e,t={}){let{pullRequest:r,reviewer:n,isRequired:o}=e,i={id:n.id,isRequired:o};if(!(await this.config.request({method:"PUT",url:`${t.baseUrl||v}/${encodeURIComponent(r.repository.owner.login)}/${encodeURIComponent(r.repository.project)}/_apis/git/repositories/${r.repository.name}/pullrequests/${r.id}/reviewers/${n.id}?api-version=6.0`,body:JSON.stringify(i),headers:{...P(this.config,t),"Content-Type":"application/json"}})).body.id)throw new Error("Could not add pull request reviewer")}async removePullRequestReviewer(e,t={}){let{pullRequest:r,reviewer:n}=e;await this.config.request({method:"DELETE",url:`${t.baseUrl||v}/${encodeURIComponent(r.repository.owner.login)}/${encodeURIComponent(r.repository.project)}/_apis/git/repositories/${r.repository.name}/pullrequests/${r.id}/reviewers/${n.id}?api-version=6.0`,headers:{...P(this.config,t),Accept:"application/json"}})}async setPullRequestReviewers(e,t={}){let{pullRequest:r,reviewers:n}=e;for(let o of n)r.assignees.find(i=>i.id===o.id)||await this.addPullRequestReviewer({pullRequest:r,reviewer:o,isRequired:!0},t);for(let o of r.assignees)n.find(i=>o.id===i.id)||await this.removePullRequestReviewer({pullRequest:r,reviewer:o},t)}async getIssuesForAzureProject(e,t={}){let{page:r,assigneeLogins:n,authorLogin:o,mentionLogin:i,statusByWorkItemIdByStatusId:a}=e||{},u=r||1,l=200,p=["[Microsoft.VSTS.Common.ClosedDate] = ''","[System.TeamProject] = @project","[Microsoft.VSTS.Common.ResolvedDate] = ''"];o&&p.push(`[System.CreatedBy] = '${o.replace("'","''")}'`),n&&n[0]&&p.push(`[System.AssignedTo] = '${n[0].replace("'","''")}'`),i&&p.push("[System.Id] IN (@recentMentions)");let d=`Select [Microsoft.VSTS.Common.ClosedDate], [Microsoft.VSTS.Common.ResolvedDate] From WorkItems Where ${p.join(" AND ")} order by [System.CreatedDate] desc`,c=await this.config.request({url:`${t.baseUrl||v}/${encodeURIComponent(e.namespace)}/${encodeURIComponent(e.project)}/_apis/wit/wiql?api-version=6.0`,body:JSON.stringify({query:d}),method:"POST",headers:{...P(this.config,t),"Content-Type":"application/json"}}),g=c.body.workItems.slice((u-1)*l,l*u).map(I=>I.id);if(g.length==0)return{pageInfo:{hasNextPage:!1,nextPage:null},data:[]};let m=await this.config.request({url:`${t.baseUrl||v}/${encodeURIComponent(e.namespace)}/${encodeURIComponent(e.project)}/_apis/wit/workitemsbatch?api-version=6.0`,body:JSON.stringify({ids:g,$expand:"Links"}),method:"POST",headers:{...P(this.config,t),"Content-Type":"application/json"}});return{pageInfo:{hasNextPage:c.body.workItems.length>l*u,nextPage:u+1},data:m.body.value.map(I=>$r(e.namespace,e.project,I,a||{}))}}async updateIssue(e,t,r={}){return await this.config.request({method:"PATCH",url:`${r.baseUrl||v}/${encodeURIComponent(e.project.namespace)}/${encodeURIComponent(e.project.name)}/_apis/wit/workitems/${e.id}?api-version=6.0`,body:JSON.stringify(t),headers:{...P(this.config,r),"Content-Type":"application/json-patch+json"}})}async setIssueStatus(e,t={}){var a;let{issue:r,status:n}=e,o=[{op:"add",path:"/fields/System.State",value:n.name}];if(!((a=(await this.updateIssue(r,o,t)).body.fields)!=null&&a["System.State"]))throw new Error("Could not set issue status")}async setIssueAssignee(e,t={}){var a;let{issue:r,assignee:n}=e,o=[{op:"add",path:"/fields/System.AssignedTo",value:(n==null?void 0:n.name)??""}];if(!((a=(await this.updateIssue(r,o,t)).body.fields)!=null&&a["System.State"]))throw new Error("Could not set issue assignee")}async setIssueLabels(e,t={}){var u;let{issue:r,labels:n}=e,i=[{op:"replace",path:"/fields/System.Tags",value:n.map(l=>l.name).join(";")}];if(!((u=(await this.updateIssue(r,i,t)).body.fields)!=null&&u["System.Tags"]))throw new Error("Could not set issue tags")}async getIssueTypesForAzureProject(e,t={}){if(!e.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let{namespace:r,project:n}=e;return{data:(await this.config.request({url:`${t.baseUrl||v}/${encodeURIComponent(r)}/${encodeURIComponent(n||"")}/_apis/wit/workitemtypes?api-version=6.0`,headers:{...P(this.config,t)}})).body.value}}async getLabelsForProject(e,t={}){let{namespace:r,project:n}=e;return{data:(await this.config.request({url:`${t.baseUrl||v}/${encodeURIComponent(r)}/${encodeURIComponent(n||"")}/_apis/wit/tags?api-version=6.0`,headers:{...P(this.config,t)}})).body.value.map(i=>({color:null,description:null,id:i.id,name:i.name,url:i.url}))}}};var A=(s,e={})=>f(e.token||s.token,e.isPAT||s.isPAT);var T="https://api.bitbucket.org/2.0",Gr={OPEN:"OPEN",MERGED:"MERGED",DECLINED:"CLOSED"},Xt=s=>({id:s.uuid,name:s.display_name||s.nickname,username:s.nickname||s.display_name,email:null,avatarUrl:s.links.avatar.href,url:s.links.html.href}),Kt=s=>{var e,t;return{id:s.uuid,namespace:s.workspace.slug,name:s.slug,webUrl:s.links.html.href,httpsUrl:((e=s.links.clone.find(r=>r.name==="https"))==null?void 0:e.href)??null,sshUrl:((t=s.links.clone.find(r=>r.name==="ssh"))==null?void 0:t.href)??null,defaultBranch:{name:s.mainbranch.name},permission:null}},st=s=>{let e=s.id;return{id:e.toString(),title:s.title,number:e,state:Gr[s.state],isDraft:!1,commentCount:s.comment_count,upvoteCount:null,author:Xt(s.author),createdDate:new Date(s.created_on),updatedDate:new Date(s.updated_on),closedDate:null,mergedDate:null,repository:{id:s.destination.repository.uuid,name:s.destination.repository.name,owner:{login:s.destination.repository.full_name.split("/")[0]},remoteInfo:null},headCommit:{buildStatuses:null},baseRef:{name:s.destination.branch.name,oid:s.destination.commit.hash},headRef:{name:s.source.branch.name,oid:s.source.commit.hash},url:s.links.html.href,assignees:null,reviews:null,reviewDecision:null,additions:null,deletions:null,fileCount:null,commitCount:null,headRepository:null,mergeableState:"UNKNOWN",permissions:null}},te=class extends G{async refreshToken(e){return{data:(await this.config.request({url:"https://bitbucket.org/site/oauth2/access_token",method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded",Authorization:`Basic ${e.base64ClientIDColonClientSecret}`},body:`grant_type=refresh_token&refresh_token=${e.refreshToken}`})).body}}async getCurrentUser(e={},t={}){let r=await this.config.request({url:`${T}/user`,headers:A(this.config,t)});return{data:Xt(r.body)}}async getUserForCommit(e,t={}){var i;let n=(await this.config.request({url:`${T}/repositories/${e.repo.namespace}/${e.repo.name}/commit/${e.oid}`,headers:A(this.config,t)})).body.author,o=n.raw.match(/([^<]+)<(.+)>/);return{data:{name:o?o[1].trim():null,email:o?o[2]:null,avatarUrl:((i=n.user)==null?void 0:i.links.avatar.href)||null}}}async getRepo(e,t={}){let r=await this.config.request({url:`${T}/repositories/${e.namespace}/${e.name}`,headers:A(this.config,t)});return{data:Kt(r.body)}}async getRepos(e,t={}){let r=[],n=[];return await Promise.all(e.map(async o=>{try{let i=await this.getRepo(o,t);r.push(i.data)}catch(i){n.push({input:o,error:i})}})),{data:r,errors:n}}async getReposForCurrentUser(e,t={}){let r=new URL(`${T}/repositories`);r.searchParams.set("role","member"),r.searchParams.set("pagelen",S.toString()),e.cursor&&r.searchParams.set("after",e.cursor);let n=await this.config.request({url:r.toString(),headers:A(this.config,t)}),o=!!n.body.next,i=null;return n.body.next&&(i=new URL(n.body.next).searchParams.get("after")),{pageInfo:{hasNextPage:o,endCursor:i},data:n.body.values.map(Kt)}}async getBranches(e,t={}){var i;let r=new URL(`${T}/repositories/${e.repo.namespace}/${e.repo.name}/refs/branches`);r.searchParams.set("page",((i=e.page)==null?void 0:i.toString())||"1"),r.searchParams.set("pagelen",S.toString());let n=await this.config.request({url:r.toString(),headers:A(this.config,t)}),o=!!n.body.next;return{pageInfo:{hasNextPage:o,nextPage:o?n.body.page+1:null},data:n.body.values.map(a=>{let u=new Date(a.target.date);return{name:a.name,commit:{oid:a.target.hash,authoredDate:u,committedDate:u}}})}}async getTags(e,t={}){let r=new URL(`${T}/repositories/${e.repo.namespace}/${e.repo.name}/refs/tags`);r.searchParams.set("pagelen",S.toString()),e.cursor&&r.searchParams.set("page",e.cursor);let n=await this.config.request({url:r.toString(),headers:A(this.config,t)}),o=!!n.body.next,i=null;return n.body.next&&(i=new URL(n.body.next).searchParams.get("page")),{pageInfo:{hasNextPage:o,endCursor:i},data:n.body.values.map(a=>{let u=new Date(a.target.date);return{name:a.name,commit:{oid:a.target.hash,authoredDate:u,committedDate:u}}})}}async getPullRequestsForUser(e,t={}){var i;let r=new URL(`${T}/pullrequests/${e.userId}`);r.searchParams.set("page",((i=e.page)==null?void 0:i.toString())||"1"),r.searchParams.set("pagelen","50");let n=await this.config.request({url:r.toString(),headers:A(this.config,t)}),o=!!n.body.next;return{pageInfo:{hasNextPage:o,nextPage:o?n.body.page+1:null},data:n.body.values.map(st)}}async getPullRequestsForRepoBase(e,t={}){var n;let r=new URL(`${T}/repositories/${encodeURI(e.repo.namespace)}/${encodeURI(e.repo.name)}/pullrequests?state=OPEN`);return r.searchParams.set("page",((n=e.page)==null?void 0:n.toString())||"1"),r.searchParams.set("pagelen","50"),await this.config.request({url:r.toString(),headers:A(this.config,t)})}async getPullRequestsForRepo(e,t={}){let r=[],n=await this.getPullRequestsForRepoBase(e,t);n.body.values.forEach(i=>{if(e.authorLogin&&i.author.uuid!==e.authorLogin)return null;r.push(st(i))});let o=!!n.body.next;return{pageInfo:{hasNextPage:o,nextPage:o?n.body.page+1:null},data:r}}async getPullRequestsForRepos(e,t={}){let r=[];return await Promise.all(e.repos.map(async n=>{try{(await this.getPullRequestsForRepoBase({repo:n,...e},t)).body.values.forEach(i=>{if(e.authorLogin&&i.author.uuid!==e.authorLogin)return null;r.push(st(i))})}catch(o){if(o.statusCode!==404&&o.statusCode!==401)throw o}})),{data:r}}async closePullRequest(e,t={}){let{pullRequest:r}=e;if(!(await this.config.request({method:"POST",url:`${T}/repositories/${r.repository.owner.login}/${r.repository.name}/pullrequests/${r.id}/decline`,headers:A(this.config,t)})).body.title)throw new Error("Could not close pull request")}async mergePullRequest(e,t={}){let{pullRequest:r,mergeStrategy:n}=e,o;switch(n){case"MERGE_COMMIT":{o="merge_commit";break}case"FAST_FORWARD":{o="fast_forward";break}case"SQUASH":{o="squash";break}}let i={merge_strategy:o,type:"pullrequest"};if(!(await this.config.request({method:"POST",url:`${T}/repositories/${r.repository.owner.login}/${r.repository.name}/pullrequests/${r.id}/merge`,body:JSON.stringify(i),headers:{...A(this.config,t),"Content-Type":"application/json"}})).body.title)throw new Error("Could not merge pull request")}async setPullRequestReviewers(e,t={}){let{pullRequest:r,reviewers:n}=e,o={reviewers:n.map(a=>{if(a.username)throw new Error('Bitbucket reviewer requires "username" for this function.');return{username:a.username}})};if(!(await this.config.request({method:"PUT",url:`${T}/repositories/${r.repository.owner.login}/${r.repository.name}/pullrequests/${r.id}`,body:JSON.stringify(o),headers:{...A(this.config,t),"Content-Type":"application/json"}})).body.title)throw new Error("Could not set pull request reviewers")}};var nt=s=>({name:s.displayName,email:s.emailAddress,avatarUrl:s.avatarUrl??null,id:s.id.toString(),username:s.name,url:s.links.self[0].href}),re=s=>{var u,l,p,d,c,g;let e={OPEN:"OPEN",MERGED:"MERGED",DECLINED:"CLOSED"},t={UNAPPROVED:"REVIEW_REQUESTED",NEEDS_WORK:"CHANGES_REQUESTED",APPROVED:"APPROVED"},r=s.reviewers.map(m=>({reviewer:nt(m.user),state:t[m.status]})),n=((u=s.toRef.repository.links.clone.find(m=>m.name==="ssh"))==null?void 0:u.href)??null,o=((l=s.toRef.repository.links.clone.find(m=>m.name==="https"))==null?void 0:l.href)??null;o||(o=((p=s.toRef.repository.links.clone.find(m=>m.name==="http"))==null?void 0:p.href)??null);let i=((d=s.fromRef.repository.links.clone.find(m=>m.name==="ssh"))==null?void 0:d.href)??null,a=((c=s.fromRef.repository.links.clone.find(m=>m.name==="https"))==null?void 0:c.href)??null;return a||(a=((g=s.fromRef.repository.links.clone.find(m=>m.name==="http"))==null?void 0:g.href)??null),{id:s.id.toString(),number:s.id,title:s.title,url:s.links.self[0].href,state:e[s.state],isDraft:!1,createdDate:new Date(s.createdDate),updatedDate:new Date(s.updatedDate),closedDate:s.closedDate?new Date(s.closedDate):null,mergedDate:s.state=="MERGED"&&s.closedDate?new Date(s.closedDate):null,baseRef:{name:s.toRef.displayId,oid:s.toRef.latestCommit},headRef:{name:s.fromRef.displayId,oid:s.fromRef.latestCommit},commentCount:s.properties.commentCount,upvoteCount:null,commitCount:null,fileCount:null,additions:null,deletions:null,author:nt(s.author.user),assignees:null,reviews:r,reviewDecision:z(r),repository:{id:s.toRef.repository.id.toString(),name:s.toRef.repository.name,owner:{login:s.toRef.repository.project.key},remoteInfo:o&&n?{cloneUrlHTTPS:o,cloneUrlSSH:n}:null},headRepository:{id:s.fromRef.repository.id.toString(),name:s.fromRef.repository.name,owner:{login:s.fromRef.repository.project.key},remoteInfo:a&&i?{cloneUrlHTTPS:a,cloneUrlSSH:i}:null},headCommit:null,mergeableState:"UNKNOWN",permissions:null,version:s.version}},Yt=s=>{var e,t,r;return{id:s.id.toString(),namespace:s.project.key,name:s.slug,webUrl:((e=s.links.self[0])==null?void 0:e.href)??null,httpsUrl:((t=s.links.clone.find(n=>n.name==="https"))==null?void 0:t.href)??null,sshUrl:((r=s.links.clone.find(n=>n.name==="ssh"))==null?void 0:r.href)??null,defaultBranch:null,permission:null}},se=class extends k{getBaseUrl(e){let t=e.baseUrl||this.config.baseUrl;if(!t)throw new Error('Bitbucket Server requires "baseUrl"');return t}getRequestHeaders(e){return f(e.token||this.config.token)}async getCurrentUser(e={},t={}){let r=await this.config.request({url:`${this.getBaseUrl(t)}/users?limit=2`,headers:this.getRequestHeaders(t)}),{headers:{"x-auserid":n,"x-ausername":o}}=r,i=n?parseInt(n,10):null,a=decodeURIComponent(o),l=(await this.config.request({url:`${this.getBaseUrl(t)}/users?filter=${o}&avatarSize=64`,headers:this.getRequestHeaders(t)})).body.values.find(({emailAddress:p,id:d,name:c,slug:g})=>i?i===d:a===c||a===p||a===g);if(!l)throw new Error("Could not find current Bitbucket Server user");return{data:nt(l)}}async getRepo(e,t={}){let r=await this.config.request({url:`${this.getBaseUrl(t)}/projects/${e.namespace}/repos/${e.name}`,headers:this.getRequestHeaders(t)});return{data:Yt(r.body)}}async getRepos(e,t={}){let r=[],n=[];return await Promise.all(e.map(async o=>{try{let i=await this.getRepo(o,t);r.push(i.data)}catch(i){n.push({input:o,error:i})}})),{data:r,errors:n}}async getReposForCurrentUser(e,t={}){let r=e.page??0,n=await this.config.request({url:`${this.getBaseUrl(t)}/repos?start=${r}`,headers:this.getRequestHeaders(t)});return{pageInfo:{hasNextPage:!n.body.isLastPage,nextPage:n.body.nextPageStart},data:n.body.values.map(Yt)}}async getPullRequestsForRepoBase(e,t={}){var n;let r=new URL(`${this.getBaseUrl(t)}/projects/${encodeURI(e.repo.namespace)}/repos/${encodeURI(e.repo.name)}/pull-requests?state=OPEN`);return r.searchParams.set("start",((n=e.page)==null?void 0:n.toString())||"0"),r.searchParams.set("limit","50"),await this.config.request({url:r.toString(),headers:this.getRequestHeaders(t)})}async getPullRequestsForRepo(e,t={}){let r=[],n=await this.getPullRequestsForRepoBase(e,t);n.body.values.forEach(i=>{if(e.authorLogin&&i.author.user.name!==e.authorLogin)return null;r.push(re(i))});let o=n.body.values.length!==0;return{pageInfo:{hasNextPage:o,nextPage:o?n.body.start+n.body.values.length:null},data:r}}async getPullRequestsForRepos(e,t={}){let r=[];return await Promise.all(e.repos.map(async n=>{try{(await this.getPullRequestsForRepoBase({repo:n,...e},t)).body.values.forEach(i=>{if(e.authorLogin&&i.author.user.name!==e.authorLogin)return null;r.push(re(i))})}catch(o){if(o.statusCode!==404&&o.statusCode!==401)throw o}})),{data:r}}async getPullRequestsForCurrentUser(e,t={}){var i;let r=new URL(`${this.getBaseUrl(t)}/dashboard/pull-requests`);r.searchParams.set("state","OPEN"),r.searchParams.set("start",((i=e.page)==null?void 0:i.toString())||"0"),r.searchParams.set("limit","50");let n=await this.config.request({url:r.toString(),headers:this.getRequestHeaders(t)}),o=n.body.values.length!==0;return{pageInfo:{hasNextPage:o,nextPage:o?n.body.start+n.body.values.length:null},data:n.body.values.map(re)}}async closePullRequest(e,t={}){let{pullRequest:r}=e;if(r.version===void 0)throw new Error('Bitbucket Server requires "version" for this function.');if(!(await this.config.request({method:"POST",url:`${this.getBaseUrl(t)}/projects/${r.repository.owner.login}/repos/${r.repository.name}/pull-requests/${r.id}/decline`,body:JSON.stringify({version:r.version}),headers:{...this.getRequestHeaders(t),"Content-Type":"application/json"}})).body.title)throw new Error("Could not close pull request")}async mergePullRequest(e,t={}){let{pullRequest:r,mergeStrategyId:n}=e;if(e.mergeStrategy)throw new Error('Bitbucket Server uses "mergeStrategyId" instead of "mergeStrategy".');if(r.version===void 0)throw new Error('Bitbucket Server requires "version" for this function.');if(!(await this.config.request({method:"POST",url:`${this.getBaseUrl(t)}/projects/${r.repository.owner.login}/repos/${r.repository.name}/pull-requests/${r.id}/merge`,body:JSON.stringify({strategyId:n,version:r.version}),headers:{...this.getRequestHeaders(t),"Content-Type":"application/json"}})).body.title)throw new Error("Could not merge pull request")}async getMergeStrategies(e={}){let t=await this.config.request({url:`${this.getBaseUrl(e)}/admin/pull-requests/git`,headers:{...this.getRequestHeaders(e),"Content-Type":"application/json"}});return{data:{defaultStrategy:t.body.mergeConfig.defaultStrategy,strategies:t.body.mergeConfig.strategies}}}async setPullRequestReviewers(e,t={}){let{pullRequest:r,reviewers:n}=e;if(r.version===void 0)throw new Error('Bitbucket Server requires "version" for this function.');let o={reviewers:n.map(a=>{if(a.username)throw new Error('Bitbucket Server reviewer requires "username" for this function.');return{user:{name:a.username}}}),version:r.version};if(!(await this.config.request({method:"PUT",url:`${this.getBaseUrl(t)}/projects/${r.repository.owner.login}/repos/${r.repository.name}/pull-requests/${r.id}`,body:JSON.stringify(o),headers:{...this.getRequestHeaders(t),"Content-Type":"application/json"}})).body.title)throw new Error("Could not set pull request reviewers")}};var rr=require("js-base64");var me=(t=>(t.Open="OPEN",t.Closed="CLOSED",t))(me||{});var Tr={AS_CODE_OWNER:[3,0,0],CHECK_RUN:[3,0,0],LATEST_REVIEWS:[3,0,0],VIEWER_CAN_MERGE_AS_ADMIN:[3,5,0]},he=(s,e)=>{let t=Tr[e];for(let r=0;r<3;r++){if(s[r]>t[r])return!0;if(s[r]<t[r])return!1}return!0},Ie="https://api.github.com",Or=`${Ie}/graphql`,Re=`
1
+ "use strict";var Pr=Object.create;var pe=Object.defineProperty;var Er=Object.getOwnPropertyDescriptor;var vr=Object.getOwnPropertyNames;var qr=Object.getPrototypeOf,Sr=Object.prototype.hasOwnProperty;var x=(s,e)=>{for(var t in e)pe(s,t,{get:e[t],enumerable:!0})},Qt=(s,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of vr(e))!Sr.call(s,n)&&n!==t&&pe(s,n,{get:()=>e[n],enumerable:!(r=Er(e,n))||r.enumerable});return s};var Cr=(s,e,t)=>(t=s!=null?Pr(qr(s)):{},Qt(e||!s||!s.__esModule?pe(t,"default",{value:s,enumerable:!0}):t,s)),Dr=s=>Qt(pe({},"__esModule",{value:!0}),s);var Fs={};x(Fs,{AzureDevOps:()=>ee,AzureDevopsUtils:()=>Te,Bitbucket:()=>te,BitbucketServer:()=>se,BitbucketServerUtils:()=>xe,BitbucketUtils:()=>Oe,EntityIdentifierProviderType:()=>U,EntityIdentifierUtils:()=>Je,EntityType:()=>L,EntityVersion:()=>D,GitBuildStatusStage:()=>Bt,GitBuildStatusState:()=>Z,GitDiffLineType:()=>et,GitHub:()=>ne,GitHubIssueCloseReason:()=>wr,GitHubUtils:()=>Ke,GitIssueState:()=>me,GitLab:()=>oe,GitLabUtils:()=>Xe,GitMergeStrategy:()=>K,GitProviderUtils:()=>Ve,GitPullRequestMergeableState:()=>Q,GitPullRequestReviewState:()=>_,GitPullRequestState:()=>W,Jira:()=>ae,JiraServer:()=>ue,JiraUtils:()=>Ye,PullRequestAsyncStatus:()=>br,Trello:()=>le,TrelloUtils:()=>Ze,Utils:()=>js,default:()=>Bs,isFetch:()=>de});module.exports=Dr(Fs);var Bt=(n=>(n.Build="build",n.Production="production",n.Staging="staging",n.Test="test",n))(Bt||{}),Z=(p=>(p.ActionRequired="ACTION_REQUIRED",p.Cancelled="CANCELLED",p.Error="ERROR",p.Failed="FAILED",p.Pending="PENDING",p.Running="RUNNING",p.Skipped="SKIPPED",p.Success="SUCCESS",p.Warning="WARNING",p.OptionalActionRequired="OPTIONAL_ACTION_REQUIRED",p))(Z||{}),K=(o=>(o.MergeCommit="MERGE_COMMIT",o.Rebase="REBASE",o.RebaseThenMergeCommit="REBASE_THEN_MERGE_COMMIT",o.FastForward="FAST_FORWARD",o.Squash="SQUASH",o))(K||{}),W=(r=>(r.Open="OPEN",r.Closed="CLOSED",r.Merged="MERGED",r))(W||{}),_=(n=>(n.Approved="APPROVED",n.ChangesRequested="CHANGES_REQUESTED",n.Commented="COMMENTED",n.ReviewRequested="REVIEW_REQUESTED",n))(_||{}),Q=(a=>(a.Behind="BEHIND",a.Blocked="BLOCKED",a.Conflicts="CONFLICTS",a.Mergeable="MERGEABLE",a.Unknown="UNKNOWN",a.UnknownAndBlocked="UNKNOWN_AND_BLOCKED",a.Unstable="UNSTABLE",a))(Q||{}),et=(r=>(r.ADDED="ADDED",r.DELETED="DELETED",r.UNMODIFIED="UNMODIFIED",r))(et||{});var jt={APPROVED:0,COMMENTED:1,REVIEW_REQUESTED:2,CHANGES_REQUESTED:3},z=s=>!s||s.length===0?null:s.reduce((e,t)=>jt[t.state]>jt[e]?t.state:e,"APPROVED");var S=100;var Ft=Cr(require("node-fetch")),Mt=globalThis.fetch||Ft.default;var Lr=async s=>{let e=s.headers.get("content-type")||"",t=null;if(e.startsWith("application/json")){let n=await s.text();t=n.trim().length>0?JSON.parse(n):null}else if(e.startsWith("text/")||e==="")t=await s.text();else if(e.startsWith("application/vnd.github.raw+json"))t=await s.arrayBuffer();else throw new Error(`Unsupported content-type: ${e}`);let r={body:t,headers:Object.fromEntries(s.headers.entries()),status:s.status,statusText:s.statusText};if(!s.ok){let n=new Error(s.statusText);throw Object.assign(n,{response:r}),n}return r},tt=s=>async({url:e,...t})=>{let r=await s(e,t);return Lr(r)};var de=(s,e=!1)=>s.name==="fetch"||e;var G=class{constructor(e){let t=(e==null?void 0:e.request)||Mt;this.config={...e,request:de(t,e==null?void 0:e.forceIsFetch)?tt(t):t}}updateConfig(e){this.config={...this.config,...e,request:e.request&&de(e.request,(e==null?void 0:e.forceIsFetch)??this.config.forceIsFetch)?tt(e.request):this.config.request}}},k=class extends G{};var f=(s,e)=>{let t={};return s&&(t.Authorization=`${e?"Basic":"Bearer"} ${s}`),t},zt=s=>s?s.reduce((e,t)=>(e[t]=!0,e),{}):void 0,H=(s,e,t)=>!s||e.some(r=>s[r])?t:"",Ht=async s=>{var n,o,i;let e=[],t=!0,r;for(;t;){let a=await s(r);e=e.concat(a.data),t=!!((n=a==null?void 0:a.pageInfo)!=null&&n.hasNextPage),r=((o=a==null?void 0:a.pageInfo)==null?void 0:o.endCursor)||((i=a==null?void 0:a.pageInfo)==null?void 0:i.nextPage)}return e};var P=(s,e={})=>f(e.token||s.token,e.isPAT||s.isPAT),Wt=s=>s.url.replace("/_apis/git/repositories/","/_git/").replace(`/${s.repository.project.id}/`,`/${encodeURIComponent(s.repository.project.name)}/`).replace(`/${s.repository.id}/`,`/${encodeURIComponent(s.repository.name)}/`).replace("/pullRequests/","/pullrequest/");var Jt="https://app.vssps.visualstudio.com/_apis",v="https://dev.azure.com",Ur={active:"OPEN",completed:"MERGED",abandoned:"CLOSED"},Ar={10:"APPROVED",5:"APPROVED",0:"REVIEW_REQUESTED",[-5]:"CHANGES_REQUESTED",[-10]:"CHANGES_REQUESTED"},rt=s=>({id:s.id,name:s.displayName??null,username:(s.uniqueName||s.displayName)??null,email:null,avatarUrl:s.imageUrl??null,url:null}),ge=s=>s.startsWith("refs/heads/")?s.replace("refs/heads/",""):s,ce=(s,e)=>{var n;let t=[],r=[];return e.reviewers.forEach(o=>{let i={reviewer:rt(o),state:Ar[o.vote??0]||"REVIEW_REQUESTED"};o.isRequired&&t.push(i),r.push(i)}),{id:e.pullRequestId.toString(),title:e.title,number:e.codeReviewId,state:Ur[e.status],isDraft:e.isDraft,commentCount:null,upvoteCount:null,author:rt(e.createdBy),createdDate:new Date(e.creationDate),updatedDate:new Date(e.closedDate||e.creationDate),closedDate:e.closedDate?new Date(e.closedDate):null,mergedDate:e.closedDate&&e.status==="completed"?new Date(e.closedDate):null,repository:{id:e.repository.id,name:e.repository.name,project:e.repository.project.name,owner:{login:s},remoteInfo:null},headCommit:{buildStatuses:null},baseRef:{name:ge(e.targetRefName),oid:e.lastMergeTargetCommit.commitId},headRef:{name:ge(e.sourceRefName),oid:e.lastMergeSourceCommit.commitId},url:Wt(e),assignees:e.reviewers.map(rt),reviews:r,reviewDecision:z(t),additions:null,deletions:null,fileCount:null,commitCount:null,headRepository:null,mergeableState:"UNKNOWN",labels:((n=e.labels)==null?void 0:n.map(o=>({color:null,description:null,id:o.id,name:o.name})))??[],permissions:null}},Vt=(s,e)=>({id:e.id,name:e.name,namespace:s,project:e.project.name,webUrl:e.webUrl,httpsUrl:e.remoteUrl,sshUrl:e.sshUrl,defaultBranch:e.defaultBranch?{name:ge(e.defaultBranch)}:null,permission:null}),$r=(s,e,t,r)=>{var l,p,d,c,g,m;let n=t.fields,o=n["System.AssignedTo"],i=n["System.State"],a=n["System.WorkItemType"],u;return i&&a&&(u=(l=r[a])==null?void 0:l[i]),{id:t.id.toString(),number:t.id.toString(),title:n["System.Title"],commentCount:n["System.CommentCount"],author:{avatarUrl:((d=(p=n["System.CreatedBy"]._links)==null?void 0:p.avatar)==null?void 0:d.href)??null,email:null,id:n["System.CreatedBy"].id,name:n["System.CreatedBy"].uniqueName??null,username:n["System.CreatedBy"].displayName??null,url:null},closedDate:n["Microsoft.VSTS.Common.ClosedDate"]?new Date(n["Microsoft.VSTS.Common.ClosedDate"]):null,createdDate:new Date(n["System.CreatedDate"]),updatedDate:new Date(n["System.ChangedDate"]),url:t._links.html.href,assignees:o?[{avatarUrl:((g=(c=o._links)==null?void 0:c.avatar)==null?void 0:g.href)??null,email:null,id:o.id,name:o.uniqueName??null,username:o.displayName??null,url:null}]:[],description:null,state:{name:(u==null?void 0:u.title)||i,color:null},type:n["System.WorkItemType"],repository:null,project:{namespace:s,name:e,resourceId:null,key:null,id:null},upvoteCount:0,labels:((m=t.fields["System.Tags"])==null?void 0:m.split(";").map(I=>({color:null,description:null,id:null,name:I.trim()})))??[]}},ee=class extends G{async getCurrentUser(e={},t={}){if(t.isPAT||this.config.isPAT)throw new Error("Azure DevOps does not support PATs for this function.");let r=await this.config.request({url:`${Jt}/profile/profiles/me`,headers:P(this.config,t)});return{data:{id:r.body.id,name:r.body.displayName,username:r.body.displayName,email:r.body.emailAddress,avatarUrl:null,url:null}}}async getCurrentUserForInstance(e,t={}){let n=(await this.config.request({url:`${v}/${encodeURIComponent(e.namespace)}/_apis/ConnectionData`,headers:P(this.config,t)})).body.authorizedUser;if(n.providerDisplayName==="Anonymous")throw new Error("Current user not found.");return{data:{id:n.id,name:n.providerDisplayName,username:n.providerDisplayName,email:n.properties.Account.$value,avatarUrl:null}}}async getUserForCommit(e,t={}){if(!e.repo.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let n=(await this.config.request({url:`${v}/${encodeURIComponent(e.repo.namespace)}/${encodeURIComponent(e.repo.project)}/_apis/git/repositories/${encodeURIComponent(e.repo.name)}/commits/${e.oid}`,headers:P(this.config,t)})).body.author;return{data:{name:n.name,email:n.email,avatarUrl:n.imageUrl}}}async getOrgsForUser(e,t={}){return{data:(await this.config.request({url:`${Jt}/accounts?memberId=${e.userId}&api-version=6.0`,headers:P(this.config,t)})).body.value.map(n=>({id:n.accountId,name:n.accountName}))}}async getAzureProjects(e,t={}){let r=new URL(`${v}/${encodeURIComponent(e.namespace)}/_apis/projects`);r.searchParams.set("$top",S.toString()),e.cursor&&r.searchParams.set("$skip",e.cursor);let n=await this.config.request({url:r.toString(),headers:P(this.config,t)}),o=n.headers["x-ms-continuationtoken"];return{pageInfo:{hasNextPage:!!o,endCursor:o||null},data:n.body.value.map(i=>({id:i.id,name:i.name,namespace:e.namespace}))}}async getAzureProjectScopeDescriptor(e,t={}){let{namespace:r,projectId:n}=e;return{data:{scope:(await this.config.request({url:`https://vssps.dev.azure.com/${encodeURIComponent(r)}/_apis/graph/descriptors/${n}?api-version=6.0`,headers:P(this.config,t)})).body.value}}}async getAzureGraphAccountsForAzureProject(e,t={}){let{namespace:r,projectScopeDescriptor:n,cursor:o}=e,i=new URL(`https://vssps.dev.azure.com/${encodeURIComponent(r)}/_apis/graph/users`);n&&i.searchParams.set("scopeDescriptor",n),o&&i.searchParams.set("continuationToken",o);let a=await this.config.request({url:i.toString(),headers:P(this.config,t)}),u=a.headers["x-ms-continuationtoken"];return{pageInfo:{endCursor:u||null,hasNextPage:!!u},data:a.body.value.map(l=>{var p,d,c,g;return{avatarUrl:((d=(p=l._links)==null?void 0:p.avatar)==null?void 0:d.href)??null,descriptor:l.descriptor??null,email:l.mailAddress??null,name:l.displayName??null,storageKeyURL:((g=(c=l._links)==null?void 0:c.storageKey)==null?void 0:g.href)??null,username:l.displayName??null}})}}async getAccountFromAzureGraphAccount(e,t={}){let{azureGraphAccount:r}=e;if(!r.storageKeyURL)throw new Error("Expected 'storageKeyURL' to not be null for 'azureGraphAccount'");let n=await this.config.request({url:r.storageKeyURL,headers:P(this.config,t)});return{data:{avatarUrl:r.avatarUrl,email:r.email,id:n.body.value,name:r.name,username:r.username,url:null}}}async getAccountsFromAzureGraphAccounts(e,t={}){let r=[];for(let n of e.azureGraphAccounts){let o=await this.getAccountFromAzureGraphAccount({azureGraphAccount:n},t);r.push(o.data)}return{data:r}}async getRepo(e,t={}){if(!e.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let r=await this.config.request({url:`${v}/${encodeURIComponent(e.namespace)}/${encodeURIComponent(e.project)}/_apis/git/repositories/${encodeURIComponent(e.name)}`,headers:P(this.config,t)});return{data:Vt(e.namespace,r.body)}}async getRepos(e,t={}){let r=[],n=[];return await Promise.all(e.map(async o=>{try{let i=await this.getRepo(o,t);r.push(i.data)}catch(i){n.push({input:o,error:i})}})),{data:r,errors:n}}async getReposForAzureProject(e,t={}){if(!e.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');return{data:(await this.config.request({url:`${v}/${encodeURIComponent(e.namespace)}/${encodeURIComponent(e.project)}/_apis/git/repositories`,headers:P(this.config,t)})).body.value.map(n=>Vt(e.namespace,n))}}async getRefs(e,t,r={}){if(!t.repo.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let n=new URL(`${v}/${encodeURIComponent(t.repo.namespace)}/${encodeURIComponent(t.repo.project)}/_apis/git/repositories/${encodeURIComponent(t.repo.name)}/refs`);n.searchParams.set("filter",e),n.searchParams.set("$top",S.toString()),t.cursor&&n.searchParams.set("continuationToken",t.cursor);let o=await this.config.request({url:n.toString(),headers:P(this.config,r)}),i=o.headers["x-ms-continuationtoken"];return{pageInfo:{hasNextPage:!!i,endCursor:i||null},data:o.body.value.map(a=>({name:ge(a.name),commit:{oid:a.objectId,authoredDate:null,committedDate:null}}))}}async getBranches(e,t={}){return this.getRefs("heads",e,t)}async getTags(e,t={}){return this.getRefs("tags",e,t)}async getPullRequestsForRepoBase(e,t={},r=100){let{page:n,repo:o,assigneeLogins:i,authorLogin:a}=e||{},u=n||1;if(!o.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let l="searchCriteria.status=1";return i&&i.length&&(l+=`&searchCriteria.reviewerId=${i[0]}`),a&&(l+=`&searchCriteria.creatorId=${a}`),await this.config.request({url:`${t.baseUrl||v}/${encodeURIComponent(o.namespace)}/${encodeURIComponent(o.project||"")}/_apis/git/repositories/${encodeURIComponent(o.name)}/pullRequests?${l}&%24top=${r}&%24skip=${(u-1)*r}`,headers:P(this.config,t)})}async getPullRequestsForRepo(e,t={}){let n=e.page||1,o=await this.getPullRequestsForRepoBase(e,t,100);return{pageInfo:{hasNextPage:o.body.value.length===100,nextPage:n+1},data:o.body.value.map(i=>ce(e.repo.namespace,i))}}async getPullRequestsForRepos(e,t={}){if(!e.repos.every(o=>o.project))throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let{repos:r}=e||{},n=[];return await Promise.all(r.map(async o=>{try{(await this.getPullRequestsForRepoBase({repo:o,...e},t)).body.value.forEach(a=>{n.push(ce(o.namespace,a))})}catch(i){if(i.statusCode!==404&&i.statusCode!==401)throw i}})),{data:n}}async getPullRequestsForProjectBase(e,t={},r=100){let{namespace:n,project:o,page:i,assigneeLogins:a,authorLogin:u}=e,l=i||1,p=new URL(`${t.baseUrl||v}/${encodeURIComponent(n)}/${encodeURIComponent(o)}/_apis/git/pullRequests`);return p.searchParams.set("searchCriteria.status","1"),p.searchParams.set("$top",r.toString()),p.searchParams.set("$skip",((l-1)*r).toString()),a&&a.length&&p.searchParams.set("searchCriteria.reviewerId",a[0]),u&&p.searchParams.set("searchCriteria.creatorId",u),await this.config.request({url:p.toString(),headers:P(this.config,t)})}async getPullRequestsForProject(e,t={}){let n=e.page||1,o=await this.getPullRequestsForProjectBase(e,t,100);return{pageInfo:{hasNextPage:o.body.value.length===100,nextPage:n+1},data:o.body.value.map(i=>ce(e.namespace,i))}}async getPullRequestsForProjects(e,t={}){let{projects:r}=e||{},n=[];return await Promise.all(r.map(async o=>{try{(await this.getPullRequestsForProjectBase({...o,...e},t)).body.value.forEach(a=>{n.push(ce(o.namespace,a))})}catch(i){if(i.statusCode!==404&&i.statusCode!==401)throw i}})),{data:n}}async getAzurePullRequestLastMergeStatus(e,t={}){if(!e.repo.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let{repo:{namespace:r,project:n,name:o},pullRequestId:i}=e,a=await this.config.request({url:`${t.baseUrl||v}/${encodeURIComponent(r)}/${encodeURIComponent(n||"")}/_apis/git/repositories/${o}/pullrequests/${i}?includeCommits=true?api-version=6.0`,headers:{...P(this.config,t)}});if(!a.body.mergeStatus)throw new Error("Could not fetch pull request");return{data:a.body.mergeStatus}}async updatePullRequest(e,t,r){return await this.config.request({method:"PATCH",url:`${r.baseUrl||v}/${encodeURIComponent(e.repository.owner.login)}/${encodeURIComponent(e.repository.project)}/_apis/git/repositories/${e.repository.name}/pullrequests/${e.id}?api-version=6.0`,body:t,headers:{...P(this.config,r),"Content-Type":"application/json"}})}async closePullRequest(e,t={}){let{pullRequest:r}=e,n={status:"abandoned"};if(!(await this.updatePullRequest(r,JSON.stringify(n),t)).body.status)throw new Error("Could not close pull request")}async mergePullRequest(e,t={}){var u;let{pullRequest:r,mergeStrategy:n}=e,o;switch(n){case"MERGE_COMMIT":{o="noFastForward";break}case"REBASE":{o="rebase";break}case"REBASE_THEN_MERGE_COMMIT":{o="rebaseMerge";break}case"SQUASH":{o="squash";break}}let i={completionOptions:{mergeStrategy:o},lastMergeSourceCommit:{commitId:(u=r.headRef)==null?void 0:u.oid},status:"completed"};if(!(await this.updatePullRequest(r,JSON.stringify(i),t)).body.status)throw new Error("Could not merge pull request")}async addPullRequestLabel(e,t={}){let{pullRequest:r,label:n}=e;if(!r.repository.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let o={name:n.name};if(!(await this.config.request({method:"POST",url:`${t.baseUrl||v}/${encodeURIComponent(r.repository.owner.login)}/${encodeURIComponent(r.repository.project)}/_apis/git/repositories/${r.repository.name}/pullrequests/${r.id}/labels?api-version=6.0`,body:JSON.stringify(o),headers:{...P(this.config,t),"Content-Type":"application/json"}})).body.id)throw new Error("Could not add pull request label")}async removePullRequestLabel(e,t={}){let{pullRequest:r,label:n}=e;if(!r.repository.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');await this.config.request({method:"DELETE",url:`${t.baseUrl||v}/${encodeURIComponent(r.repository.owner.login)}/${encodeURIComponent(r.repository.project)}/_apis/git/repositories/${r.repository.name}/pullrequests/${r.id}/labels/${encodeURIComponent(n.name)}?api-version=6.0`,headers:{...P(this.config,t)}})}async setPullRequestLabels(e,t={}){let{pullRequest:r,labels:n}=e;if(!r.repository.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let o=r.labels;if(!o)throw new Error('Azure DevOps requires "labels" for this function.');for(let i of n)o.find(a=>a.id===i.id)||await this.addPullRequestLabel({pullRequest:r,label:i},t);for(let i of o)n.find(a=>i.id===a.id)||await this.removePullRequestLabel({pullRequest:r,label:i},t)}async setPullRequestAsDraft(e,t={}){let{pullRequest:r,isDraft:n}=e,o={isDraft:n};if(!(await this.updatePullRequest(r,JSON.stringify(o),t)).body.status)throw new Error("Could not set the pull request as draft")}async addPullRequestReviewer(e,t={}){let{pullRequest:r,reviewer:n,isRequired:o}=e,i={id:n.id,isRequired:o};if(!(await this.config.request({method:"PUT",url:`${t.baseUrl||v}/${encodeURIComponent(r.repository.owner.login)}/${encodeURIComponent(r.repository.project)}/_apis/git/repositories/${r.repository.name}/pullrequests/${r.id}/reviewers/${n.id}?api-version=6.0`,body:JSON.stringify(i),headers:{...P(this.config,t),"Content-Type":"application/json"}})).body.id)throw new Error("Could not add pull request reviewer")}async removePullRequestReviewer(e,t={}){let{pullRequest:r,reviewer:n}=e;await this.config.request({method:"DELETE",url:`${t.baseUrl||v}/${encodeURIComponent(r.repository.owner.login)}/${encodeURIComponent(r.repository.project)}/_apis/git/repositories/${r.repository.name}/pullrequests/${r.id}/reviewers/${n.id}?api-version=6.0`,headers:{...P(this.config,t),Accept:"application/json"}})}async setPullRequestReviewers(e,t={}){let{pullRequest:r,reviewers:n}=e;for(let o of n)r.assignees.find(i=>i.id===o.id)||await this.addPullRequestReviewer({pullRequest:r,reviewer:o,isRequired:!0},t);for(let o of r.assignees)n.find(i=>o.id===i.id)||await this.removePullRequestReviewer({pullRequest:r,reviewer:o},t)}async getIssuesForAzureProject(e,t={}){let{page:r,assigneeLogins:n,authorLogin:o,mentionLogin:i,statusByWorkItemIdByStatusId:a}=e||{},u=r||1,l=200,p=["[Microsoft.VSTS.Common.ClosedDate] = ''","[System.TeamProject] = @project","[Microsoft.VSTS.Common.ResolvedDate] = ''"];o&&p.push(`[System.CreatedBy] = '${o.replace("'","''")}'`),n&&n[0]&&p.push(`[System.AssignedTo] = '${n[0].replace("'","''")}'`),i&&p.push("[System.Id] IN (@recentMentions)");let d=`Select [Microsoft.VSTS.Common.ClosedDate], [Microsoft.VSTS.Common.ResolvedDate] From WorkItems Where ${p.join(" AND ")} order by [System.CreatedDate] desc`,c=await this.config.request({url:`${t.baseUrl||v}/${encodeURIComponent(e.namespace)}/${encodeURIComponent(e.project)}/_apis/wit/wiql?api-version=6.0`,body:JSON.stringify({query:d}),method:"POST",headers:{...P(this.config,t),"Content-Type":"application/json"}}),g=c.body.workItems.slice((u-1)*l,l*u).map(I=>I.id);if(g.length==0)return{pageInfo:{hasNextPage:!1,nextPage:null},data:[]};let m=await this.config.request({url:`${t.baseUrl||v}/${encodeURIComponent(e.namespace)}/${encodeURIComponent(e.project)}/_apis/wit/workitemsbatch?api-version=6.0`,body:JSON.stringify({ids:g,$expand:"Links"}),method:"POST",headers:{...P(this.config,t),"Content-Type":"application/json"}});return{pageInfo:{hasNextPage:c.body.workItems.length>l*u,nextPage:u+1},data:m.body.value.map(I=>$r(e.namespace,e.project,I,a||{}))}}async updateIssue(e,t,r={}){return await this.config.request({method:"PATCH",url:`${r.baseUrl||v}/${encodeURIComponent(e.project.namespace)}/${encodeURIComponent(e.project.name)}/_apis/wit/workitems/${e.id}?api-version=6.0`,body:JSON.stringify(t),headers:{...P(this.config,r),"Content-Type":"application/json-patch+json"}})}async setIssueStatus(e,t={}){var a;let{issue:r,status:n}=e,o=[{op:"add",path:"/fields/System.State",value:n.name}];if(!((a=(await this.updateIssue(r,o,t)).body.fields)!=null&&a["System.State"]))throw new Error("Could not set issue status")}async setIssueAssignee(e,t={}){var a;let{issue:r,assignee:n}=e,o=[{op:"add",path:"/fields/System.AssignedTo",value:(n==null?void 0:n.name)??""}];if(!((a=(await this.updateIssue(r,o,t)).body.fields)!=null&&a["System.State"]))throw new Error("Could not set issue assignee")}async setIssueLabels(e,t={}){var u;let{issue:r,labels:n}=e,i=[{op:"replace",path:"/fields/System.Tags",value:n.map(l=>l.name).join(";")}];if(!((u=(await this.updateIssue(r,i,t)).body.fields)!=null&&u["System.Tags"]))throw new Error("Could not set issue tags")}async getIssueTypesForAzureProject(e,t={}){if(!e.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let{namespace:r,project:n}=e;return{data:(await this.config.request({url:`${t.baseUrl||v}/${encodeURIComponent(r)}/${encodeURIComponent(n||"")}/_apis/wit/workitemtypes?api-version=6.0`,headers:{...P(this.config,t)}})).body.value}}async getLabelsForProject(e,t={}){let{namespace:r,project:n}=e;return{data:(await this.config.request({url:`${t.baseUrl||v}/${encodeURIComponent(r)}/${encodeURIComponent(n||"")}/_apis/wit/tags?api-version=6.0`,headers:{...P(this.config,t)}})).body.value.map(i=>({color:null,description:null,id:i.id,name:i.name,url:i.url}))}}};var A=(s,e={})=>f(e.token||s.token,e.isPAT||s.isPAT);var T="https://api.bitbucket.org/2.0",Gr={OPEN:"OPEN",MERGED:"MERGED",DECLINED:"CLOSED"},Xt=s=>({id:s.uuid,name:s.display_name||s.nickname,username:s.nickname||s.display_name,email:null,avatarUrl:s.links.avatar.href,url:s.links.html.href}),Kt=s=>{var e,t;return{id:s.uuid,namespace:s.workspace.slug,name:s.slug,webUrl:s.links.html.href,httpsUrl:((e=s.links.clone.find(r=>r.name==="https"))==null?void 0:e.href)??null,sshUrl:((t=s.links.clone.find(r=>r.name==="ssh"))==null?void 0:t.href)??null,defaultBranch:{name:s.mainbranch.name},permission:null}},st=s=>{let e=s.id;return{id:e.toString(),title:s.title,number:e,state:Gr[s.state],isDraft:!1,commentCount:s.comment_count,upvoteCount:null,author:Xt(s.author),createdDate:new Date(s.created_on),updatedDate:new Date(s.updated_on),closedDate:null,mergedDate:null,repository:{id:s.destination.repository.uuid,name:s.destination.repository.name,owner:{login:s.destination.repository.full_name.split("/")[0]},remoteInfo:null},headCommit:{buildStatuses:null},baseRef:{name:s.destination.branch.name,oid:s.destination.commit.hash},headRef:{name:s.source.branch.name,oid:s.source.commit.hash},url:s.links.html.href,assignees:null,reviews:null,reviewDecision:null,additions:null,deletions:null,fileCount:null,commitCount:null,headRepository:null,mergeableState:"UNKNOWN",permissions:null}},te=class extends G{async refreshToken(e){return{data:(await this.config.request({url:"https://bitbucket.org/site/oauth2/access_token",method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded",Authorization:`Basic ${e.base64ClientIDColonClientSecret}`},body:`grant_type=refresh_token&refresh_token=${e.refreshToken}`})).body}}async getCurrentUser(e={},t={}){let r=await this.config.request({url:`${T}/user`,headers:A(this.config,t)});return{data:Xt(r.body)}}async getUserForCommit(e,t={}){var i;let n=(await this.config.request({url:`${T}/repositories/${e.repo.namespace}/${e.repo.name}/commit/${e.oid}`,headers:A(this.config,t)})).body.author,o=n.raw.match(/([^<]+)<(.+)>/);return{data:{name:o?o[1].trim():null,email:o?o[2]:null,avatarUrl:((i=n.user)==null?void 0:i.links.avatar.href)||null}}}async getRepo(e,t={}){let r=await this.config.request({url:`${T}/repositories/${e.namespace}/${e.name}`,headers:A(this.config,t)});return{data:Kt(r.body)}}async getRepos(e,t={}){let r=[],n=[];return await Promise.all(e.map(async o=>{try{let i=await this.getRepo(o,t);r.push(i.data)}catch(i){n.push({input:o,error:i})}})),{data:r,errors:n}}async getReposForCurrentUser(e,t={}){let r=new URL(`${T}/repositories`);r.searchParams.set("role","member"),r.searchParams.set("pagelen",S.toString()),e.cursor&&r.searchParams.set("after",e.cursor);let n=await this.config.request({url:r.toString(),headers:A(this.config,t)}),o=!!n.body.next,i=null;return n.body.next&&(i=new URL(n.body.next).searchParams.get("after")),{pageInfo:{hasNextPage:o,endCursor:i},data:n.body.values.map(Kt)}}async getBranches(e,t={}){var i;let r=new URL(`${T}/repositories/${e.repo.namespace}/${e.repo.name}/refs/branches`);r.searchParams.set("page",((i=e.page)==null?void 0:i.toString())||"1"),r.searchParams.set("pagelen",S.toString());let n=await this.config.request({url:r.toString(),headers:A(this.config,t)}),o=!!n.body.next;return{pageInfo:{hasNextPage:o,nextPage:o?n.body.page+1:null},data:n.body.values.map(a=>{let u=new Date(a.target.date);return{name:a.name,commit:{oid:a.target.hash,authoredDate:u,committedDate:u}}})}}async getTags(e,t={}){let r=new URL(`${T}/repositories/${e.repo.namespace}/${e.repo.name}/refs/tags`);r.searchParams.set("pagelen",S.toString()),e.cursor&&r.searchParams.set("page",e.cursor);let n=await this.config.request({url:r.toString(),headers:A(this.config,t)}),o=!!n.body.next,i=null;return n.body.next&&(i=new URL(n.body.next).searchParams.get("page")),{pageInfo:{hasNextPage:o,endCursor:i},data:n.body.values.map(a=>{let u=new Date(a.target.date);return{name:a.name,commit:{oid:a.target.hash,authoredDate:u,committedDate:u}}})}}async getPullRequestsForUser(e,t={}){var i;let r=new URL(`${T}/pullrequests/${e.userId}`);r.searchParams.set("page",((i=e.page)==null?void 0:i.toString())||"1"),r.searchParams.set("pagelen","50");let n=await this.config.request({url:r.toString(),headers:A(this.config,t)}),o=!!n.body.next;return{pageInfo:{hasNextPage:o,nextPage:o?n.body.page+1:null},data:n.body.values.map(st)}}async getPullRequestsForRepoBase(e,t={}){var n;let r=new URL(`${T}/repositories/${encodeURI(e.repo.namespace)}/${encodeURI(e.repo.name)}/pullrequests?state=OPEN`);return r.searchParams.set("page",((n=e.page)==null?void 0:n.toString())||"1"),r.searchParams.set("pagelen","50"),await this.config.request({url:r.toString(),headers:A(this.config,t)})}async getPullRequestsForRepo(e,t={}){let r=[],n=await this.getPullRequestsForRepoBase(e,t);n.body.values.forEach(i=>{if(e.authorLogin&&i.author.uuid!==e.authorLogin)return null;r.push(st(i))});let o=!!n.body.next;return{pageInfo:{hasNextPage:o,nextPage:o?n.body.page+1:null},data:r}}async getPullRequestsForRepos(e,t={}){let r=[];return await Promise.all(e.repos.map(async n=>{try{(await this.getPullRequestsForRepoBase({repo:n,...e},t)).body.values.forEach(i=>{if(e.authorLogin&&i.author.uuid!==e.authorLogin)return null;r.push(st(i))})}catch(o){if(o.statusCode!==404&&o.statusCode!==401)throw o}})),{data:r}}async closePullRequest(e,t={}){let{pullRequest:r}=e;if(!(await this.config.request({method:"POST",url:`${T}/repositories/${r.repository.owner.login}/${r.repository.name}/pullrequests/${r.id}/decline`,headers:A(this.config,t)})).body.title)throw new Error("Could not close pull request")}async mergePullRequest(e,t={}){let{pullRequest:r,mergeStrategy:n}=e,o;switch(n){case"MERGE_COMMIT":{o="merge_commit";break}case"FAST_FORWARD":{o="fast_forward";break}case"SQUASH":{o="squash";break}}let i={merge_strategy:o,type:"pullrequest"};if(!(await this.config.request({method:"POST",url:`${T}/repositories/${r.repository.owner.login}/${r.repository.name}/pullrequests/${r.id}/merge`,body:JSON.stringify(i),headers:{...A(this.config,t),"Content-Type":"application/json"}})).body.title)throw new Error("Could not merge pull request")}async setPullRequestReviewers(e,t={}){let{pullRequest:r,reviewers:n}=e,o={reviewers:n.map(a=>{if(a.username)throw new Error('Bitbucket reviewer requires "username" for this function.');return{username:a.username}})};if(!(await this.config.request({method:"PUT",url:`${T}/repositories/${r.repository.owner.login}/${r.repository.name}/pullrequests/${r.id}`,body:JSON.stringify(o),headers:{...A(this.config,t),"Content-Type":"application/json"}})).body.title)throw new Error("Could not set pull request reviewers")}};var nt=s=>({name:s.displayName,email:s.emailAddress,avatarUrl:s.avatarUrl??null,id:s.id.toString(),username:s.name,url:s.links.self[0].href}),re=s=>{var u,l,p,d,c,g;let e={OPEN:"OPEN",MERGED:"MERGED",DECLINED:"CLOSED"},t={UNAPPROVED:"REVIEW_REQUESTED",NEEDS_WORK:"CHANGES_REQUESTED",APPROVED:"APPROVED"},r=s.reviewers.map(m=>({reviewer:nt(m.user),state:t[m.status]})),n=((u=s.toRef.repository.links.clone.find(m=>m.name==="ssh"))==null?void 0:u.href)??null,o=((l=s.toRef.repository.links.clone.find(m=>m.name==="https"))==null?void 0:l.href)??null;o||(o=((p=s.toRef.repository.links.clone.find(m=>m.name==="http"))==null?void 0:p.href)??null);let i=((d=s.fromRef.repository.links.clone.find(m=>m.name==="ssh"))==null?void 0:d.href)??null,a=((c=s.fromRef.repository.links.clone.find(m=>m.name==="https"))==null?void 0:c.href)??null;return a||(a=((g=s.fromRef.repository.links.clone.find(m=>m.name==="http"))==null?void 0:g.href)??null),{id:s.id.toString(),number:s.id,title:s.title,url:s.links.self[0].href,state:e[s.state],isDraft:!1,createdDate:new Date(s.createdDate),updatedDate:new Date(s.updatedDate),closedDate:s.closedDate?new Date(s.closedDate):null,mergedDate:s.state=="MERGED"&&s.closedDate?new Date(s.closedDate):null,baseRef:{name:s.toRef.displayId,oid:s.toRef.latestCommit},headRef:{name:s.fromRef.displayId,oid:s.fromRef.latestCommit},commentCount:s.properties.commentCount,upvoteCount:null,commitCount:null,fileCount:null,additions:null,deletions:null,author:nt(s.author.user),assignees:null,reviews:r,reviewDecision:z(r),repository:{id:s.toRef.repository.id.toString(),name:s.toRef.repository.name,owner:{login:s.toRef.repository.project.key},remoteInfo:o&&n?{cloneUrlHTTPS:o,cloneUrlSSH:n}:null},headRepository:{id:s.fromRef.repository.id.toString(),name:s.fromRef.repository.name,owner:{login:s.fromRef.repository.project.key},remoteInfo:a&&i?{cloneUrlHTTPS:a,cloneUrlSSH:i}:null},headCommit:null,mergeableState:"UNKNOWN",permissions:null,version:s.version}},Yt=s=>{var e,t,r;return{id:s.id.toString(),namespace:s.project.key,name:s.slug,webUrl:((e=s.links.self[0])==null?void 0:e.href)??null,httpsUrl:((t=s.links.clone.find(n=>n.name==="https"))==null?void 0:t.href)??null,sshUrl:((r=s.links.clone.find(n=>n.name==="ssh"))==null?void 0:r.href)??null,defaultBranch:null,permission:null}},se=class extends k{getBaseUrl(e){let t=e.baseUrl||this.config.baseUrl;if(!t)throw new Error('Bitbucket Server requires "baseUrl"');return t}getRequestHeaders(e){return f(e.token||this.config.token)}async getCurrentUser(e={},t={}){let r=await this.config.request({url:`${this.getBaseUrl(t)}/users?limit=2`,headers:this.getRequestHeaders(t)}),{headers:{"x-auserid":n,"x-ausername":o}}=r,i=n?parseInt(n,10):null,a=decodeURIComponent(o),l=(await this.config.request({url:`${this.getBaseUrl(t)}/users?filter=${o}&avatarSize=64`,headers:this.getRequestHeaders(t)})).body.values.find(({emailAddress:p,id:d,name:c,slug:g})=>i?i===d:a===c||a===p||a===g);if(!l)throw new Error("Could not find current Bitbucket Server user");return{data:nt(l)}}async getRepo(e,t={}){let r=await this.config.request({url:`${this.getBaseUrl(t)}/projects/${e.namespace}/repos/${e.name}`,headers:this.getRequestHeaders(t)});return{data:Yt(r.body)}}async getRepos(e,t={}){let r=[],n=[];return await Promise.all(e.map(async o=>{try{let i=await this.getRepo(o,t);r.push(i.data)}catch(i){n.push({input:o,error:i})}})),{data:r,errors:n}}async getReposForCurrentUser(e,t={}){let r=e.page??0,n=await this.config.request({url:`${this.getBaseUrl(t)}/repos?start=${r}`,headers:this.getRequestHeaders(t)});return{pageInfo:{hasNextPage:!n.body.isLastPage,nextPage:n.body.nextPageStart},data:n.body.values.map(Yt)}}async getPullRequestsForRepoBase(e,t={}){var n;let r=new URL(`${this.getBaseUrl(t)}/projects/${encodeURI(e.repo.namespace)}/repos/${encodeURI(e.repo.name)}/pull-requests?state=OPEN`);return r.searchParams.set("start",((n=e.page)==null?void 0:n.toString())||"0"),r.searchParams.set("limit","50"),await this.config.request({url:r.toString(),headers:this.getRequestHeaders(t)})}async getPullRequestsForRepo(e,t={}){let r=[],n=await this.getPullRequestsForRepoBase(e,t);n.body.values.forEach(i=>{if(e.authorLogin&&i.author.user.name!==e.authorLogin)return null;r.push(re(i))});let o=n.body.values.length!==0;return{pageInfo:{hasNextPage:o,nextPage:o?n.body.start+n.body.values.length:null},data:r}}async getPullRequestsForRepos(e,t={}){let r=[];return await Promise.all(e.repos.map(async n=>{try{(await this.getPullRequestsForRepoBase({repo:n,...e},t)).body.values.forEach(i=>{if(e.authorLogin&&i.author.user.name!==e.authorLogin)return null;r.push(re(i))})}catch(o){if(o.statusCode!==404&&o.statusCode!==401)throw o}})),{data:r}}async getPullRequestsForCurrentUser(e,t={}){var i;let r=new URL(`${this.getBaseUrl(t)}/dashboard/pull-requests`);r.searchParams.set("state","OPEN"),r.searchParams.set("start",((i=e.page)==null?void 0:i.toString())||"0"),r.searchParams.set("limit","50");let n=await this.config.request({url:r.toString(),headers:this.getRequestHeaders(t)}),o=n.body.values.length!==0;return{pageInfo:{hasNextPage:o,nextPage:o?n.body.start+n.body.values.length:null},data:n.body.values.map(re)}}async closePullRequest(e,t={}){let{pullRequest:r}=e;if(r.version===void 0)throw new Error('Bitbucket Server requires "version" for this function.');if(!(await this.config.request({method:"POST",url:`${this.getBaseUrl(t)}/projects/${r.repository.owner.login}/repos/${r.repository.name}/pull-requests/${r.id}/decline`,body:JSON.stringify({version:r.version}),headers:{...this.getRequestHeaders(t),"Content-Type":"application/json"}})).body.title)throw new Error("Could not close pull request")}async mergePullRequest(e,t={}){let{pullRequest:r,mergeStrategyId:n}=e;if(e.mergeStrategy)throw new Error('Bitbucket Server uses "mergeStrategyId" instead of "mergeStrategy".');if(r.version===void 0)throw new Error('Bitbucket Server requires "version" for this function.');if(!(await this.config.request({method:"POST",url:`${this.getBaseUrl(t)}/projects/${r.repository.owner.login}/repos/${r.repository.name}/pull-requests/${r.id}/merge`,body:JSON.stringify({strategyId:n,version:r.version}),headers:{...this.getRequestHeaders(t),"Content-Type":"application/json"}})).body.title)throw new Error("Could not merge pull request")}async getMergeStrategies(e={}){let t=await this.config.request({url:`${this.getBaseUrl(e)}/admin/pull-requests/git`,headers:{...this.getRequestHeaders(e),"Content-Type":"application/json"}});return{data:{defaultStrategy:t.body.mergeConfig.defaultStrategy,strategies:t.body.mergeConfig.strategies}}}async setPullRequestReviewers(e,t={}){let{pullRequest:r,reviewers:n}=e;if(r.version===void 0)throw new Error('Bitbucket Server requires "version" for this function.');let o={reviewers:n.map(a=>{if(a.username)throw new Error('Bitbucket Server reviewer requires "username" for this function.');return{user:{name:a.username}}}),version:r.version};if(!(await this.config.request({method:"PUT",url:`${this.getBaseUrl(t)}/projects/${r.repository.owner.login}/repos/${r.repository.name}/pull-requests/${r.id}`,body:JSON.stringify(o),headers:{...this.getRequestHeaders(t),"Content-Type":"application/json"}})).body.title)throw new Error("Could not set pull request reviewers")}};var rr=require("js-base64");var me=(t=>(t.Open="OPEN",t.Closed="CLOSED",t))(me||{});var Tr={AS_CODE_OWNER:[3,0,0],CHECK_RUN:[3,0,0],LATEST_REVIEWS:[3,0,0],VIEWER_CAN_MERGE_AS_ADMIN:[3,5,0]},he=(s,e)=>{let t=Tr[e];for(let r=0;r<3;r++){if(s[r]>t[r])return!0;if(s[r]<t[r])return!1}return!0},Ie="https://api.github.com",Or=`${Ie}/graphql`,Re=`
2
2
  description
3
3
  dueOn
4
4
  id
@@ -1084,5 +1084,5 @@ query getLabelsForRepo(
1084
1084
  }
1085
1085
  }
1086
1086
  }
1087
- `,variables:{fullPath:`${r}/${n}`,after:o}},t);return{pageInfo:((l=(u=(a=i.body.data)==null?void 0:a.project)==null?void 0:u.labels)==null?void 0:l.pageInfo)??{endCursor:null,hasNextPage:!1},data:((g=(c=(d=(p=i.body.data)==null?void 0:p.project)==null?void 0:d.labels)==null?void 0:c.nodes)==null?void 0:g.map(Et))??[]}}};var bs="https://api.atlassian.com/ex/jira",ve=10,qt=["assignee","comment","summary","created","creator","updated","votes","issuetype","status","labels","components","project"],St=(s,e,t)=>{var o,i,a,u;let r=s.fields.assignee,n=!t;return{id:s.id,commentCount:s.fields.comment.comments.length,number:s.key,title:s.fields.summary,url:e?`${e}/browse/${s.key}`:null,closedDate:null,createdDate:new Date(s.fields.created),author:qe(s.fields.creator,e,n),updatedDate:new Date(s.fields.updated),assignees:r?[qe(r,e,n)]:[],description:null,repository:null,project:{name:s.fields.project.name,resourceId:t??null,key:s.fields.project.key,namespace:null},state:vs(s.fields.status),statusTransitions:((o=s.transitions)==null?void 0:o.map(ws))??[],components:((i=s.fields.components)==null?void 0:i.map(Ps))??[],type:s.fields.issuetype.name,upvoteCount:((a=s.fields.votes)==null?void 0:a.votes)||0,labels:((u=s.fields.labels)==null?void 0:u.map(l=>({color:null,description:null,id:null,name:l})))??[]}},ws=s=>{let e;switch(s.to.statusCategory.name){case"To Do":e="TO_DO";break;case"In Progress":e="IN_PROGRESS";break;default:e="DONE";break}return{name:s.name,id:s.id,to:{id:s.to.id,name:s.to.name,color:s.to.statusCategory.colorName,category:e}}},Ps=s=>({description:s.description??null,id:s.id,name:s.name}),Es=(s,e,t)=>t&&s.name?`${e}/secure/ViewProfile.jspa?name=${encodeURIComponent(s.name)}`:`${e}/jira/people/${s.accountId}`,qe=(s,e,t)=>({id:(t?s.key:s.accountId)??"",name:s.displayName,email:s.emailAddress,avatarUrl:s.avatarUrls["48x48"],username:s.displayName,url:Es(s,e,t)}),vs=s=>{let e;switch(s.statusCategory.name){case"To Do":e="TO_DO";break;case"In Progress":e="IN_PROGRESS";break;default:e="DONE";break}return{id:s.id,name:s.name,color:s.statusCategory.colorName,category:e}},V=(s,e,t)=>t?`${e.baseUrl||bs}/${t}`:`${(e==null?void 0:e.baseUrl)||s.baseUrl}`,Se=async(s,e,t,r={})=>{let{number:n,resourceId:o}=e||{},i=await s.request({url:`${V(s,r,o)}/rest/api/2/issue/${n}?fields=${qt.join(",")}&expand=transitions`,headers:f(r.token||s.token)});return{data:St(i.body,t,o)}},Ce=async(s,e,t,r={})=>{let{page:n,resourceId:o}=e||{},i=n??0,a=`statusCategory != Done AND (creator = currentUser() OR assignee = currentUser()
1087
+ `,variables:{fullPath:`${r}/${n}`,after:o}},t);return{pageInfo:((l=(u=(a=i.body.data)==null?void 0:a.project)==null?void 0:u.labels)==null?void 0:l.pageInfo)??{endCursor:null,hasNextPage:!1},data:((g=(c=(d=(p=i.body.data)==null?void 0:p.project)==null?void 0:d.labels)==null?void 0:c.nodes)==null?void 0:g.map(Et))??[]}}};var bs="https://api.atlassian.com/ex/jira",ve=10,qt=["assignee","comment","summary","created","creator","updated","votes","issuetype","status","labels","components","project"],St=(s,e,t)=>{var o,i,a,u;let r=s.fields.assignee,n=!t;return{id:s.id,commentCount:s.fields.comment.comments.length,number:s.key,title:s.fields.summary,url:e?`${e}/browse/${s.key}`:null,closedDate:null,createdDate:new Date(s.fields.created),author:qe(s.fields.creator,e,n),updatedDate:new Date(s.fields.updated),assignees:r?[qe(r,e,n)]:[],description:null,repository:null,project:{name:s.fields.project.name,resourceId:t??null,key:s.fields.project.key,namespace:null,id:s.fields.project.id},state:vs(s.fields.status),statusTransitions:((o=s.transitions)==null?void 0:o.map(ws))??[],components:((i=s.fields.components)==null?void 0:i.map(Ps))??[],type:s.fields.issuetype.name,upvoteCount:((a=s.fields.votes)==null?void 0:a.votes)||0,labels:((u=s.fields.labels)==null?void 0:u.map(l=>({color:null,description:null,id:null,name:l})))??[]}},ws=s=>{let e;switch(s.to.statusCategory.name){case"To Do":e="TO_DO";break;case"In Progress":e="IN_PROGRESS";break;default:e="DONE";break}return{name:s.name,id:s.id,to:{id:s.to.id,name:s.to.name,color:s.to.statusCategory.colorName,category:e}}},Ps=s=>({description:s.description??null,id:s.id,name:s.name}),Es=(s,e,t)=>t&&s.name?`${e}/secure/ViewProfile.jspa?name=${encodeURIComponent(s.name)}`:`${e}/jira/people/${s.accountId}`,qe=(s,e,t)=>({id:(t?s.key:s.accountId)??"",name:s.displayName,email:s.emailAddress,avatarUrl:s.avatarUrls["48x48"],username:s.displayName,url:Es(s,e,t)}),vs=s=>{let e;switch(s.statusCategory.name){case"To Do":e="TO_DO";break;case"In Progress":e="IN_PROGRESS";break;default:e="DONE";break}return{id:s.id,name:s.name,color:s.statusCategory.colorName,category:e}},V=(s,e,t)=>t?`${e.baseUrl||bs}/${t}`:`${(e==null?void 0:e.baseUrl)||s.baseUrl}`,Se=async(s,e,t,r={})=>{let{number:n,resourceId:o}=e||{},i=await s.request({url:`${V(s,r,o)}/rest/api/2/issue/${n}?fields=${qt.join(",")}&expand=transitions`,headers:f(r.token||s.token)});return{data:St(i.body,t,o)}},Ce=async(s,e,t,r={})=>{let{page:n,resourceId:o}=e||{},i=n??0,a=`statusCategory != Done AND (creator = currentUser() OR assignee = currentUser()
1088
1088
  OR comment ~ currentUser() OR summary ~ currentUser() OR description ~ currentUser())`,l=(await s.request({url:`${V(s,r,o)}/rest/api/2/search?jql=${a}&startAt=${i}&maxResults=${ve}&fields=${qt.join(",")}&expand=transitions`,headers:f(r.token||s.token)})).body.issues.map(d=>St(d,t,o)),p=l.length==ve;return{data:l,pageInfo:{hasNextPage:p,nextPage:p?i+l.length:null}}},ur=async(s,e,t,r={})=>{let{page:n,resourceId:o,jql:i}=e||{},a=n??0,l=(await s.request({url:`${V(s,r,o)}/rest/api/2/search?jql=${i.join(" AND ")}&startAt=${a}&maxResults=${ve}&fields=${qt.join(",")}&expand=transitions`,headers:f(r.token||s.token)})).body.issues.map(d=>St(d,t,o)),p=l.length==ve;return{data:l,pageInfo:{hasNextPage:p,nextPage:p?a+l.length:null}}},De=async(s,e,t,r={})=>{let{assigneeLogins:n,authorLogin:o,mentionLogin:i,page:a,projectKey:u,resourceId:l}=e||{},p=a??0,d=[`project = "${u}"`,"statusCategory != Done"];return o&&d.push(`creator in ("${o}")`),n&&n.length!==0&&d.push(`assignee in ("${n.join('", "')}")`),i&&d.push(`comment ~ "${i}"`),ur(s,{resourceId:l,jql:d,page:p},t,r)},Le=async(s,e,t,r={})=>{let{assigneeLogins:n,authorLogin:o,mentionLogin:i,page:a,projectKeys:u,resourceId:l}=e||{},p=a??0,c=["("+u.map(g=>`project = "${g}"`).join(" OR ")+")","statusCategory != Done"];return o&&c.push(`creator in ("${o}")`),n&&n.length!==0&&c.push(`assignee in ("${n.join('", "')}")`),i&&c.push(`comment ~ "${i}"`),ur(s,{resourceId:l,jql:c,page:p},t,r)},Ue=async(s,e,t={})=>{let{issue:r,labels:n}=e;if(!r.project)throw new Error('Jira requires a "project" for this function.');let o={fields:{labels:n.map(i=>i.name)}};await s.request({method:"PUT",url:`${V(s,t,r.project.resourceId??void 0)}/rest/api/2/issue/${r.id}`,body:JSON.stringify(o),headers:{...f(t.token||s.token),"Content-Type":"application/json"}})},Ae=async(s,e,t={})=>{let{issue:r,components:n}=e;if(!r.project)throw new Error('Jira requires a "project" for this function.');let o={fields:{components:n.map(i=>({id:i.id}))}};await s.request({method:"PUT",url:`${V(s,t,r.project.resourceId??void 0)}/rest/api/2/issue/${r.id}`,body:JSON.stringify(o),headers:{...f(t.token||s.token),"Content-Type":"application/json"}})},$e=async(s,e,t={})=>{let{issue:r,status:n}=e;if(!r.project)throw new Error('Jira requires a "project" for this function.');if(!n.id)throw new Error('Jira requires a status "id" for this function.');let o={transition:{id:n.id}};await s.request({method:"POST",url:`${V(s,t,r.project.resourceId??void 0)}/rest/api/2/issue/${r.id}/transitions`,body:JSON.stringify(o),headers:{...f(t.token||s.token),"Content-Type":"application/json"}})},Ge=async(s,e,t={})=>{let{resourceId:r,projectIdOrKey:n}=e,o=new URL(`${V(s,t,r)}/rest/api/2/project/${n}/components`);return{data:(await s.request({url:o.toString(),headers:f(t.token||s.token)})).body}};var ie="https://api.atlassian.com/ex/jira",Ct=100,ae=class extends G{constructor(){super(...arguments);this._resourceUrlCache={}}async getResourceUrl(t,r={}){var i;let n=r.token||this.config.token;if(!n)return null;let o=this._resourceUrlCache[n];return o?o[t.resourceId]??null:(await this.getJiraResourcesForCurrentUser(r),((i=this._resourceUrlCache[n])==null?void 0:i[t.resourceId])??null)}async getCurrentUserForResource(t,r={}){let n=await this.getResourceUrl({resourceId:t.resourceId},r),o=await this.config.request({url:`${r.baseUrl||ie}/${t.resourceId}/rest/api/2/myself`,headers:f(r.token||this.config.token)});return{data:{name:o.body.displayName,email:o.body.emailAddress,avatarUrl:o.body.avatarUrls["48x48"],id:o.body.accountId,username:o.body.displayName,url:n?`${n}/jira/people/${o.body.accountId}`:null}}}async getJiraResourcesForCurrentUser(t={}){let r=await this.config.request({url:`${t.baseUrl||"https://api.atlassian.com/"}/oauth/token/accessible-resources`,headers:f(t.token||this.config.token)}),n=t.token||this.config.token,o=n?this._resourceUrlCache[n]||{}:void 0,i=r.body.map(a=>(o&&(o[a.id]=a.url),{avatarUrl:a.avatarUrl,id:a.id,name:a.name,url:a.url}));return n&&(this._resourceUrlCache[n]=o),{data:i}}async getJiraProjectsForResource(t,r={}){let n=new URL(`${r.baseUrl||ie}/${t.resourceId}/rest/api/2/project/search`);n.searchParams.set("maxResults",Ct.toString()),t.cursor&&n.searchParams.set("startAt",t.cursor);let o=await this.config.request({url:n.toString(),headers:f(r.token||this.config.token)});return{pageInfo:{hasNextPage:o.body.values.length!==0,endCursor:(o.body.startAt+o.body.values.length).toString()},data:o.body.values.map(i=>({id:i.id,key:i.key,name:i.name,resourceId:t.resourceId}))}}async getJiraProjectsForResources(t,r={}){let n=[];return await Promise.all(t.resourceIds.map(async o=>Ht(i=>this.getJiraProjectsForResource({resourceId:o,cursor:i},r)))).then((...o)=>{o.forEach(i=>{n=n.concat(...i)})}),{data:n}}async getAccountsForJiraProject(t,r={}){let{resourceId:n,projectKey:o,cursor:i}=t,a=await this.getResourceUrl({resourceId:n},r),u=new URL(`${r.baseUrl||ie}/${n}/rest/api/2/user/assignable/search`);u.searchParams.set("maxResults",Ct.toString()),i&&u.searchParams.set("startAt",i),u.searchParams.set("project",o);let l=await this.config.request({url:u.toString(),headers:f(r.token||this.config.token)});return{pageInfo:{hasNextPage:l.body.length!==0,endCursor:((i?parseInt(i):0)+l.body.length).toString()},data:l.body.filter(p=>p.accountType!=="app"&&p.active).map(p=>qe(p,a,!1))}}async getComponentsForJiraProject(t,r={}){return await Ge(this.config,t,r)}async getIssue(t,r={}){let n=await this.getResourceUrl({resourceId:t.resourceId},r);return await Se(this.config,t,n,r)}async getIssuesForProject(t,r={}){let n=await this.getResourceUrl({resourceId:t.resourceId},r);return await De(this.config,t,n,r)}async getIssuesForProjects(t,r={}){let n=await this.getResourceUrl({resourceId:t.resourceId},r);return await Le(this.config,t,n,r)}async getIssuesForResourceForCurrentUser(t,r={}){let n=await this.getResourceUrl({resourceId:t.resourceId},r);return await Ce(this.config,t,n,r)}async setIssueStatus(t,r={}){await $e(this.config,t,r)}async setIssueAssignee(t,r={}){let{issue:n,assignee:o}=t;if(!n.project)throw new Error('Jira Cloud requires a "project" for this function.');if(!n.project.resourceId)throw new Error('Jira Cloud requires a project "resourceId" for this function.');let i={accountId:o==null?void 0:o.id};await this.config.request({method:"PUT",url:`${r.baseUrl||ie}/${n.project.resourceId}/rest/api/2/issue/${n.id}/assignee`,body:JSON.stringify(i),headers:{...f(r.token||this.config.token),"Content-Type":"application/json"}})}async setIssueComponents(t,r={}){await Ae(this.config,t,r)}async setIssueLabels(t,r={}){await Ue(this.config,t,r)}async getLabelsForResource(t,r={}){let{resourceId:n,cursor:o}=t,i=new URL(`${r.baseUrl||ie}/${n}/rest/api/2/label`);i.searchParams.set("maxResults",Ct.toString()),o&&i.searchParams.set("startAt",o);let a=await this.config.request({url:i.toString(),headers:f(r.token||this.config.token)});return{pageInfo:{hasNextPage:!a.body.isLast,endCursor:(a.body.startAt+a.body.values.length).toString()},data:a.body.values.map(u=>({color:null,description:null,id:null,name:u}))}}};var ue=class extends k{async getCurrentUser(e={}){let t=await this.config.request({url:`${(e==null?void 0:e.baseUrl)||this.config.baseUrl}/rest/api/2/myself`,headers:f((e==null?void 0:e.token)||this.config.token)});return{data:{name:t.body.displayName,email:t.body.emailAddress,avatarUrl:t.body.avatarUrls["48x48"],id:t.body.key,username:t.body.displayName,url:null}}}async getJiraProjects(e={}){return{data:(await this.config.request({url:`${(e==null?void 0:e.baseUrl)||this.config.baseUrl}/rest/api/2/project`,headers:f((e==null?void 0:e.token)||this.config.token)})).body.map(r=>({id:r.id,name:r.name}))}}async getIssue(e,t={}){if(!t.baseUrl)throw new Error('Jira Server requires a "baseUrl" for this function.');return await Se(this.config,e,t.baseUrl,t)}async getIssuesForProject(e,t={}){if(!t.baseUrl)throw new Error('Jira Server requires a "baseUrl" for this function.');return await De(this.config,e,t.baseUrl,t)}async getIssuesForProjects(e,t={}){if(!t.baseUrl)throw new Error('Jira Server requires a "baseUrl" for this function.');return await Le(this.config,e,t.baseUrl,t)}async getIssuesForResourceForCurrentUser(e,t={}){if(!t.baseUrl)throw new Error('Jira Server requires a "baseUrl" for this function.');return await Ce(this.config,e,t.baseUrl,t)}async setIssueStatus(e,t={}){await $e(this.config,e,t)}async setIssueLabels(e,t={}){await Ue(this.config,e,t)}async setIssueComponents(e,t={}){await Ae(this.config,e,t)}async getLabels(e={}){return{data:(await this.config.request({url:`${(e==null?void 0:e.baseUrl)||this.config.baseUrl}/rest/api/2/jql/autocompletedata/suggestions?fieldName=labels`,headers:f(e.token||this.config.token)})).body.results.map(({displayName:r})=>({color:null,description:null,id:null,name:r}))}}async getComponentsForJiraProject(e,t={}){return await Ge(this.config,e,t)}};var M="https://api.trello.com",qs=1e3,Ss=(s,e)=>{let t=new Date(1e3*parseInt(s.id.substring(0,8),16));return{id:s.id,commentCount:s.badges.comments,number:s.idShort.toString(),title:s.name,url:s.url,closedDate:null,createdDate:new Date(t.toISOString()),author:null,updatedDate:new Date(s.dateLastActivity),assignees:s.idMembers.map(r=>({id:r,username:null,name:null,email:null,avatarUrl:null,url:null})),description:null,state:e[s.idList??""]?{id:s.idList,name:e[s.idList].name,color:null}:null,type:null,repository:null,upvoteCount:s.badges.votes,labels:s.labels.map(r=>({color:r.color,description:null,id:r.id,name:r.name}))}},le=class extends G{async getCurrentUser(e,t={}){let r=await this.config.request({url:`${t.baseUrl||M}/1/members/me?key=${e.appKey}&token=${t.token||this.config.token}`,headers:f(t.token||this.config.token)});return{data:{name:r.body.fullName,email:r.body.email,avatarUrl:r.body.avatarHash?`https://trello-members.s3.amazonaws.com/${r.body.id}/${r.body.avatarHash}/50.png`:null,id:r.body.id,username:r.body.username,url:r.body.url}}}async getBoardsForCurrentUser(e,t={}){return{data:(await this.config.request({url:`${t.baseUrl||M}/1/members/me/boards?fields=name&key=${e.appKey}&token=${t.token||this.config.token}&filter=open`,headers:f(t.token||this.config.token)})).body.map(n=>({id:n.id,name:n.name}))}}async getListsForTrelloBoard(e,t={}){let{appKey:r,boardId:n}=e;return{data:(await this.config.request({url:`${t.baseUrl||M}/1/boards/${n}/lists?key=${r}&token=${t.token||this.config.token}`,headers:f(t.token||this.config.token)})).body}}async getAccountsForTrelloBoard(e,t={}){let{appKey:r,boardId:n}=e;return{data:(await this.config.request({url:`${t.baseUrl||M}/1/boards/${n}/members?key=${r}&token=${t.token||this.config.token}`,headers:f(t.token||this.config.token)})).body.map(i=>({id:i.id,name:i.fullName,username:i.username,email:null,avatarUrl:null,url:null}))}}async getIssuesForBoard(e,t={}){let r=["-is:archived","sort:edited"],{appKey:n,boardId:o,filterText:i,assigneeLogins:a,trelloBoardListsById:u}=e||{};a&&r.push("@me");let l=`${i?`${i}`:""}${r.join(" ")} board:${o}`;return{data:(await this.config.request({url:`${t.baseUrl||M}/1/search?key=${n}&query=${l}&cards_limit=${qs}&token=${t.token||this.config.token}`,headers:f(t.token||this.config.token)})).body.cards.map(d=>Ss(d,u||{}))}}async updateIssue(e,t,r,n){return await this.config.request({method:"PUT",url:`${n.baseUrl||M}/1/cards/${t.id}?key=${e}&token=${n.token||this.config.token}&${r}`,headers:f(n.token||this.config.token)})}async setIssueStatus(e,t={}){let{appKey:r,issue:n,status:o}=e;if(!o.id)throw new Error('Trello requires a status "id" for this function.');let i=`idList=${o.id}`;if(!(await this.updateIssue(r,n,i,t)).body.id)throw new Error("Could not set issue status")}async setIssueAssignees(e,t={}){let{appKey:r,issue:n,assignees:o}=e,i=o.map(l=>l.id),a=`idMembers=${encodeURIComponent(i.join(","))}`;if(!(await this.updateIssue(r,n,a,t)).body.id)throw new Error("Could not set issue status")}async setIssueLabels(e,t={}){let{appKey:r,issue:n,labels:o}=e,i=o.map(u=>u.id).join(",");if(!(await this.config.request({method:"PUT",url:`${t.baseUrl||M}/1/cards/${n.id}?key=${r}&token=${t.token||this.config.token}&idLabels=${encodeURIComponent(i)}`,headers:f(t.token||this.config.token)})).body.id)throw new Error("Could not set issue status")}async setIssueArchived(e,t={}){let{appKey:r,issue:n,archived:o}=e;if(!(await this.config.request({method:"PUT",url:`${t.baseUrl||M}/1/cards/${n.id}?key=${r}&token=${t.token||this.config.token}&closed=${o}`,headers:f(t.token||this.config.token)})).body.id)throw new Error("Could not update issue archived status")}async archiveIssue(e,t={}){await this.setIssueArchived({...e,archived:!0},t)}async unArchiveIssue(e,t={}){await this.setIssueArchived({...e,archived:!1},t)}async getLabelsForBoard(e,t={}){let{appKey:r,boardId:n}=e;return{data:(await this.config.request({url:`${t.baseUrl||M}/1/boards/${n}/labels?key=${r}&token=${t.token||this.config.token}`,headers:f(t.token||this.config.token)})).body.map(i=>({color:i.color,description:null,id:i.id,name:i.name}))}}};var Te={};x(Te,{default:()=>Cs});var Cs={};var Oe={};x(Oe,{default:()=>Ds});var Ds={};var xe={};x(xe,{restApiPullRequestToCommonPullRequest:()=>Ls});var Ls=s=>re(s);var Je={};x(Je,{decode:()=>Gs,decodeV0:()=>Ts,encode:()=>$s,validate:()=>As});var D=(t=>(t.Zero="0",t.One="1",t))(D||{}),L=(t=>(t.PullRequest="pr",t.Issue="issue",t))(L||{}),U=(p=>(p.Azure="azure",p.Github="github",p.GithubEnterprise="githubEnterprise",p.Gitlab="gitlab",p.GitlabSelfHosted="gitlabSelfHosted",p.Bitbucket="bitbucket",p.BitbucketServer="bitbucketServer",p.Jira="jira",p.JiraServer="jiraServer",p.Trello="trello",p))(U||{});var ke=class{constructor(){}validate(e){if(!e.organizationName)throw new Error("organizationName is required");if(!e.projectId)throw new Error("projectId is required");if(!e.entityId)throw new Error("issueId is required")}encode(e){if(this.validate(e),!e.organizationName||!e.projectId||!e.entityId)throw new Error("Missing required fields for Azure DevOps issue uniqueId");let t=[];return t.push("azure"),t.push("issue"),t.push("1"),t.push(e.domain||""),t.push(e.organizationName),t.push(e.projectId),t.push(e.entityId),JSON.stringify(t)}decode(e){if(e.length<7)throw new Error("Invalid Azure DevOps issue uniqueId, check version");return{provider:e[0],entityType:e[1],version:e[2],domain:e[3]==""?null:e[3],resourceId:null,accountOrOrgId:null,organizationName:e[4],projectId:e[5],repoId:null,entityId:e[6]}}};var Ne=class{constructor(){}validate(e){if(!e.organizationName)throw new Error("organizationName is required");if(!e.projectId)throw new Error("projectId is required");if(!e.repoId)throw new Error("repoId is required");if(!e.entityId)throw new Error("entityId is required")}encode(e){if(this.validate(e),!e.organizationName||!e.projectId||!e.repoId||!e.entityId)throw new Error("Missing required fields for Azure DevOps pull request uniqueId");let t=[];return t.push("azure"),t.push("pr"),t.push("1"),t.push(e.domain||""),t.push(e.organizationName),t.push(e.projectId),t.push(e.repoId),t.push(e.entityId),JSON.stringify(t)}decode(e){if(e.length<8)throw new Error("Invalid Azure DevOps pull request uniqueId, check version");return{provider:e[0],entityType:e[1],version:e[2],domain:e[3]==""?null:e[3],resourceId:null,accountOrOrgId:null,organizationName:e[4],projectId:e[5],repoId:e[6],entityId:e[7]}}};var _e=class{constructor(){}validate(e){if(e.domain&&e.provider=="bitbucket")throw new Error("domain is only supported for BitbucketServer");if(!e.repoId)throw new Error("repoId is required");if(!e.entityId)throw new Error("issueId is required")}encode(e){if(this.validate(e),!e.repoId||!e.entityId)throw new Error("Missing required fields for Bitbucket DevOps issue uniqueId");let t=[];return t.push(e.domain?"bitbucketServer":"bitbucket"),t.push("issue"),t.push("1"),t.push(e.domain||""),t.push(e.repoId),t.push(e.entityId),JSON.stringify(t)}decode(e){if(e.length<6)throw new Error("Invalid Bitbucket DevOps issue uniqueId, check version");return{provider:e[0],entityType:e[1],version:e[2],domain:e[3]==""?null:e[3],resourceId:null,accountOrOrgId:null,organizationName:null,projectId:null,repoId:e[4],entityId:e[5]}}};var Qe=class{constructor(){}validate(e){if(e.domain&&e.provider=="bitbucket")throw new Error("domain is only supported for BitbucketServer");if(!e.repoId)throw new Error("repoId is required");if(!e.entityId)throw new Error("entityId is required")}encode(e){if(this.validate(e),!e.repoId||!e.entityId)throw new Error("Missing required fields for Bitbucket DevOps pull request uniqueId");let t=[];return t.push(e.domain?"bitbucketServer":"bitbucket"),t.push("pr"),t.push("1"),t.push(e.domain||""),t.push(e.repoId),t.push(e.entityId),JSON.stringify(t)}decode(e){if(e.length<6)throw new Error("Invalid Bitbucket DevOps pull request uniqueId, check version");return{provider:e[0],entityType:e[1],version:e[2],domain:e[3]==""?null:e[3],resourceId:null,accountOrOrgId:null,organizationName:null,projectId:null,repoId:e[4],entityId:e[5]}}};var Be=class{constructor(){}validate(e){if(e.domain&&e.provider=="github")throw new Error("domain is only supported for GithubEnterprise");if(!e.entityId)throw new Error("entityId is required")}encode(e){if(this.validate(e),!e.entityId)throw new Error("Missing required fields for Github issue uniqueId");let t=[];return t.push(e.domain?"githubEnterprise":"github"),t.push("issue"),t.push("1"),t.push(e.domain||""),t.push(e.entityId),JSON.stringify(t)}decode(e){if(e.length<5)throw new Error("Invalid Github issue uniqueId, check version");return{provider:e[0],entityType:e[1],version:e[2],domain:e[3]==""?null:e[3],resourceId:null,accountOrOrgId:null,organizationName:null,projectId:null,repoId:null,entityId:e[4]}}};var je=class{constructor(){}validate(e){if(e.domain&&e.provider=="github")throw new Error("domain is only supported for GithubEnterprise");if(!e.entityId)throw new Error("entityId is required")}encode(e){if(this.validate(e),!e.entityId)throw new Error("Missing required fields for Github pull request uniqueId");let t=[];return t.push(e.domain?"githubEnterprise":"github"),t.push("pr"),t.push("1"),t.push(e.domain||""),t.push(e.entityId),JSON.stringify(t)}decode(e){if(e.length<5)throw new Error("Invalid Github pull request uniqueId, check version");return{provider:e[0],entityType:e[1],version:e[2],domain:e[3]==""?null:e[3],resourceId:null,accountOrOrgId:null,organizationName:null,projectId:null,repoId:null,entityId:e[4]}}};var Fe=class{constructor(){}validate(e){if(e.domain&&e.provider=="gitlab")throw new Error("domain is only supported for GitlabSelfHosted");if(!e.entityId)throw new Error("entityId is required")}encode(e){if(this.validate(e),!e.entityId)throw new Error("Missing required fields for Gitlab issue uniqueId");let t=[];return t.push(e.domain?"gitlabSelfHosted":"gitlab"),t.push("issue"),t.push("1"),t.push(e.domain||""),t.push(e.entityId),JSON.stringify(t)}decode(e){if(e.length<5)throw new Error("Invalid Gitlab issue uniqueId, check version");return{provider:e[0],entityType:e[1],version:e[2],domain:e[3]==""?null:e[3],resourceId:null,accountOrOrgId:null,organizationName:null,projectId:null,repoId:null,entityId:e[4]}}};var Me=class{constructor(){}validate(e){if(e.domain&&e.provider=="gitlab")throw new Error("domain is only supported for GitlabSelfHosted");if(!e.entityId)throw new Error("entityId is required")}encode(e){if(this.validate(e),!e.entityId)throw new Error("Missing required fields for Gitlab pull request uniqueId");let t=[];return t.push(e.domain?"gitlabSelfHosted":"gitlab"),t.push("pr"),t.push("1"),t.push(e.domain||""),t.push(e.entityId),JSON.stringify(t)}decode(e){if(e.length<5)throw new Error("Invalid Gitlab pull request uniqueId, check version");return{provider:e[0],entityType:e[1],version:e[2],domain:e[3]==""?null:e[3],resourceId:null,accountOrOrgId:null,organizationName:null,projectId:null,repoId:null,entityId:e[4]}}};var ze=class{constructor(){}validate(e){if(e.domain&&e.provider=="jira")throw new Error("domain is only supported for JiraServer");if(e.resourceId&&e.provider=="jiraServer")throw new Error("resourceId is only supported for Jira Cloud");if(!e.resourceId&&e.provider=="jira")throw new Error("resourceId is required");if(!e.projectId)throw new Error("projectId is required");if(!e.entityId)throw new Error("entityId is required")}encode(e){if(this.validate(e),!e.projectId||!e.entityId)throw new Error("Missing required fields for Jira issue uniqueId");let t=[];return t.push(e.domain?"jiraServer":"jira"),t.push("issue"),t.push("1"),t.push(e.domain||""),t.push(e.resourceId||""),t.push(e.projectId),t.push(e.entityId),JSON.stringify(t)}decode(e){if(e.length<7)throw new Error("Invalid Jira issue uniqueId, check version");return{provider:e[0],entityType:e[1],version:e[2],domain:e[3]==""?null:e[3],resourceId:e[4]==""?null:e[4],accountOrOrgId:null,organizationName:null,projectId:e[5],repoId:null,entityId:e[6]}}};var He=class{constructor(){}validate(e){if(!e.accountOrOrgId)throw new Error("accountOrOrgId is required");if(!e.projectId)throw new Error("projectId is required");if(!e.entityId)throw new Error("entityId is required")}encode(e){if(this.validate(e),!e.accountOrOrgId||!e.projectId||!e.entityId)throw new Error("Missing required fields for Trello issue uniqueId");let t=[];return t.push("trello"),t.push("issue"),t.push("1"),t.push(""),t.push(e.accountOrOrgId),t.push(e.projectId),t.push(e.entityId),JSON.stringify(t)}decode(e){if(e.length<7)throw new Error("Invalid Trello issue uniqueId, check version");return{provider:e[0],entityType:e[1],version:e[2],domain:e[3]==""?null:e[3],resourceId:null,accountOrOrgId:e[4],organizationName:null,projectId:e[5],repoId:null,entityId:e[6]}}};var We=(s,e)=>{if(!e)throw new Error("entityType is required");if(!s)throw new Error("provider is required");switch(s){case"azure":return e==="pr"?new Ne:new ke;case"bitbucket":case"bitbucketServer":return e==="pr"?new Qe:new _e;case"github":case"githubEnterprise":return e==="pr"?new je:new Be;case"gitlab":case"gitlabSelfHosted":return e==="pr"?new Me:new Fe;case"jira":case"jiraServer":if(e==="pr")throw new Error("EntityType PullRequest is not valid for Jira");return new ze;case"trello":if(e==="pr")throw new Error("EntityType PullRequest is not valid for Jira");return new He;default:throw new Error("unknown provider")}},Us=s=>{if(!s.entityType)throw new Error("entityType is required");if(!s.provider)throw new Error("provider is required");if(!s.entityId)throw new Error("entityID is required")},As=s=>{if(s.version==="0"){Us(s);return}We(s.provider,s.entityType).validate(s)},$s=s=>We(s.provider,s.entityType).encode(s),Gs=s=>{let e=JSON.parse(s);if(!e||!e.length)throw new Error("invalid issue unique id");return We(e[0],e[1]).decode(e)},Ts=(s,e,t)=>{if(!t)throw new Error("entityID is required");try{let r=JSON.parse(t);if(!r||!r.length)throw new Error("Invalid pull request uniqueId");let n=[s,e,"0",...r];return We(s,e).decode(n)}catch{return{provider:s,entityType:e,version:"0",domain:"",resourceId:null,accountOrOrgId:null,organizationName:null,projectId:null,repoId:null,entityId:t}}};var Ve={};x(Ve,{CHANGES_REQUESTED_ACTION_CATEGORY:()=>mr,CHANGES_REQUESTED_BUCKET_ID:()=>Tt,CONFLICTS_ACTION_CATEGORY:()=>cr,CONFLICTS_BUCKET_ID:()=>$t,DRAFT_ACTION_CATEGORY:()=>Ir,DRAFT_BUCKET_ID:()=>kt,FAILING_CI_ACTION_CATEGORY:()=>dr,FAILING_CI_BUCKET_ID:()=>At,NEEDS_MY_REVIEW_ACTION_CATEGORY:()=>gr,NEEDS_MY_REVIEW_BUCKET_ID:()=>Gt,OTHER_ACTION_CATEGORY:()=>Rr,OTHER_BUCKET_ID:()=>Nt,PINNED_BUCKET_ID:()=>Dt,READY_TO_MERGE_ACTION_CATEGORY:()=>lr,READY_TO_MERGE_BUCKET_ID:()=>Lt,REVIEWER_COMMENTED_ACTION_CATEGORY:()=>hr,REVIEWER_COMMENTED_BUCKET_ID:()=>Ot,SNOOZED_BUCKET_ID:()=>_t,UNASSIGNED_REVIEWERS_ACTION_CATEGORY:()=>pr,UNASSIGNED_REVIEWERS_BUCKET_ID:()=>Ut,WAITING_FOR_REVIEW_ACTION_CATEGORY:()=>fr,WAITING_FOR_REVIEW_BUCKET_ID:()=>xt,getActionablePullRequests:()=>yr,groupPullRequestsIntoBuckets:()=>Os});var $=(s,e,t,r)=>({id:s,faIconName:t,name:e,priority:r,pullRequests:[]}),Dt="pinned",Lt="readyToMerge",Ut="unassignedReviewers",At="failingCI",$t="conflicts",Gt="needsMyReview",Tt="changesRequested",Ot="reviewerCommented",xt="waitingForReview",kt="draft",Nt="other",_t="snoozed",lr="readyToMerge",pr="unassignedReviewers",dr="failingCI",cr="conflicts",gr="needsMyReview",mr="changesRequested",hr="reviewerCommented",fr="waitingForReview",Ir="draft",Rr="other",yr=(s,e,t)=>s.map(r=>{var u,l,p,d,c,g,m,I,w,h,y,q,C,Y;let o={...r,...{suggestedActionCategory:Rr,priority:1e3,viewer:{canMerge:!1,isAuthor:!1,isAssignee:!1,isReviewer:!1,shouldMerge:!1,shouldAssignReviewer:!1,waitingOnReviews:!1,shouldReview:!1},failingCI:!1,hasConflicts:!1,changeRequestReviewCount:0,codeSuggestionsCount:0,commentReviewCount:0,approvalReviewCount:0}};o.viewer.isAuthor=((u=r.author)==null?void 0:u.id)===e.id,o.viewer.isAssignee=((l=r.assignees)==null?void 0:l.some(E=>E.id===e.id))??!1,o.viewer.isReviewer=((p=r.reviews)==null?void 0:p.some(E=>E.reviewer.id===e.id))??!1,o.viewer.canMerge=((d=r.permissions)==null?void 0:d.canMerge)??!0,o.hasConflicts=r.mergeableState==="CONFLICTS",o.failingCI=((g=(c=r.headCommit)==null?void 0:c.buildStatuses)==null?void 0:g.some(E=>E.state==="ERROR"||E.state==="FAILED"))??!1,o.commentReviewCount=((m=r.reviews)==null?void 0:m.filter(E=>E.state==="COMMENTED").length)??0,o.approvalReviewCount=((I=r.reviews)==null?void 0:I.filter(E=>E.state==="APPROVED").length)??0,o.changeRequestReviewCount=((w=r.reviews)==null?void 0:w.filter(E=>E.state==="CHANGES_REQUESTED").length)??0;let i=(h=t==null?void 0:t.enrichedItemsByUniqueId)==null?void 0:h[r.uuid];i!=null&&(o.viewer.enrichedItems=i,i.some(E=>E.type==="pin")&&(o.viewer.pinned=!0,o.priority-=800),i.some(E=>E.type==="snooze")&&(o.viewer.snoozed=!0));let a=((q=(y=t==null?void 0:t.codeSuggestionsCountByPrUuid)==null?void 0:y[r.uuid])==null?void 0:q.count)||0;return a&&(o.codeSuggestionsCount=a),(o.viewer.isAuthor||o.viewer.isAssignee&&!o.viewer.isReviewer)&&o.viewer.canMerge&&!o.isDraft&&!o.failingCI&&r.mergeableState==="MERGEABLE"&&(!r.reviewDecision||r.reviewDecision==="APPROVED")&&(o.viewer.shouldMerge=!0,o.suggestedActionCategory=lr),o.viewer.isAuthor&&r.isDraft&&(o.suggestedActionCategory=Ir),o.viewer.isAuthor&&r.reviewDecision==="REVIEW_REQUESTED"&&(o.suggestedActionCategory=fr,o.viewer.waitingOnReviews=!0),o.viewer.isAuthor&&r.reviewDecision==="COMMENTED"&&(o.suggestedActionCategory=hr),o.viewer.isAuthor&&o.failingCI&&(o.suggestedActionCategory=dr),o.viewer.isAuthor&&o.hasConflicts&&(o.suggestedActionCategory=cr),o.viewer.isAuthor&&(r.reviewDecision==="CHANGES_REQUESTED"||o.codeSuggestionsCount>0)&&(o.suggestedActionCategory=mr),o.viewer.isAuthor&&!((C=r.reviews)!=null&&C.length)&&(o.suggestedActionCategory=pr,o.viewer.shouldAssignReviewer=!0),(Y=r.reviews)!=null&&Y.some(E=>E.reviewer.id===e.id&&E.state==="REVIEW_REQUESTED")&&(o.suggestedActionCategory=gr,o.viewer.shouldReview=!0),o}),Os=(s,e,t)=>{let r={pinned:$(Dt,"Pinned","thumbtack",-1),readyToMerge:$(Lt,"Ready to Merge","code-merge",0),unassignedReviewers:$(Ut,"Unassigned Reviewers","user-plus",1),failingCI:$(At,"Failing CI","circle-x",2),conflicts:$($t,"Resolve Conflicts","triangle-exclamation",3),needsMyReview:$(Gt,"Needs My Review","eye",4),changesRequested:$(Tt,"Suggested Changes","file-plus",5),reviewerCommented:$(Ot,"Reviewer Commented","comment",6),waitingForReview:$(xt,"Waiting for Review","circle-pause",7),draft:$(kt,"Draft","compass-drafting",8),other:$(Nt,"Other","ellipsis",9),snoozed:$(_t,"Snoozed","snooze",10)},o=yr(s,e,t).reduce((i,a)=>(i[a.uuid]=a,i),{});return s.forEach(i=>{let a=o[i.uuid],u=!0;if(a.viewer.snoozed){r[_t].pullRequests.push(i);return}a.viewer.pinned&&r[Dt].pullRequests.push(i),(a.viewer.isAuthor||a.viewer.isAssignee&&!a.viewer.isReviewer)&&!a.isDraft&&a.viewer.canMerge&&a.mergeableState==="MERGEABLE"&&(!i.reviewDecision||i.reviewDecision==="APPROVED")&&(r[Lt].pullRequests.push(i),u=!1),a.viewer.shouldAssignReviewer&&(r[Ut].pullRequests.push(i),u=!1),a.viewer.isAuthor&&a.failingCI&&(r[At].pullRequests.push(i),u=!1),a.viewer.isAuthor&&a.hasConflicts&&(r[$t].pullRequests.push(i),u=!1),a.viewer.shouldReview&&(r[Gt].pullRequests.push(i),u=!1),a.viewer.isAuthor&&(a.reviewDecision==="CHANGES_REQUESTED"||a.codeSuggestionsCount>0)&&(r[Tt].pullRequests.push(i),u=!1),a.viewer.isAuthor&&a.reviewDecision==="COMMENTED"&&(r[Ot].pullRequests.push(i),u=!1),a.viewer.isAuthor&&a.reviewDecision==="REVIEW_REQUESTED"&&(r[xt].pullRequests.push(i),u=!1),a.isDraft&&(r[kt].pullRequests.push(i),u=!1),u&&r[Nt].pullRequests.push(i)}),Object.values(r).forEach(i=>{i.pullRequests.sort((a,u)=>o[a.uuid].priority-o[u.uuid].priority)}),r};var Ke={};x(Ke,{getPullRequestRank:()=>xs});var xs=(s,e,t)=>{var i,a,u;let r=0,n,o;return(i=s.reviews)==null||i.forEach(l=>{l.reviewer.id===e&&(n=l.state),l.state==="CHANGES_REQUESTED"?o="CHANGES_REQUESTED":l.state==="APPROVED"&&o!=="CHANGES_REQUESTED"&&(o="APPROVED")}),o||(o="REVIEW_REQUESTED"),((a=s.author)==null?void 0:a.id)===e?r+=1e3:(u=s.assignees)!=null&&u.find(l=>l.id===e)?r+=900:n==="REVIEW_REQUESTED"?r+=800:t&&(r+=700),o==="APPROVED"?s.mergeableState==="MERGEABLE"?r+=100:s.mergeableState==="CONFLICTS"?r+=90:r+=80:o=="CHANGES_REQUESTED"&&(r+=70),r};var Xe={};x(Xe,{default:()=>ks});var ks={};var Ye={};x(Ye,{default:()=>Ns});var Ns={};var Ze={};x(Ze,{default:()=>_s});var _s={};var br=(i=>(i.Conflicts="conflicts",i.Failure="failure",i.NotSet="notSet",i.Queued="queued",i.RejectedByPolicy="rejectedByPolicy",i.Succeeded="succeeded",i))(br||{});var wr=(t=>(t.Completed="COMPLETED",t.NotPlanned="NOT_PLANNED",t))(wr||{});var Qs=s=>{let e={request:s==null?void 0:s.request};return{azureDevOps:new ee({...e,...s==null?void 0:s.azureDevOps}),bitbucket:new te({...e,...s==null?void 0:s.bitbucket}),bitbucketServer:new se({...e,...s==null?void 0:s.bitbucketServer}),github:new ne({...e,...s==null?void 0:s.github}),gitlab:new oe({...e,...s==null?void 0:s.gitlab}),jira:new ae({...e,...s==null?void 0:s.jira}),jiraServer:new ue({...e,...s==null?void 0:s.jiraServer}),trello:new le({...e,...s==null?void 0:s.trello})}},Bs=Qs;var js={azureDevOps:Te,bitbucket:Oe,bitbucketServer:xe,github:Ke,gitlab:Xe,gitProvider:Ve,jira:Ye,trello:Ze,entityIdentifier:Je};
@@ -62,11 +62,11 @@ export declare class AzureDevOps extends Provider implements GitProvider, IssueP
62
62
  };
63
63
  data: {
64
64
  avatarUrl: string | null;
65
- descriptor: string;
66
- email: string;
67
- name: string;
68
- storageKeyURL: string;
69
- username: string;
65
+ descriptor: string | null;
66
+ email: string | null;
67
+ name: string | null;
68
+ storageKeyURL: string | null;
69
+ username: string | null;
70
70
  }[];
71
71
  }>;
72
72
  getAccountFromAzureGraphAccount(input: {
@@ -76,8 +76,8 @@ export declare class AzureDevOps extends Provider implements GitProvider, IssueP
76
76
  avatarUrl: string | null;
77
77
  email: string | null;
78
78
  id: string;
79
- name: string;
80
- username: string;
79
+ name: string | null;
80
+ username: string | null;
81
81
  url: null;
82
82
  };
83
83
  }>;
@@ -88,8 +88,8 @@ export declare class AzureDevOps extends Provider implements GitProvider, IssueP
88
88
  avatarUrl: string | null;
89
89
  email: string | null;
90
90
  id: string;
91
- name: string;
92
- username: string;
91
+ name: string | null;
92
+ username: string | null;
93
93
  url: null;
94
94
  }[];
95
95
  }>;
@@ -7,11 +7,11 @@ export interface WorkItemState {
7
7
  }
8
8
  export interface AzureGraphAccount {
9
9
  avatarUrl: string | null;
10
- descriptor: string;
10
+ descriptor: string | null;
11
11
  email: string | null;
12
- name: string;
13
- storageKeyURL: string;
14
- username: string;
12
+ name: string | null;
13
+ storageKeyURL: string | null;
14
+ username: string | null;
15
15
  }
16
16
  export declare enum PullRequestAsyncStatus {
17
17
  Conflicts = "conflicts",
@@ -53,6 +53,7 @@ export interface Issue {
53
53
  resourceId: string | null;
54
54
  name: string;
55
55
  key: string | null;
56
+ id: string | null;
56
57
  };
57
58
  state: {
58
59
  id?: string;
@@ -49,18 +49,19 @@ export interface Project extends ProjectBase {
49
49
  url: string;
50
50
  revision: number;
51
51
  }
52
+ interface Link {
53
+ href: string;
54
+ }
52
55
  export interface AzureUser {
53
- displayName: string;
54
- url: string;
55
- _links: {
56
- avatar: Link;
57
- };
56
+ descriptor?: string;
57
+ displayName?: string;
58
58
  id: string;
59
- uniqueName: string | null;
60
- imageUrl: string | null;
61
- }
62
- interface CreatedBy extends AzureUser {
63
- descriptor: string;
59
+ imageUrl?: string;
60
+ uniqueName?: string;
61
+ url?: string;
62
+ _links?: {
63
+ avatar?: Link;
64
+ };
64
65
  }
65
66
  interface CommitBase {
66
67
  commitId: string;
@@ -69,7 +70,7 @@ interface CommitBase {
69
70
  export interface Ref {
70
71
  name: string;
71
72
  objectId: string;
72
- creator: CreatedBy;
73
+ creator: AzureUser;
73
74
  url: string;
74
75
  }
75
76
  export interface WorkItemTagDefinition {
@@ -84,10 +85,10 @@ interface Label {
84
85
  active: boolean;
85
86
  }
86
87
  export interface AzureReviewer extends AzureUser {
87
- reviewerUrl: string;
88
- vote: AzurePullRequestReviewState;
89
- hasDeclined: boolean;
90
- isFlagged: boolean;
88
+ reviewerUrl?: string;
89
+ vote?: AzurePullRequestReviewState;
90
+ hasDeclined?: boolean;
91
+ isFlagged?: boolean;
91
92
  isRequired?: boolean;
92
93
  }
93
94
  interface CompletionOptions {
@@ -105,7 +106,7 @@ export interface AzurePullRequest {
105
106
  pullRequestId: number;
106
107
  codeReviewId: number;
107
108
  status: PullRequestState;
108
- createdBy: CreatedBy;
109
+ createdBy: AzureUser;
109
110
  creationDate: string;
110
111
  closedDate?: string;
111
112
  title: string;
@@ -124,20 +125,6 @@ export interface AzurePullRequest {
124
125
  completionOptions?: CompletionOptions;
125
126
  supportsIterations: boolean;
126
127
  }
127
- interface Link {
128
- href: string;
129
- }
130
- interface Identity {
131
- descriptor: string;
132
- displayName: string;
133
- id: string;
134
- imageUrl: string;
135
- uniqueName: string;
136
- url: string;
137
- _links: {
138
- avatar: Link;
139
- };
140
- }
141
128
  interface WIQLColumnOrField {
142
129
  referenceName: string;
143
130
  name: string;
@@ -162,16 +149,16 @@ export interface AzureIssue {
162
149
  rev: number;
163
150
  fields: {
164
151
  'System.AreaPath': string;
165
- 'System.AssignedTo'?: Identity;
152
+ 'System.AssignedTo'?: AzureUser;
166
153
  'System.TeamProject': string;
167
154
  'System.IterationPath': string;
168
155
  'System.WorkItemType': string;
169
156
  'System.State': string;
170
157
  'System.Reason': string;
171
158
  'System.CreatedDate': string;
172
- 'System.CreatedBy': Identity;
159
+ 'System.CreatedBy': AzureUser;
173
160
  'System.ChangedDate': string;
174
- 'System.ChangedBy': Identity;
161
+ 'System.ChangedBy': AzureUser;
175
162
  'System.CommentCount': number;
176
163
  'System.Title': string;
177
164
  'System.BoardColumn': string;
@@ -179,11 +166,11 @@ export interface AzureIssue {
179
166
  'System.Tags'?: string;
180
167
  'Microsoft.VSTS.Common.StateChangeDate': string;
181
168
  'Microsoft.VSTS.Common.ClosedDate'?: string;
182
- 'Microsoft.VSTS.Common.ClosedBy'?: Identity;
169
+ 'Microsoft.VSTS.Common.ClosedBy'?: AzureUser;
183
170
  'Microsoft.VSTS.Common.ResolvedDate'?: string;
184
- 'Microsoft.VSTS.Common.ResolvedBy'?: Identity;
171
+ 'Microsoft.VSTS.Common.ResolvedBy'?: AzureUser;
185
172
  'Microsoft.VSTS.Common.ActivatedDate'?: string;
186
- 'Microsoft.VSTS.Common.ActivatedBy'?: Identity;
173
+ 'Microsoft.VSTS.Common.ActivatedBy'?: AzureUser;
187
174
  'Microsoft.VSTS.Common.Priority': number;
188
175
  'System.Description'?: string;
189
176
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gitkraken/provider-apis",
3
- "version": "0.23.0",
3
+ "version": "0.24.0",
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",