@gitkraken/provider-apis 0.29.8 → 0.29.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.providers.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";var ur=Object.create;var de=Object.defineProperty;var lr=Object.getOwnPropertyDescriptor;var pr=Object.getOwnPropertyNames;var dr=Object.getPrototypeOf,cr=Object.prototype.hasOwnProperty;var gr=(t,s)=>{for(var e in s)de(t,e,{get:s[e],enumerable:!0})},Pt=(t,s,e,r)=>{if(s&&typeof s=="object"||typeof s=="function")for(let n of pr(s))!cr.call(t,n)&&n!==e&&de(t,n,{get:()=>s[n],enumerable:!(r=lr(s,n))||r.enumerable});return t};var mr=(t,s,e)=>(e=t!=null?ur(dr(t)):{},Pt(s||!t||!t.__esModule?de(e,"default",{value:t,enumerable:!0}):e,t)),hr=t=>Pt(de({},"__esModule",{value:!0}),t);var Ns={};gr(Ns,{AzureDevOps:()=>K,Bitbucket:()=>X,BitbucketServer:()=>Z,EntityIdentifierProviderType:()=>ar,EntityType:()=>or,EntityVersion:()=>nr,GitBuildStatusStage:()=>wt,GitBuildStatusState:()=>ce,GitDiffLineType:()=>je,GitHub:()=>ee,GitHubIssueCloseReason:()=>ir,GitIssueState:()=>Re,GitLab:()=>re,GitMergeStrategy:()=>V,GitPullRequestMergeableState:()=>J,GitPullRequestReviewState:()=>B,GitPullRequestState:()=>H,GraphQLErrors:()=>b,Jira:()=>se,JiraServer:()=>ne,PullRequestAsyncStatus:()=>sr,Trello:()=>oe,default:()=>ks,isFetch:()=>ge});module.exports=hr(Ns);var wt=(n=>(n.Build="build",n.Production="production",n.Staging="staging",n.Test="test",n))(wt||{}),ce=(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))(ce||{}),V=(o=>(o.MergeCommit="MERGE_COMMIT",o.Rebase="REBASE",o.RebaseThenMergeCommit="REBASE_THEN_MERGE_COMMIT",o.FastForward="FAST_FORWARD",o.Squash="SQUASH",o))(V||{}),H=(r=>(r.Open="OPEN",r.Closed="CLOSED",r.Merged="MERGED",r))(H||{}),B=(n=>(n.Approved="APPROVED",n.ChangesRequested="CHANGES_REQUESTED",n.Commented="COMMENTED",n.ReviewRequested="REVIEW_REQUESTED",n))(B||{}),J=(u=>(u.Behind="BEHIND",u.Blocked="BLOCKED",u.Conflicts="CONFLICTS",u.FailingChecks="FAILING_CHECKS",u.Mergeable="MERGEABLE",u.Unknown="UNKNOWN",u.UnknownAndBlocked="UNKNOWN_AND_BLOCKED",u.Unstable="UNSTABLE",u))(J||{}),je=(r=>(r.ADDED="ADDED",r.DELETED="DELETED",r.UNMODIFIED="UNMODIFIED",r))(je||{});var St={APPROVED:0,COMMENTED:1,REVIEW_REQUESTED:2,CHANGES_REQUESTED:3},k=t=>!t||t.length===0?null:t.reduce((s,e)=>St[e.state]>St[s]?e.state:s,"APPROVED");var C=100;var vt=mr(require("node-fetch")),Et=globalThis.fetch||vt.default;var fr=async t=>{let s=t.headers.get("content-type")||"",e=null;if(s.startsWith("application/json")){let n=await t.text();e=n.trim().length>0?JSON.parse(n):null}else if(s.startsWith("text/")||s==="")e=await t.text();else if(s.startsWith("application/vnd.github.raw+json"))e=await t.arrayBuffer();else throw new Error(`Unsupported content-type: ${s}`);let r={body:e,headers:Object.fromEntries(t.headers.entries()),status:t.status,statusText:t.statusText};if(!t.ok){let n=new Error(t.statusText);throw Object.assign(n,{response:r}),n}return r},Be=t=>async({url:s,...e})=>{let r=await t(s,e);return fr(r)};var ge=(t,s=!1)=>t.name==="fetch"||s;var O=class{constructor(s){let e=(s==null?void 0:s.request)||Et;this.config={...s,request:ge(e,s==null?void 0:s.forceIsFetch)?Be(e):e}}updateConfig(s){this.config={...this.config,...s,request:s.request&&ge(s.request,(s==null?void 0:s.forceIsFetch)??this.config.forceIsFetch)?Be(s.request):this.config.request}}},A=class extends O{};var R=(t,s)=>{let e={};return t&&(e.Authorization=`${s?"Basic":"Bearer"} ${t}`),e},qt=t=>t?t.reduce((s,e)=>(s[e]=!0,s),{}):void 0,z=(t,s,e)=>!t||s.some(r=>t[r])?e:"",Ct=async t=>{var n,o,a;let s=[],e=!0,r;for(;e;){let i=await t(r);s=s.concat(i.data),e=!!((n=i==null?void 0:i.pageInfo)!=null&&n.hasNextPage),r=((o=i==null?void 0:i.pageInfo)==null?void 0:o.endCursor)||((a=i==null?void 0:i.pageInfo)==null?void 0:a.nextPage)}return s};async function Dt(t){return(await Promise.allSettled(t)).map(e=>Ir(e)).filter(e=>e!=null)}function Ir(t,s=void 0){return(t==null?void 0:t.status)==="fulfilled"?t.value:s}var Rr="https://app.vssps.visualstudio.com/_apis",br="https://vssps.dev.azure.com/",yr="https://dev.azure.com",S=(t,s={})=>R(s.token||t.token,s.isPAT||t.isPAT),Lt=t=>t.url.replace("/_apis/git/repositories/","/_git/").replace(`/${t.repository.project.id}/`,`/${encodeURIComponent(t.repository.project.name)}/`).replace(`/${t.repository.id}/`,`/${encodeURIComponent(t.repository.name)}/`).replace("/pullRequests/","/pullrequest/"),ze=(t,s)=>{let e=s.baseUrl||t.baseUrl||Rr;return e=e.replace(/\/$/,""),e},v=(t,s)=>{let e=s.baseUrl||t.baseUrl||yr;return e=e.replace(/\/$/,""),e},Me=(t,s)=>{let e=s.baseUrl||t.baseUrl||br;return e=e.replace(/\/$/,""),e};var Pr={active:"OPEN",completed:"MERGED",abandoned:"CLOSED"},wr={10:"APPROVED",5:"APPROVED",0:"REVIEW_REQUESTED",[-5]:"CHANGES_REQUESTED",[-10]:"CHANGES_REQUESTED"},We=t=>({id:t.id,name:t.displayName??null,username:(t.uniqueName||t.displayName)??null,email:null,avatarUrl:t.imageUrl??null,url:null}),he=t=>t.startsWith("refs/heads/")?t.replace("refs/heads/",""):t,Sr=t=>{switch(t){case"conflicts":return"CONFLICTS";case"failure":return"FAILING_CHECKS";case"rejectedByPolicy":return"BLOCKED";case"succeeded":return"MERGEABLE";case"notSet":case"queued":default:return"UNKNOWN"}},me=(t,s)=>{var n;let e=[],r=[];return s.reviewers.forEach(o=>{let a={reviewer:We(o),state:wr[o.vote??0]||"REVIEW_REQUESTED"};o.isRequired&&e.push(a),r.push(a)}),{id:s.pullRequestId.toString(),title:s.title,number:s.codeReviewId,state:Pr[s.status],isDraft:s.isDraft,commentCount:null,upvoteCount:null,author:We(s.createdBy),createdDate:new Date(s.creationDate),updatedDate:new Date(s.closedDate||s.creationDate),closedDate:s.closedDate?new Date(s.closedDate):null,mergedDate:s.closedDate&&s.status==="completed"?new Date(s.closedDate):null,repository:{id:s.repository.id,name:s.repository.name,project:s.repository.project.name,owner:{login:t},remoteInfo:null},headCommit:{buildStatuses:null},baseRef:{name:he(s.targetRefName),oid:s.lastMergeTargetCommit.commitId},headRef:{name:he(s.sourceRefName),oid:s.lastMergeSourceCommit.commitId},url:Lt(s),assignees:s.reviewers.map(We),reviews:r,reviewDecision:k(e),additions:null,deletions:null,fileCount:null,commitCount:null,headRepository:s.forkSource?{id:s.forkSource.repository.id,name:s.forkSource.repository.name,project:void 0,owner:{login:t},remoteInfo:null}:{id:s.repository.id,name:s.repository.name,project:s.repository.project.name,owner:{login:t},remoteInfo:null},mergeableState:Sr(s.mergeStatus),labels:((n=s.labels)==null?void 0:n.map(o=>({color:null,description:null,id:o.id,name:o.name})))??[],permissions:null}},$t=(t,s)=>({id:s.id,name:s.name,namespace:t,project:s.project.name,projectId:s.project.id,webUrl:s.webUrl,httpsUrl:s.remoteUrl,sshUrl:s.sshUrl,defaultBranch:s.defaultBranch?{name:he(s.defaultBranch)}:null,permissions:null}),vr=(t,s,e,r)=>{var l,p,d,c,g,m;let n=e.fields,o=n["System.AssignedTo"],a=n["System.State"],i=n["System.WorkItemType"],u;return a&&i&&(u=(l=r[i])==null?void 0:l[a]),{id:e.id.toString(),number:e.id.toString(),title:n["System.Title"],commentCount:n["System.CommentCount"],author:{avatarUrl:((d=(p=n["System.CreatedBy"]._links)==null?void 0:p.avatar)==null?void 0:d.href)??null,email:null,id:n["System.CreatedBy"].id,name:n["System.CreatedBy"].uniqueName??null,username:n["System.CreatedBy"].displayName??null,url:null},closedDate:n["Microsoft.VSTS.Common.ClosedDate"]?new Date(n["Microsoft.VSTS.Common.ClosedDate"]):null,createdDate:new Date(n["System.CreatedDate"]),updatedDate:new Date(n["System.ChangedDate"]),url:e._links.html.href,assignees:o?[{avatarUrl:((g=(c=o._links)==null?void 0:c.avatar)==null?void 0:g.href)??null,email:null,id:o.id,name:o.uniqueName??null,username:o.displayName??null,url:null}]:[],description:n["System.Description"]??null,state:{name:(u==null?void 0:u.title)||a,color:null},type:n["System.WorkItemType"],repository:null,project:{namespace:t,name:s,resourceId:null,key:null,id:null},upvoteCount:0,labels:((m=e.fields["System.Tags"])==null?void 0:m.split(";").map(I=>({color:null,description:null,id:null,name:I.trim()})))??[]}},K=class extends A{async getCurrentUser(s={},e={}){if(e.isPAT||this.config.isPAT)throw new Error("Azure DevOps does not support PATs for this function.");let r=`${ze(this.config,e)}/profile/profiles/me`,n=await this.config.request({url:r,headers:S(this.config,e)});return{data:{id:n.body.id,name:n.body.displayName,username:n.body.displayName,email:n.body.emailAddress,avatarUrl:null,url:null}}}async getCurrentUserForInstance(s,e={}){let n=(await this.config.request({url:`${v(this.config,e)}/${encodeURIComponent(s.namespace)}/_apis/ConnectionData`,headers:S(this.config,e)})).body.authorizedUser;if(n.providerDisplayName==="Anonymous")throw new Error("Current user not found.");return{data:{id:n.id,name:n.providerDisplayName,username:n.providerDisplayName,email:n.properties.Account.$value,avatarUrl:null,url:null}}}async getUserForCommit(s,e={}){if(!s.repo.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let n=(await this.config.request({url:`${v(this.config,e)}/${encodeURIComponent(s.repo.namespace)}/${encodeURIComponent(s.repo.project)}/_apis/git/repositories/${encodeURIComponent(s.repo.name)}/commits/${s.oid}`,headers:S(this.config,e)})).body.author;return{data:{name:n.name,email:n.email,avatarUrl:n.imageUrl}}}async getOrgsForUser(s,e={}){let r=`${ze(this.config,e)}/accounts?memberId=${s.userId}&api-version=6.0`;return{data:(await this.config.request({url:r,headers:S(this.config,e)})).body.value.map(o=>({id:o.accountId,name:o.accountName}))}}async getCollectionsForUser(s,e={}){let r=`${v(this.config,e)}/_apis/projectCollections`;return{data:(await this.config.request({url:r,headers:S(this.config,e)})).body.value.map(o=>({id:o.id,name:o.name}))}}async getAzureProjects(s,e={}){let r=new URL(`${v(this.config,e)}/${encodeURIComponent(s.namespace)}/_apis/projects`);r.searchParams.set("$top",C.toString()),s.cursor&&r.searchParams.set("$skip",s.cursor);let n=await this.config.request({url:r.toString(),headers:S(this.config,e)}),o=n.headers["x-ms-continuationtoken"];return{pageInfo:{hasNextPage:!!o,endCursor:o||null},data:n.body.value.map(a=>({id:a.id,name:a.name,namespace:s.namespace}))}}async getAzureProjectScopeDescriptor(s,e={}){let{namespace:r,projectId:n}=s;return{data:{scope:(await this.config.request({url:`${Me(this.config,e)}/${encodeURIComponent(r)}/_apis/graph/descriptors/${n}?api-version=6.0`,headers:S(this.config,e)})).body.value}}}async getAzureGraphAccountsForAzureProject(s,e={}){let{namespace:r,projectScopeDescriptor:n,cursor:o}=s,a=new URL(`${Me(this.config,e)}/${encodeURIComponent(r)}/_apis/graph/users`);n&&a.searchParams.set("scopeDescriptor",n),o&&a.searchParams.set("continuationToken",o);let i=await this.config.request({url:a.toString(),headers:S(this.config,e)}),u=i.headers["x-ms-continuationtoken"];return{pageInfo:{endCursor:u||null,hasNextPage:!!u},data:i.body.value.map(l=>{var p,d,c,g;return{avatarUrl:((d=(p=l._links)==null?void 0:p.avatar)==null?void 0:d.href)??null,descriptor:l.descriptor??null,email:l.mailAddress??null,name:l.displayName??null,storageKeyURL:((g=(c=l._links)==null?void 0:c.storageKey)==null?void 0:g.href)??null,username:l.displayName??null}})}}async getAccountFromAzureGraphAccount(s,e={}){let{azureGraphAccount:r}=s;if(!r.storageKeyURL)throw new Error("Expected 'storageKeyURL' to not be null for 'azureGraphAccount'");let n=await this.config.request({url:r.storageKeyURL,headers:S(this.config,e)});return{data:{avatarUrl:r.avatarUrl,email:r.email,id:n.body.value,name:r.name,username:r.username,url:null}}}async getAccountsFromAzureGraphAccounts(s,e={}){let r=[];for(let n of s.azureGraphAccounts){let o=await this.getAccountFromAzureGraphAccount({azureGraphAccount:n},e);r.push(o.data)}return{data:r}}async getRepo(s,e={}){if(!s.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let r=await this.config.request({url:`${v(this.config,e)}/${encodeURIComponent(s.namespace)}/${encodeURIComponent(s.project)}/_apis/git/repositories/${encodeURIComponent(s.name)}`,headers:S(this.config,e)});return{data:$t(s.namespace,r.body)}}async getRepos(s,e={}){let r=[],n=[];return await Promise.all(s.map(async o=>{try{let a=await this.getRepo(o,e);r.push(a.data)}catch(a){n.push({input:o,error:a})}})),{data:r,errors:n}}async getReposForAzureProject(s,e={}){if(!s.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');return{data:(await this.config.request({url:`${v(this.config,e)}/${encodeURIComponent(s.namespace)}/${encodeURIComponent(s.project)}/_apis/git/repositories`,headers:S(this.config,e)})).body.value.map(n=>$t(s.namespace,n))}}async getRefs(s,e,r={}){if(!e.repo.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let n=new URL(`${v(this.config,r)}/${encodeURIComponent(e.repo.namespace)}/${encodeURIComponent(e.repo.project)}/_apis/git/repositories/${encodeURIComponent(e.repo.name)}/refs`);n.searchParams.set("filter",s),n.searchParams.set("$top",C.toString()),e.cursor&&n.searchParams.set("continuationToken",e.cursor);let o=await this.config.request({url:n.toString(),headers:S(this.config,r)}),a=o.headers["x-ms-continuationtoken"];return{pageInfo:{hasNextPage:!!a,endCursor:a||null},data:o.body.value.map(i=>({name:he(i.name),commit:{oid:i.objectId,authoredDate:null,committedDate:null}}))}}async getBranches(s,e={}){return this.getRefs("heads",s,e)}async getTags(s,e={}){return this.getRefs("tags",s,e)}async getPullRequestsForRepoBase(s,e={},r=100){let{page:n,repo:o,assigneeLogins:a,authorLogin:i}=s||{},u=n||1;if(!o.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let l="searchCriteria.status=1";return a&&a.length&&(l+=`&searchCriteria.reviewerId=${a[0]}`),i&&(l+=`&searchCriteria.creatorId=${i}`),await this.config.request({url:`${v(this.config,e)}/${encodeURIComponent(o.namespace)}/${encodeURIComponent(o.project||"")}/_apis/git/repositories/${encodeURIComponent(o.name)}/pullRequests?${l}&%24top=${r}&%24skip=${(u-1)*r}`,headers:S(this.config,e)})}async getPullRequestsForRepo(s,e={}){let n=s.page||1,o=await this.getPullRequestsForRepoBase(s,e,100);return{pageInfo:{hasNextPage:o.body.value.length===100,nextPage:n+1},data:o.body.value.map(a=>me(s.repo.namespace,a))}}async getPullRequestsForRepos(s,e={}){if(!s.repos.every(o=>o.project))throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let{repos:r}=s||{},n=[];return await Promise.all(r.map(async o=>{try{(await this.getPullRequestsForRepoBase({repo:o,...s},e)).body.value.forEach(i=>{n.push(me(o.namespace,i))})}catch(a){if(a.statusCode!==404&&a.statusCode!==401)throw a}})),{data:n}}async getPullRequestsForProjectBase(s,e={},r=100){let{namespace:n,project:o,page:a,assigneeLogins:i,authorLogin:u,repo:l}=s;if(l!=null&&l.project&&l.project!==o)throw new Error("Could not fetch pull requests, project mismatch");let p=a||1,d=new URL(`${v(this.config,e)}/${encodeURIComponent(n)}/${encodeURIComponent(o)}/_apis/git/pullRequests`);return d.searchParams.set("searchCriteria.status","1"),d.searchParams.set("$top",r.toString()),d.searchParams.set("$skip",((p-1)*r).toString()),l!=null&&l.id&&(l==null?void 0:l.project)===o&&d.searchParams.set("searchCriteria.repositoryId",l.id),i&&i.length&&d.searchParams.set("searchCriteria.reviewerId",i[0]),u&&d.searchParams.set("searchCriteria.creatorId",u),await this.config.request({url:d.toString(),headers:S(this.config,e)})}async getPullRequestsForProject(s,e={}){let n=s.page||1,o=await this.getPullRequestsForProjectBase(s,e,100);return{pageInfo:{hasNextPage:(o==null?void 0:o.body.value.length)===100,nextPage:n+1},data:(o==null?void 0:o.body.value.map(a=>me(s.namespace,a)))||[]}}async getPullRequestsForProjects(s,e={}){let{projects:r}=s||{},n=[];return await Promise.all(r.map(async o=>{try{if(!s.repo||s.repo.project&&s.repo.project===o.project){let a=await this.getPullRequestsForProjectBase({...o,...s},e);a==null||a.body.value.forEach(i=>{n.push(me(o.namespace,i))})}}catch(a){if(a.statusCode!==404&&a.statusCode!==401)throw a}})),{data:n}}async getAzurePullRequestLastMergeStatus(s,e={}){if(!s.repo.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let{repo:{namespace:r,project:n,name:o},pullRequestId:a}=s,i=await this.config.request({url:`${v(this.config,e)}/${encodeURIComponent(r)}/${encodeURIComponent(n||"")}/_apis/git/repositories/${o}/pullrequests/${a}?includeCommits=true?api-version=6.0`,headers:{...S(this.config,e)}});if(!i.body.mergeStatus)throw new Error("Could not fetch pull request");return{data:i.body.mergeStatus}}async updatePullRequest(s,e,r){return await this.config.request({method:"PATCH",url:`${v(this.config,r)}/${encodeURIComponent(s.repository.owner.login)}/${encodeURIComponent(s.repository.project)}/_apis/git/repositories/${s.repository.name}/pullrequests/${s.id}?api-version=6.0`,body:e,headers:{...S(this.config,r),"Content-Type":"application/json"}})}async closePullRequest(s,e={}){let{pullRequest:r}=s,n={status:"abandoned"};if(!(await this.updatePullRequest(r,JSON.stringify(n),e)).body.status)throw new Error("Could not close pull request")}async mergePullRequest(s,e={}){var u;let{pullRequest:r,mergeStrategy:n}=s,o;switch(n){case"MERGE_COMMIT":{o="noFastForward";break}case"REBASE":{o="rebase";break}case"REBASE_THEN_MERGE_COMMIT":{o="rebaseMerge";break}case"SQUASH":{o="squash";break}}let a={completionOptions:{mergeStrategy:o},lastMergeSourceCommit:{commitId:(u=r.headRef)==null?void 0:u.oid},status:"completed"};if(!(await this.updatePullRequest(r,JSON.stringify(a),e)).body.status)throw new Error("Could not merge pull request")}async addPullRequestLabel(s,e={}){let{pullRequest:r,label:n}=s;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:`${v(this.config,e)}/${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:{...S(this.config,e),"Content-Type":"application/json"}})).body.id)throw new Error("Could not add pull request label")}async removePullRequestLabel(s,e={}){let{pullRequest:r,label:n}=s;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:`${v(this.config,e)}/${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:{...S(this.config,e)}})}async setPullRequestLabels(s,e={}){let{pullRequest:r,labels:n}=s;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 a of n)o.find(i=>i.id===a.id)||await this.addPullRequestLabel({pullRequest:r,label:a},e);for(let a of o)n.find(i=>a.id===i.id)||await this.removePullRequestLabel({pullRequest:r,label:a},e)}async setPullRequestAsDraft(s,e={}){let{pullRequest:r,isDraft:n}=s,o={isDraft:n};if(!(await this.updatePullRequest(r,JSON.stringify(o),e)).body.status)throw new Error("Could not set the pull request as draft")}async addPullRequestReviewer(s,e={}){let{pullRequest:r,reviewer:n,isRequired:o}=s,a={id:n.id,isRequired:o};if(!(await this.config.request({method:"PUT",url:`${v(this.config,e)}/${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(a),headers:{...S(this.config,e),"Content-Type":"application/json"}})).body.id)throw new Error("Could not add pull request reviewer")}async removePullRequestReviewer(s,e={}){let{pullRequest:r,reviewer:n}=s;await this.config.request({method:"DELETE",url:`${v(this.config,e)}/${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:{...S(this.config,e),Accept:"application/json"}})}async setPullRequestReviewers(s,e={}){let{pullRequest:r,reviewers:n}=s;for(let o of n)r.assignees.find(a=>a.id===o.id)||await this.addPullRequestReviewer({pullRequest:r,reviewer:o,isRequired:!0},e);for(let o of r.assignees)n.find(a=>o.id===a.id)||await this.removePullRequestReviewer({pullRequest:r,reviewer:o},e)}async getIssuesForAzureProject(s,e={}){let{page:r,assigneeLogins:n,authorLogin:o,mentionLogin:a,labelNames:i,statusByWorkItemIdByStatusId:u}=s||{},l=r||1,p=200,d=["[Microsoft.VSTS.Common.ClosedDate] = ''","[System.TeamProject] = @project","[Microsoft.VSTS.Common.ResolvedDate] = ''"];o&&d.push(`[System.CreatedBy] = '${o.replace("'","''")}'`),n&&n[0]&&d.push(`[System.AssignedTo] = '${n[0].replace("'","''")}'`),a&&d.push("[System.Id] IN (@recentMentions)"),i&&i.forEach(h=>d.push(`[System.Tags] Contains '${h}'`));let c=`Select [Microsoft.VSTS.Common.ClosedDate], [Microsoft.VSTS.Common.ResolvedDate] From WorkItems Where ${d.join(" AND ")} order by [System.CreatedDate] desc`,g=await this.config.request({url:`${v(this.config,e)}/${encodeURIComponent(s.namespace)}/${encodeURIComponent(s.project)}/_apis/wit/wiql?api-version=6.0`,body:JSON.stringify({query:c}),method:"POST",headers:{...S(this.config,e),"Content-Type":"application/json"}}),m=g.body.workItems.slice((l-1)*p,p*l).map(h=>h.id);if(m.length==0)return{pageInfo:{hasNextPage:!1,nextPage:null},data:[]};let I=await this.config.request({url:`${v(this.config,e)}/${encodeURIComponent(s.namespace)}/${encodeURIComponent(s.project)}/_apis/wit/workitemsbatch?api-version=6.0`,body:JSON.stringify({ids:m,$expand:"Links"}),method:"POST",headers:{...S(this.config,e),"Content-Type":"application/json"}});return{pageInfo:{hasNextPage:g.body.workItems.length>p*l,nextPage:l+1},data:I.body.value.map(h=>vr(s.namespace,s.project,h,u||{}))}}async getPermissionsForRepos(s,e={}){let{namespace:r,repos:n}=s,o={4:["canPush","canCreateWebhook"],1024:["isAdmin"],2048:["isAdmin"],4096:["isAdmin"],8192:["isAdmin"]},a=p=>{let d="2e9eb7ed-3c0a-47d4-87c1-0ffdd275fd87",c=`repoV2/${p.projectId}/${p.id}`;return Object.keys(o).map(g=>({securityNamespaceId:d,token:c,permissions:g}))},i={alwaysAllowAdministrators:!1,evaluations:n.flatMap(a)};return{data:(await this.config.request({method:"POST",url:`${v(this.config,e)}/${encodeURIComponent(r)}/_apis/security/permissionevaluationbatch?api-version=7.0`,body:JSON.stringify(i),headers:{...S(this.config,e),"Content-Type":"application/json"}})).body.evaluations.reduce((p,d)=>{let[,c,g]=d.token.split("/"),m=`${c}/${g}`,I=o[d.permissions];for(let h of I)p[m]===void 0&&(p[m]={canCreateWebhook:!0,canPush:!0,isAdmin:!0}),d.value===!1&&(p[m][h]=!1);return p},{})}}async decorateReposWithPermissions(s,e={}){let{namespace:r,repos:n}=s,o=await this.getPermissionsForRepos({namespace:r,repos:n},e);return{data:n.map(a=>({...a,permissions:o.data[`${a.projectId}/${a.id}`]}))}}async updateIssue(s,e,r={}){return await this.config.request({method:"PATCH",url:`${v(this.config,r)}/${encodeURIComponent(s.project.namespace)}/${encodeURIComponent(s.project.name)}/_apis/wit/workitems/${s.id}?api-version=6.0`,body:JSON.stringify(e),headers:{...S(this.config,r),"Content-Type":"application/json-patch+json"}})}async setIssueStatus(s,e={}){var i;let{issue:r,status:n}=s,o=[{op:"add",path:"/fields/System.State",value:n.name}];if(!((i=(await this.updateIssue(r,o,e)).body.fields)!=null&&i["System.State"]))throw new Error("Could not set issue status")}async setIssueAssignee(s,e={}){var i;let{issue:r,assignee:n}=s,o=[{op:"add",path:"/fields/System.AssignedTo",value:(n==null?void 0:n.name)??""}];if(!((i=(await this.updateIssue(r,o,e)).body.fields)!=null&&i["System.State"]))throw new Error("Could not set issue assignee")}async setIssueLabels(s,e={}){var u;let{issue:r,labels:n}=s,a=[{op:"replace",path:"/fields/System.Tags",value:n.map(l=>l.name).join(";")}];if(!((u=(await this.updateIssue(r,a,e)).body.fields)!=null&&u["System.Tags"]))throw new Error("Could not set issue tags")}async getIssueTypesForAzureProject(s,e={}){if(!s.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let{namespace:r,project:n}=s;return{data:(await this.config.request({url:`${v(this.config,e)}/${encodeURIComponent(r)}/${encodeURIComponent(n||"")}/_apis/wit/workitemtypes?api-version=6.0`,headers:{...S(this.config,e)}})).body.value}}async getLabelsForProject(s,e={}){let{namespace:r,project:n}=s;return{data:(await this.config.request({url:`${v(this.config,e)}/${encodeURIComponent(r)}/${encodeURIComponent(n||"")}/_apis/wit/tags?api-version=6.0`,headers:{...S(this.config,e)}})).body.value.map(a=>({color:null,description:null,id:a.id,name:a.name,url:a.url}))}}};var L=(t,s={})=>R(s.token||t.token,s.isPAT||t.isPAT);var $="https://api.bitbucket.org/2.0",Er={OPEN:"OPEN",MERGED:"MERGED",DECLINED:"CLOSED"},fe=t=>({id:t.uuid,name:t.display_name||t.nickname,username:t.nickname||t.display_name,email:null,avatarUrl:t.links.avatar.href,url:t.links.html.href}),Ut=t=>{let s=t.links.clone,e=s==null?void 0:s.find(n=>n.name==="ssh"),r=s==null?void 0:s.find(n=>n.name==="https");return e&&r?{cloneUrlHTTPS:r.href,cloneUrlSSH:e.href}:null},At=t=>{var s,e;return{id:t.uuid,namespace:t.workspace.slug,name:t.slug,webUrl:t.links.html.href,httpsUrl:((s=t.links.clone.find(r=>r.name==="https"))==null?void 0:s.href)??null,sshUrl:((e=t.links.clone.find(r=>r.name==="ssh"))==null?void 0:e.href)??null,defaultBranch:{name:t.mainbranch.name},permissions:null}},He=t=>{var r;let s=t.id,e=((r=t.participants)==null?void 0:r.map(n=>{let o="REVIEW_REQUESTED";return n.approved?o="APPROVED":n.state==="changes_requested"?o="CHANGES_REQUESTED":n.participated_on!==null&&(o="COMMENTED"),{reviewer:fe(n.user),state:o}}))??[];return{id:s.toString(),title:t.title,number:s,state:Er[t.state],isDraft:!1,commentCount:t.comment_count,upvoteCount:null,author:fe(t.author),createdDate:new Date(t.created_on),updatedDate:new Date(t.updated_on),closedDate:null,mergedDate:null,repository:{id:t.destination.repository.uuid,name:t.destination.repository.name,owner:{login:t.destination.repository.full_name.split("/")[0]},remoteInfo:Ut(t.destination.repository)},headCommit:{buildStatuses:null},baseRef:{name:t.destination.branch.name,oid:t.destination.commit.hash},headRef:{name:t.source.branch.name,oid:t.source.commit.hash},url:t.links.html.href,assignees:null,reviews:e,reviewDecision:k(e),additions:null,deletions:null,fileCount:null,commitCount:null,headRepository:{id:t.source.repository.uuid,name:t.source.repository.name,owner:{login:t.source.repository.full_name.split("/")[0]},remoteInfo:Ut(t.source.repository)},mergeableState:"MERGEABLE",permissions:null}},qr=t=>{switch(t){case"owner":case"admin":return{canCreateWebhook:!0,canPush:!0,isAdmin:!0};case"write":return{canCreateWebhook:!1,canPush:!0,isAdmin:!1};case"read":case"none":return{canCreateWebhook:!1,canPush:!1,isAdmin:!1}}},X=class extends O{async refreshToken(s){return{data:(await this.config.request({url:"https://bitbucket.org/site/oauth2/access_token",method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded",Authorization:`Basic ${s.base64ClientIDColonClientSecret}`},body:`grant_type=refresh_token&refresh_token=${s.refreshToken}`})).body}}async getCurrentUser(s={},e={}){let r=await this.config.request({url:`${$}/user`,headers:L(this.config,e)});return{data:fe(r.body)}}async getUserForCommit(s,e={}){var a;let n=(await this.config.request({url:`${$}/repositories/${s.repo.namespace}/${s.repo.name}/commit/${s.oid}`,headers:L(this.config,e)})).body.author,o=n.raw.match(/([^<]+)<(.+)>/);return{data:{name:o?o[1].trim():null,email:o?o[2]:null,avatarUrl:((a=n.user)==null?void 0:a.links.avatar.href)||null}}}async getRepo(s,e={}){let r=await this.config.request({url:`${$}/repositories/${s.namespace}/${s.name}`,headers:L(this.config,e)});return{data:At(r.body)}}async getRepos(s,e={}){let r=[],n=[];return await Promise.all(s.map(async o=>{try{let a=await this.getRepo(o,e);r.push(a.data)}catch(a){n.push({input:o,error:a})}})),{data:r,errors:n}}async getReposForCurrentUser(s,e={}){let r=new URL(`${$}/repositories`);r.searchParams.set("role","member"),r.searchParams.set("pagelen",C.toString()),s.cursor&&r.searchParams.set("after",s.cursor);let n=await this.config.request({url:r.toString(),headers:L(this.config,e)}),o=!!n.body.next,a=null;return n.body.next&&(a=new URL(n.body.next).searchParams.get("after")),{pageInfo:{hasNextPage:o,endCursor:a},data:n.body.values.map(At)}}async getBranches(s,e={}){var a;let r=new URL(`${$}/repositories/${s.repo.namespace}/${s.repo.name}/refs/branches`);r.searchParams.set("page",((a=s.page)==null?void 0:a.toString())||"1"),r.searchParams.set("pagelen",C.toString());let n=await this.config.request({url:r.toString(),headers:L(this.config,e)}),o=!!n.body.next;return{pageInfo:{hasNextPage:o,nextPage:o?n.body.page+1:null},data:n.body.values.map(i=>{let u=new Date(i.target.date);return{name:i.name,commit:{oid:i.target.hash,authoredDate:u,committedDate:u}}})}}async getTags(s,e={}){let r=new URL(`${$}/repositories/${s.repo.namespace}/${s.repo.name}/refs/tags`);r.searchParams.set("pagelen",C.toString()),s.cursor&&r.searchParams.set("page",s.cursor);let n=await this.config.request({url:r.toString(),headers:L(this.config,e)}),o=!!n.body.next,a=null;return n.body.next&&(a=new URL(n.body.next).searchParams.get("page")),{pageInfo:{hasNextPage:o,endCursor:a},data:n.body.values.map(i=>{let u=new Date(i.target.date);return{name:i.name,commit:{oid:i.target.hash,authoredDate:u,committedDate:u}}})}}async getWorkspacesForUser(s,e={}){var a;let r=new URL(`${$}/user/permissions/workspaces`);r.searchParams.set("page",((a=s.page)==null?void 0:a.toString())||"1"),r.searchParams.set("pagelen","50");let n=await this.config.request({url:r.toString(),headers:L(this.config,e)}),o=!!n.body.next;return{pageInfo:{hasNextPage:o,nextPage:o?n.body.page+1:null},data:n.body.values.map(i=>({id:i.workspace.uuid,slug:i.workspace.slug,name:i.workspace.name}))}}async getPullRequestsForUserAndWorkspace(s,e={}){var a;let r=new URL(`${$}/workspaces/${s.workspaceSlug}/pullrequests/${s.userId}`);if(r.searchParams.set("fields","+values.participants,+values.destination.repository.links.clone.*,+values.source.repository.links.clone.*"),r.searchParams.set("page",((a=s.page)==null?void 0:a.toString())||"1"),r.searchParams.set("pagelen","50"),s.repos&&s.repos.length>0){let i=`state = "open" AND (${s.repos.map(u=>`source.repository.full_name = "${u.namespace}/${u.name}"`).join(" OR ")})`;r.searchParams.set("q",i)}let n=await this.config.request({url:r.toString(),headers:L(this.config,e)}),o=!!n.body.next;return{pageInfo:{hasNextPage:o,nextPage:o?n.body.page+1:null},data:n.body.values.map(He)}}async getPullRequestsForRepoBase(s,e={}){var a;let r=new URL(`${$}/repositories/${encodeURI(s.repo.namespace)}/${encodeURI(s.repo.name)}/pullrequests?state=OPEN`),n=[];s.reviewerId&&n.push(`reviewers.uuid="${s.reviewerId}"`),s.authorLogin&&n.push(`author.uuid="${s.authorLogin}"`);let o='state="OPEN"';return n.length&&(o+=` AND (${n.join(s.useOrFilter?" OR ":" AND ")})`),r.searchParams.set("fields","+values.participants,+values.destination.repository.links.clone.*,+values.source.repository.links.clone.*"),r.searchParams.set("page",((a=s.page)==null?void 0:a.toString())||"1"),r.searchParams.set("pagelen","50"),r.searchParams.set("q",o),await this.config.request({url:r.toString(),headers:L(this.config,e)})}async getPullRequestsForRepo(s,e={}){let r=[],n=await this.getPullRequestsForRepoBase(s,e);n.body.values.forEach(a=>{r.push(He(a))});let o=!!n.body.next;return{pageInfo:{hasNextPage:o,nextPage:o?n.body.page+1:null},data:r}}async getPullRequestsForRepos(s,e={}){let r=[];return await Promise.all(s.repos.map(async n=>{try{(await this.getPullRequestsForRepoBase({repo:n,...s},e)).body.values.forEach(a=>{r.push(He(a))})}catch(o){if(o.statusCode!==404&&o.statusCode!==401)throw o}})),{data:r}}async getAccountsForWorkspace(s,e={}){var a;let r=new URL(`${$}/workspaces/${encodeURI(s.workspace)}/members`);r.searchParams.set("page",((a=s.page)==null?void 0:a.toString())||"1"),r.searchParams.set("pagelen","100");let n=await this.config.request({url:r.toString(),headers:L(this.config,e)}),o=!!n.body.next;return{pageInfo:{hasNextPage:o,nextPage:o?n.body.page+1:null},data:n.body.values.map(i=>fe(i.user))}}async getReposPermissionsForCurrentUser(s,e={}){var a;let r=new URL(`${$}/user/permissions/repositories`);r.searchParams.set("page",((a=s.page)==null?void 0:a.toString())||"1"),r.searchParams.set("pagelen","100");let n=await this.config.request({url:r.toString(),headers:L(this.config,e)}),o=!!n.body.next;return{pageInfo:{hasNextPage:o,nextPage:o?n.body.page+1:null},data:n.body.values.reduce((i,u)=>({...i,[u.repository.uuid]:qr(u.permission)}),{})}}async decorateReposWithPermissions(s,e={}){let r={},n=1;do{let o=await this.getReposPermissionsForCurrentUser({page:n},e);r={...o.data,...r},n=o.pageInfo.hasNextPage?o.pageInfo.nextPage:null}while(n!==null);return{data:s.repos.map(o=>({...o,permissions:r[o.id]??{canCreateWebhook:!1,canPush:!1,isAdmin:!1}}))}}async closePullRequest(s,e={}){let{pullRequest:r}=s;if(!(await this.config.request({method:"POST",url:`${$}/repositories/${r.repository.owner.login}/${r.repository.name}/pullrequests/${r.id}/decline`,headers:L(this.config,e)})).body.title)throw new Error("Could not close pull request")}async mergePullRequest(s,e={}){let{pullRequest:r,mergeStrategy:n}=s,o;switch(n){case"MERGE_COMMIT":{o="merge_commit";break}case"FAST_FORWARD":{o="fast_forward";break}case"SQUASH":{o="squash";break}}let a={merge_strategy:o,type:"pullrequest"};if(!(await this.config.request({method:"POST",url:`${$}/repositories/${r.repository.owner.login}/${r.repository.name}/pullrequests/${r.id}/merge`,body:JSON.stringify(a),headers:{...L(this.config,e),"Content-Type":"application/json"}})).body.title)throw new Error("Could not merge pull request")}async setPullRequestReviewers(s,e={}){let{pullRequest:r,reviewers:n}=s,o={reviewers:n.map(i=>{if(i.username)throw new Error('Bitbucket reviewer requires "username" for this function.');return{username:i.username}})};if(!(await this.config.request({method:"PUT",url:`${$}/repositories/${r.repository.owner.login}/${r.repository.name}/pullrequests/${r.id}`,body:JSON.stringify(o),headers:{...L(this.config,e),"Content-Type":"application/json"}})).body.title)throw new Error("Could not set pull request reviewers")}};var Gt=t=>t?t.find(s=>s.permission==="USER_ADMIN"||s.permission==="PROJECT_ADMIN"||s.permission==="ADMIN"||s.permission==="SYS_ADMIN"||s.permission==="REPO_ADMIN")?{canCreateWebhook:!0,canPush:!0,isAdmin:!0}:t.find(s=>s.permission==="REPO_WRITE"||s.permission==="REPO_CREATE"||s.permission==="PROJECT_CREATE"||s.permission==="PROJECT_WRITE")?{canCreateWebhook:!1,canPush:!0,isAdmin:!1}:{canCreateWebhook:!1,canPush:!1,isAdmin:!1}:{canCreateWebhook:!1,canPush:!1,isAdmin:!1};var ie=t=>{let s=t.links.self[0].href;return{name:t.displayName,email:t.emailAddress,avatarUrl:t.avatarUrl??(s&&`${s}/avatar.png`),id:t.id.toString(),username:t.name,url:s}},Ie=t=>{var u,l,p,d,c,g;let s={OPEN:"OPEN",MERGED:"MERGED",DECLINED:"CLOSED"},e={UNAPPROVED:"REVIEW_REQUESTED",NEEDS_WORK:"CHANGES_REQUESTED",APPROVED:"APPROVED"},r=t.reviewers.map(m=>({reviewer:ie(m.user),state:e[m.status]})),n=((u=t.toRef.repository.links.clone.find(m=>m.name==="ssh"))==null?void 0:u.href)??null,o=((l=t.toRef.repository.links.clone.find(m=>m.name==="https"))==null?void 0:l.href)??null;o||(o=((p=t.toRef.repository.links.clone.find(m=>m.name==="http"))==null?void 0:p.href)??null);let a=((d=t.fromRef.repository.links.clone.find(m=>m.name==="ssh"))==null?void 0:d.href)??null,i=((c=t.fromRef.repository.links.clone.find(m=>m.name==="https"))==null?void 0:c.href)??null;return i||(i=((g=t.fromRef.repository.links.clone.find(m=>m.name==="http"))==null?void 0:g.href)??null),{id:t.id.toString(),number:t.id,title:t.title,url:t.links.self[0].href,state:s[t.state],isDraft:!1,createdDate:new Date(t.createdDate),updatedDate:new Date(t.updatedDate),closedDate:t.closedDate?new Date(t.closedDate):null,mergedDate:t.state=="MERGED"&&t.closedDate?new Date(t.closedDate):null,baseRef:{name:t.toRef.displayId,oid:t.toRef.latestCommit},headRef:{name:t.fromRef.displayId,oid:t.fromRef.latestCommit},commentCount:t.properties.commentCount,upvoteCount:null,commitCount:null,fileCount:null,additions:null,deletions:null,author:ie(t.author.user),assignees:null,reviews:r,reviewDecision:k(r),repository:{id:t.toRef.repository.id.toString(),name:t.toRef.repository.name,owner:{login:t.toRef.repository.project.key},remoteInfo:o&&n?{cloneUrlHTTPS:o,cloneUrlSSH:n}:null},headRepository:{id:t.fromRef.repository.id.toString(),name:t.fromRef.repository.name,owner:{login:t.fromRef.repository.project.key},remoteInfo:i&&a?{cloneUrlHTTPS:i,cloneUrlSSH:a}:null},headCommit:null,mergeableState:"MERGEABLE",permissions:null,version:t.version}},Tt=t=>{var s,e,r;return{id:t.id.toString(),namespace:t.project.key,name:t.slug,webUrl:((s=t.links.self[0])==null?void 0:s.href)??null,httpsUrl:((e=t.links.clone.find(n=>n.name==="https"||n.name==="http"))==null?void 0:e.href)??null,sshUrl:((r=t.links.clone.find(n=>n.name==="ssh"))==null?void 0:r.href)??null,defaultBranch:null,permissions:null}},Z=class extends A{getBaseUrl(s){let e=s.baseUrl||this.config.baseUrl;if(!e)throw new Error('Bitbucket Server requires "baseUrl"');return e}getRequestHeaders(s){return R(s.token||this.config.token)}async getCurrentUser(s={},e={}){let r=await this.config.request({url:`${this.getBaseUrl(e)}/users?limit=2`,headers:this.getRequestHeaders(e)}),{headers:{"x-auserid":n,"x-ausername":o}}=r,a=n?parseInt(n,10):null,i=decodeURIComponent(o),l=(await this.config.request({url:`${this.getBaseUrl(e)}/users?filter=${o}&avatarSize=64`,headers:this.getRequestHeaders(e)})).body.values.find(({emailAddress:p,id:d,name:c,slug:g})=>a?a===d:i===c||i===p||i===g);if(!l)throw new Error("Could not find current Bitbucket Server user");return{data:ie(l)}}async getUserForCommit(s,e){let{repo:r,oid:n}=s,o=await this.config.request({url:`${this.getBaseUrl(e)}/projects/${r.namespace}/repos/${r.name}/commits/${n}`,headers:this.getRequestHeaders(e)});if(!o.body.author)throw new Error("Could not find user for commit");return{data:ie(o.body.author)}}async getRepo(s,e={}){let r=await this.config.request({url:`${this.getBaseUrl(e)}/projects/${s.namespace}/repos/${s.name}`,headers:this.getRequestHeaders(e)});return{data:Tt(r.body)}}async getRepos(s,e={}){let r=[],n=[];return await Promise.all(s.map(async o=>{try{let a=await this.getRepo(o,e);r.push(a.data)}catch(a){n.push({input:o,error:a})}})),{data:r,errors:n}}async getReposForCurrentUser(s,e={}){let r=s.page??0,n=await this.config.request({url:`${this.getBaseUrl(e)}/repos?start=${r}`,headers:this.getRequestHeaders(e)});return{pageInfo:{hasNextPage:!n.body.isLastPage,nextPage:n.body.nextPageStart},data:n.body.values.map(Tt)}}async getRepoPermissionsForUsername(s,e={}){var n;let r=new URL(`${this.getBaseUrl(e)}/projects/${s.repo.namespace}/repos/${s.repo.name}/permissions/search?filterText=${s.username}`);try{let o=await this.config.request({url:r.toString(),headers:this.getRequestHeaders(e)});return{data:Gt(o.body.values)}}catch(o){if(((n=o.response)==null?void 0:n.status)===401)return{data:{canCreateWebhook:!1,canPush:!1,isAdmin:!1}};throw o}}async decorateReposWithPermissions(s,e={}){return await Promise.all(s.repos.map(async n=>{let o=await this.getRepoPermissionsForUsername({repo:n,username:s.username},e);return{...n,permissions:o.data}}))}async getPullRequestsForRepoBase(s,e={}){var n;let r=new URL(`${this.getBaseUrl(e)}/projects/${encodeURI(s.repo.namespace)}/repos/${encodeURI(s.repo.name)}/pull-requests?state=OPEN`);return r.searchParams.set("start",((n=s.page)==null?void 0:n.toString())||"0"),r.searchParams.set("limit","50"),await this.config.request({url:r.toString(),headers:this.getRequestHeaders(e)})}async getPullRequestsForRepo(s,e={}){let r=[],n=await this.getPullRequestsForRepoBase(s,e);n.body.values.forEach(a=>{if(s.authorLogin&&a.author.user.name!==s.authorLogin)return null;r.push(Ie(a))});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(s,e={}){let r=[];return await Promise.all(s.repos.map(async n=>{try{(await this.getPullRequestsForRepoBase({repo:n,...s},e)).body.values.forEach(a=>{if(s.authorLogin&&a.author.user.name!==s.authorLogin)return null;r.push(Ie(a))})}catch(o){if(o.statusCode!==404&&o.statusCode!==401)throw o}})),{data:r}}async getPullRequestsForCurrentUser(s,e={}){var a;let r=new URL(`${this.getBaseUrl(e)}/dashboard/pull-requests`);r.searchParams.set("state","OPEN"),r.searchParams.set("start",((a=s.page)==null?void 0:a.toString())||"0"),r.searchParams.set("limit","50");let n=await this.config.request({url:r.toString(),headers:this.getRequestHeaders(e)}),o=n.body.values.length!==0;return{pageInfo:{hasNextPage:o,nextPage:o?n.body.start+n.body.values.length:null},data:n.body.values.map(Ie)}}async closePullRequest(s,e={}){let{pullRequest:r}=s;if(r.version===void 0)throw new Error('Bitbucket Server requires "version" for this function.');if(!(await this.config.request({method:"POST",url:`${this.getBaseUrl(e)}/projects/${r.repository.owner.login}/repos/${r.repository.name}/pull-requests/${r.id}/decline`,body:JSON.stringify({version:r.version}),headers:{...this.getRequestHeaders(e),"Content-Type":"application/json"}})).body.title)throw new Error("Could not close pull request")}async mergePullRequest(s,e={}){let{pullRequest:r,mergeStrategyId:n}=s;if(s.mergeStrategy)throw new Error('Bitbucket Server uses "mergeStrategyId" instead of "mergeStrategy".');if(r.version===void 0)throw new Error('Bitbucket Server requires "version" for this function.');if(!(await this.config.request({method:"POST",url:`${this.getBaseUrl(e)}/projects/${r.repository.owner.login}/repos/${r.repository.name}/pull-requests/${r.id}/merge`,body:JSON.stringify({strategyId:n,version:r.version}),headers:{...this.getRequestHeaders(e),"Content-Type":"application/json"}})).body.title)throw new Error("Could not merge pull request")}async getMergeStrategies(s={}){let e=await this.config.request({url:`${this.getBaseUrl(s)}/admin/pull-requests/git`,headers:{...this.getRequestHeaders(s),"Content-Type":"application/json"}});return{data:{defaultStrategy:e.body.mergeConfig.defaultStrategy,strategies:e.body.mergeConfig.strategies}}}async setPullRequestReviewers(s,e={}){let{pullRequest:r,reviewers:n}=s;if(r.version===void 0)throw new Error('Bitbucket Server requires "version" for this function.');let o={reviewers:n.map(i=>{if(i.username)throw new Error('Bitbucket Server reviewer requires "username" for this function.');return{user:{name:i.username}}}),version:r.version};if(!(await this.config.request({method:"PUT",url:`${this.getBaseUrl(e)}/projects/${r.repository.owner.login}/repos/${r.repository.name}/pull-requests/${r.id}`,body:JSON.stringify(o),headers:{...this.getRequestHeaders(e),"Content-Type":"application/json"}})).body.title)throw new Error("Could not set pull request reviewers")}async getAccountsForProject(s,e={}){var a;let r=new URL(`${this.getBaseUrl(e)}/projects/${encodeURI(s.project)}/permissions/users`);r.searchParams.set("start",((a=s.page)==null?void 0:a.toString())||"0"),r.searchParams.set("limit","50");let n=await this.config.request({url:r.toString(),headers:this.getRequestHeaders(e)}),o=n.body.values.length!==0;return{pageInfo:{hasNextPage:o,nextPage:o?n.body.start+n.body.values.length:null},data:n.body.values.map(i=>ie(i.user))}}};var Qt=require("js-base64");var Re=(e=>(e.Open="OPEN",e.Closed="CLOSED",e))(Re||{});var b=class extends Error{constructor(e,r){let n=r==null?void 0:r.map(a=>`'${a.message}'`).join(", "),o=n?`${e}: ${n}`:e;super(o);this.graphQLErrors=r??[]}};var Cr={AS_CODE_OWNER:[3,0,0],CHECK_RUN:[3,0,0],LATEST_REVIEWS:[3,0,0],VIEWER_CAN_MERGE_AS_ADMIN:[3,5,0],ISSUE_FULL_DATABASE_ID:[3,12,0],PR_FULL_DATABASE_ID:[3,13,0],PR_REVIEW_FULL_DATABASE_ID:[3,13,0],PR_REVIEW_COMMENT_FULL_DATABASE_ID:[3,13,0]},Ot=15,xt=100,U=t=>!!t,_=(t,s)=>{let e=Cr[s];for(let r=0;r<3;r++){if(t[r]>e[r])return!0;if(t[r]<e[r])return!1}return!0},ye="https://api.github.com",Dr=`${ye}/graphql`,Pe=`
|
|
1
|
+
"use strict";var lr=Object.create;var de=Object.defineProperty;var pr=Object.getOwnPropertyDescriptor;var dr=Object.getOwnPropertyNames;var cr=Object.getPrototypeOf,gr=Object.prototype.hasOwnProperty;var mr=(t,s)=>{for(var e in s)de(t,e,{get:s[e],enumerable:!0})},St=(t,s,e,r)=>{if(s&&typeof s=="object"||typeof s=="function")for(let n of dr(s))!gr.call(t,n)&&n!==e&&de(t,n,{get:()=>s[n],enumerable:!(r=pr(s,n))||r.enumerable});return t};var hr=(t,s,e)=>(e=t!=null?lr(cr(t)):{},St(s||!t||!t.__esModule?de(e,"default",{value:t,enumerable:!0}):e,t)),fr=t=>St(de({},"__esModule",{value:!0}),t);var Ns={};mr(Ns,{AzureDevOps:()=>K,Bitbucket:()=>X,BitbucketServer:()=>Z,EntityIdentifierProviderType:()=>ir,EntityType:()=>ar,EntityVersion:()=>or,GitBuildStatusStage:()=>vt,GitBuildStatusState:()=>ce,GitDiffLineType:()=>Be,GitHub:()=>ee,GitHubIssueCloseReason:()=>ur,GitIssueState:()=>Re,GitLab:()=>re,GitMergeStrategy:()=>V,GitPullRequestMergeableState:()=>J,GitPullRequestReviewState:()=>B,GitPullRequestState:()=>H,GraphQLErrors:()=>b,Jira:()=>se,JiraServer:()=>ne,PullRequestAsyncStatus:()=>nr,Trello:()=>oe,default:()=>ks,isFetch:()=>ge});module.exports=fr(Ns);var vt=(n=>(n.Build="build",n.Production="production",n.Staging="staging",n.Test="test",n))(vt||{}),ce=(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))(ce||{}),V=(o=>(o.MergeCommit="MERGE_COMMIT",o.Rebase="REBASE",o.RebaseThenMergeCommit="REBASE_THEN_MERGE_COMMIT",o.FastForward="FAST_FORWARD",o.Squash="SQUASH",o))(V||{}),H=(r=>(r.Open="OPEN",r.Closed="CLOSED",r.Merged="MERGED",r))(H||{}),B=(n=>(n.Approved="APPROVED",n.ChangesRequested="CHANGES_REQUESTED",n.Commented="COMMENTED",n.ReviewRequested="REVIEW_REQUESTED",n))(B||{}),J=(u=>(u.Behind="BEHIND",u.Blocked="BLOCKED",u.Conflicts="CONFLICTS",u.FailingChecks="FAILING_CHECKS",u.Mergeable="MERGEABLE",u.Unknown="UNKNOWN",u.UnknownAndBlocked="UNKNOWN_AND_BLOCKED",u.Unstable="UNSTABLE",u))(J||{}),Be=(r=>(r.ADDED="ADDED",r.DELETED="DELETED",r.UNMODIFIED="UNMODIFIED",r))(Be||{});var Et={APPROVED:0,COMMENTED:1,REVIEW_REQUESTED:2,CHANGES_REQUESTED:3},k=t=>!t||t.length===0?null:t.reduce((s,e)=>Et[e.state]>Et[s]?e.state:s,"APPROVED");var C=100;var qt=hr(require("node-fetch")),Ct=globalThis.fetch||qt.default;var Ir=async t=>{let s=t.headers.get("content-type")||"",e=null;if(s.startsWith("application/json")){let n=await t.text();e=n.trim().length>0?JSON.parse(n):null}else if(s.startsWith("text/")||s==="")e=await t.text();else if(s.startsWith("application/vnd.github.raw+json"))e=await t.arrayBuffer();else throw new Error(`Unsupported content-type: ${s}`);let r={body:e,headers:Object.fromEntries(t.headers.entries()),status:t.status,statusText:t.statusText};if(!t.ok){let n=new Error(t.statusText);throw Object.assign(n,{response:r}),n}return r},ze=t=>async({url:s,...e})=>{let r=await t(s,e);return Ir(r)};var ge=(t,s=!1)=>t.name==="fetch"||s;var O=class{constructor(s){let e=(s==null?void 0:s.request)||Ct;this.config={...s,request:ge(e,s==null?void 0:s.forceIsFetch)?ze(e):e}}updateConfig(s){this.config={...this.config,...s,request:s.request&&ge(s.request,(s==null?void 0:s.forceIsFetch)??this.config.forceIsFetch)?ze(s.request):this.config.request}}},A=class extends O{};var R=(t,s)=>{let e={};return t&&(e.Authorization=`${s?"Basic":"Bearer"} ${t}`),e},Dt=t=>t?t.reduce((s,e)=>(s[e]=!0,s),{}):void 0,z=(t,s,e)=>!t||s.some(r=>t[r])?e:"",Lt=async t=>{var n,o,a;let s=[],e=!0,r;for(;e;){let i=await t(r);s=s.concat(i.data),e=!!((n=i==null?void 0:i.pageInfo)!=null&&n.hasNextPage),r=((o=i==null?void 0:i.pageInfo)==null?void 0:o.endCursor)||((a=i==null?void 0:i.pageInfo)==null?void 0:a.nextPage)}return s};async function Me(t){return(await Promise.allSettled(t)).map(e=>Rr(e)).filter(e=>e!=null)}function Rr(t,s=void 0){return(t==null?void 0:t.status)==="fulfilled"?t.value:s}var br="https://app.vssps.visualstudio.com/_apis",yr="https://vssps.dev.azure.com/",Pr="https://dev.azure.com",S=(t,s={})=>R(s.token||t.token,s.isPAT||t.isPAT),$t=t=>t.url.replace("/_apis/git/repositories/","/_git/").replace(`/${t.repository.project.id}/`,`/${encodeURIComponent(t.repository.project.name)}/`).replace(`/${t.repository.id}/`,`/${encodeURIComponent(t.repository.name)}/`).replace("/pullRequests/","/pullrequest/"),We=(t,s)=>{let e=s.baseUrl||t.baseUrl||br;return e=e.replace(/\/$/,""),e},v=(t,s)=>{let e=s.baseUrl||t.baseUrl||Pr;return e=e.replace(/\/$/,""),e},He=(t,s)=>{let e=s.baseUrl||t.baseUrl||yr;return e=e.replace(/\/$/,""),e};var wr={active:"OPEN",completed:"MERGED",abandoned:"CLOSED"},Sr={10:"APPROVED",5:"APPROVED",0:"REVIEW_REQUESTED",[-5]:"CHANGES_REQUESTED",[-10]:"CHANGES_REQUESTED"},Je=t=>({id:t.id,name:t.displayName??null,username:(t.uniqueName||t.displayName)??null,email:null,avatarUrl:t.imageUrl??null,url:null}),he=t=>t.startsWith("refs/heads/")?t.replace("refs/heads/",""):t,vr=t=>{switch(t){case"conflicts":return"CONFLICTS";case"failure":return"FAILING_CHECKS";case"rejectedByPolicy":return"BLOCKED";case"succeeded":return"MERGEABLE";case"notSet":case"queued":default:return"UNKNOWN"}},me=(t,s)=>{var n;let e=[],r=[];return s.reviewers.forEach(o=>{let a={reviewer:Je(o),state:Sr[o.vote??0]||"REVIEW_REQUESTED"};o.isRequired&&e.push(a),r.push(a)}),{id:s.pullRequestId.toString(),title:s.title,number:s.codeReviewId,state:wr[s.status],isDraft:s.isDraft,commentCount:null,upvoteCount:null,author:Je(s.createdBy),createdDate:new Date(s.creationDate),updatedDate:new Date(s.closedDate||s.creationDate),closedDate:s.closedDate?new Date(s.closedDate):null,mergedDate:s.closedDate&&s.status==="completed"?new Date(s.closedDate):null,repository:{id:s.repository.id,name:s.repository.name,project:s.repository.project.name,owner:{login:t},remoteInfo:null},headCommit:{buildStatuses:null},baseRef:{name:he(s.targetRefName),oid:s.lastMergeTargetCommit.commitId},headRef:{name:he(s.sourceRefName),oid:s.lastMergeSourceCommit.commitId},url:$t(s),assignees:s.reviewers.map(Je),reviews:r,reviewDecision:k(e),additions:null,deletions:null,fileCount:null,commitCount:null,headRepository:s.forkSource?{id:s.forkSource.repository.id,name:s.forkSource.repository.name,project:void 0,owner:{login:t},remoteInfo:null}:{id:s.repository.id,name:s.repository.name,project:s.repository.project.name,owner:{login:t},remoteInfo:null},mergeableState:vr(s.mergeStatus),labels:((n=s.labels)==null?void 0:n.map(o=>({color:null,description:null,id:o.id,name:o.name})))??[],permissions:null}},Ut=(t,s)=>({id:s.id,name:s.name,namespace:t,project:s.project.name,projectId:s.project.id,webUrl:s.webUrl,httpsUrl:s.remoteUrl,sshUrl:s.sshUrl,defaultBranch:s.defaultBranch?{name:he(s.defaultBranch)}:null,permissions:null}),Er=(t,s,e,r)=>{var l,p,d,c,g,m;let n=e.fields,o=n["System.AssignedTo"],a=n["System.State"],i=n["System.WorkItemType"],u;return a&&i&&(u=(l=r[i])==null?void 0:l[a]),{id:e.id.toString(),number:e.id.toString(),title:n["System.Title"],commentCount:n["System.CommentCount"],author:{avatarUrl:((d=(p=n["System.CreatedBy"]._links)==null?void 0:p.avatar)==null?void 0:d.href)??null,email:null,id:n["System.CreatedBy"].id,name:n["System.CreatedBy"].uniqueName??null,username:n["System.CreatedBy"].displayName??null,url:null},closedDate:n["Microsoft.VSTS.Common.ClosedDate"]?new Date(n["Microsoft.VSTS.Common.ClosedDate"]):null,createdDate:new Date(n["System.CreatedDate"]),updatedDate:new Date(n["System.ChangedDate"]),url:e._links.html.href,assignees:o?[{avatarUrl:((g=(c=o._links)==null?void 0:c.avatar)==null?void 0:g.href)??null,email:null,id:o.id,name:o.uniqueName??null,username:o.displayName??null,url:null}]:[],description:n["System.Description"]??null,state:{name:(u==null?void 0:u.title)||a,color:null},type:n["System.WorkItemType"],repository:null,project:{namespace:t,name:s,resourceId:null,key:null,id:null},upvoteCount:0,labels:((m=e.fields["System.Tags"])==null?void 0:m.split(";").map(f=>({color:null,description:null,id:null,name:f.trim()})))??[]}},K=class extends A{async getCurrentUser(s={},e={}){if(e.isPAT||this.config.isPAT)throw new Error("Azure DevOps does not support PATs for this function.");let r=`${We(this.config,e)}/profile/profiles/me`,n=await this.config.request({url:r,headers:S(this.config,e)});return{data:{id:n.body.id,name:n.body.displayName,username:n.body.displayName,email:n.body.emailAddress,avatarUrl:null,url:null}}}async getCurrentUserForInstance(s,e={}){let n=(await this.config.request({url:`${v(this.config,e)}/${encodeURIComponent(s.namespace)}/_apis/ConnectionData`,headers:S(this.config,e)})).body.authorizedUser;if(n.providerDisplayName==="Anonymous")throw new Error("Current user not found.");return{data:{id:n.id,name:n.providerDisplayName,username:n.providerDisplayName,email:n.properties.Account.$value,avatarUrl:null,url:null}}}async getUserForCommit(s,e={}){if(!s.repo.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let n=(await this.config.request({url:`${v(this.config,e)}/${encodeURIComponent(s.repo.namespace)}/${encodeURIComponent(s.repo.project)}/_apis/git/repositories/${encodeURIComponent(s.repo.name)}/commits/${s.oid}`,headers:S(this.config,e)})).body.author;return{data:{name:n.name,email:n.email,avatarUrl:n.imageUrl}}}async getOrgsForUser(s,e={}){let r=`${We(this.config,e)}/accounts?memberId=${s.userId}&api-version=6.0`;return{data:(await this.config.request({url:r,headers:S(this.config,e)})).body.value.map(o=>({id:o.accountId,name:o.accountName}))}}async getCollectionsForUser(s,e={}){let r=`${v(this.config,e)}/_apis/projectCollections`;return{data:(await this.config.request({url:r,headers:S(this.config,e)})).body.value.map(o=>({id:o.id,name:o.name}))}}async getAzureProjects(s,e={}){let r=new URL(`${v(this.config,e)}/${encodeURIComponent(s.namespace)}/_apis/projects`);r.searchParams.set("$top",C.toString()),s.cursor&&r.searchParams.set("$skip",s.cursor);let n=await this.config.request({url:r.toString(),headers:S(this.config,e)}),o=n.headers["x-ms-continuationtoken"];return{pageInfo:{hasNextPage:!!o,endCursor:o||null},data:n.body.value.map(a=>({id:a.id,name:a.name,namespace:s.namespace}))}}async getAzureProjectScopeDescriptor(s,e={}){let{namespace:r,projectId:n}=s;return{data:{scope:(await this.config.request({url:`${He(this.config,e)}/${encodeURIComponent(r)}/_apis/graph/descriptors/${n}?api-version=6.0`,headers:S(this.config,e)})).body.value}}}async getAzureGraphAccountsForAzureProject(s,e={}){let{namespace:r,projectScopeDescriptor:n,cursor:o}=s,a=new URL(`${He(this.config,e)}/${encodeURIComponent(r)}/_apis/graph/users`);n&&a.searchParams.set("scopeDescriptor",n),o&&a.searchParams.set("continuationToken",o);let i=await this.config.request({url:a.toString(),headers:S(this.config,e)}),u=i.headers["x-ms-continuationtoken"];return{pageInfo:{endCursor:u||null,hasNextPage:!!u},data:i.body.value.map(l=>{var p,d,c,g;return{avatarUrl:((d=(p=l._links)==null?void 0:p.avatar)==null?void 0:d.href)??null,descriptor:l.descriptor??null,email:l.mailAddress??null,name:l.displayName??null,storageKeyURL:((g=(c=l._links)==null?void 0:c.storageKey)==null?void 0:g.href)??null,username:l.displayName??null}})}}async getAccountFromAzureGraphAccount(s,e={}){let{azureGraphAccount:r}=s;if(!r.storageKeyURL)throw new Error("Expected 'storageKeyURL' to not be null for 'azureGraphAccount'");let n=await this.config.request({url:r.storageKeyURL,headers:S(this.config,e)});return{data:{avatarUrl:r.avatarUrl,email:r.email,id:n.body.value,name:r.name,username:r.username,url:null}}}async getAccountsFromAzureGraphAccounts(s,e={}){let r=[];for(let n of s.azureGraphAccounts){let o=await this.getAccountFromAzureGraphAccount({azureGraphAccount:n},e);r.push(o.data)}return{data:r}}async getRepo(s,e={}){if(!s.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let r=await this.config.request({url:`${v(this.config,e)}/${encodeURIComponent(s.namespace)}/${encodeURIComponent(s.project)}/_apis/git/repositories/${encodeURIComponent(s.name)}`,headers:S(this.config,e)});return{data:Ut(s.namespace,r.body)}}async getRepos(s,e={}){let r=[],n=[];return await Promise.all(s.map(async o=>{try{let a=await this.getRepo(o,e);r.push(a.data)}catch(a){n.push({input:o,error:a})}})),{data:r,errors:n}}async getReposForAzureProject(s,e={}){if(!s.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');return{data:(await this.config.request({url:`${v(this.config,e)}/${encodeURIComponent(s.namespace)}/${encodeURIComponent(s.project)}/_apis/git/repositories`,headers:S(this.config,e)})).body.value.map(n=>Ut(s.namespace,n))}}async getRefs(s,e,r={}){if(!e.repo.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let n=new URL(`${v(this.config,r)}/${encodeURIComponent(e.repo.namespace)}/${encodeURIComponent(e.repo.project)}/_apis/git/repositories/${encodeURIComponent(e.repo.name)}/refs`);n.searchParams.set("filter",s),n.searchParams.set("$top",C.toString()),e.cursor&&n.searchParams.set("continuationToken",e.cursor);let o=await this.config.request({url:n.toString(),headers:S(this.config,r)}),a=o.headers["x-ms-continuationtoken"];return{pageInfo:{hasNextPage:!!a,endCursor:a||null},data:o.body.value.map(i=>({name:he(i.name),commit:{oid:i.objectId,authoredDate:null,committedDate:null}}))}}async getBranches(s,e={}){return this.getRefs("heads",s,e)}async getTags(s,e={}){return this.getRefs("tags",s,e)}async getPullRequestsForRepoBase(s,e={},r=100){let{page:n,repo:o,assigneeLogins:a,authorLogin:i}=s||{},u=n||1;if(!o.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let l="searchCriteria.status=1";return a&&a.length&&(l+=`&searchCriteria.reviewerId=${a[0]}`),i&&(l+=`&searchCriteria.creatorId=${i}`),await this.config.request({url:`${v(this.config,e)}/${encodeURIComponent(o.namespace)}/${encodeURIComponent(o.project||"")}/_apis/git/repositories/${encodeURIComponent(o.name)}/pullRequests?${l}&%24top=${r}&%24skip=${(u-1)*r}`,headers:S(this.config,e)})}async getPullRequestsForRepo(s,e={}){let n=s.page||1,o=await this.getPullRequestsForRepoBase(s,e,100);return{pageInfo:{hasNextPage:o.body.value.length===100,nextPage:n+1},data:o.body.value.map(a=>me(s.repo.namespace,a))}}async getPullRequestsForRepos(s,e={}){if(!s.repos.every(o=>o.project))throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let{repos:r}=s||{},n=[];return await Promise.all(r.map(async o=>{try{(await this.getPullRequestsForRepoBase({repo:o,...s},e)).body.value.forEach(i=>{n.push(me(o.namespace,i))})}catch(a){if(a.statusCode!==404&&a.statusCode!==401)throw a}})),{data:n}}async getPullRequestsForProjectBase(s,e={},r=100){let{namespace:n,project:o,page:a,assigneeLogins:i,authorLogin:u,repo:l}=s;if(l!=null&&l.project&&l.project!==o)throw new Error("Could not fetch pull requests, project mismatch");let p=a||1,d=new URL(`${v(this.config,e)}/${encodeURIComponent(n)}/${encodeURIComponent(o)}/_apis/git/pullRequests`);return d.searchParams.set("searchCriteria.status","1"),d.searchParams.set("$top",r.toString()),d.searchParams.set("$skip",((p-1)*r).toString()),l!=null&&l.id&&(l==null?void 0:l.project)===o&&d.searchParams.set("searchCriteria.repositoryId",l.id),i&&i.length&&d.searchParams.set("searchCriteria.reviewerId",i[0]),u&&d.searchParams.set("searchCriteria.creatorId",u),await this.config.request({url:d.toString(),headers:S(this.config,e)})}async getPullRequestsForProject(s,e={}){let n=s.page||1,o=await this.getPullRequestsForProjectBase(s,e,100);return{pageInfo:{hasNextPage:(o==null?void 0:o.body.value.length)===100,nextPage:n+1},data:(o==null?void 0:o.body.value.map(a=>me(s.namespace,a)))||[]}}async getPullRequestsForProjects(s,e={}){let{projects:r}=s||{},n=[];return await Promise.all(r.map(async o=>{try{if(!s.repo||s.repo.project&&s.repo.project===o.project){let a=await this.getPullRequestsForProjectBase({...o,...s},e);a==null||a.body.value.forEach(i=>{n.push(me(o.namespace,i))})}}catch(a){if(a.statusCode!==404&&a.statusCode!==401)throw a}})),{data:n}}async getAzurePullRequestLastMergeStatus(s,e={}){if(!s.repo.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let{repo:{namespace:r,project:n,name:o},pullRequestId:a}=s,i=await this.config.request({url:`${v(this.config,e)}/${encodeURIComponent(r)}/${encodeURIComponent(n||"")}/_apis/git/repositories/${o}/pullrequests/${a}?includeCommits=true?api-version=6.0`,headers:{...S(this.config,e)}});if(!i.body.mergeStatus)throw new Error("Could not fetch pull request");return{data:i.body.mergeStatus}}async updatePullRequest(s,e,r){return await this.config.request({method:"PATCH",url:`${v(this.config,r)}/${encodeURIComponent(s.repository.owner.login)}/${encodeURIComponent(s.repository.project)}/_apis/git/repositories/${s.repository.name}/pullrequests/${s.id}?api-version=6.0`,body:e,headers:{...S(this.config,r),"Content-Type":"application/json"}})}async closePullRequest(s,e={}){let{pullRequest:r}=s,n={status:"abandoned"};if(!(await this.updatePullRequest(r,JSON.stringify(n),e)).body.status)throw new Error("Could not close pull request")}async mergePullRequest(s,e={}){var u;let{pullRequest:r,mergeStrategy:n}=s,o;switch(n){case"MERGE_COMMIT":{o="noFastForward";break}case"REBASE":{o="rebase";break}case"REBASE_THEN_MERGE_COMMIT":{o="rebaseMerge";break}case"SQUASH":{o="squash";break}}let a={completionOptions:{mergeStrategy:o},lastMergeSourceCommit:{commitId:(u=r.headRef)==null?void 0:u.oid},status:"completed"};if(!(await this.updatePullRequest(r,JSON.stringify(a),e)).body.status)throw new Error("Could not merge pull request")}async addPullRequestLabel(s,e={}){let{pullRequest:r,label:n}=s;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:`${v(this.config,e)}/${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:{...S(this.config,e),"Content-Type":"application/json"}})).body.id)throw new Error("Could not add pull request label")}async removePullRequestLabel(s,e={}){let{pullRequest:r,label:n}=s;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:`${v(this.config,e)}/${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:{...S(this.config,e)}})}async setPullRequestLabels(s,e={}){let{pullRequest:r,labels:n}=s;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 a of n)o.find(i=>i.id===a.id)||await this.addPullRequestLabel({pullRequest:r,label:a},e);for(let a of o)n.find(i=>a.id===i.id)||await this.removePullRequestLabel({pullRequest:r,label:a},e)}async setPullRequestAsDraft(s,e={}){let{pullRequest:r,isDraft:n}=s,o={isDraft:n};if(!(await this.updatePullRequest(r,JSON.stringify(o),e)).body.status)throw new Error("Could not set the pull request as draft")}async addPullRequestReviewer(s,e={}){let{pullRequest:r,reviewer:n,isRequired:o}=s,a={id:n.id,isRequired:o};if(!(await this.config.request({method:"PUT",url:`${v(this.config,e)}/${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(a),headers:{...S(this.config,e),"Content-Type":"application/json"}})).body.id)throw new Error("Could not add pull request reviewer")}async removePullRequestReviewer(s,e={}){let{pullRequest:r,reviewer:n}=s;await this.config.request({method:"DELETE",url:`${v(this.config,e)}/${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:{...S(this.config,e),Accept:"application/json"}})}async setPullRequestReviewers(s,e={}){let{pullRequest:r,reviewers:n}=s;for(let o of n)r.assignees.find(a=>a.id===o.id)||await this.addPullRequestReviewer({pullRequest:r,reviewer:o,isRequired:!0},e);for(let o of r.assignees)n.find(a=>o.id===a.id)||await this.removePullRequestReviewer({pullRequest:r,reviewer:o},e)}async getIssuesForAzureProject(s,e={}){let{page:r,assigneeLogins:n,authorLogin:o,mentionLogin:a,labelNames:i,statusByWorkItemIdByStatusId:u}=s||{},l=r||1,p=200,d=["[Microsoft.VSTS.Common.ClosedDate] = ''","[System.TeamProject] = @project","[Microsoft.VSTS.Common.ResolvedDate] = ''"];o&&d.push(`[System.CreatedBy] = '${o.replace("'","''")}'`),n&&n[0]&&d.push(`[System.AssignedTo] = '${n[0].replace("'","''")}'`),a&&d.push("[System.Id] IN (@recentMentions)"),i&&i.forEach(h=>d.push(`[System.Tags] Contains '${h}'`));let c=`Select [Microsoft.VSTS.Common.ClosedDate], [Microsoft.VSTS.Common.ResolvedDate] From WorkItems Where ${d.join(" AND ")} order by [System.CreatedDate] desc`,g=await this.config.request({url:`${v(this.config,e)}/${encodeURIComponent(s.namespace)}/${encodeURIComponent(s.project)}/_apis/wit/wiql?api-version=6.0`,body:JSON.stringify({query:c}),method:"POST",headers:{...S(this.config,e),"Content-Type":"application/json"}}),m=g.body.workItems.slice((l-1)*p,p*l).map(h=>h.id);if(m.length==0)return{pageInfo:{hasNextPage:!1,nextPage:null},data:[]};let f=await this.config.request({url:`${v(this.config,e)}/${encodeURIComponent(s.namespace)}/${encodeURIComponent(s.project)}/_apis/wit/workitemsbatch?api-version=6.0`,body:JSON.stringify({ids:m,$expand:"Links"}),method:"POST",headers:{...S(this.config,e),"Content-Type":"application/json"}});return{pageInfo:{hasNextPage:g.body.workItems.length>p*l,nextPage:l+1},data:f.body.value.map(h=>Er(s.namespace,s.project,h,u||{}))}}async getPermissionsForRepos(s,e={}){let{namespace:r,repos:n}=s,o={4:["canPush","canCreateWebhook"],1024:["isAdmin"],2048:["isAdmin"],4096:["isAdmin"],8192:["isAdmin"]},a=p=>{let d="2e9eb7ed-3c0a-47d4-87c1-0ffdd275fd87",c=`repoV2/${p.projectId}/${p.id}`;return Object.keys(o).map(g=>({securityNamespaceId:d,token:c,permissions:g}))},i={alwaysAllowAdministrators:!1,evaluations:n.flatMap(a)};return{data:(await this.config.request({method:"POST",url:`${v(this.config,e)}/${encodeURIComponent(r)}/_apis/security/permissionevaluationbatch?api-version=7.0`,body:JSON.stringify(i),headers:{...S(this.config,e),"Content-Type":"application/json"}})).body.evaluations.reduce((p,d)=>{let[,c,g]=d.token.split("/"),m=`${c}/${g}`,f=o[d.permissions];for(let h of f)p[m]===void 0&&(p[m]={canCreateWebhook:!0,canPush:!0,isAdmin:!0}),d.value===!1&&(p[m][h]=!1);return p},{})}}async decorateReposWithPermissions(s,e={}){let{namespace:r,repos:n}=s,o=await this.getPermissionsForRepos({namespace:r,repos:n},e);return{data:n.map(a=>({...a,permissions:o.data[`${a.projectId}/${a.id}`]}))}}async updateIssue(s,e,r={}){return await this.config.request({method:"PATCH",url:`${v(this.config,r)}/${encodeURIComponent(s.project.namespace)}/${encodeURIComponent(s.project.name)}/_apis/wit/workitems/${s.id}?api-version=6.0`,body:JSON.stringify(e),headers:{...S(this.config,r),"Content-Type":"application/json-patch+json"}})}async setIssueStatus(s,e={}){var i;let{issue:r,status:n}=s,o=[{op:"add",path:"/fields/System.State",value:n.name}];if(!((i=(await this.updateIssue(r,o,e)).body.fields)!=null&&i["System.State"]))throw new Error("Could not set issue status")}async setIssueAssignee(s,e={}){var i;let{issue:r,assignee:n}=s,o=[{op:"add",path:"/fields/System.AssignedTo",value:(n==null?void 0:n.name)??""}];if(!((i=(await this.updateIssue(r,o,e)).body.fields)!=null&&i["System.State"]))throw new Error("Could not set issue assignee")}async setIssueLabels(s,e={}){var u;let{issue:r,labels:n}=s,a=[{op:"replace",path:"/fields/System.Tags",value:n.map(l=>l.name).join(";")}];if(!((u=(await this.updateIssue(r,a,e)).body.fields)!=null&&u["System.Tags"]))throw new Error("Could not set issue tags")}async getIssueTypesForAzureProject(s,e={}){if(!s.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let{namespace:r,project:n}=s;return{data:(await this.config.request({url:`${v(this.config,e)}/${encodeURIComponent(r)}/${encodeURIComponent(n||"")}/_apis/wit/workitemtypes?api-version=6.0`,headers:{...S(this.config,e)}})).body.value}}async getLabelsForProject(s,e={}){let{namespace:r,project:n}=s;return{data:(await this.config.request({url:`${v(this.config,e)}/${encodeURIComponent(r)}/${encodeURIComponent(n||"")}/_apis/wit/tags?api-version=6.0`,headers:{...S(this.config,e)}})).body.value.map(a=>({color:null,description:null,id:a.id,name:a.name,url:a.url}))}}};var L=(t,s={})=>R(s.token||t.token,s.isPAT||t.isPAT);var $="https://api.bitbucket.org/2.0",qr={OPEN:"OPEN",MERGED:"MERGED",DECLINED:"CLOSED"},fe=t=>({id:t.uuid,name:t.display_name||t.nickname,username:t.nickname||t.display_name,email:null,avatarUrl:t.links.avatar.href,url:t.links.html.href}),At=t=>{let s=t.links.clone,e=s==null?void 0:s.find(n=>n.name==="ssh"),r=s==null?void 0:s.find(n=>n.name==="https");return e&&r?{cloneUrlHTTPS:r.href,cloneUrlSSH:e.href}:null},Gt=t=>{var s,e;return{id:t.uuid,namespace:t.workspace.slug,name:t.slug,webUrl:t.links.html.href,httpsUrl:((s=t.links.clone.find(r=>r.name==="https"))==null?void 0:s.href)??null,sshUrl:((e=t.links.clone.find(r=>r.name==="ssh"))==null?void 0:e.href)??null,defaultBranch:{name:t.mainbranch.name},permissions:null}},Ve=t=>{var r;let s=t.id,e=((r=t.participants)==null?void 0:r.map(n=>{let o="REVIEW_REQUESTED";return n.approved?o="APPROVED":n.state==="changes_requested"?o="CHANGES_REQUESTED":n.participated_on!==null&&(o="COMMENTED"),{reviewer:fe(n.user),state:o}}))??[];return{id:s.toString(),title:t.title,number:s,state:qr[t.state],isDraft:!1,commentCount:t.comment_count,upvoteCount:null,author:fe(t.author),createdDate:new Date(t.created_on),updatedDate:new Date(t.updated_on),closedDate:null,mergedDate:null,repository:{id:t.destination.repository.uuid,name:t.destination.repository.name,owner:{login:t.destination.repository.full_name.split("/")[0]},remoteInfo:At(t.destination.repository)},headCommit:{buildStatuses:null},baseRef:{name:t.destination.branch.name,oid:t.destination.commit.hash},headRef:{name:t.source.branch.name,oid:t.source.commit.hash},url:t.links.html.href,assignees:null,reviews:e,reviewDecision:k(e),additions:null,deletions:null,fileCount:null,commitCount:null,headRepository:{id:t.source.repository.uuid,name:t.source.repository.name,owner:{login:t.source.repository.full_name.split("/")[0]},remoteInfo:At(t.source.repository)},mergeableState:"MERGEABLE",permissions:null}},Cr=t=>{switch(t){case"owner":case"admin":return{canCreateWebhook:!0,canPush:!0,isAdmin:!0};case"write":return{canCreateWebhook:!1,canPush:!0,isAdmin:!1};case"read":case"none":return{canCreateWebhook:!1,canPush:!1,isAdmin:!1}}},X=class extends O{async refreshToken(s){return{data:(await this.config.request({url:"https://bitbucket.org/site/oauth2/access_token",method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded",Authorization:`Basic ${s.base64ClientIDColonClientSecret}`},body:`grant_type=refresh_token&refresh_token=${s.refreshToken}`})).body}}async getCurrentUser(s={},e={}){let r=await this.config.request({url:`${$}/user`,headers:L(this.config,e)});return{data:fe(r.body)}}async getUserForCommit(s,e={}){var a;let n=(await this.config.request({url:`${$}/repositories/${s.repo.namespace}/${s.repo.name}/commit/${s.oid}`,headers:L(this.config,e)})).body.author,o=n.raw.match(/([^<]+)<(.+)>/);return{data:{name:o?o[1].trim():null,email:o?o[2]:null,avatarUrl:((a=n.user)==null?void 0:a.links.avatar.href)||null}}}async getRepo(s,e={}){let r=await this.config.request({url:`${$}/repositories/${s.namespace}/${s.name}`,headers:L(this.config,e)});return{data:Gt(r.body)}}async getRepos(s,e={}){let r=[],n=[];return await Promise.all(s.map(async o=>{try{let a=await this.getRepo(o,e);r.push(a.data)}catch(a){n.push({input:o,error:a})}})),{data:r,errors:n}}async getReposForCurrentUser(s,e={}){let r=new URL(`${$}/repositories`);r.searchParams.set("role","member"),r.searchParams.set("pagelen",C.toString()),s.cursor&&r.searchParams.set("after",s.cursor);let n=await this.config.request({url:r.toString(),headers:L(this.config,e)}),o=!!n.body.next,a=null;return n.body.next&&(a=new URL(n.body.next).searchParams.get("after")),{pageInfo:{hasNextPage:o,endCursor:a},data:n.body.values.map(Gt)}}async getBranches(s,e={}){var a;let r=new URL(`${$}/repositories/${s.repo.namespace}/${s.repo.name}/refs/branches`);r.searchParams.set("page",((a=s.page)==null?void 0:a.toString())||"1"),r.searchParams.set("pagelen",C.toString());let n=await this.config.request({url:r.toString(),headers:L(this.config,e)}),o=!!n.body.next;return{pageInfo:{hasNextPage:o,nextPage:o?n.body.page+1:null},data:n.body.values.map(i=>{let u=new Date(i.target.date);return{name:i.name,commit:{oid:i.target.hash,authoredDate:u,committedDate:u}}})}}async getTags(s,e={}){let r=new URL(`${$}/repositories/${s.repo.namespace}/${s.repo.name}/refs/tags`);r.searchParams.set("pagelen",C.toString()),s.cursor&&r.searchParams.set("page",s.cursor);let n=await this.config.request({url:r.toString(),headers:L(this.config,e)}),o=!!n.body.next,a=null;return n.body.next&&(a=new URL(n.body.next).searchParams.get("page")),{pageInfo:{hasNextPage:o,endCursor:a},data:n.body.values.map(i=>{let u=new Date(i.target.date);return{name:i.name,commit:{oid:i.target.hash,authoredDate:u,committedDate:u}}})}}async getWorkspacesForUser(s,e={}){var a;let r=new URL(`${$}/user/permissions/workspaces`);r.searchParams.set("page",((a=s.page)==null?void 0:a.toString())||"1"),r.searchParams.set("pagelen","50");let n=await this.config.request({url:r.toString(),headers:L(this.config,e)}),o=!!n.body.next;return{pageInfo:{hasNextPage:o,nextPage:o?n.body.page+1:null},data:n.body.values.map(i=>({id:i.workspace.uuid,slug:i.workspace.slug,name:i.workspace.name}))}}async getPullRequestsForUserAndWorkspace(s,e={}){var a;let r=new URL(`${$}/workspaces/${s.workspaceSlug}/pullrequests/${s.userId}`);if(r.searchParams.set("fields","+values.participants,+values.destination.repository.links.clone.*,+values.source.repository.links.clone.*"),r.searchParams.set("page",((a=s.page)==null?void 0:a.toString())||"1"),r.searchParams.set("pagelen","50"),s.repos&&s.repos.length>0){let i=`state = "open" AND (${s.repos.map(u=>`source.repository.full_name = "${u.namespace}/${u.name}"`).join(" OR ")})`;r.searchParams.set("q",i)}let n=await this.config.request({url:r.toString(),headers:L(this.config,e)}),o=!!n.body.next;return{pageInfo:{hasNextPage:o,nextPage:o?n.body.page+1:null},data:n.body.values.map(Ve)}}async getPullRequestsForRepoBase(s,e={}){var a;let r=new URL(`${$}/repositories/${encodeURI(s.repo.namespace)}/${encodeURI(s.repo.name)}/pullrequests?state=OPEN`),n=[];s.reviewerId&&n.push(`reviewers.uuid="${s.reviewerId}"`),s.authorLogin&&n.push(`author.uuid="${s.authorLogin}"`);let o='state="OPEN"';return n.length&&(o+=` AND (${n.join(s.useOrFilter?" OR ":" AND ")})`),r.searchParams.set("fields","+values.participants,+values.destination.repository.links.clone.*,+values.source.repository.links.clone.*"),r.searchParams.set("page",((a=s.page)==null?void 0:a.toString())||"1"),r.searchParams.set("pagelen","50"),r.searchParams.set("q",o),await this.config.request({url:r.toString(),headers:L(this.config,e)})}async getPullRequestsForRepo(s,e={}){let r=[],n=await this.getPullRequestsForRepoBase(s,e);n.body.values.forEach(a=>{r.push(Ve(a))});let o=!!n.body.next;return{pageInfo:{hasNextPage:o,nextPage:o?n.body.page+1:null},data:r}}async getPullRequestsForRepos(s,e={}){let r=[];return await Promise.all(s.repos.map(async n=>{try{(await this.getPullRequestsForRepoBase({repo:n,...s},e)).body.values.forEach(a=>{r.push(Ve(a))})}catch(o){if(o.statusCode!==404&&o.statusCode!==401)throw o}})),{data:r}}async getAccountsForWorkspace(s,e={}){var a;let r=new URL(`${$}/workspaces/${encodeURI(s.workspace)}/members`);r.searchParams.set("page",((a=s.page)==null?void 0:a.toString())||"1"),r.searchParams.set("pagelen","100");let n=await this.config.request({url:r.toString(),headers:L(this.config,e)}),o=!!n.body.next;return{pageInfo:{hasNextPage:o,nextPage:o?n.body.page+1:null},data:n.body.values.map(i=>fe(i.user))}}async getReposPermissionsForCurrentUser(s,e={}){var a;let r=new URL(`${$}/user/permissions/repositories`);r.searchParams.set("page",((a=s.page)==null?void 0:a.toString())||"1"),r.searchParams.set("pagelen","100");let n=await this.config.request({url:r.toString(),headers:L(this.config,e)}),o=!!n.body.next;return{pageInfo:{hasNextPage:o,nextPage:o?n.body.page+1:null},data:n.body.values.reduce((i,u)=>({...i,[u.repository.uuid]:Cr(u.permission)}),{})}}async decorateReposWithPermissions(s,e={}){let r={},n=1;do{let o=await this.getReposPermissionsForCurrentUser({page:n},e);r={...o.data,...r},n=o.pageInfo.hasNextPage?o.pageInfo.nextPage:null}while(n!==null);return{data:s.repos.map(o=>({...o,permissions:r[o.id]??{canCreateWebhook:!1,canPush:!1,isAdmin:!1}}))}}async closePullRequest(s,e={}){let{pullRequest:r}=s;if(!(await this.config.request({method:"POST",url:`${$}/repositories/${r.repository.owner.login}/${r.repository.name}/pullrequests/${r.id}/decline`,headers:L(this.config,e)})).body.title)throw new Error("Could not close pull request")}async mergePullRequest(s,e={}){let{pullRequest:r,mergeStrategy:n}=s,o;switch(n){case"MERGE_COMMIT":{o="merge_commit";break}case"FAST_FORWARD":{o="fast_forward";break}case"SQUASH":{o="squash";break}}let a={merge_strategy:o,type:"pullrequest"};if(!(await this.config.request({method:"POST",url:`${$}/repositories/${r.repository.owner.login}/${r.repository.name}/pullrequests/${r.id}/merge`,body:JSON.stringify(a),headers:{...L(this.config,e),"Content-Type":"application/json"}})).body.title)throw new Error("Could not merge pull request")}async setPullRequestReviewers(s,e={}){let{pullRequest:r,reviewers:n}=s,o={reviewers:n.map(i=>{if(i.username)throw new Error('Bitbucket reviewer requires "username" for this function.');return{username:i.username}})};if(!(await this.config.request({method:"PUT",url:`${$}/repositories/${r.repository.owner.login}/${r.repository.name}/pullrequests/${r.id}`,body:JSON.stringify(o),headers:{...L(this.config,e),"Content-Type":"application/json"}})).body.title)throw new Error("Could not set pull request reviewers")}};var Tt=t=>t?t.find(s=>s.permission==="USER_ADMIN"||s.permission==="PROJECT_ADMIN"||s.permission==="ADMIN"||s.permission==="SYS_ADMIN"||s.permission==="REPO_ADMIN")?{canCreateWebhook:!0,canPush:!0,isAdmin:!0}:t.find(s=>s.permission==="REPO_WRITE"||s.permission==="REPO_CREATE"||s.permission==="PROJECT_CREATE"||s.permission==="PROJECT_WRITE")?{canCreateWebhook:!1,canPush:!0,isAdmin:!1}:{canCreateWebhook:!1,canPush:!1,isAdmin:!1}:{canCreateWebhook:!1,canPush:!1,isAdmin:!1};var ie=t=>{let s=t.links.self[0].href;return{name:t.displayName,email:t.emailAddress,avatarUrl:t.avatarUrl??(s&&`${s}/avatar.png`),id:t.id.toString(),username:t.name,url:s}},Ie=t=>{var u,l,p,d,c,g;let s={OPEN:"OPEN",MERGED:"MERGED",DECLINED:"CLOSED"},e={UNAPPROVED:"REVIEW_REQUESTED",NEEDS_WORK:"CHANGES_REQUESTED",APPROVED:"APPROVED"},r=t.reviewers.map(m=>({reviewer:ie(m.user),state:e[m.status]})),n=((u=t.toRef.repository.links.clone.find(m=>m.name==="ssh"))==null?void 0:u.href)??null,o=((l=t.toRef.repository.links.clone.find(m=>m.name==="https"))==null?void 0:l.href)??null;o||(o=((p=t.toRef.repository.links.clone.find(m=>m.name==="http"))==null?void 0:p.href)??null);let a=((d=t.fromRef.repository.links.clone.find(m=>m.name==="ssh"))==null?void 0:d.href)??null,i=((c=t.fromRef.repository.links.clone.find(m=>m.name==="https"))==null?void 0:c.href)??null;return i||(i=((g=t.fromRef.repository.links.clone.find(m=>m.name==="http"))==null?void 0:g.href)??null),{id:t.id.toString(),number:t.id,title:t.title,url:t.links.self[0].href,state:s[t.state],isDraft:!1,createdDate:new Date(t.createdDate),updatedDate:new Date(t.updatedDate),closedDate:t.closedDate?new Date(t.closedDate):null,mergedDate:t.state=="MERGED"&&t.closedDate?new Date(t.closedDate):null,baseRef:{name:t.toRef.displayId,oid:t.toRef.latestCommit},headRef:{name:t.fromRef.displayId,oid:t.fromRef.latestCommit},commentCount:t.properties.commentCount,upvoteCount:null,commitCount:null,fileCount:null,additions:null,deletions:null,author:ie(t.author.user),assignees:null,reviews:r,reviewDecision:k(r),repository:{id:t.toRef.repository.id.toString(),name:t.toRef.repository.name,owner:{login:t.toRef.repository.project.key},remoteInfo:o&&n?{cloneUrlHTTPS:o,cloneUrlSSH:n}:null},headRepository:{id:t.fromRef.repository.id.toString(),name:t.fromRef.repository.name,owner:{login:t.fromRef.repository.project.key},remoteInfo:i&&a?{cloneUrlHTTPS:i,cloneUrlSSH:a}:null},headCommit:null,mergeableState:"MERGEABLE",permissions:null,version:t.version}},Ot=t=>{var s,e,r;return{id:t.id.toString(),namespace:t.project.key,name:t.slug,webUrl:((s=t.links.self[0])==null?void 0:s.href)??null,httpsUrl:((e=t.links.clone.find(n=>n.name==="https"||n.name==="http"))==null?void 0:e.href)??null,sshUrl:((r=t.links.clone.find(n=>n.name==="ssh"))==null?void 0:r.href)??null,defaultBranch:null,permissions:null}},Z=class extends A{getBaseUrl(s){let e=s.baseUrl||this.config.baseUrl;if(!e)throw new Error('Bitbucket Server requires "baseUrl"');return e}getRequestHeaders(s){return R(s.token||this.config.token)}async getCurrentUser(s={},e={}){let r=await this.config.request({url:`${this.getBaseUrl(e)}/users?limit=2`,headers:this.getRequestHeaders(e)}),{headers:{"x-auserid":n,"x-ausername":o}}=r,a=n?parseInt(n,10):null,i=decodeURIComponent(o),l=(await this.config.request({url:`${this.getBaseUrl(e)}/users?filter=${o}&avatarSize=64`,headers:this.getRequestHeaders(e)})).body.values.find(({emailAddress:p,id:d,name:c,slug:g})=>a?a===d:i===c||i===p||i===g);if(!l)throw new Error("Could not find current Bitbucket Server user");return{data:ie(l)}}async getUserForCommit(s,e){let{repo:r,oid:n}=s,o=await this.config.request({url:`${this.getBaseUrl(e)}/projects/${r.namespace}/repos/${r.name}/commits/${n}`,headers:this.getRequestHeaders(e)});if(!o.body.author)throw new Error("Could not find user for commit");return{data:ie(o.body.author)}}async getRepo(s,e={}){let r=await this.config.request({url:`${this.getBaseUrl(e)}/projects/${s.namespace}/repos/${s.name}`,headers:this.getRequestHeaders(e)});return{data:Ot(r.body)}}async getRepos(s,e={}){let r=[],n=[];return await Promise.all(s.map(async o=>{try{let a=await this.getRepo(o,e);r.push(a.data)}catch(a){n.push({input:o,error:a})}})),{data:r,errors:n}}async getReposForCurrentUser(s,e={}){let r=s.page??0,n=await this.config.request({url:`${this.getBaseUrl(e)}/repos?start=${r}`,headers:this.getRequestHeaders(e)});return{pageInfo:{hasNextPage:!n.body.isLastPage,nextPage:n.body.nextPageStart},data:n.body.values.map(Ot)}}async getRepoPermissionsForUsername(s,e={}){var n;let r=new URL(`${this.getBaseUrl(e)}/projects/${s.repo.namespace}/repos/${s.repo.name}/permissions/search?filterText=${s.username}`);try{let o=await this.config.request({url:r.toString(),headers:this.getRequestHeaders(e)});return{data:Tt(o.body.values)}}catch(o){if(((n=o.response)==null?void 0:n.status)===401)return{data:{canCreateWebhook:!1,canPush:!1,isAdmin:!1}};throw o}}async decorateReposWithPermissions(s,e={}){return await Promise.all(s.repos.map(async n=>{let o=await this.getRepoPermissionsForUsername({repo:n,username:s.username},e);return{...n,permissions:o.data}}))}async getPullRequestsForRepoBase(s,e={}){var n;let r=new URL(`${this.getBaseUrl(e)}/projects/${encodeURI(s.repo.namespace)}/repos/${encodeURI(s.repo.name)}/pull-requests?state=OPEN`);return r.searchParams.set("start",((n=s.page)==null?void 0:n.toString())||"0"),r.searchParams.set("limit","50"),await this.config.request({url:r.toString(),headers:this.getRequestHeaders(e)})}async getPullRequestsForRepo(s,e={}){let r=[],n=await this.getPullRequestsForRepoBase(s,e);n.body.values.forEach(a=>{if(s.authorLogin&&a.author.user.name!==s.authorLogin)return null;r.push(Ie(a))});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(s,e={}){let r=[];return await Promise.all(s.repos.map(async n=>{try{(await this.getPullRequestsForRepoBase({repo:n,...s},e)).body.values.forEach(a=>{if(s.authorLogin&&a.author.user.name!==s.authorLogin)return null;r.push(Ie(a))})}catch(o){if(o.statusCode!==404&&o.statusCode!==401)throw o}})),{data:r}}async getPullRequestsForCurrentUser(s,e={}){var a;let r=new URL(`${this.getBaseUrl(e)}/dashboard/pull-requests`);r.searchParams.set("state","OPEN"),r.searchParams.set("start",((a=s.page)==null?void 0:a.toString())||"0"),r.searchParams.set("limit","50");let n=await this.config.request({url:r.toString(),headers:this.getRequestHeaders(e)}),o=n.body.values.length!==0;return{pageInfo:{hasNextPage:o,nextPage:o?n.body.start+n.body.values.length:null},data:n.body.values.map(Ie)}}async closePullRequest(s,e={}){let{pullRequest:r}=s;if(r.version===void 0)throw new Error('Bitbucket Server requires "version" for this function.');if(!(await this.config.request({method:"POST",url:`${this.getBaseUrl(e)}/projects/${r.repository.owner.login}/repos/${r.repository.name}/pull-requests/${r.id}/decline`,body:JSON.stringify({version:r.version}),headers:{...this.getRequestHeaders(e),"Content-Type":"application/json"}})).body.title)throw new Error("Could not close pull request")}async mergePullRequest(s,e={}){let{pullRequest:r,mergeStrategyId:n}=s;if(s.mergeStrategy)throw new Error('Bitbucket Server uses "mergeStrategyId" instead of "mergeStrategy".');if(r.version===void 0)throw new Error('Bitbucket Server requires "version" for this function.');if(!(await this.config.request({method:"POST",url:`${this.getBaseUrl(e)}/projects/${r.repository.owner.login}/repos/${r.repository.name}/pull-requests/${r.id}/merge`,body:JSON.stringify({strategyId:n,version:r.version}),headers:{...this.getRequestHeaders(e),"Content-Type":"application/json"}})).body.title)throw new Error("Could not merge pull request")}async getMergeStrategies(s={}){let e=await this.config.request({url:`${this.getBaseUrl(s)}/admin/pull-requests/git`,headers:{...this.getRequestHeaders(s),"Content-Type":"application/json"}});return{data:{defaultStrategy:e.body.mergeConfig.defaultStrategy,strategies:e.body.mergeConfig.strategies}}}async setPullRequestReviewers(s,e={}){let{pullRequest:r,reviewers:n}=s;if(r.version===void 0)throw new Error('Bitbucket Server requires "version" for this function.');let o={reviewers:n.map(i=>{if(i.username)throw new Error('Bitbucket Server reviewer requires "username" for this function.');return{user:{name:i.username}}}),version:r.version};if(!(await this.config.request({method:"PUT",url:`${this.getBaseUrl(e)}/projects/${r.repository.owner.login}/repos/${r.repository.name}/pull-requests/${r.id}`,body:JSON.stringify(o),headers:{...this.getRequestHeaders(e),"Content-Type":"application/json"}})).body.title)throw new Error("Could not set pull request reviewers")}async getAccountsForProject(s,e={}){var a;let r=new URL(`${this.getBaseUrl(e)}/projects/${encodeURI(s.project)}/permissions/users`);r.searchParams.set("start",((a=s.page)==null?void 0:a.toString())||"0"),r.searchParams.set("limit","50");let n=await this.config.request({url:r.toString(),headers:this.getRequestHeaders(e)}),o=n.body.values.length!==0;return{pageInfo:{hasNextPage:o,nextPage:o?n.body.start+n.body.values.length:null},data:n.body.values.map(i=>ie(i.user))}}};var jt=require("js-base64");var Re=(e=>(e.Open="OPEN",e.Closed="CLOSED",e))(Re||{});var b=class extends Error{constructor(e,r){let n=r==null?void 0:r.map(a=>`'${a.message}'`).join(", "),o=n?`${e}: ${n}`:e;super(o);this.graphQLErrors=r??[]}};var Dr={AS_CODE_OWNER:[3,0,0],CHECK_RUN:[3,0,0],LATEST_REVIEWS:[3,0,0],VIEWER_CAN_MERGE_AS_ADMIN:[3,5,0],ISSUE_FULL_DATABASE_ID:[3,12,0],PR_FULL_DATABASE_ID:[3,13,0],PR_REVIEW_FULL_DATABASE_ID:[3,13,0],PR_REVIEW_COMMENT_FULL_DATABASE_ID:[3,13,0]},xt=15,kt=100,U=t=>!!t,_=(t,s)=>{let e=Dr[s];for(let r=0;r<3;r++){if(t[r]>e[r])return!0;if(t[r]<e[r])return!1}return!0},ye="https://api.github.com",Lr=`${ye}/graphql`,Pe=`
|
|
2
2
|
description
|
|
3
3
|
dueOn
|
|
4
4
|
id
|
|
@@ -6,7 +6,7 @@ number
|
|
|
6
6
|
state
|
|
7
7
|
title
|
|
8
8
|
url
|
|
9
|
-
|
|
9
|
+
`,$r=`
|
|
10
10
|
... on CheckRun {
|
|
11
11
|
completedAt
|
|
12
12
|
conclusion
|
|
@@ -20,7 +20,7 @@ color
|
|
|
20
20
|
description
|
|
21
21
|
id
|
|
22
22
|
name
|
|
23
|
-
`,
|
|
23
|
+
`,Nt=t=>{if(t.endsWith("/api/graphql"))throw new Error("The graphql endpoint is being used as the baseUrl. This package uses both GraphQL and REST APIs, and the REST version cannot be assumed. Use the REST endpoint as the baseUrl instead.")},Ur=(t,s)=>{let e=s.baseUrl||t.baseUrl;return e?(e=e.replace(/\/$/,""),Nt(e),be.test(e)&&(e=e.replace(be,"")),`${e}/api/graphql`):Lr},Y=(t,s)=>{let e=s.baseUrl||t.baseUrl;return e?(e=e.replace(/\/$/,""),Nt(e),be.test(e)&&(e=e.replace(be,"")),`${e}/api/v3`):ye},y=(t,s,e)=>{let r=R(e.token||t.token);return r["X-Github-Next-Global-ID"]="1",r["Content-Type"]="application/json",r.Accept="application/vnd.github.merge-info-preview+json",t.request({url:Ur(t,e),method:"POST",headers:r,body:JSON.stringify(s)})},Ar={user:!0,"user:email":!0,"read:user":!0},F=t=>t.some(s=>Ar[s]),G=(t=!1,s=!1,e)=>`
|
|
24
24
|
__typename
|
|
25
25
|
${z(e,["graphQLId"],"id")}
|
|
26
26
|
${z(e,["id"],"databaseId")}
|
|
@@ -29,7 +29,7 @@ ${z(e,["name","username"],"login")}
|
|
|
29
29
|
${s?z(e,["email"],"email"):""}
|
|
30
30
|
${z(e,["avatarUrl"],`avatarUrl${t?"(size: $avatarSize)":""}`)}
|
|
31
31
|
${z(e,["url"],"url")}
|
|
32
|
-
`,
|
|
32
|
+
`,Gr=(t=!1)=>`
|
|
33
33
|
latestReviews(first: 100) {
|
|
34
34
|
nodes {
|
|
35
35
|
author {
|
|
@@ -37,20 +37,20 @@ latestReviews(first: 100) {
|
|
|
37
37
|
${G(!1,t)}
|
|
38
38
|
}
|
|
39
39
|
... on EnterpriseUserAccount {
|
|
40
|
-
${
|
|
40
|
+
${Ke(!1)}
|
|
41
41
|
}
|
|
42
42
|
}
|
|
43
43
|
state
|
|
44
44
|
}
|
|
45
45
|
}
|
|
46
|
-
`,
|
|
46
|
+
`,_t=(t=!1)=>`
|
|
47
47
|
__typename
|
|
48
48
|
id
|
|
49
49
|
databaseId
|
|
50
50
|
login
|
|
51
51
|
avatarUrl${t?"(size: $avatarSize)":""}
|
|
52
52
|
url
|
|
53
|
-
`,
|
|
53
|
+
`,Ke=(t=!1)=>`
|
|
54
54
|
__typename
|
|
55
55
|
id
|
|
56
56
|
login
|
|
@@ -67,10 +67,10 @@ author {
|
|
|
67
67
|
${G(!1,s)}
|
|
68
68
|
}
|
|
69
69
|
... on Bot {
|
|
70
|
-
${
|
|
70
|
+
${_t(!1)}
|
|
71
71
|
}
|
|
72
72
|
... on EnterpriseUserAccount {
|
|
73
|
-
${
|
|
73
|
+
${Ke(!1)}
|
|
74
74
|
}
|
|
75
75
|
}
|
|
76
76
|
commits(last: 1) {
|
|
@@ -83,7 +83,7 @@ commits(last: 1) {
|
|
|
83
83
|
contexts(first: 100) {
|
|
84
84
|
totalCount
|
|
85
85
|
nodes {
|
|
86
|
-
${!e||_(e,"CHECK_RUN")
|
|
86
|
+
${!e||_(e,"CHECK_RUN")?$r:""}
|
|
87
87
|
... on StatusContext {
|
|
88
88
|
context
|
|
89
89
|
createdAt
|
|
@@ -158,7 +158,7 @@ reviewRequests(first: 100) {
|
|
|
158
158
|
}
|
|
159
159
|
}
|
|
160
160
|
}
|
|
161
|
-
${!e||_(e,"LATEST_REVIEWS")?
|
|
161
|
+
${!e||_(e,"LATEST_REVIEWS")?Gr(s):""}
|
|
162
162
|
additions
|
|
163
163
|
deletions
|
|
164
164
|
changedFiles
|
|
@@ -173,7 +173,7 @@ labels(first: 100) {
|
|
|
173
173
|
}
|
|
174
174
|
}
|
|
175
175
|
${!e||_(e,"VIEWER_CAN_MERGE_AS_ADMIN")?"viewerCanMergeAsAdmin":""}
|
|
176
|
-
`,
|
|
176
|
+
`,Tr=(t=!1,s)=>`
|
|
177
177
|
id
|
|
178
178
|
${!s||_(s,"ISSUE_FULL_DATABASE_ID")?"fullDatabaseId":"databaseId"}
|
|
179
179
|
title
|
|
@@ -182,10 +182,10 @@ author {
|
|
|
182
182
|
${G(!1,t)}
|
|
183
183
|
}
|
|
184
184
|
... on Bot {
|
|
185
|
-
${
|
|
185
|
+
${_t(!1)}
|
|
186
186
|
}
|
|
187
187
|
... on EnterpriseUserAccount {
|
|
188
|
-
${
|
|
188
|
+
${Ke(!1)}
|
|
189
189
|
}
|
|
190
190
|
}
|
|
191
191
|
closedAt
|
|
@@ -221,7 +221,7 @@ labels(first: 100) {
|
|
|
221
221
|
${we}
|
|
222
222
|
}
|
|
223
223
|
}
|
|
224
|
-
`,
|
|
224
|
+
`,Or={"-linked":"-linked",archived:"archived",assignee:"assignee",author:"author",base:"base",closed:"closed",commenter:"commenter",comments:"comments",created:"created",draft:"draft",head:"head",label:"label",language:"language",linked:"linked",in:"in",interactions:"interactions",involves:"involves",is:"is",mentions:"mentions",merged:"merged",milestone:"milestone",no:"no",org:"org",project:"project",reactions:"reactions",repo:"repo",review:"review","reviewed-by":"reviewed-by","review-requested":"review-requested",state:"state",status:"status",team:"team","team-review-requested":"team-review-requested",type:"type",updated:"updated",user:"user","user-review-requested":"user-review-requested"},xr=new RegExp('(([^\\s]+:)?\\"(?:[^\\"\\\\]|\\\\.)*\\"?)|([^\\"\\s]+)',"g"),Xe=t=>{let s=[];return(t.match(xr)??[]).forEach(r=>{if(r.includes(":")&&r!="is:closed"){let n=r.split(":")[0];Or[n]&&s.push(r)}}),s},Ze=(t,s,e,r)=>{let n=t==="issue";return{query:`
|
|
225
225
|
query SearchIssuesOrPullRequests($query: String! $after: String) {
|
|
226
226
|
search(type:ISSUE query:$query first: ${r.maxPageSize} after:$after) {
|
|
227
227
|
pageInfo {
|
|
@@ -230,18 +230,18 @@ query SearchIssuesOrPullRequests($query: String! $after: String) {
|
|
|
230
230
|
}
|
|
231
231
|
nodes {
|
|
232
232
|
... on ${n?"Issue":"PullRequest"} {
|
|
233
|
-
${n?
|
|
233
|
+
${n?Tr(r.supportsEmail,r.enterpriseVersion??null):Se(r.supportsDrafts??!1,r.supportsEmail,r.enterpriseVersion??null)}
|
|
234
234
|
}
|
|
235
235
|
}
|
|
236
236
|
}
|
|
237
|
-
}`,variables:{query:`is:${t} is:open ${r.includeFromArchivedRepos?"":"archived:false"} ${s}`,after:e}}},
|
|
237
|
+
}`,variables:{query:`is:${t} is:open ${r.includeFromArchivedRepos?"":"archived:false"} ${s}`,after:e}}},kr="Field 'isDraft' doesn't exist on type 'PullRequest'",ve=(t=[])=>t.some(s=>(s==null?void 0:s.message)===kr),Nr=/@@ -(\d+)(?:,\d+ | )\+(\d+)(?:,\d+ | )@@(?:\\n)?/,_r=`
|
|
238
238
|
\
|
|
239
|
-
+`,
|
|
239
|
+
+`,Ft=(t,s,e,r)=>{let n=Nr.exec(t);if(!n||!n[0]||!n[1])return[];let o=parseInt(n[1],10),a=parseInt(n[2],10),i=t.replace(_r,`
|
|
240
240
|
+`).split(`
|
|
241
|
-
`).slice(1),u=o-1,l=a-1,p=i.map(g=>{let m,
|
|
242
|
-
`;break}case"+":{m="ADDED",l+=1,
|
|
243
|
-
`;break}default:m="UNMODIFIED",l+=1,u+=1,
|
|
244
|
-
`}return{line:
|
|
241
|
+
`).slice(1),u=o-1,l=a-1,p=i.map(g=>{let m,f;switch(g[0]){case"-":{m="DELETED",u+=1,f=`${g.slice(1)}
|
|
242
|
+
`;break}case"+":{m="ADDED",l+=1,f=`${g.slice(1)}
|
|
243
|
+
`;break}default:m="UNMODIFIED",l+=1,u+=1,f=`${g}
|
|
244
|
+
`}return{line:f,oldLineNumber:m!=="ADDED"?u:null,newLineNumber:m!=="DELETED"?l:null,type:m}}),d=e,c=s;if(d!==null&&c!==null&&r!==null&&d<c){let g=0,m=p.length,f=r==="LEFT"?"oldLineNumber":"newLineNumber";for(let h=0;h<p.length;h++){let I=p[h][f];I===d?g=h:I===c&&(m=h)}p=p.slice(g,m+1)}return p};var Ye=`
|
|
245
245
|
id
|
|
246
246
|
databaseId
|
|
247
247
|
owner {
|
|
@@ -254,7 +254,7 @@ defaultBranchRef {
|
|
|
254
254
|
name
|
|
255
255
|
}
|
|
256
256
|
viewerPermission
|
|
257
|
-
`,
|
|
257
|
+
`,rt={__typename:"User",id:"U_kgDNJ5k",databaseId:10137,name:"Deleted user",login:"ghost",email:"",avatarUrl:"https://avatars.githubusercontent.com/u/10137?v=4",url:"https://github.com/ghost"},Fr={APPROVED:"APPROVED",CHANGES_REQUESTED:"CHANGES_REQUESTED",COMMENTED:"COMMENTED",REVIEW_REQUESTED:"REVIEW_REQUESTED"},Qr={MERGEABLE:"MERGEABLE",CONFLICTING:"CONFLICTS",UNKNOWN:"UNKNOWN"},jr={BEHIND:"BEHIND",BLOCKED:"BLOCKED",UNKNOWN:"UNKNOWN_AND_BLOCKED",UNSTABLE:"UNSTABLE",CLEAN:null,DIRTY:null,DRAFT:null,HAS_HOOKS:null},Br={OPEN:"OPEN",CLOSED:"CLOSED"},zr=["ADMIN","MAINTAIN","TRIAGE","WRITE"],st=t=>({color:`#${t.color}`,description:t.description,graphQLId:t.id,id:null,name:t.name}),Mr=t=>({canCreateWebhook:t==="ADMIN",canPush:t==="ADMIN"||t==="MAINTAIN"||t==="WRITE",isAdmin:t==="ADMIN"}),et=t=>({id:t.databaseId.toString(),graphQLId:t.id,namespace:t.owner.login,name:t.name,webUrl:t.url,httpsUrl:t.url.endsWith(".git")?t.url:`${t.url}.git`,sshUrl:t.sshUrl,defaultBranch:t.defaultBranchRef,permissions:Mr(t.viewerPermission)}),Wr=t=>({canCreateWebhook:t.admin,canPush:t.admin||t.maintain||t.push,isAdmin:t.admin}),Qt=t=>({id:t.id.toString(),graphQLId:t.node_id,namespace:t.owner.login,name:t.name,webUrl:t.html_url,httpsUrl:t.clone_url,sshUrl:t.ssh_url,defaultBranch:{name:t.default_branch},permissions:Wr(t.permissions)}),Hr=t=>({path:t.path,isDirectory:t.type==="tree"}),Jr={OPEN:"OPEN",CLOSED:"CLOSED",MERGED:"MERGED"},Vr={id:!0,graphQLId:!0,name:!0,username:!0,email:!0,avatarUrl:!0,url:!0},x=(t,s=Vr)=>{let e={};return s.id&&(e.id="databaseId"in t?t.databaseId.toString():t.id),s.graphQLId&&(e.graphQLId=t.id),s.name&&(e.name=t.name??t.login),s.username&&(e.username=t.login),s.email&&(e.email=t.email??null),s.avatarUrl&&(e.avatarUrl=t.avatarUrl),s.url&&(e.url=t.url),e},Kr=(t,s)=>{let e={IN_PROGRESS:"RUNNING",PENDING:"PENDING",QUEUED:"PENDING",REQUESTED:"PENDING",WAITING:"PENDING"};return t!=="COMPLETED"?e[t]:{ACTION_REQUIRED:"ACTION_REQUIRED",CANCELLED:"CANCELLED",FAILURE:"FAILED",NEUTRAL:null,SKIPPED:"SKIPPED",STALE:"FAILED",STARTUP_FAILURE:"FAILED",SUCCESS:"SUCCESS",TIMED_OUT:"ERROR"}[s]},Xr=t=>({ERROR:"ERROR",EXPECTED:"PENDING",FAILURE:"FAILED",PENDING:"PENDING",SUCCESS:"SUCCESS"})[t],tt=t=>{var a,i,u,l,p,d,c,g,m,f,h,P;let s=null;t.author?s=t.author:s=rt;let e=(((a=t.reviewRequests)==null?void 0:a.nodes)||[]).filter(U).filter(I=>!I.asCodeOwner),r=(i=t.headRepository)==null?void 0:i.url;r&&!r.endsWith(".git")&&(r=`${r}.git`);let n=(u=t.repository)==null?void 0:u.url;n&&!n.endsWith(".git")&&(n=`${n}.git`);let o=e.filter(I=>I.requestedReviewer&&"__typename"in I.requestedReviewer).map(I=>({reviewer:x(I.requestedReviewer),state:"REVIEW_REQUESTED"})).concat((((l=t.latestReviews)==null?void 0:l.nodes)||[]).filter(U).map(I=>{let E=rt;return I.author&&I.author.__typename&&(E=I.author),{reviewer:x(E),state:Fr[I.state]}}));return{id:t.fullDatabaseId!==void 0?t.fullDatabaseId:t.databaseId.toString(),graphQLId:t.id,title:t.title,number:t.number,state:Jr[t.state],commentCount:t.comments.totalCount,upvoteCount:t.reactions.totalCount,author:s&&s.__typename?x(s):null,createdDate:new Date(t.createdAt),isDraft:t.isDraft,repository:{id:t.repository.databaseId.toString(),graphQLId:t.repository.id,name:t.repository.name,owner:{login:t.repository.owner.login},remoteInfo:{cloneUrlHTTPS:n,cloneUrlSSH:t.repository.sshUrl}},headRepository:t.headRepository?{id:t.headRepository.databaseId.toString(),graphQLId:t.headRepository.id,name:t.headRepository.name,owner:{login:t.headRepository.owner.login},remoteInfo:{cloneUrlHTTPS:r,cloneUrlSSH:t.headRepository.sshUrl}}:null,headCommit:{buildStatuses:((g=(c=(d=(p=t.commits.nodes)==null?void 0:p.filter(U)[0])==null?void 0:d.commit.statusCheckRollup)==null?void 0:c.contexts.nodes)==null?void 0:g.filter(U).map(I=>"context"in I?{completedAt:null,description:I.description,name:I.context,state:Xr(I.state),startedAt:new Date(I.createdAt),stage:null,url:I.targetUrl}:{completedAt:I.completedAt?new Date(I.completedAt):null,description:null,name:I.name,state:Kr(I.status,I.conclusion),startedAt:I.startedAt?new Date(I.startedAt):null,stage:null,url:I.permalink}))??[]},headRef:t.headRef?{name:t.headRef.name,oid:((m=t.headRef.target)==null?void 0:m.oid)??null}:null,baseRef:t.baseRef?{name:t.baseRef.name,oid:((f=t.baseRef.target)==null?void 0:f.oid)??null}:null,url:t.url,updatedDate:new Date(t.updatedAt),closedDate:t.closedAt?new Date(t.closedAt):null,mergedDate:t.mergedAt?new Date(t.mergedAt):null,assignees:t.assignees.nodes?t.assignees.nodes.filter(U).map(I=>x(I)):null,reviews:o,reviewDecision:k(o),additions:t.additions,deletions:t.deletions,fileCount:t.changedFiles,commitCount:t.commits.totalCount,mergeableState:jr[t.mergeStateStatus]??Qr[t.mergeable],milestone:t.milestone?nt(t.milestone):null,labels:((P=(h=t.labels)==null?void 0:h.nodes)==null?void 0:P.filter(U).map(st))??[],permissions:{canMerge:zr.includes(t.repository.viewerPermission),canMergeAndBypassProtections:t.viewerCanMergeAsAdmin??!1}}},Zr=t=>{var h,P;let{comments:s,isOutdated:e,isResolved:r,originalLine:n,originalStartLine:o,startDiffSide:a}=t,i=(h=s.nodes)==null?void 0:h[0];if(!i)return null;let{author:u,body:l,databaseId:p,fullDatabaseId:d,id:c,path:g,publishedAt:m,url:f}=i;return{author:u?{avatarUrl:u.avatarUrl,email:null,name:u.login}:null,body:l,createdAt:m?new Date(m):null,diffLines:Ft(i.diffHunk,n,o,a),id:d??p.toString(),isOutdated:e,isResolved:r,graphQLId:c,filename:g,replies:((P=s.nodes)==null?void 0:P.filter(U).slice(1).map(Yr))??[],url:f}},Yr=t=>({author:t.author?{avatarUrl:t.author.avatarUrl,email:null,name:t.author.login}:null,body:t.body,createdAt:t.publishedAt?new Date(t.publishedAt):null,graphQLId:t.id,id:t.fullDatabaseId??t.databaseId.toString(),url:t.url}),es=t=>{var e,r,n;let s=null;return t.author?s=t.author:s=rt,{id:t.fullDatabaseId!==void 0?t.fullDatabaseId:t.databaseId.toString(),graphQLId:t.id,number:t.number,title:t.title,author:s&&s.__typename?x(s):null,commentCount:t.comments.totalCount,closedDate:t.closedAt?new Date(t.closedAt):null,createdDate:new Date(t.createdAt),description:null,state:{name:Br[t.state],color:null},type:null,repository:{id:t.repository.databaseId.toString(),graphQLId:t.repository.id,name:t.repository.name,owner:{login:t.repository.owner.login}},url:t.url,updatedDate:new Date(t.updatedAt),assignees:((e=t.assignees.nodes)==null?void 0:e.filter(U).map(o=>x(o)))??[],upvoteCount:t.reactions.totalCount,milestone:t.milestone?nt(t.milestone):null,labels:((n=(r=t.labels)==null?void 0:r.nodes)==null?void 0:n.filter(U).map(st))??[]}},nt=t=>({id:t.number.toString(),graphQLId:t.id.toString(),number:t.number,title:t.title,description:t.description,isOpen:t.state=="OPEN",url:t.url,startDate:null,dueDate:t.dueOn?new Date(t.dueOn):null}),ee=class extends A{constructor(){super(...arguments);this._scopesCache={};this._enterpriseVersionsCache={}}async getScopes(e){let r=e.token||this.config.token;if(!r)return[];let n=this._scopesCache[r];if(!n){let a=(await y(this.config,{query:"query { rateLimit(dryRun: true) { __typename } }"},e)).headers["x-oauth-scopes"];n=a?a.split(", "):[],this._scopesCache[r]=n}return n}async getEnterpriseVersion(e){let r=e.baseUrl||this.config.baseUrl;if(!r)return null;let n=this._enterpriseVersionsCache[r];if(!n){let o=await this.config.request({url:`${Y(this.config,e)}/meta`,headers:R(e.token||this.config.token)});if(!o.body.installed_version)return null;n=o.body.installed_version.split(".").slice(0,3).map(a=>parseInt(a,10)),this._enterpriseVersionsCache[r]=n}return n}getEnterpriseAvatarUrlIfNeeded(e,r,n){let o=n.baseUrl||this.config.baseUrl;return!o||o.startsWith(ye)?e:r?`https://avatars.githubusercontent.com/u/e?email=${encodeURIComponent(r)}`:""}async getCurrentUser(e={},r={}){var u;if(e.fields&&!e.fields.length)throw new Error('"fields" must contain at least one field or be omitted');let n=Dt(e.fields),o=await this.getScopes(r),a=await y(this.config,{query:`
|
|
258
258
|
query getCurrentUser {
|
|
259
259
|
viewer {
|
|
260
260
|
${G(!1,F(o),n)}
|
|
@@ -320,7 +320,7 @@ mutation createCommitOnBranch(
|
|
|
320
320
|
}
|
|
321
321
|
}
|
|
322
322
|
}
|
|
323
|
-
`,variables:{branchName:u.name,expectedHeadOid:u.oid,fileChanges:{additions:Object.entries(a).map(([p,d])=>({contents:
|
|
323
|
+
`,variables:{branchName:u.name,expectedHeadOid:u.oid,fileChanges:{additions:Object.entries(a).map(([p,d])=>({contents:jt.Base64.encode(d),path:p})),deletions:o.map(p=>({path:p}))},message:{body:n.description,headline:n.summary},repositoryNameWithOwner:`${i.namespace}/${i.name}`}},r);if(!l.body.data)throw new b("Could not create commit",l.body.errors);return{data:{name:l.body.data.createCommitOnBranch.ref.name,commit:{authoredDate:new Date(l.body.data.createCommitOnBranch.commit.authoredDate),committedDate:new Date(l.body.data.createCommitOnBranch.commit.committedDate),oid:l.body.data.createCommitOnBranch.commit.oid}}}}async getAccountForEmail(e,r={}){var i,u,l;let n=await this.getScopes(r),o=await y(this.config,{query:`
|
|
324
324
|
query getAccountForEmail($query: String! $avatarSize: Int) {
|
|
325
325
|
search(query: $query, type: USER, first: 1) {
|
|
326
326
|
nodes {
|
|
@@ -371,22 +371,22 @@ query getOrgMember($cursor: String, $first: Int!, $login: String!) {
|
|
|
371
371
|
}
|
|
372
372
|
}
|
|
373
373
|
}
|
|
374
|
-
`,variables:{cursor:e.cursor,first:C,login:e.org}},r);if(!((i=(a=n.body.data)==null?void 0:a.viewer.organization)!=null&&i.membersWithRole)&&((u=n.body.errors)!=null&&u.length))throw new b("Could not read the members of the organization",n.body.errors);let o=((p=(l=n.body.data)==null?void 0:l.viewer.organization)==null?void 0:p.membersWithRole.nodes)||[];return{pageInfo:{hasNextPage:((c=(d=n.body.data)==null?void 0:d.viewer.organization)==null?void 0:c.membersWithRole.pageInfo.hasNextPage)??!1,endCursor:((m=(g=n.body.data)==null?void 0:g.viewer.organization)==null?void 0:m.membersWithRole.pageInfo.endCursor)??null},data:o.map(
|
|
374
|
+
`,variables:{cursor:e.cursor,first:C,login:e.org}},r);if(!((i=(a=n.body.data)==null?void 0:a.viewer.organization)!=null&&i.membersWithRole)&&((u=n.body.errors)!=null&&u.length))throw new b("Could not read the members of the organization",n.body.errors);let o=((p=(l=n.body.data)==null?void 0:l.viewer.organization)==null?void 0:p.membersWithRole.nodes)||[];return{pageInfo:{hasNextPage:((c=(d=n.body.data)==null?void 0:d.viewer.organization)==null?void 0:c.membersWithRole.pageInfo.hasNextPage)??!1,endCursor:((m=(g=n.body.data)==null?void 0:g.viewer.organization)==null?void 0:m.membersWithRole.pageInfo.endCursor)??null},data:o.map(f=>x({...f,avatarUrl:this.getEnterpriseAvatarUrlIfNeeded(f.avatarUrl,f.email,r)}))}}async getRepo(e,r={}){var o;let n=await y(this.config,{query:`
|
|
375
375
|
query getRepo($owner: String!, $name: String!) {
|
|
376
376
|
repository(owner: $owner, name: $name) {
|
|
377
|
-
${
|
|
377
|
+
${Ye}
|
|
378
378
|
}
|
|
379
379
|
}
|
|
380
|
-
`,variables:{owner:e.namespace,name:e.name}},r);if(!((o=n.body.data)!=null&&o.repository))throw new b(`Repository ${e.namespace}/${e.name} not found`,n.body.errors);return{data:
|
|
380
|
+
`,variables:{owner:e.namespace,name:e.name}},r);if(!((o=n.body.data)!=null&&o.repository))throw new b(`Repository ${e.namespace}/${e.name} not found`,n.body.errors);return{data:et(n.body.data.repository)}}async getRepos(e,r={}){let n=e.map(({namespace:u,name:l},p)=>`
|
|
381
381
|
getRepo_${p}: repository(owner: "${u}", name: "${l}") {
|
|
382
|
-
${
|
|
382
|
+
${Ye}
|
|
383
383
|
}
|
|
384
384
|
`).join(`
|
|
385
385
|
`),o=await y(this.config,{query:`
|
|
386
386
|
query batchGetRepos {
|
|
387
387
|
${n}
|
|
388
388
|
}
|
|
389
|
-
`},r);if(!o.body.data)throw new b("Could not fetch repos",o.body.errors);let a=[],i=[];return e.forEach((u,l)=>{let p=o.body.data[`getRepo_${l}`];p?a.push(
|
|
389
|
+
`},r);if(!o.body.data)throw new b("Could not fetch repos",o.body.errors);let a=[],i=[];return e.forEach((u,l)=>{let p=o.body.data[`getRepo_${l}`];p?a.push(et(p)):i.push({input:u})}),{data:a,errors:i}}async fetchMultipleRESTPages(e,r,n,o){let a=[];for(let d=0;d<r;d++)a.push(n(e+d));let i=await Promise.all(a),u=[];for(let d of i){if(!d.body)throw new Error(d.statusText||"Unknown error");u=u.concat(d.body.map(c=>o(c)))}let l=i.every(d=>d.body.length===100),p=e+r;return{data:u,pageInfo:{hasNextPage:l,nextPage:l?p:null}}}async getReposForCurrentUser(e,r={}){if(e.simultaneousPagesToFetch&&e.simultaneousPagesToFetch>40)throw new Error("The argument 'simultaneousPagesToFetch' cannot exceed 40 for 'getReposForCurrentUser'");let n=new URLSearchParams;n.append("per_page","100"),e.affiliations&&n.append("affiliation",e.affiliations.join(","));let o=a=>this.config.request({url:`${Y(this.config,r)}/user/repos?${n.toString()}&page=${a}`,headers:{...R(r.token||this.config.token),Accept:"application/vnd.github.raw+json","X-Github-Next-Global-ID":1}});return await this.fetchMultipleRESTPages(e.page??1,e.simultaneousPagesToFetch??4,o,Qt)}async getReposForOrg(e,r={}){if(e.simultaneousPagesToFetch&&e.simultaneousPagesToFetch>40)throw new Error("The argument 'simultaneousPagesToFetch' cannot exceed 40 for 'getReposForOrg'");let n=o=>this.config.request({url:`${Y(this.config,r)}/orgs/${e.orgName}/repos?per_page=100&page=${o}`,headers:{...R(r.token||this.config.token),Accept:"application/vnd.github.raw+json","X-Github-Next-Global-ID":1}});return await this.fetchMultipleRESTPages(e.page??1,e.simultaneousPagesToFetch??4,n,Qt)}async getReposForUsernames(e,r={}){if(!e.usernames.length)return{pageInfo:{endCursor:null,hasNextPage:!1},data:[]};let n=await y(this.config,{query:`
|
|
390
390
|
query getReposForUsernames($query: String!, $cursor: String, $first: Int!) {
|
|
391
391
|
search(query: $query, type: REPOSITORY, first: $first, after: $cursor) {
|
|
392
392
|
pageInfo {
|
|
@@ -395,12 +395,12 @@ query getReposForUsernames($query: String!, $cursor: String, $first: Int!) {
|
|
|
395
395
|
}
|
|
396
396
|
nodes {
|
|
397
397
|
... on Repository {
|
|
398
|
-
${
|
|
398
|
+
${Ye}
|
|
399
399
|
}
|
|
400
400
|
}
|
|
401
401
|
}
|
|
402
402
|
}
|
|
403
|
-
`,variables:{query:`fork:true ${e.usernames.map(a=>`user:${a}`).join(" ")}`,cursor:e.cursor,first:C}},r);if(!n.body.data)throw new b("Could not fetch repos for usernames",n.body.errors);let o=n.body.data.search.nodes||[];return{pageInfo:n.body.data.search.pageInfo,data:o.map(
|
|
403
|
+
`,variables:{query:`fork:true ${e.usernames.map(a=>`user:${a}`).join(" ")}`,cursor:e.cursor,first:C}},r);if(!n.body.data)throw new b("Could not fetch repos for usernames",n.body.errors);let o=n.body.data.search.nodes||[];return{pageInfo:n.body.data.search.pageInfo,data:o.map(et)}}async getReposForOwners(e,r={}){return this.getReposForUsernames({usernames:e.owners.filter(n=>n.username).map(n=>n.username),cursor:e.cursor},r)}async getRefs(e,r,n={}){var u;let o=await y(this.config,{query:`
|
|
404
404
|
query getRefs($owner: String!, $name: String!, $refPrefix: String!, $cursor: String, $first: Int!) {
|
|
405
405
|
repository(owner: $owner, name: $name) {
|
|
406
406
|
refs(refPrefix: $refPrefix first: $first after: $cursor) {
|
|
@@ -460,7 +460,7 @@ query getBlame($owner: String!, $name: String!, $ref: String!, $path: String!) {
|
|
|
460
460
|
}
|
|
461
461
|
}
|
|
462
462
|
}
|
|
463
|
-
`,variables:{owner:e.repo.namespace,name:e.repo.name,ref:e.ref,path:e.path}},r),o=(i=n.body.data)==null?void 0:i.repository;if(!o)throw new b("Blame repository not found.",n.body.errors);let a=o.object;if(!a||!("blame"in a))throw new b("Ref not found.",n.body.errors);if(a.blame.ranges.length===0)throw new b("File not found.",n.body.errors);return{data:{ranges:a.blame.ranges.map(u=>{var l;return{startingLine:u.startingLine,endingLine:u.endingLine,commit:{oid:u.commit.oid,parentOids:((l=u.commit.parents.nodes)==null?void 0:l.map(p=>p.oid))||[],authoredDate:new Date(u.commit.authoredDate),author:u.commit.author?{name:u.commit.author.name,email:u.commit.author.email,avatarUrl:u.commit.author.avatarUrl}:null,committedDate:new Date(u.commit.committedDate),committer:u.commit.committer?{name:u.commit.committer.name,email:u.commit.committer.email,avatarUrl:u.commit.committer.avatarUrl}:null,message:u.commit.message,fileCount:u.commit.changedFilesIfAvailable,additions:u.commit.additions,deletions:u.commit.deletions}}})}}}async getFileContents(e,r={}){let n=await this.config.request({url:`${Y(this.config,r)}/repos/${e.repo.namespace}/${e.repo.name}/contents/${encodeURIComponent(e.path)}?ref=${e.ref}`,headers:{...R(r.token||this.config.token),Accept:"application/vnd.github.raw+json"}});if(n.headers["content-type"].startsWith("application/json"))throw new Error(`GitHub: got directory when fetching "${e.path}", getFileContents does not support fetching directories`);if(!n.headers["content-type"].startsWith("application/vnd.github.raw+json"))throw new Error(`GitHub: unsupported content type "${n.headers["content-type"]}" when fetching "${e.path}"`);return{data:new Blob([n.body])}}async searchPullRequests(e,r={}){var p;let n=await this.getEnterpriseVersion(r),o=await this.getScopes(r),a=F(o),i=d=>{let c=d&&typeof e.isDraft=="boolean"?`${e.query} draft:${e.isDraft}`:e.query;return
|
|
463
|
+
`,variables:{owner:e.repo.namespace,name:e.repo.name,ref:e.ref,path:e.path}},r),o=(i=n.body.data)==null?void 0:i.repository;if(!o)throw new b("Blame repository not found.",n.body.errors);let a=o.object;if(!a||!("blame"in a))throw new b("Ref not found.",n.body.errors);if(a.blame.ranges.length===0)throw new b("File not found.",n.body.errors);return{data:{ranges:a.blame.ranges.map(u=>{var l;return{startingLine:u.startingLine,endingLine:u.endingLine,commit:{oid:u.commit.oid,parentOids:((l=u.commit.parents.nodes)==null?void 0:l.map(p=>p.oid))||[],authoredDate:new Date(u.commit.authoredDate),author:u.commit.author?{name:u.commit.author.name,email:u.commit.author.email,avatarUrl:u.commit.author.avatarUrl}:null,committedDate:new Date(u.commit.committedDate),committer:u.commit.committer?{name:u.commit.committer.name,email:u.commit.committer.email,avatarUrl:u.commit.committer.avatarUrl}:null,message:u.commit.message,fileCount:u.commit.changedFilesIfAvailable,additions:u.commit.additions,deletions:u.commit.deletions}}})}}}async getFileContents(e,r={}){let n=await this.config.request({url:`${Y(this.config,r)}/repos/${e.repo.namespace}/${e.repo.name}/contents/${encodeURIComponent(e.path)}?ref=${e.ref}`,headers:{...R(r.token||this.config.token),Accept:"application/vnd.github.raw+json"}});if(n.headers["content-type"].startsWith("application/json"))throw new Error(`GitHub: got directory when fetching "${e.path}", getFileContents does not support fetching directories`);if(!n.headers["content-type"].startsWith("application/vnd.github.raw+json"))throw new Error(`GitHub: unsupported content type "${n.headers["content-type"]}" when fetching "${e.path}"`);return{data:new Blob([n.body])}}async searchPullRequests(e,r={}){var p;let n=await this.getEnterpriseVersion(r),o=await this.getScopes(r),a=F(o),i=d=>{let c=d&&typeof e.isDraft=="boolean"?`${e.query} draft:${e.isDraft}`:e.query;return Ze("pr",c,e.cursor,{maxPageSize:e.maxPageSize??xt,supportsEmail:a,supportsDrafts:d,enterpriseVersion:n,includeFromArchivedRepos:e.includeFromArchivedRepos})},u=await y(this.config,i(!0),r);u.body.errors&&ve(u.body.errors)&&(this.config.baseUrl||r.baseUrl)&&(u=await y(this.config,i(!1),r));let{data:l}=u.body;if(!l)throw new b("Could not search pull requests",u.body.errors);return{pageInfo:{hasNextPage:l.search.pageInfo.hasNextPage,endCursor:l.search.pageInfo.endCursor},data:((p=l.search.nodes)==null?void 0:p.filter(U).map(tt))||[]}}async searchIssues(e,r={}){var l;let n=await this.getEnterpriseVersion(r),o=await this.getScopes(r),a=F(o),i=await y(this.config,Ze("issue",e.query,e.cursor,{supportsEmail:a,includeFromArchivedRepos:e.includeFromArchivedRepos,maxPageSize:e.maxPageSize??kt,enterpriseVersion:n}),r),{data:u}=i.body;if(!u)throw new b("Could not search issues",i.body.errors);return{pageInfo:{hasNextPage:u.search.pageInfo.hasNextPage,endCursor:u.search.pageInfo.endCursor},data:((l=u.search.nodes)==null?void 0:l.filter(U).map(es))||[]}}async getPullRequestsAssociatedWithUser(e,r={}){var o;let n=[`involves:${e.username}`];return(o=e.repos)!=null&&o.length&&e.repos.forEach(a=>{n.push(`repo:${a.namespace}/${a.name}`)}),e.labelNames&&e.labelNames.forEach(a=>{n.push(`label:"${a}"`)}),this.searchPullRequests({query:n.join(" "),cursor:e.cursor,includeFromArchivedRepos:e.includeFromArchivedRepos,maxPageSize:e.maxPageSize},r)}async getPullRequestsForRepos(e,r={}){let{assigneeLogins:n,updatedBefore:o,authorLogin:a,repos:i,reviewRequestedLogin:u,startQuery:l,mentionLogin:p,labelNames:d,maxPageSize:c}=e,g=Xe(l||"");return i.forEach(m=>{g.push(`repo:${m.namespace}/${m.name}`)}),n&&n.forEach(m=>{g.push(`assignee:${m}`)}),o&&g.push(`updated:<${o}`),a&&g.push(`author:${a}`),u&&g.push(`review-requested:${u}`),p&&g.push(`mentions:${p}`),d&&d.forEach(m=>{g.push(`label:"${m}"`)}),this.searchPullRequests({query:`sort:updated ${g.join(" ")}`,isDraft:e.isDraft,cursor:e.cursor,includeFromArchivedRepos:e.includeFromArchivedRepos,maxPageSize:c},r)}async getPullRequestForRepo(e,r={}){var d;let n=await this.getEnterpriseVersion(r),o=await this.getScopes(r),a=F(o),i=c=>({query:`query getPullRequest(
|
|
464
464
|
$owner: String!
|
|
465
465
|
$name: String!
|
|
466
466
|
$number: Int!
|
|
@@ -473,7 +473,7 @@ query getBlame($owner: String!, $name: String!, $ref: String!, $path: String!) {
|
|
|
473
473
|
${Se(c,a,n)}
|
|
474
474
|
}
|
|
475
475
|
}
|
|
476
|
-
}`,variables:{owner:e.repo.namespace,name:e.repo.name,number:e.number}}),u=await y(this.config,i(!0),r);u.body.errors&&ve(u.body.errors)&&(this.config.baseUrl||r.baseUrl)&&(u=await y(this.config,i(!1),r));let{data:l}=u.body;if(!l)throw new b("Could not fetch pull request by number",u.body.errors);let p=(d=u.body.data)==null?void 0:d.repository.pullRequest;return{data:p?
|
|
476
|
+
}`,variables:{owner:e.repo.namespace,name:e.repo.name,number:e.number}}),u=await y(this.config,i(!0),r);u.body.errors&&ve(u.body.errors)&&(this.config.baseUrl||r.baseUrl)&&(u=await y(this.config,i(!1),r));let{data:l}=u.body;if(!l)throw new b("Could not fetch pull request by number",u.body.errors);let p=(d=u.body.data)==null?void 0:d.repository.pullRequest;return{data:p?tt(p):null}}async getPullRequestByGraphQLId(e,r={}){var d;let n=await this.getEnterpriseVersion(r),o=await this.getScopes(r),a=F(o),i=c=>({query:`query getPullRequest(
|
|
477
477
|
$graphQLId: ID!
|
|
478
478
|
) {
|
|
479
479
|
node(id: $graphQLId) {
|
|
@@ -481,7 +481,7 @@ query getBlame($owner: String!, $name: String!, $ref: String!, $path: String!) {
|
|
|
481
481
|
${Se(c,a,n)}
|
|
482
482
|
}
|
|
483
483
|
}
|
|
484
|
-
}`,variables:{graphQLId:e.graphQLId}}),u=await y(this.config,i(!0),r);u.body.errors&&ve(u.body.errors)&&(this.config.baseUrl||r.baseUrl)&&(u=await y(this.config,i(!1),r));let{data:l}=u.body;if(!l)throw new b("Could not fetch pull request by id",u.body.errors);let p=(d=u.body.data)==null?void 0:d.node;return{data:p?
|
|
484
|
+
}`,variables:{graphQLId:e.graphQLId}}),u=await y(this.config,i(!0),r);u.body.errors&&ve(u.body.errors)&&(this.config.baseUrl||r.baseUrl)&&(u=await y(this.config,i(!1),r));let{data:l}=u.body;if(!l)throw new b("Could not fetch pull request by id",u.body.errors);let p=(d=u.body.data)==null?void 0:d.node;return{data:p?tt(p):null}}async closePullRequest(e,r={}){var i,u,l;let{pullRequest:{graphQLId:n}}=e;if(!n)throw new Error('GitHub requires "graphQLId" for this function.');let o=`mutation ClosePullRequest($pullRequestGraphQLId: ID!) {
|
|
485
485
|
closePullRequest(input: { pullRequestId: $pullRequestGraphQLId }) {
|
|
486
486
|
pullRequest {
|
|
487
487
|
id
|
|
@@ -537,7 +537,7 @@ query getBlame($owner: String!, $name: String!, $ref: String!, $path: String!) {
|
|
|
537
537
|
id
|
|
538
538
|
}
|
|
539
539
|
}
|
|
540
|
-
}`,u=await y(this.config,{query:i,variables:{pullRequestGraphQLId:n.graphQLId,assigneeGraphQLIds:a}},r);if(!((d=(p=(l=u.body.data)==null?void 0:l.updatePullRequest)==null?void 0:p.pullRequest)!=null&&d.id))throw new b("Could not set pull request assignees",u.body.errors)}async getReviewsForPullRequest(e,r={}){var c,g,m,
|
|
540
|
+
}`,u=await y(this.config,{query:i,variables:{pullRequestGraphQLId:n.graphQLId,assigneeGraphQLIds:a}},r);if(!((d=(p=(l=u.body.data)==null?void 0:l.updatePullRequest)==null?void 0:p.pullRequest)!=null&&d.id))throw new b("Could not set pull request assignees",u.body.errors)}async getReviewsForPullRequest(e,r={}){var c,g,m,f;let n=await this.getEnterpriseVersion(r),{repo:{namespace:o,name:a},pullRequestId:i}=e,u=`query getPullRequests(
|
|
541
541
|
$namespace: String!
|
|
542
542
|
$name: String!
|
|
543
543
|
$pullRequestId: Int!
|
|
@@ -589,13 +589,13 @@ query getBlame($owner: String!, $name: String!, $ref: String!, $path: String!) {
|
|
|
589
589
|
}
|
|
590
590
|
}
|
|
591
591
|
}
|
|
592
|
-
}`,l=await y(this.config,{query:u,variables:{namespace:o,name:a,pullRequestId:i}},r),p=((g=(c=l.body.data)==null?void 0:c.repository.pullRequest.reviewThreads.nodes)==null?void 0:g.filter(U).reduce((h,P)=>{var T,D;if(!((D=(T=P.comments.nodes)==null?void 0:T[0])!=null&&D.pullRequestReview))return h;let
|
|
592
|
+
}`,l=await y(this.config,{query:u,variables:{namespace:o,name:a,pullRequestId:i}},r),p=((g=(c=l.body.data)==null?void 0:c.repository.pullRequest.reviewThreads.nodes)==null?void 0:g.filter(U).reduce((h,P)=>{var T,D;if(!((D=(T=P.comments.nodes)==null?void 0:T[0])!=null&&D.pullRequestReview))return h;let I=P.comments.nodes[0].pullRequestReview,E=Zr(P);return E&&(h[I.id]||(h[I.id]=[]),h[I.id].push(E)),h},{}))??{};return{data:((f=(m=l.body.data)==null?void 0:m.repository.pullRequest.reviews.nodes)==null?void 0:f.filter(U).filter(h=>p[h.id]).map(h=>({author:h.author?{avatarUrl:h.author.avatarUrl,email:null,name:h.author.login}:null,body:h.body,createdAt:h.publishedAt?new Date(h.publishedAt):null,id:h.fullDatabaseId??h.databaseId.toString(),graphQLId:h.id,reviewComments:p[h.id],url:h.url})))??[]}}async getIssuesAssociatedWithUser(e,r={}){var c;let[n,o]=((c=e.cursor)==null?void 0:c.split(";"))||[void 0,void 0],a=[];e.labelNames&&e.labelNames.forEach(g=>{a.push(`label:"${g}"`)});let[i,u]=await Promise.all([n==="null"?null:this.searchIssues({query:`author:${e.username} ${a.join(" ")}`,cursor:n,includeFromArchivedRepos:e.includeFromArchivedRepos,maxPageSize:e.maxPageSize},r),o==="null"?null:this.searchIssues({query:`assignee:${e.username} ${a.join(" ")}`,cursor:o,includeFromArchivedRepos:e.includeFromArchivedRepos,maxPageSize:e.maxPageSize},r)]),l={},p=[],d=g=>{l[g.id]||(l[g.id]=!0,p.push(g))};return i==null||i.data.forEach(d),u==null||u.data.forEach(d),{pageInfo:{hasNextPage:(i==null?void 0:i.pageInfo.hasNextPage)||(u==null?void 0:u.pageInfo.hasNextPage)||!1,endCursor:`${(i==null?void 0:i.pageInfo.hasNextPage)&&(i==null?void 0:i.pageInfo.endCursor)||"null"};${(u==null?void 0:u.pageInfo.hasNextPage)&&(u==null?void 0:u.pageInfo.endCursor)||"null"}`},data:p}}async setPullRequestLabels(e,r={}){var u,l,p;let{pullRequest:n,labels:o}=e;if(!n.graphQLId)throw new Error('GitHub requires "graphQLId" for this function.');let a=`mutation SetPullRequestLabels($pullRequestGraphQLId: ID!, $labelGraphQLIds: [ID!]) {
|
|
593
593
|
updatePullRequest(input: { pullRequestId: $pullRequestGraphQLId, labelIds: $labelGraphQLIds }) {
|
|
594
594
|
pullRequest {
|
|
595
595
|
id
|
|
596
596
|
}
|
|
597
597
|
}
|
|
598
|
-
}`,i=await y(this.config,{query:a,variables:{pullRequestGraphQLId:n.graphQLId,labelGraphQLIds:o.map(d=>{if(!d.graphQLId)throw new Error('GitHub requires label "graphQLId" for this function.');return d.graphQLId})}},r);if(!((p=(l=(u=i.body.data)==null?void 0:u.updatePullRequest)==null?void 0:l.pullRequest)!=null&&p.id))throw new b("Could not set pull request labels",i.body.errors)}async getIssuesForRepos(e,r={}){let n=
|
|
598
|
+
}`,i=await y(this.config,{query:a,variables:{pullRequestGraphQLId:n.graphQLId,labelGraphQLIds:o.map(d=>{if(!d.graphQLId)throw new Error('GitHub requires label "graphQLId" for this function.');return d.graphQLId})}},r);if(!((p=(l=(u=i.body.data)==null?void 0:u.updatePullRequest)==null?void 0:l.pullRequest)!=null&&p.id))throw new b("Could not set pull request labels",i.body.errors)}async getIssuesForRepos(e,r={}){let n=Xe(e.startQuery||""),{cursor:o,assigneeLogins:a,updatedBefore:i,authorLogin:u,mentionLogin:l,labelNames:p}=e;return e.repos.forEach(d=>{n.push(`repo:${d.namespace}/${d.name}`)}),a&&a.forEach(d=>{n.push(`assignee:${d}`)}),i&&n.push(`updated:<${i}`),u&&n.push(`author:${u}`),l&&n.push(`mentions:${l}`),p&&p.forEach(d=>{n.push(`label:"${d}"`)}),this.searchIssues({query:`sort:updated ${n.join(" ")}`,cursor:o,includeFromArchivedRepos:e.includeFromArchivedRepos,maxPageSize:e.maxPageSize},r)}async closeIssueWithReason(e,r={}){var u,l,p;let{issue:n,reason:o}=e;if(!n.graphQLId)throw new Error('GitHub requires "graphQLId" for this function.');let a=`mutation CloseIssueWithReason($issueGraphQLId: ID!, $reason: IssueClosedStateReason!) {
|
|
599
599
|
closeIssue(input: { issueId: $issueGraphQLId, stateReason: $reason }) {
|
|
600
600
|
issue {
|
|
601
601
|
id
|
|
@@ -645,7 +645,7 @@ query getLabelsForRepo($owner: String!, $name: String! $cursor: String, $first:
|
|
|
645
645
|
}
|
|
646
646
|
}
|
|
647
647
|
}
|
|
648
|
-
`,variables:{owner:n,name:o,cursor:a,first:C}},r);if(!i.body.data)throw new b("Could not fetch milestones",i.body.errors);return{pageInfo:((u=i.body.data.repository.milestones)==null?void 0:u.pageInfo)??{endCursor:null,hasNextPage:!1},data:((p=(l=i.body.data.repository.milestones)==null?void 0:l.nodes)==null?void 0:p.map(
|
|
648
|
+
`,variables:{owner:n,name:o,cursor:a,first:C}},r);if(!i.body.data)throw new b("Could not fetch milestones",i.body.errors);return{pageInfo:((u=i.body.data.repository.milestones)==null?void 0:u.pageInfo)??{endCursor:null,hasNextPage:!1},data:((p=(l=i.body.data.repository.milestones)==null?void 0:l.nodes)==null?void 0:p.map(nt))??[]}}async getLabelsForRepo(e,r={}){var u,l,p;let{repo:{namespace:n,name:o},cursor:a}=e,i=await y(this.config,{query:`
|
|
649
649
|
query getLabelsForRepo($owner: String!, $name: String! $cursor: String, $first: Int!) {
|
|
650
650
|
repository(owner: $owner, name: $name) {
|
|
651
651
|
labels(first: $first, after: $cursor) {
|
|
@@ -659,7 +659,7 @@ query getLabelsForRepo($owner: String!, $name: String! $cursor: String, $first:
|
|
|
659
659
|
}
|
|
660
660
|
}
|
|
661
661
|
}
|
|
662
|
-
`,variables:{owner:n,name:o,cursor:a,first:C}},r);if(!i.body.data)throw new b("Could not fetch labels",i.body.errors);return{pageInfo:((u=i.body.data.repository.labels)==null?void 0:u.pageInfo)??{endCursor:null,hasNextPage:!1},data:((p=(l=i.body.data.repository.labels)==null?void 0:l.nodes)==null?void 0:p.map(
|
|
662
|
+
`,variables:{owner:n,name:o,cursor:a,first:C}},r);if(!i.body.data)throw new b("Could not fetch labels",i.body.errors);return{pageInfo:((u=i.body.data.repository.labels)==null?void 0:u.pageInfo)??{endCursor:null,hasNextPage:!1},data:((p=(l=i.body.data.repository.labels)==null?void 0:l.nodes)==null?void 0:p.map(st))??[]}}async getTreeForRepo(e,r={}){let n=await this.config.request({url:`${Y(this.config,r)}/repos/${e.repo.namespace}/${e.repo.name}/git/trees/${e.branch}?recursive=1`,headers:{...R(r.token||this.config.token)}});if(!n.body)throw new Error("Could not fetch trees");return{data:n.body.tree.map(Hr)}}};var ts="https://gitlab.com/api/v4",rs="https://gitlab.com/api/graphql",ot=/\/api\/v\d+$/,Bt=t=>{if(t.endsWith("/api/graphql"))throw new Error("The graphql endpoint is being used as the baseUrl. This package uses both GraphQL and REST APIs, and the REST version cannot be assumed. Use the REST endpoint as the baseUrl instead.")},Ee=(t,s)=>{let e=s.baseUrl||t.baseUrl;return e?(e=e.replace(/\/$/,""),Bt(e),ot.test(e)||(e=e+"/api/v4"),e):ts},ss=(t,s)=>{let e=s.baseUrl||t.baseUrl;return e?(e=e.replace(/\/$/,""),Bt(e),ot.test(e)&&(e=e.replace(ot,"")),`${e}/api/graphql`):rs},w=(t,s,e)=>{let r=R(e.token||t.token);return t.request({url:ss(t,e),method:"POST",headers:{...r,"Content-Type":"application/json"},body:JSON.stringify(s)})},qe=t=>t==null?void 0:t.map(s=>`"${s.message}"`).join(", ");var pt=t=>t.split("/").slice(0,-1).join("/"),dt=t=>t.split("/").at(-1)??"",Ce=t=>({id:t.id.replace(te,""),graphQLId:t.id,namespace:pt(t.fullPath),name:dt(t.fullPath),webUrl:t.webUrl}),zt=t=>({id:t.id.replace(te,""),graphQLId:t.id,httpsUrl:t.httpUrlToRepo,namespace:pt(t.fullPath),name:dt(t.fullPath),sshUrl:t.sshUrlToRepo,webUrl:t.webUrl}),ns={assigned:"assignedMergeRequests",authored:"authoredMergeRequests",reviewRequested:"reviewRequestedMergeRequests"},os={CAN_BE_MERGED:"MERGEABLE",CANNOT_BE_MERGED:"CONFLICTS",CANNOT_BE_MERGED_RECHECK:"UNKNOWN",UNCHECKED:"UNKNOWN",CHECKING:"UNKNOWN"};var as="gid://gitlab/User/",te="gid://gitlab/Project/",is="gid://gitlab/MergeRequest/",us="gid://gitlab/Issue/",ls="gid://gitlab/ProjectLabel/",ps="gid://gitlab/Milestone/",ds="gid://gitlab/Ci::Build/",ct=`
|
|
663
663
|
description
|
|
664
664
|
dueDate
|
|
665
665
|
id
|
|
@@ -668,7 +668,7 @@ startDate
|
|
|
668
668
|
state
|
|
669
669
|
title
|
|
670
670
|
webPath
|
|
671
|
-
`,
|
|
671
|
+
`,at=`
|
|
672
672
|
id
|
|
673
673
|
fullPath
|
|
674
674
|
webUrl
|
|
@@ -689,12 +689,12 @@ username
|
|
|
689
689
|
publicEmail
|
|
690
690
|
avatarUrl
|
|
691
691
|
webUrl
|
|
692
|
-
`,
|
|
692
|
+
`,gt=`
|
|
693
693
|
color
|
|
694
694
|
description
|
|
695
695
|
id
|
|
696
696
|
title
|
|
697
|
-
`,
|
|
697
|
+
`,it=`
|
|
698
698
|
author {
|
|
699
699
|
${Q}
|
|
700
700
|
}
|
|
@@ -711,7 +711,7 @@ id
|
|
|
711
711
|
iid
|
|
712
712
|
labels {
|
|
713
713
|
nodes {
|
|
714
|
-
${
|
|
714
|
+
${gt}
|
|
715
715
|
}
|
|
716
716
|
}
|
|
717
717
|
state
|
|
@@ -722,9 +722,9 @@ upvotes
|
|
|
722
722
|
userNotesCount
|
|
723
723
|
webUrl
|
|
724
724
|
milestone {
|
|
725
|
-
${
|
|
725
|
+
${ct}
|
|
726
726
|
}
|
|
727
|
-
`,
|
|
727
|
+
`,cs=`
|
|
728
728
|
stages {
|
|
729
729
|
nodes {
|
|
730
730
|
jobs {
|
|
@@ -740,7 +740,7 @@ stages {
|
|
|
740
740
|
name
|
|
741
741
|
}
|
|
742
742
|
}
|
|
743
|
-
`,
|
|
743
|
+
`,Mt=(t,s,e)=>`
|
|
744
744
|
id
|
|
745
745
|
state
|
|
746
746
|
author {
|
|
@@ -784,13 +784,13 @@ reviewers {
|
|
|
784
784
|
mergeStatusEnum
|
|
785
785
|
labels {
|
|
786
786
|
nodes {
|
|
787
|
-
${
|
|
787
|
+
${gt}
|
|
788
788
|
}
|
|
789
789
|
}
|
|
790
790
|
${t?"project { id httpUrlToRepo fullPath sshUrlToRepo webUrl archived } sourceProject { id httpUrlToRepo fullPath sshUrlToRepo webUrl }":""}
|
|
791
|
-
${s?`milestone { ${
|
|
792
|
-
${e?`headPipeline { ${
|
|
793
|
-
`,M=t=>`${t.namespace}/${t.name}`,
|
|
791
|
+
${s?`milestone { ${ct} }`:""}
|
|
792
|
+
${e?`headPipeline { ${cs} }`:""}
|
|
793
|
+
`,M=t=>`${t.namespace}/${t.name}`,gs=t=>`${t.namespace}/${t.name}`,ms=t=>({canCreateWebhook:t.adminOperations,canPush:t.pushCode,isAdmin:t.adminOperations}),ut=t=>{var s;return{id:t.id.replace(te,""),graphQLId:t.id,namespace:pt(t.fullPath),name:dt(t.fullPath),webUrl:t.webUrl,httpsUrl:t.httpUrlToRepo,sshUrl:t.sshUrlToRepo,defaultBranch:(s=t.repository)!=null&&s.rootRef?{name:t.repository.rootRef}:null,permissions:ms(t.userPermissions)}},hs=t=>({path:t.path,isDirectory:t.type==="tree"}),fs={opened:"OPEN",merged:"MERGED",closed:"CLOSED"},Ht=(t,s,e)=>!s&&(t!=null&&t.startsWith("/"))?`https://gitlab.com${t}`:s&&(t!=null&&t.startsWith("/"))&&e?`${e.replace(/\/+?$/,"")}${t}`:t,j=(t,s,e)=>{let r=Ht(t.avatarUrl,s,e);return{id:t.id.replace(as,""),graphQLId:t.id,name:t.name,username:t.username,email:t.publicEmail??null,avatarUrl:r,url:t.webUrl}},mt=t=>({color:t.color,description:t.description,id:t.id.replace(ls,""),graphQLId:t.id,name:t.title}),Is=(t,s)=>t?t==="FAILED"&&s?"WARNING":{CANCELED:"CANCELLED",CREATED:"PENDING",FAILED:"FAILED",MANUAL:"OPTIONAL_ACTION_REQUIRED",PENDING:"PENDING",PREPARING:"RUNNING",RUNNING:"RUNNING",SCHEDULED:"PENDING",SKIPPED:"SKIPPED",SUCCESS:"SUCCESS",WAITING_FOR_CALLBACK:"PENDING",WAITING_FOR_RESOURCE:"PENDING"}[t]:null,Rs=(t,s,e)=>{var n;let r={APPROVED:"APPROVED",REQUESTED_CHANGES:"CHANGES_REQUESTED",REVIEWED:"COMMENTED",UNAPPROVED:"REVIEW_REQUESTED",UNREVIEWED:"REVIEW_REQUESTED"};return{reviewer:j(t,s,e),state:(n=t.mergeRequestInteraction)!=null&&n.reviewState?r[t.mergeRequestInteraction.reviewState]:"REVIEW_REQUESTED"}},Wt=(t,s,e,r,n)=>{var a,i,u,l,p,d,c,g,m,f,h,P;let o=(a=t.reviewers)!=null&&a.nodes?t.reviewers.nodes.map(I=>Rs(I,r,n)):null;return{id:t.id.replace(is,""),graphQLId:t.id,title:t.title,number:parseInt(t.iid,10),state:fs[t.state],commentCount:t.userNotesCount||0,upvoteCount:t.upvotes,author:t.author?j(t.author,r,n):null,createdDate:new Date(t.createdAt),isDraft:t.draft,repository:{id:s.id,graphQLId:s.graphQLId,name:s.name,owner:{login:s.namespace},remoteInfo:s.httpsUrl&&s.sshUrl?{cloneUrlHTTPS:s.httpsUrl,cloneUrlSSH:s.sshUrl}:null},headRepository:e?{id:e.id,graphQLId:e.graphQLId,name:e.name,owner:{login:e.namespace},remoteInfo:{cloneUrlHTTPS:e.httpsUrl,cloneUrlSSH:e.sshUrl}}:null,headCommit:{buildStatuses:((l=(u=(i=t.headPipeline)==null?void 0:i.stages)==null?void 0:u.nodes)==null?void 0:l.flatMap(I=>{var E,T;return((T=(E=I.jobs)==null?void 0:E.nodes)==null?void 0:T.map(D=>({completedAt:D.finishedAt?new Date(D.finishedAt):null,description:null,name:D.name??null,state:Is(D.status,D.allowFailure),stage:I.name??null,startedAt:new Date(D.createdAt),url:`${s.webUrl}/-/jobs/${D.id.replace(ds,"")}`})))??[]}))??[]},baseRef:{name:t.targetBranch,oid:((p=t.diffRefs)==null?void 0:p.baseSha)??null},headRef:{name:t.sourceBranch,oid:((d=t.diffRefs)==null?void 0:d.headSha)??null},url:t.webUrl,updatedDate:new Date(t.updatedAt),closedDate:t.mergedAt?new Date(t.mergedAt):null,mergedDate:t.mergedAt?new Date(t.mergedAt):null,assignees:(c=t.assignees)!=null&&c.nodes?t.assignees.nodes.map(I=>j(I,r,n)):null,reviews:o,reviewDecision:k(o),additions:((g=t.diffStatsSummary)==null?void 0:g.additions)||0,deletions:((m=t.diffStatsSummary)==null?void 0:m.deletions)||0,fileCount:((f=t.diffStatsSummary)==null?void 0:f.fileCount)||0,commitCount:t.commitCount||0,mergeableState:os[t.mergeStatusEnum],milestone:t.milestone?ht(t.milestone,s.webUrl):null,labels:((P=(h=t.labels)==null?void 0:h.nodes)==null?void 0:P.map(mt))??[],permissions:null}},lt=(t,s,e,r)=>{var n,o;return{author:j(t.author,e,r),assignees:t.assignees.nodes.map(a=>j(a,e,r)),commentCount:t.userNotesCount,closedDate:t.closedAt?new Date(t.closedAt):null,createdDate:new Date(t.createdAt),description:t.description,graphQLId:t.id,id:t.id.replace(us,""),labels:((o=(n=t.labels)==null?void 0:n.nodes)==null?void 0:o.map(mt))??[],number:t.iid,repository:{id:s.id.replace(te,""),graphQLId:s.id,name:s.name,owner:{login:s.namespace}},updatedDate:new Date(t.updatedAt),upvoteCount:t.upvotes,state:{name:t.state,color:null},type:t.type,title:t.title,url:t.webUrl,milestone:t.milestone?ht(t.milestone,s.webUrl):null}},ht=(t,s)=>({id:t.id.replace(ps,""),graphQLId:t.id,number:parseInt(t.iid,10),title:t.title,description:t.description,isOpen:t.state==="active",url:`${s}/-/${t.webPath.replace(/.+?\/-\//,"")}`,startDate:t.startDate?new Date(t.startDate):null,dueDate:t.dueDate?new Date(t.dueDate):null}),re=class extends A{getIsSelfHosted(s){return!!s.baseUrl||!!this.config.baseUrl}async getCurrentUser(s={},e={}){var o;let n=(o=(await w(this.config,{query:`
|
|
794
794
|
query getCurrentUser {
|
|
795
795
|
currentUser {
|
|
796
796
|
${Q}
|
|
@@ -812,7 +812,7 @@ query getUserForCommit($fullPath: ID!, $oid: String!) {
|
|
|
812
812
|
}
|
|
813
813
|
}
|
|
814
814
|
}
|
|
815
|
-
`,variables:{fullPath:r,oid:s.oid}},e)).body.data)==null?void 0:i.project)==null?void 0:u.repository)==null?void 0:l.tree)==null?void 0:p.lastCommit;if(!o)throw new Error("Commit not found.");let a=
|
|
815
|
+
`,variables:{fullPath:r,oid:s.oid}},e)).body.data)==null?void 0:i.project)==null?void 0:u.repository)==null?void 0:l.tree)==null?void 0:p.lastCommit;if(!o)throw new Error("Commit not found.");let a=Ht(o.author.avatarUrl,this.getIsSelfHosted(e),this.config.baseUrl??e.baseUrl);return{data:{name:o.authorName,email:o.authorEmail,avatarUrl:a}}}async getAccountForEmail(s,e={}){var o,a,i;let n=(i=(a=(o=(await w(this.config,{query:`
|
|
816
816
|
query getAccountForEmail($email: String!) {
|
|
817
817
|
users(search: $email) {
|
|
818
818
|
nodes {
|
|
@@ -847,22 +847,22 @@ query getAccountsForRepo(
|
|
|
847
847
|
}
|
|
848
848
|
}
|
|
849
849
|
}
|
|
850
|
-
`,variables:{fullPath:`${r}/${n}`,after:o}},e),i=(d=(p=(l=(u=a.body.data)==null?void 0:u.project)==null?void 0:l.projectMembers)==null?void 0:p.nodes)==null?void 0:d.map(
|
|
850
|
+
`,variables:{fullPath:`${r}/${n}`,after:o}},e),i=(d=(p=(l=(u=a.body.data)==null?void 0:u.project)==null?void 0:l.projectMembers)==null?void 0:p.nodes)==null?void 0:d.map(f=>f.user).filter(f=>f!==null);return{pageInfo:((m=(g=(c=a.body.data)==null?void 0:c.project)==null?void 0:g.projectMembers)==null?void 0:m.pageInfo)??{endCursor:null,hasNextPage:!1},data:(i==null?void 0:i.map(f=>j(f,this.getIsSelfHosted(e),this.config.baseUrl??e.baseUrl)))??[]}}async getRepo(s,e={}){var o;let r=M(s),n=await w(this.config,{query:`
|
|
851
851
|
query getRepo($fullPath: ID!) {
|
|
852
852
|
project(fullPath: $fullPath) {
|
|
853
|
-
${
|
|
853
|
+
${at}
|
|
854
854
|
}
|
|
855
855
|
}
|
|
856
|
-
`,variables:{fullPath:r}},e);if(!((o=n.body.data)!=null&&o.project))throw new Error(`Repository ${r} not found`);return{data:
|
|
856
|
+
`,variables:{fullPath:r}},e);if(!((o=n.body.data)!=null&&o.project))throw new Error(`Repository ${r} not found`);return{data:ut(n.body.data.project)}}async getReposBase(s,e={}){let n=s.map(M).map((u,l)=>`
|
|
857
857
|
getRepo_${l}: project(fullPath: "${u}") {
|
|
858
|
-
${
|
|
858
|
+
${at}
|
|
859
859
|
}
|
|
860
860
|
`).join(`
|
|
861
861
|
`),o=await w(this.config,{query:`
|
|
862
862
|
query batchGetRepos {
|
|
863
863
|
${n}
|
|
864
864
|
}
|
|
865
|
-
`},e);if(!o.body.data)throw new Error(qe(o.body.errors)||o.statusText||"Unknown error");let a=[],i=[];return s.forEach((u,l)=>{let p=o.body.data[`getRepo_${l}`];p?a.push(
|
|
865
|
+
`},e);if(!o.body.data)throw new Error(qe(o.body.errors)||o.statusText||"Unknown error");let a=[],i=[];return s.forEach((u,l)=>{let p=o.body.data[`getRepo_${l}`];p?a.push(ut(p)):i.push({input:u})}),{data:a,errors:i}}async getRepos(s,e={}){let r=[];for(let a=0;a<s.length;a+=15)r.push(s.slice(a,a+15));return(await Promise.all(r.map(a=>this.getReposBase(a,e)))).reduce((a,i)=>({data:[...a.data,...i.data],errors:[...a.errors,...i.errors]}),{data:[],errors:[]})}async getReposForCurrentUser(s,e={}){var o,a,i,u,l;let r=await w(this.config,{query:`
|
|
866
866
|
query getReposForCurrentUser($after: String) {
|
|
867
867
|
projects(membership: true first: 100 after: $after) {
|
|
868
868
|
pageInfo {
|
|
@@ -870,11 +870,11 @@ query getReposForCurrentUser($after: String) {
|
|
|
870
870
|
hasNextPage
|
|
871
871
|
}
|
|
872
872
|
nodes {
|
|
873
|
-
${
|
|
873
|
+
${at}
|
|
874
874
|
}
|
|
875
875
|
}
|
|
876
876
|
}
|
|
877
|
-
`,variables:{after:s.cursor}},e);if(!((o=r.body.data)!=null&&o.projects))throw new Error(qe(r.body.errors)||r.statusText||"Unknown error");let n=((i=(a=r.body.data)==null?void 0:a.projects)==null?void 0:i.nodes)||[];return{pageInfo:(l=(u=r.body.data)==null?void 0:u.projects)==null?void 0:l.pageInfo,data:n.map(
|
|
877
|
+
`,variables:{after:s.cursor}},e);if(!((o=r.body.data)!=null&&o.projects))throw new Error(qe(r.body.errors)||r.statusText||"Unknown error");let n=((i=(a=r.body.data)==null?void 0:a.projects)==null?void 0:i.nodes)||[];return{pageInfo:(l=(u=r.body.data)==null?void 0:u.projects)==null?void 0:l.pageInfo,data:n.map(ut)}}async getRefs(s,e,r={}){var u;let n=M(e.repo),o=new URL(`${Ee(this.config,r)}/projects/${encodeURIComponent(n)}/repository/${s}`);o.searchParams.set("page",((u=e.page)==null?void 0:u.toString())||"1"),o.searchParams.set("per_page",C.toString());let a=await this.config.request({url:o.toString(),headers:R(r.token||this.config.token)}),i=a.headers["x-next-page"];return{pageInfo:{hasNextPage:!!i,nextPage:i?parseInt(i,10):null},data:a.body.map(l=>({name:l.name,commit:{oid:l.commit.id,authoredDate:new Date(l.commit.authored_date),committedDate:new Date(l.commit.committed_date)}}))}}async getBranches(s,e={}){return this.getRefs("branches",s,e)}async getTags(s,e={}){return this.getRefs("tags",s,e)}async getBlame(s,e={}){let r=M(s.repo),n=new URL(`${Ee(this.config,e)}/projects/${encodeURIComponent(r)}/repository/files/${encodeURIComponent(s.path)}/blame`);n.searchParams.set("ref",s.ref);let o=await this.config.request({url:n.toString(),headers:R(e.token||this.config.token)}),a=0;return{data:{ranges:o.body.map(i=>{let u=a+1;return a+=i.lines.length,{startingLine:u,endingLine:a,commit:{oid:i.commit.id,parentOids:i.commit.parent_ids,authoredDate:new Date(i.commit.authored_date),author:{name:i.commit.author_name,email:i.commit.author_email,avatarUrl:null},committedDate:new Date(i.commit.committed_date),committer:{name:i.commit.committer_name,email:i.commit.committer_email,avatarUrl:null},message:i.commit.message,fileCount:null,additions:null,deletions:null}}})}}}async getPullRequestsForUser(s,e={}){var i,u,l,p;let r="";(i=s.repo)!=null&&i.id?r=`projectId:"${s.repo.id}"`:(u=s.repo)!=null&&u.namespace&&((l=s.repo)!=null&&l.name)&&(r=`projectPath:"${s.repo.namespace}/${s.repo.name}"`);let n=ns[s.association],o=await w(this.config,{query:`
|
|
878
878
|
query getPullRequestsForUser($username: String! $cursor: String $labelNames: [String!]) {
|
|
879
879
|
user(username: $username) {
|
|
880
880
|
${n}(state:opened first:100 after:$cursor labels: $labelNames${r?` ${r}`:""}) {
|
|
@@ -883,12 +883,12 @@ query getPullRequestsForUser($username: String! $cursor: String $labelNames: [St
|
|
|
883
883
|
hasNextPage
|
|
884
884
|
}
|
|
885
885
|
nodes {
|
|
886
|
-
${
|
|
886
|
+
${Mt(!0,!0,!0)}
|
|
887
887
|
}
|
|
888
888
|
}
|
|
889
889
|
}
|
|
890
890
|
}
|
|
891
|
-
`,variables:{username:s.username,cursor:s.cursor,labelNames:s.labelNames}},e);if(!o.body.data)throw new Error(qe(o.body.errors)||o.statusText||"Unknown error");if(!o.body.data.user)throw new Error("User not found");let a=o.body.data.user[n];if(!a)throw new Error("Unexpected response");return{pageInfo:a.pageInfo,data:((p=a.nodes)==null?void 0:p.filter(d=>s.includeFromArchivedRepos||!d.project.archived).map(d=>
|
|
891
|
+
`,variables:{username:s.username,cursor:s.cursor,labelNames:s.labelNames}},e);if(!o.body.data)throw new Error(qe(o.body.errors)||o.statusText||"Unknown error");if(!o.body.data.user)throw new Error("User not found");let a=o.body.data.user[n];if(!a)throw new Error("Unexpected response");return{pageInfo:a.pageInfo,data:((p=a.nodes)==null?void 0:p.filter(d=>s.includeFromArchivedRepos||!d.project.archived).map(d=>Wt(d,zt(d.project),zt(d.sourceProject),this.getIsSelfHosted(e),this.config.baseUrl??e.baseUrl)))||[]}}async getPullRequestsAssociatedWithUser(s,e={}){var D,pe;let[r,n,o]=((D=s.cursor)==null?void 0:D.split(";"))||[void 0,void 0,void 0],a=(r==null?void 0:r.split("-"))||[],i=(n==null?void 0:n.split("-"))||[],u=(o==null?void 0:o.split("-"))||[],l=[],p=[],d=[],c=0;do{let q=s.repos&&s.repos[c];a[c]==="null"?l.push(null):l.push(this.getPullRequestsForUser({username:s.username,association:"authored",cursor:a[c],includeFromArchivedRepos:s.includeFromArchivedRepos,labelNames:s.labelNames,...q&&{repo:q}},e)),i[c]==="null"?p.push(null):p.push(this.getPullRequestsForUser({username:s.username,association:"assigned",cursor:i[c],includeFromArchivedRepos:s.includeFromArchivedRepos,labelNames:s.labelNames,...q&&{repo:q}},e)),u[c]==="null"?d.push(null):d.push(this.getPullRequestsForUser({username:s.username,association:"reviewRequested",cursor:u[c],includeFromArchivedRepos:s.includeFromArchivedRepos,labelNames:s.labelNames,...q&&{repo:q}},e)),c++}while(c<(((pe=s.repos)==null?void 0:pe.length)||0));let g=[l,p,d].flat(),m=await Promise.all(g),f={},h=[],P=q=>{f[q.id]||(f[q.id]=!0,h.push(q))},I=!1,T=m.map((q,Pt)=>{var wt;let ae="";return q&&q.data.forEach(P),q!=null&&q.pageInfo.hasNextPage?(I=!0,ae+=`${q.pageInfo.endCursor||"null"}`):ae+="null",(wt=s.repos)!=null&&wt.length&&(Pt+1)%s.repos.length!==0?ae+="-":Pt+1<m.length&&(ae+=";"),ae}).join("");return{pageInfo:{hasNextPage:I,endCursor:T},data:h}}getVariablesForPullRequests(s){let{updatedBefore:e,isDraft:r,authorLogin:n,assigneeLogins:o,labelNames:a,reviewRequestedLogin:i}=s||{},u={},l=[],p=[],d=(c,g,m)=>{l.push(`$${c}: ${m}`),p.push(`${c}: $${c}`),u[c]=g};return e&&d("updatedBefore",e,"Time"),n&&d("authorUsername",n,"String"),o&&d("assigneeUsername",o[0],"String"),a&&d("labelName",a,"[String]"),r!=null&&d("draft",r,"Boolean"),i&&d("reviewerUsername",i,"String"),{variables:u,variableTypes:l,mergeRequestArguments:p}}async getPullRequestsForRepoBase(s,e={},r){var h,P,I;let{cursor:n,repo:o}=s||{},a=M(o),{variables:i,variableTypes:u,mergeRequestArguments:l}=this.getVariablesForPullRequests(s),p={fullPath:a,...i},d=await w(this.config,{query:`
|
|
892
892
|
query getPullRequestsForRepo(
|
|
893
893
|
$fullPath: ID!
|
|
894
894
|
$after: String
|
|
@@ -913,12 +913,12 @@ query getPullRequestsForRepo(
|
|
|
913
913
|
hasNextPage
|
|
914
914
|
}
|
|
915
915
|
nodes {
|
|
916
|
-
${
|
|
916
|
+
${Mt(!1,!0,!0)}
|
|
917
917
|
}
|
|
918
918
|
}
|
|
919
919
|
}
|
|
920
920
|
}
|
|
921
|
-
`,variables:{...p,after:n}},e),c=[],g=(h=d.body.data)==null?void 0:h.project;if(!r&&(g!=null&&g.archived))return{pageInfo:null,data:[]};let m=Ce(g||{id:"",fullPath:"",webUrl:""});return(((P=g==null?void 0:g.mergeRequests)==null?void 0:P.nodes)||[]).forEach(E=>{c.push(
|
|
921
|
+
`,variables:{...p,after:n}},e),c=[],g=(h=d.body.data)==null?void 0:h.project;if(!r&&(g!=null&&g.archived))return{pageInfo:null,data:[]};let m=Ce(g||{id:"",fullPath:"",webUrl:""});return(((P=g==null?void 0:g.mergeRequests)==null?void 0:P.nodes)||[]).forEach(E=>{c.push(Wt(E,m,null,this.getIsSelfHosted(e),this.config.baseUrl??e.baseUrl))}),{pageInfo:(I=g==null?void 0:g.mergeRequests)==null?void 0:I.pageInfo,data:c}}async getPullRequestsForRepo(s,e={}){return this.getPullRequestsForRepoBase(s,e,!1)}async getPullRequestsForRepos(s,e={}){let{repos:r,assigneeLogins:n,updatedBefore:o,authorLogin:a,labelNames:i,isDraft:u,reviewRequestedLogin:l}=s;return{data:(await Promise.all(r.map(d=>this.getPullRequestsForRepoBase({repo:d,assigneeLogins:n,updatedBefore:o,authorLogin:a,labelNames:i,isDraft:u,reviewRequestedLogin:l},e,s.includeFromArchivedRepos??!1)))).flatMap(d=>d.data)}}async closePullRequest(s,e={}){var i,u,l;let{pullRequest:r}=s,n=`mutation ClosePullRequest($fullPath: ID!, $pullRequestId: String!) {
|
|
922
922
|
mergeRequestUpdate(input: { projectPath: $fullPath, iid: $pullRequestId, state: CLOSED }) {
|
|
923
923
|
errors,
|
|
924
924
|
mergeRequest {
|
|
@@ -983,18 +983,18 @@ query getPullRequestsForRepo(
|
|
|
983
983
|
id
|
|
984
984
|
}
|
|
985
985
|
}
|
|
986
|
-
}`;if(!((p=(l=(u=(await w(this.config,{query:a,variables:{fullPath:`${r.repository.owner.login}/${r.repository.name}`,pullRequestId:r.number.toString(),labelGraphQLIds:o}},e)).body.data)==null?void 0:u.mergeRequestSetLabels)==null?void 0:l.mergeRequest)!=null&&p.id))throw new Error("Could not set pull request labels")}async getIssue(s,e={}){var o,a,i;let r=
|
|
986
|
+
}`;if(!((p=(l=(u=(await w(this.config,{query:a,variables:{fullPath:`${r.repository.owner.login}/${r.repository.name}`,pullRequestId:r.number.toString(),labelGraphQLIds:o}},e)).body.data)==null?void 0:u.mergeRequestSetLabels)==null?void 0:l.mergeRequest)!=null&&p.id))throw new Error("Could not set pull request labels")}async getIssue(s,e={}){var o,a,i;let r=gs(s),n=await w(this.config,{query:`
|
|
987
987
|
query GetSingleIssue($projectId: ID!, $issueNumber: String!) {
|
|
988
988
|
project(fullPath: $projectId) {
|
|
989
989
|
id
|
|
990
990
|
fullPath
|
|
991
991
|
webUrl
|
|
992
992
|
issue(iid: $issueNumber) {
|
|
993
|
-
${
|
|
993
|
+
${it}
|
|
994
994
|
}
|
|
995
995
|
}
|
|
996
996
|
}
|
|
997
|
-
`,variables:{issueNumber:s.number,projectId:r}},e);if(!((o=n.body.data)!=null&&o.project))throw new Error(`Repository ${r} not found`);if(!((i=(a=n.body.data)==null?void 0:a.project)!=null&&i.issue))throw new Error(`Issue ${s.number} not found`);return{data:
|
|
997
|
+
`,variables:{issueNumber:s.number,projectId:r}},e);if(!((o=n.body.data)!=null&&o.project))throw new Error(`Repository ${r} not found`);if(!((i=(a=n.body.data)==null?void 0:a.project)!=null&&i.issue))throw new Error(`Issue ${s.number} not found`);return{data:lt(n.body.data.project.issue,Ce(n.body.data.project),this.getIsSelfHosted(e),this.config.baseUrl??e.baseUrl)}}getVariablesForIssues(s){let{updatedBefore:e,authorLogin:r,assigneeLogins:n,labelNames:o}=s||{},a={},i=[],u=[],l=(p,d,c)=>{i.push(`$${p}: ${c}`),u.push(`${p}: $${p}`),a[p]=d};return e&&l("updatedBefore",e,"Time"),r&&l("authorUsername",r,"String"),n&&l("assigneeUsername",n[0],"String"),o&&l("labelName",o,"[String]"),{variables:a,variableTypes:i,issueArguments:u}}async getIssuesForRepo(s,e={}){var h,P,I;let{cursor:r,repo:n}=s||{},o=M(n),{variables:a,variableTypes:i,issueArguments:u}=this.getVariablesForIssues(s),l={fullPath:o,...a},p=`
|
|
998
998
|
query GetIssuesFromProject(
|
|
999
999
|
$fullPath: ID!
|
|
1000
1000
|
$after: String
|
|
@@ -1014,7 +1014,7 @@ query GetSingleIssue($projectId: ID!, $issueNumber: String!) {
|
|
|
1014
1014
|
${u.length?u.join(" "):""}
|
|
1015
1015
|
) {
|
|
1016
1016
|
nodes {
|
|
1017
|
-
${
|
|
1017
|
+
${it}
|
|
1018
1018
|
}
|
|
1019
1019
|
pageInfo {
|
|
1020
1020
|
endCursor
|
|
@@ -1022,7 +1022,7 @@ query GetSingleIssue($projectId: ID!, $issueNumber: String!) {
|
|
|
1022
1022
|
}
|
|
1023
1023
|
}
|
|
1024
1024
|
}
|
|
1025
|
-
}`,d=await w(this.config,{query:p,variables:{...l,after:r}},e),c=[],g=(h=d.body.data)==null?void 0:h.project,m=Ce(g||{id:"",fullPath:"",webUrl:""});return(((P=g==null?void 0:g.issues)==null?void 0:P.nodes)||[]).forEach(E=>{c.push(
|
|
1025
|
+
}`,d=await w(this.config,{query:p,variables:{...l,after:r}},e),c=[],g=(h=d.body.data)==null?void 0:h.project,m=Ce(g||{id:"",fullPath:"",webUrl:""});return(((P=g==null?void 0:g.issues)==null?void 0:P.nodes)||[]).forEach(E=>{c.push(lt(E,m,this.getIsSelfHosted(e),this.config.baseUrl??e.baseUrl))}),{pageInfo:((I=g==null?void 0:g.issues)==null?void 0:I.pageInfo)??{endCursor:null,hasNextPage:!1},data:c.sort((E,T)=>(E.updatedDate||E.createdDate).getTime()-(T.updatedDate||T.createdDate).getTime())}}async getIssuesForRepos(s,e={}){var g,m,f,h,P;let{cursor:r}=s||{},n=s.repoIds.map(I=>I.toString().startsWith(te)?I:`${te}${I}`),{variables:o,variableTypes:a,mergeRequestArguments:i}=this.getVariablesForPullRequests(s),u={projectIds:n,...o},l=`
|
|
1026
1026
|
query GetIssuesFromProject(
|
|
1027
1027
|
$projectIds: [ID!]
|
|
1028
1028
|
$after: String
|
|
@@ -1048,12 +1048,12 @@ query GetSingleIssue($projectId: ID!, $issueNumber: String!) {
|
|
|
1048
1048
|
${i.length?i.join(" "):""}
|
|
1049
1049
|
) {
|
|
1050
1050
|
nodes {
|
|
1051
|
-
${
|
|
1051
|
+
${it}
|
|
1052
1052
|
}
|
|
1053
1053
|
}
|
|
1054
1054
|
}
|
|
1055
1055
|
}
|
|
1056
|
-
}`,p=await w(this.config,{query:l,variables:{...u,after:r}},e),d=[];return(((m=(g=p.body.data)==null?void 0:g.projects)==null?void 0:m.nodes)||[]).forEach(
|
|
1056
|
+
}`,p=await w(this.config,{query:l,variables:{...u,after:r}},e),d=[];return(((m=(g=p.body.data)==null?void 0:g.projects)==null?void 0:m.nodes)||[]).forEach(I=>{var D;if(!s.includeFromArchivedRepos&&I.archived)return;let E=Ce(I);(((D=I.issues)==null?void 0:D.nodes)||[]).forEach(pe=>d.push(lt(pe,E,this.getIsSelfHosted(e),this.config.baseUrl??e.baseUrl)))}),{pageInfo:((P=(h=(f=p.body)==null?void 0:f.data)==null?void 0:h.projects)==null?void 0:P.pageInfo)??{endCursor:null,hasNextPage:!1},data:d.sort((I,E)=>(I.updatedDate||I.createdDate).getTime()-(E.updatedDate||E.createdDate).getTime())}}async setIssueState(s,e={}){var i,u,l;let{issue:r,state:n}=s;if(!r.repository)throw new Error('GitLab requires "repository" for this function.');let o=`mutation SetIssueState($fullPath: ID!, $issueId: String!, $status: IssueStateEvent!) {
|
|
1057
1057
|
updateIssue(input: { projectPath: $fullPath, iid: $issueId, stateEvent: $status }) {
|
|
1058
1058
|
issue {
|
|
1059
1059
|
id
|
|
@@ -1093,7 +1093,7 @@ query getLabelsForRepo(
|
|
|
1093
1093
|
webUrl
|
|
1094
1094
|
milestones(after: $after) {
|
|
1095
1095
|
nodes {
|
|
1096
|
-
${
|
|
1096
|
+
${ct}
|
|
1097
1097
|
}
|
|
1098
1098
|
pageInfo {
|
|
1099
1099
|
endCursor
|
|
@@ -1102,7 +1102,7 @@ query getLabelsForRepo(
|
|
|
1102
1102
|
}
|
|
1103
1103
|
}
|
|
1104
1104
|
}
|
|
1105
|
-
`,variables:{fullPath:`${r}/${n}`,after:o}},e);return{pageInfo:((l=(u=(i=a.body.data)==null?void 0:i.project)==null?void 0:u.milestones)==null?void 0:l.pageInfo)??{endCursor:null,hasNextPage:!1},data:((g=(c=(d=(p=a.body.data)==null?void 0:p.project)==null?void 0:d.milestones)==null?void 0:c.nodes)==null?void 0:g.map(m=>{var
|
|
1105
|
+
`,variables:{fullPath:`${r}/${n}`,after:o}},e);return{pageInfo:((l=(u=(i=a.body.data)==null?void 0:i.project)==null?void 0:u.milestones)==null?void 0:l.pageInfo)??{endCursor:null,hasNextPage:!1},data:((g=(c=(d=(p=a.body.data)==null?void 0:p.project)==null?void 0:d.milestones)==null?void 0:c.nodes)==null?void 0:g.map(m=>{var f,h;return ht(m,((h=(f=a.body.data)==null?void 0:f.project)==null?void 0:h.webUrl)||"")}))??[]}}async getLabelsForRepo(s,e={}){var i,u,l,p,d,c,g;let{repo:{namespace:r,name:n},cursor:o}=s,a=await w(this.config,{query:`
|
|
1106
1106
|
query getLabelsForRepo(
|
|
1107
1107
|
$fullPath: ID!
|
|
1108
1108
|
$after: String
|
|
@@ -1112,7 +1112,7 @@ query getLabelsForRepo(
|
|
|
1112
1112
|
) {
|
|
1113
1113
|
labels(after: $after) {
|
|
1114
1114
|
nodes {
|
|
1115
|
-
${
|
|
1115
|
+
${gt}
|
|
1116
1116
|
}
|
|
1117
1117
|
pageInfo {
|
|
1118
1118
|
endCursor
|
|
@@ -1121,17 +1121,17 @@ query getLabelsForRepo(
|
|
|
1121
1121
|
}
|
|
1122
1122
|
}
|
|
1123
1123
|
}
|
|
1124
|
-
`,variables:{fullPath:`${r}/${n}`,after:o}},e);return{pageInfo:((l=(u=(i=a.body.data)==null?void 0:i.project)==null?void 0:u.labels)==null?void 0:l.pageInfo)??{endCursor:null,hasNextPage:!1},data:((g=(c=(d=(p=a.body.data)==null?void 0:p.project)==null?void 0:d.labels)==null?void 0:c.nodes)==null?void 0:g.map(
|
|
1125
|
-
OR comment ~ currentUser() OR summary ~ currentUser() OR description ~ currentUser())`];a&&a.forEach(P=>u.push(`labels = "${P}"`));let l=`${u.join(" AND ")} ORDER BY updated DESC`,p=!o,d=p?Jt:Ht,c=new URL(`${W(t,r,o)}${d}`);c.searchParams.set("jql",l),c.searchParams.set("maxResults",De.toString()),c.searchParams.set("fields",mt.join(",")),c.searchParams.set("expand","transitions"),n&&(p?c.searchParams.set("startAt",n):c.searchParams.set("nextPageToken",n));let g=await t.request({url:c.toString(),headers:R(r.token||t.token)}),m=g.body.issues.map(P=>ht(P,i,e,o)),I=!1,h="";return p?(I=m.length==De,h=(parseInt(n??"0",10)+m.length).toString()):(I=!!g.body.nextPageToken,h=g.body.nextPageToken??null),{data:m,pageInfo:{hasNextPage:I,endCursor:h}}},Vt=async(t,s,e,r={})=>{let{cursor:n,resourceId:o,jql:a,fields:i}=s||{},u=[...mt],l=i==null?void 0:i.Sprint;l&&u.push(l);let p=!o,d=p?Jt:Ht,c=new URL(`${W(t,r,o)}${d}`);c.searchParams.set("jql",a.join(" AND ")),c.searchParams.set("maxResults",De.toString()),c.searchParams.set("fields",u.join(",")),c.searchParams.set("expand","transitions"),n&&(p?c.searchParams.set("startAt",n):c.searchParams.set("nextPageToken",n));let g=await t.request({url:c.toString(),headers:R(r.token||t.token)}),m=g.body.issues.map(P=>ht(P,i,e,o)),I=!1,h="";return p?(I=m.length==De,h=(parseInt(n??"0",10)+m.length).toString()):(I=!!g.body.nextPageToken,h=g.body.nextPageToken??null),{data:m,pageInfo:{hasNextPage:I,endCursor:h}}},Ge=async(t,s,e,r={})=>{let{assigneeLogins:n,authorLogin:o,mentionLogin:a,labelNames:i,cursor:u,projectKey:l,resourceId:p,fields:d}=s||{},c=[`project = "${l}"`,"statusCategory != Done"];return o&&c.push(`creator in ("${o}")`),n&&n.length!==0&&c.push(`assignee in ("${n.join('", "')}")`),a&&c.push(`comment ~ "${a}"`),i&&i.forEach(g=>c.push(`labels = "${g}"`)),Vt(t,{resourceId:p,jql:c,cursor:u,fields:d},e,r)},Te=async(t,s,e,r={})=>{let{assigneeLogins:n,authorLogin:o,mentionLogin:a,labelNames:i,cursor:u,projectKeys:l,resourceId:p,fields:d}=s||{},g=["("+l.map(m=>`project = "${m}"`).join(" OR ")+")","statusCategory != Done"];return o&&g.push(`creator in ("${o}")`),n&&n.length!==0&&g.push(`assignee in ("${n.join('", "')}")`),a&&g.push(`comment ~ "${a}"`),i&&i.forEach(m=>g.push(`labels = "${m}"`)),Vt(t,{resourceId:p,jql:g,fields:d,cursor:u},e,r)},Oe=async(t,s,e={})=>{let{issue:r,labels:n}=s;if(!r.project)throw new Error('Jira requires a "project" for this function.');let o={fields:{labels:n.map(a=>a.name)}};await t.request({method:"PUT",url:`${W(t,e,r.project.resourceId??void 0)}/rest/api/2/issue/${r.id}`,body:JSON.stringify(o),headers:{...R(e.token||t.token),"Content-Type":"application/json"}})},xe=async(t,s,e={})=>{let{issue:r,components:n}=s;if(!r.project)throw new Error('Jira requires a "project" for this function.');let o={fields:{components:n.map(a=>({id:a.id}))}};await t.request({method:"PUT",url:`${W(t,e,r.project.resourceId??void 0)}/rest/api/2/issue/${r.id}`,body:JSON.stringify(o),headers:{...R(e.token||t.token),"Content-Type":"application/json"}})},ke=async(t,s,e={})=>{let{issue:r,status:n}=s;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 t.request({method:"POST",url:`${W(t,e,r.project.resourceId??void 0)}/rest/api/2/issue/${r.id}/transitions`,body:JSON.stringify(o),headers:{...R(e.token||t.token),"Content-Type":"application/json"}})},Ne=async(t,s,e={})=>{let{resourceId:r,projectIdOrKey:n}=s,o=new URL(`${W(t,e,r)}/rest/api/2/project/${n}/components`);return{data:(await t.request({url:o.toString(),headers:R(e.token||t.token)})).body}};var ue="https://api.atlassian.com/ex/jira",ft=100,se=class extends O{constructor(){super(...arguments);this._resourceUrlCache={};this._issueFieldsCache={}}async getIssueFieldsForResource(e,r={}){if(!this._issueFieldsCache[e.resourceId]){let n=await $e(this.config,e,r);this._issueFieldsCache[e.resourceId]=n.reduce((o,a)=>({...o,[a.name]:a.id}),{})}return this._issueFieldsCache[e.resourceId]??null}async getResourceUrl(e,r={}){var a;let n=r.token||this.config.token;if(!n)return null;let o=this._resourceUrlCache[n];return o?o[e.resourceId]??null:(await this.getJiraResourcesForCurrentUser(r),((a=this._resourceUrlCache[n])==null?void 0:a[e.resourceId])??null)}async getCurrentUserForResource(e,r={}){let n=await this.getResourceUrl({resourceId:e.resourceId},r),o=await this.config.request({url:`${r.baseUrl||ue}/${e.resourceId}/rest/api/2/myself`,headers:R(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(e={}){let r=await this.config.request({url:`${e.baseUrl||"https://api.atlassian.com/"}/oauth/token/accessible-resources`,headers:R(e.token||this.config.token)}),n=e.token||this.config.token,o=n?this._resourceUrlCache[n]||{}:void 0,a=r.body.map(i=>(o&&(o[i.id]=i.url),{avatarUrl:i.avatarUrl,id:i.id,name:i.name,url:i.url}));return n&&(this._resourceUrlCache[n]=o),{data:a}}async getJiraProjectsForResource(e,r={}){let n=new URL(`${r.baseUrl||ue}/${e.resourceId}/rest/api/2/project/search`);n.searchParams.set("maxResults",ft.toString()),e.cursor&&n.searchParams.set("startAt",e.cursor);let o=await this.config.request({url:n.toString(),headers:R(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(a=>({id:a.id,key:a.key,name:a.name,resourceId:e.resourceId}))}}async getJiraProjectsForResources(e,r={}){let n=[];return await Promise.all(e.resourceIds.map(async o=>{try{return await Ct(a=>this.getJiraProjectsForResource({resourceId:o,cursor:a},r))}catch{return[]}})).then((...o)=>{o.forEach(a=>{n=n.concat(...a)})}),{data:n}}async getAccountsForJiraProject(e,r={}){let{resourceId:n,projectKey:o,cursor:a}=e,i=await this.getResourceUrl({resourceId:n},r),u=new URL(`${r.baseUrl||ue}/${n}/rest/api/2/user/assignable/search`);u.searchParams.set("maxResults",ft.toString()),a&&u.searchParams.set("startAt",a),u.searchParams.set("project",o);let l=await this.config.request({url:u.toString(),headers:R(r.token||this.config.token)});return{pageInfo:{hasNextPage:l.body.length!==0,endCursor:((a?parseInt(a):0)+l.body.length).toString()},data:l.body.filter(p=>p.accountType!=="app"&&p.active).map(p=>Le(p,i,!1))}}async getComponentsForJiraProject(e,r={}){return await Ne(this.config,e,r)}async getIssue(e,r={}){let n=await this.getIssueFieldsForResource({resourceId:e.resourceId},r),o=await this.getResourceUrl({resourceId:e.resourceId},r);return await Ue(this.config,{...e,fields:n},o,r)}async getIssuesForProject(e,r={}){let n=await this.getIssueFieldsForResource({resourceId:e.resourceId},r),o=await this.getResourceUrl({resourceId:e.resourceId},r);return await Ge(this.config,{...e,fields:n},o,r)}async getIssuesForProjects(e,r={}){let n=await this.getIssueFieldsForResource({resourceId:e.resourceId},r),o=await this.getResourceUrl({resourceId:e.resourceId},r);return await Te(this.config,{...e,fields:n},o,r)}async getIssuesForResourceForCurrentUser(e,r={}){let n=await this.getIssueFieldsForResource({resourceId:e.resourceId},r),o=await this.getResourceUrl({resourceId:e.resourceId},r);return await Ae(this.config,{...e,fields:n},o,r)}async setIssueStatus(e,r={}){await ke(this.config,e,r)}async setIssueAssignee(e,r={}){let{issue:n,assignee:o}=e;if(!n.project)throw new Error('Jira Cloud requires a "project" for this function.');if(!n.project.resourceId)throw new Error('Jira Cloud requires a project "resourceId" for this function.');let a={accountId:o==null?void 0:o.id};await this.config.request({method:"PUT",url:`${r.baseUrl||ue}/${n.project.resourceId}/rest/api/2/issue/${n.id}/assignee`,body:JSON.stringify(a),headers:{...R(r.token||this.config.token),"Content-Type":"application/json"}})}async setIssueComponents(e,r={}){await xe(this.config,e,r)}async setIssueLabels(e,r={}){await Oe(this.config,e,r)}async getLabelsForResource(e,r={}){let{resourceId:n,cursor:o}=e,a=new URL(`${r.baseUrl||ue}/${n}/rest/api/2/label`);a.searchParams.set("maxResults",ft.toString()),o&&a.searchParams.set("startAt",o);let i=await this.config.request({url:a.toString(),headers:R(r.token||this.config.token)});return{pageInfo:{hasNextPage:!i.body.isLast,endCursor:(i.body.startAt+i.body.values.length).toString()},data:i.body.values.map(u=>({color:null,description:null,id:null,name:u}))}}};var ne=class extends A{constructor(){super(...arguments);this._issueFieldsCache={}}async getIssueFieldsForResource(e={}){let r=(e==null?void 0:e.baseUrl)||this.config.baseUrl||"";if(!this._issueFieldsCache[r]){let n=await $e(this.config,{},e);this._issueFieldsCache[r]=n.reduce((o,a)=>({...o,[a.name]:a.id}),{})}return this._issueFieldsCache[r]??null}async getCurrentUser(e={}){let r=await this.config.request({url:`${(e==null?void 0:e.baseUrl)||this.config.baseUrl}/rest/api/2/myself`,headers:R((e==null?void 0:e.token)||this.config.token)});return{data:{name:r.body.displayName,email:r.body.emailAddress,avatarUrl:r.body.avatarUrls["48x48"],id:r.body.key,username:r.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:R((e==null?void 0:e.token)||this.config.token)})).body.map(n=>({id:n.id,name:n.name}))}}async getIssue(e,r={}){let n=e.resourceUrl||r.baseUrl||this.config.baseUrl;if(!n)throw new Error('Jira Server requires a "resourceUrl" or "baseUrl" for this function.');let o=await this.getIssueFieldsForResource(r);return await Ue(this.config,{...e,fields:o},n,r)}async getIssuesForProject(e,r={}){let n=e.resourceUrl||r.baseUrl||this.config.baseUrl;if(!n)throw new Error('Jira Server requires a "resourceUrl" or "baseUrl" for this function.');let o=await this.getIssueFieldsForResource(r);return await Ge(this.config,{...e,fields:o},n,r)}async getIssuesForProjects(e,r={}){let n=e.resourceUrl||r.baseUrl||this.config.baseUrl;if(!n)throw new Error('Jira Server requires a "resourceUrl" or "baseUrl" for this function.');let o=await this.getIssueFieldsForResource(r);return await Te(this.config,{...e,fields:o},n,r)}async getIssuesForResourceForCurrentUser(e,r={}){let n=e.resourceUrl||r.baseUrl||this.config.baseUrl;if(!n)throw new Error('Jira Server requires a "resourceUrl" or "baseUrl" for this function.');let o=await this.getIssueFieldsForResource(r);return await Ae(this.config,{...e,fields:o},n,r)}async setIssueStatus(e,r={}){await ke(this.config,e,r)}async setIssueLabels(e,r={}){await Oe(this.config,e,r)}async setIssueComponents(e,r={}){await xe(this.config,e,r)}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:R(e.token||this.config.token)})).body.results.map(({displayName:n})=>({color:null,description:null,id:null,name:n}))}}async getComponentsForJiraProject(e,r={}){return await Ne(this.config,e,r)}};var N="https://api.trello.com",Es=1e3,qs=t=>({id:t.id,username:t.username,url:t.url,name:t.fullName,email:t.email,avatarUrl:t.avatarUrl}),Cs=(t,s)=>{let e=new Date(1e3*parseInt(t.id.substring(0,8),16));return{id:t.id,commentCount:t.badges.comments,number:t.idShort.toString(),title:t.name,url:t.url,closedDate:null,createdDate:new Date(e.toISOString()),author:null,updatedDate:new Date(t.dateLastActivity),assignees:t.members.map(r=>({id:r.id,username:r.username,name:r.fullName,email:null,avatarUrl:r.avatarUrl,url:null})),description:null,state:s[t.idList??""]?{id:t.idList,name:s[t.idList].name,color:null}:null,type:null,repository:null,upvoteCount:t.badges.votes,labels:t.labels.map(r=>({color:r.color,description:null,id:r.id,name:r.name}))}},oe=class extends O{async getCurrentUser(s,e={}){let r=await this.config.request({url:`${e.baseUrl||N}/1/members/me?key=${s.appKey}&token=${e.token||this.config.token}`,headers:R(e.token||this.config.token)});return{data:{name:r.body.fullName,email:r.body.email,avatarUrl:r.body.avatarHash?`https://trello-members.s3.amazonaws.com/${r.body.id}/${r.body.avatarHash}/50.png`:null,id:r.body.id,username:r.body.username,url:r.body.url}}}async getBoardsForCurrentUser(s,e={}){return{data:(await this.config.request({url:`${e.baseUrl||N}/1/members/me/boards?fields=name&key=${s.appKey}&token=${e.token||this.config.token}&filter=open`,headers:R(e.token||this.config.token)})).body.map(n=>({id:n.id,name:n.name}))}}async getListsForTrelloBoard(s,e={}){let{appKey:r,boardId:n}=s;return{data:(await this.config.request({url:`${e.baseUrl||N}/1/boards/${n}/lists?key=${r}&token=${e.token||this.config.token}`,headers:R(e.token||this.config.token)})).body}}async getAccountForId(s,e={}){let{appKey:r,memberId:n}=s,o=await this.config.request({url:`${e.baseUrl||N}/1/members/${n}/?key=${r}&token=${e.token||this.config.token}`});return{data:qs(o.body)}}async getAccountsForTrelloBoard(s,e={}){let{appKey:r,boardId:n}=s;return{data:(await this.config.request({url:`${e.baseUrl||N}/1/boards/${n}/members?key=${r}&token=${e.token||this.config.token}`,headers:R(e.token||this.config.token)})).body.map(a=>({id:a.id,name:a.fullName,username:a.username,email:null,avatarUrl:null,url:null}))}}async getIssuesForBoard(s,e={}){let r=["-is:archived","sort:edited"],{appKey:n,boardId:o,filterText:a,assigneeLogins:i,labelNamesOrColors:u,trelloBoardListsById:l}=s||{};i&&r.push("@me"),u&&u.forEach(c=>r.push(`label:"${c}"`));let p=`${a?`${a}`:""}${r.join(" ")} board:${o}`;return{data:(await this.config.request({url:`${e.baseUrl||N}/1/search?key=${n}&query=${p}&cards_limit=${Es}&token=${e.token||this.config.token}&card_members=true`,headers:R(e.token||this.config.token)})).body.cards.map(c=>Cs(c,l||{}))}}async updateIssue(s,e,r,n){return await this.config.request({method:"PUT",url:`${n.baseUrl||N}/1/cards/${e.id}?key=${s}&token=${n.token||this.config.token}&${r}`,headers:R(n.token||this.config.token)})}async setIssueStatus(s,e={}){let{appKey:r,issue:n,status:o}=s;if(!o.id)throw new Error('Trello requires a status "id" for this function.');let a=`idList=${o.id}`;if(!(await this.updateIssue(r,n,a,e)).body.id)throw new Error("Could not set issue status")}async setIssueAssignees(s,e={}){let{appKey:r,issue:n,assignees:o}=s,a=o.map(l=>l.id),i=`idMembers=${encodeURIComponent(a.join(","))}`;if(!(await this.updateIssue(r,n,i,e)).body.id)throw new Error("Could not set issue status")}async setIssueLabels(s,e={}){let{appKey:r,issue:n,labels:o}=s,a=o.map(u=>u.id).join(",");if(!(await this.config.request({method:"PUT",url:`${e.baseUrl||N}/1/cards/${n.id}?key=${r}&token=${e.token||this.config.token}&idLabels=${encodeURIComponent(a)}`,headers:R(e.token||this.config.token)})).body.id)throw new Error("Could not set issue status")}async setIssueArchived(s,e={}){let{appKey:r,issue:n,archived:o}=s;if(!(await this.config.request({method:"PUT",url:`${e.baseUrl||N}/1/cards/${n.id}?key=${r}&token=${e.token||this.config.token}&closed=${o}`,headers:R(e.token||this.config.token)})).body.id)throw new Error("Could not update issue archived status")}async archiveIssue(s,e={}){await this.setIssueArchived({...s,archived:!0},e)}async unArchiveIssue(s,e={}){await this.setIssueArchived({...s,archived:!1},e)}async getLabelsForBoard(s,e={}){let{appKey:r,boardId:n}=s;return{data:(await this.config.request({url:`${e.baseUrl||N}/1/boards/${n}/labels?key=${r}&token=${e.token||this.config.token}`,headers:R(e.token||this.config.token)})).body.map(a=>({color:a.color,description:null,id:a.id,name:a.name}))}}};var _e=class{constructor(){this.set=new Set;this.arr=[]}push(...s){let e=s.filter(r=>!this.set.has(r.id));this.arr.push(...e),e.forEach(r=>this.set.add(r.id))}get length(){return this.arr.length}get items(){return this.arr}};var le=(a=>(a[a.None=0]="None",a[a.Assignee=1]="Assignee",a[a.Creator=2]="Creator",a[a.Mention=3]="Mention",a[a.MentionInDescription=4]="MentionInDescription",a[a.MentionInComments=5]="MentionInComments",a))(le||{});function Kt(t,s){return t?`${le[t]}:${s||""}`:s??null}function Xt(t){if(!t)return{category:0};let[s,e]=t.split(":");return s in le?{category:le[s],cursor:e||void 0}:{category:0,cursor:t}}var Ds=100;function Fe(t){return t?t instanceof Date?t:new Date(t):null}var tr=`
|
|
1124
|
+
`,variables:{fullPath:`${r}/${n}`,after:o}},e);return{pageInfo:((l=(u=(i=a.body.data)==null?void 0:i.project)==null?void 0:u.labels)==null?void 0:l.pageInfo)??{endCursor:null,hasNextPage:!1},data:((g=(c=(d=(p=a.body.data)==null?void 0:p.project)==null?void 0:d.labels)==null?void 0:c.nodes)==null?void 0:g.map(mt))??[]}}async getTreeForRepo(s,e={}){let r=M(s.repo),n=new URL(s.cursor??`${Ee(this.config,e)}/projects/${encodeURIComponent(r)}/repository/tree`);n.searchParams.set("per_page","10000"),n.searchParams.set("recursive","true"),n.searchParams.set("pagination","keyset"),n.searchParams.set("ref",s.branch);let o=await this.config.request({url:n.toString(),headers:R(e.token||this.config.token)}),a=o.headers.link;return{data:o.body.map(hs),pageInfo:{endCursor:a?a.substring(1,a.indexOf(">")):null,hasNextPage:!!a}}}};var bs="https://api.atlassian.com/ex/jira",De=100,ft=["assignee","comment","summary","created","creator","updated","votes","issuetype","status","labels","components","project","fixVersions","description"],Jt="/rest/api/2/search/jql",Vt="/rest/api/2/search",It=(t,s,e,r)=>{var i,u,l,p;let n=t.fields.assignee,o=!r,a=(t.fields[(s==null?void 0:s.Sprint)??""]??[]).filter(d=>typeof d=="object");return{id:t.id,commentCount:t.fields.comment.comments.length,number:t.key,title:t.fields.summary,url:e?`${e}/browse/${t.key}`:null,closedDate:null,createdDate:new Date(t.fields.created),author:Le(t.fields.creator,e,o),updatedDate:new Date(t.fields.updated),assignees:n?[Le(n,e,o)]:[],description:t.fields.description,repository:null,project:{name:t.fields.project.name,resourceId:r??null,key:t.fields.project.key,namespace:null,id:t.fields.project.id},state:Ss(t.fields.status),statusTransitions:((i=t.transitions)==null?void 0:i.map(ys))??[],components:((u=t.fields.components)==null?void 0:u.map(Ps))??[],type:t.fields.issuetype.name,upvoteCount:((l=t.fields.votes)==null?void 0:l.votes)||0,labels:((p=t.fields.labels)==null?void 0:p.map(d=>({color:null,description:null,id:null,name:d})))??[],sprints:a.map(vs),fixVersions:t.fields.fixVersions.map(Es)}},ys=t=>{let s;switch(t.to.statusCategory.name){case"To Do":s="TO_DO";break;case"In Progress":s="IN_PROGRESS";break;default:s="DONE";break}return{name:t.name,id:t.id,to:{id:t.to.id,name:t.to.name,color:t.to.statusCategory.colorName,category:s}}},Ps=t=>({description:t.description??null,id:t.id,name:t.name}),ws=(t,s,e)=>e&&t.name?`${s}/secure/ViewProfile.jspa?name=${encodeURIComponent(t.name)}`:`${s}/jira/people/${t.accountId}`,Le=(t,s,e)=>({id:(e?t.key:t.accountId)??"",name:t.displayName,email:t.emailAddress,avatarUrl:t.avatarUrls["48x48"],username:t.displayName,url:ws(t,s,e)}),Ss=t=>{let s;switch(t.statusCategory.name){case"To Do":s="TO_DO";break;case"In Progress":s="IN_PROGRESS";break;default:s="DONE";break}return{id:t.id,name:t.name,color:t.statusCategory.colorName,category:s}},vs=t=>({id:t.id.toString(),name:t.name,isActive:t.state==="active",startDate:t.startDate?new Date(t.startDate):null,endDate:t.endDate?new Date(t.endDate):null,completedDate:t.completeDate?new Date(t.completeDate):null}),Es=t=>({id:t.id,description:t.description,name:t.name,archived:t.archived,released:t.released,releaseDate:t.releaseDate?new Date(t.releaseDate):null}),W=(t,s,e)=>e?`${s.baseUrl||bs}/${e}`:`${(s==null?void 0:s.baseUrl)||t.baseUrl}`,$e=async(t,s,e={})=>{let{resourceId:r}=s;return(await t.request({url:`${W(t,e,r)}/rest/api/2/field`,headers:R(e.token||t.token)})).body},Ue=async(t,s,e,r={})=>{let{number:n,resourceId:o,fields:a}=s||{},i=await t.request({url:`${W(t,r,o)}/rest/api/2/issue/${n}?fields=${ft.join(",")}&expand=transitions`,headers:R(r.token||t.token)});return{data:It(i.body,a,e,o)}},Ae=async(t,s,e,r={})=>{let{cursor:n,resourceId:o,labelNames:a,fields:i}=s||{},u=["statusCategory != Done",`(creator = currentUser() OR assignee = currentUser()
|
|
1125
|
+
OR comment ~ currentUser() OR summary ~ currentUser() OR description ~ currentUser())`];a&&a.forEach(P=>u.push(`labels = "${P}"`));let l=`${u.join(" AND ")} ORDER BY updated DESC`,p=!o,d=p?Vt:Jt,c=new URL(`${W(t,r,o)}${d}`);c.searchParams.set("jql",l),c.searchParams.set("maxResults",De.toString()),c.searchParams.set("fields",ft.join(",")),c.searchParams.set("expand","transitions"),n&&(p?c.searchParams.set("startAt",n):c.searchParams.set("nextPageToken",n));let g=await t.request({url:c.toString(),headers:R(r.token||t.token)}),m=g.body.issues.map(P=>It(P,i,e,o)),f=!1,h="";return p?(f=m.length==De,h=(parseInt(n??"0",10)+m.length).toString()):(f=!!g.body.nextPageToken,h=g.body.nextPageToken??null),{data:m,pageInfo:{hasNextPage:f,endCursor:h}}},Kt=async(t,s,e,r={})=>{let{cursor:n,resourceId:o,jql:a,fields:i}=s||{},u=[...ft],l=i==null?void 0:i.Sprint;l&&u.push(l);let p=!o,d=p?Vt:Jt,c=new URL(`${W(t,r,o)}${d}`);c.searchParams.set("jql",a.join(" AND ")),c.searchParams.set("maxResults",De.toString()),c.searchParams.set("fields",u.join(",")),c.searchParams.set("expand","transitions"),n&&(p?c.searchParams.set("startAt",n):c.searchParams.set("nextPageToken",n));let g=await t.request({url:c.toString(),headers:R(r.token||t.token)}),m=g.body.issues.map(P=>It(P,i,e,o)),f=!1,h="";return p?(f=m.length==De,h=(parseInt(n??"0",10)+m.length).toString()):(f=!!g.body.nextPageToken,h=g.body.nextPageToken??null),{data:m,pageInfo:{hasNextPage:f,endCursor:h}}},Ge=async(t,s,e,r={})=>{let{assigneeLogins:n,authorLogin:o,mentionLogin:a,labelNames:i,cursor:u,projectKey:l,resourceId:p,fields:d}=s||{},c=[`project = "${l}"`,"statusCategory != Done"];return o&&c.push(`creator in ("${o}")`),n&&n.length!==0&&c.push(`assignee in ("${n.join('", "')}")`),a&&c.push(`comment ~ "${a}"`),i&&i.forEach(g=>c.push(`labels = "${g}"`)),Kt(t,{resourceId:p,jql:c,cursor:u,fields:d},e,r)},Te=async(t,s,e,r={})=>{let{assigneeLogins:n,authorLogin:o,mentionLogin:a,labelNames:i,cursor:u,projectKeys:l,resourceId:p,fields:d}=s||{},g=["("+l.map(m=>`project = "${m}"`).join(" OR ")+")","statusCategory != Done"];return o&&g.push(`creator in ("${o}")`),n&&n.length!==0&&g.push(`assignee in ("${n.join('", "')}")`),a&&g.push(`comment ~ "${a}"`),i&&i.forEach(m=>g.push(`labels = "${m}"`)),Kt(t,{resourceId:p,jql:g,fields:d,cursor:u},e,r)},Oe=async(t,s,e={})=>{let{issue:r,labels:n}=s;if(!r.project)throw new Error('Jira requires a "project" for this function.');let o={fields:{labels:n.map(a=>a.name)}};await t.request({method:"PUT",url:`${W(t,e,r.project.resourceId??void 0)}/rest/api/2/issue/${r.id}`,body:JSON.stringify(o),headers:{...R(e.token||t.token),"Content-Type":"application/json"}})},xe=async(t,s,e={})=>{let{issue:r,components:n}=s;if(!r.project)throw new Error('Jira requires a "project" for this function.');let o={fields:{components:n.map(a=>({id:a.id}))}};await t.request({method:"PUT",url:`${W(t,e,r.project.resourceId??void 0)}/rest/api/2/issue/${r.id}`,body:JSON.stringify(o),headers:{...R(e.token||t.token),"Content-Type":"application/json"}})},ke=async(t,s,e={})=>{let{issue:r,status:n}=s;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 t.request({method:"POST",url:`${W(t,e,r.project.resourceId??void 0)}/rest/api/2/issue/${r.id}/transitions`,body:JSON.stringify(o),headers:{...R(e.token||t.token),"Content-Type":"application/json"}})},Ne=async(t,s,e={})=>{let{resourceId:r,projectIdOrKey:n}=s,o=new URL(`${W(t,e,r)}/rest/api/2/project/${n}/components`);return{data:(await t.request({url:o.toString(),headers:R(e.token||t.token)})).body}};var ue="https://api.atlassian.com/ex/jira",Rt=100,se=class extends O{constructor(){super(...arguments);this._resourceUrlCache={};this._issueFieldsCache={}}async getIssueFieldsForResource(e,r={}){if(!this._issueFieldsCache[e.resourceId]){let n=await $e(this.config,e,r);this._issueFieldsCache[e.resourceId]=n.reduce((o,a)=>({...o,[a.name]:a.id}),{})}return this._issueFieldsCache[e.resourceId]??null}async getResourceUrl(e,r={}){var a;let n=r.token||this.config.token;if(!n)return null;let o=this._resourceUrlCache[n];return o?o[e.resourceId]??null:(await this.getJiraResourcesForCurrentUser(r),((a=this._resourceUrlCache[n])==null?void 0:a[e.resourceId])??null)}async getCurrentUserForResource(e,r={}){let n=await this.getResourceUrl({resourceId:e.resourceId},r),o=await this.config.request({url:`${r.baseUrl||ue}/${e.resourceId}/rest/api/2/myself`,headers:R(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(e={}){let r=await this.config.request({url:`${e.baseUrl||"https://api.atlassian.com/"}/oauth/token/accessible-resources`,headers:R(e.token||this.config.token)}),n=e.token||this.config.token,o=n?this._resourceUrlCache[n]||{}:void 0,a=r.body.map(i=>(o&&(o[i.id]=i.url),{avatarUrl:i.avatarUrl,id:i.id,name:i.name,url:i.url}));return n&&(this._resourceUrlCache[n]=o),{data:a}}async getJiraProjectsForResource(e,r={}){let n=new URL(`${r.baseUrl||ue}/${e.resourceId}/rest/api/2/project/search`);n.searchParams.set("maxResults",Rt.toString()),e.cursor&&n.searchParams.set("startAt",e.cursor);let o=await this.config.request({url:n.toString(),headers:R(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(a=>({id:a.id,key:a.key,name:a.name,resourceId:e.resourceId}))}}async getJiraProjectsForResources(e,r={}){let n=[];return await Promise.all(e.resourceIds.map(async o=>{try{return await Lt(a=>this.getJiraProjectsForResource({resourceId:o,cursor:a},r))}catch{return[]}})).then((...o)=>{o.forEach(a=>{n=n.concat(...a)})}),{data:n}}async getAccountsForJiraProject(e,r={}){let{resourceId:n,projectKey:o,cursor:a}=e,i=await this.getResourceUrl({resourceId:n},r),u=new URL(`${r.baseUrl||ue}/${n}/rest/api/2/user/assignable/search`);u.searchParams.set("maxResults",Rt.toString()),a&&u.searchParams.set("startAt",a),u.searchParams.set("project",o);let l=await this.config.request({url:u.toString(),headers:R(r.token||this.config.token)});return{pageInfo:{hasNextPage:l.body.length!==0,endCursor:((a?parseInt(a):0)+l.body.length).toString()},data:l.body.filter(p=>p.accountType!=="app"&&p.active).map(p=>Le(p,i,!1))}}async getComponentsForJiraProject(e,r={}){return await Ne(this.config,e,r)}async getIssue(e,r={}){let n=await this.getIssueFieldsForResource({resourceId:e.resourceId},r),o=await this.getResourceUrl({resourceId:e.resourceId},r);return await Ue(this.config,{...e,fields:n},o,r)}async getIssuesForProject(e,r={}){let n=await this.getIssueFieldsForResource({resourceId:e.resourceId},r),o=await this.getResourceUrl({resourceId:e.resourceId},r);return await Ge(this.config,{...e,fields:n},o,r)}async getIssuesForProjects(e,r={}){let n=await this.getIssueFieldsForResource({resourceId:e.resourceId},r),o=await this.getResourceUrl({resourceId:e.resourceId},r);return await Te(this.config,{...e,fields:n},o,r)}async getIssuesForResourceForCurrentUser(e,r={}){let n=await this.getIssueFieldsForResource({resourceId:e.resourceId},r),o=await this.getResourceUrl({resourceId:e.resourceId},r);return await Ae(this.config,{...e,fields:n},o,r)}async setIssueStatus(e,r={}){await ke(this.config,e,r)}async setIssueAssignee(e,r={}){let{issue:n,assignee:o}=e;if(!n.project)throw new Error('Jira Cloud requires a "project" for this function.');if(!n.project.resourceId)throw new Error('Jira Cloud requires a project "resourceId" for this function.');let a={accountId:o==null?void 0:o.id};await this.config.request({method:"PUT",url:`${r.baseUrl||ue}/${n.project.resourceId}/rest/api/2/issue/${n.id}/assignee`,body:JSON.stringify(a),headers:{...R(r.token||this.config.token),"Content-Type":"application/json"}})}async setIssueComponents(e,r={}){await xe(this.config,e,r)}async setIssueLabels(e,r={}){await Oe(this.config,e,r)}async getLabelsForResource(e,r={}){let{resourceId:n,cursor:o}=e,a=new URL(`${r.baseUrl||ue}/${n}/rest/api/2/label`);a.searchParams.set("maxResults",Rt.toString()),o&&a.searchParams.set("startAt",o);let i=await this.config.request({url:a.toString(),headers:R(r.token||this.config.token)});return{pageInfo:{hasNextPage:!i.body.isLast,endCursor:(i.body.startAt+i.body.values.length).toString()},data:i.body.values.map(u=>({color:null,description:null,id:null,name:u}))}}};var ne=class extends A{constructor(){super(...arguments);this._issueFieldsCache={}}async getIssueFieldsForResource(e={}){let r=(e==null?void 0:e.baseUrl)||this.config.baseUrl||"";if(!this._issueFieldsCache[r]){let n=await $e(this.config,{},e);this._issueFieldsCache[r]=n.reduce((o,a)=>({...o,[a.name]:a.id}),{})}return this._issueFieldsCache[r]??null}async getCurrentUser(e={}){let r=await this.config.request({url:`${(e==null?void 0:e.baseUrl)||this.config.baseUrl}/rest/api/2/myself`,headers:R((e==null?void 0:e.token)||this.config.token)});return{data:{name:r.body.displayName,email:r.body.emailAddress,avatarUrl:r.body.avatarUrls["48x48"],id:r.body.key,username:r.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:R((e==null?void 0:e.token)||this.config.token)})).body.map(n=>({id:n.id,name:n.name}))}}async getIssue(e,r={}){let n=e.resourceUrl||r.baseUrl||this.config.baseUrl;if(!n)throw new Error('Jira Server requires a "resourceUrl" or "baseUrl" for this function.');let o=await this.getIssueFieldsForResource(r);return await Ue(this.config,{...e,fields:o},n,r)}async getIssuesForProject(e,r={}){let n=e.resourceUrl||r.baseUrl||this.config.baseUrl;if(!n)throw new Error('Jira Server requires a "resourceUrl" or "baseUrl" for this function.');let o=await this.getIssueFieldsForResource(r);return await Ge(this.config,{...e,fields:o},n,r)}async getIssuesForProjects(e,r={}){let n=e.resourceUrl||r.baseUrl||this.config.baseUrl;if(!n)throw new Error('Jira Server requires a "resourceUrl" or "baseUrl" for this function.');let o=await this.getIssueFieldsForResource(r);return await Te(this.config,{...e,fields:o},n,r)}async getIssuesForResourceForCurrentUser(e,r={}){let n=e.resourceUrl||r.baseUrl||this.config.baseUrl;if(!n)throw new Error('Jira Server requires a "resourceUrl" or "baseUrl" for this function.');let o=await this.getIssueFieldsForResource(r);return await Ae(this.config,{...e,fields:o},n,r)}async setIssueStatus(e,r={}){await ke(this.config,e,r)}async setIssueLabels(e,r={}){await Oe(this.config,e,r)}async setIssueComponents(e,r={}){await xe(this.config,e,r)}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:R(e.token||this.config.token)})).body.results.map(({displayName:n})=>({color:null,description:null,id:null,name:n}))}}async getComponentsForJiraProject(e,r={}){return await Ne(this.config,e,r)}};var N="https://api.trello.com",qs=1e3,Cs=t=>({id:t.id,username:t.username,url:t.url,name:t.fullName,email:t.email,avatarUrl:t.avatarUrl}),Ds=(t,s)=>{let e=new Date(1e3*parseInt(t.id.substring(0,8),16));return{id:t.id,commentCount:t.badges.comments,number:t.idShort.toString(),title:t.name,url:t.url,closedDate:null,createdDate:new Date(e.toISOString()),author:null,updatedDate:new Date(t.dateLastActivity),assignees:t.members.map(r=>({id:r.id,username:r.username,name:r.fullName,email:null,avatarUrl:r.avatarUrl,url:null})),description:null,state:s[t.idList??""]?{id:t.idList,name:s[t.idList].name,color:null}:null,type:null,repository:null,upvoteCount:t.badges.votes,labels:t.labels.map(r=>({color:r.color,description:null,id:r.id,name:r.name}))}},oe=class extends O{async getCurrentUser(s,e={}){let r=await this.config.request({url:`${e.baseUrl||N}/1/members/me?key=${s.appKey}&token=${e.token||this.config.token}`,headers:R(e.token||this.config.token)});return{data:{name:r.body.fullName,email:r.body.email,avatarUrl:r.body.avatarHash?`https://trello-members.s3.amazonaws.com/${r.body.id}/${r.body.avatarHash}/50.png`:null,id:r.body.id,username:r.body.username,url:r.body.url}}}async getBoardsForCurrentUser(s,e={}){return{data:(await this.config.request({url:`${e.baseUrl||N}/1/members/me/boards?fields=name&key=${s.appKey}&token=${e.token||this.config.token}&filter=open`,headers:R(e.token||this.config.token)})).body.map(n=>({id:n.id,name:n.name}))}}async getListsForTrelloBoard(s,e={}){let{appKey:r,boardId:n}=s;return{data:(await this.config.request({url:`${e.baseUrl||N}/1/boards/${n}/lists?key=${r}&token=${e.token||this.config.token}`,headers:R(e.token||this.config.token)})).body}}async getAccountForId(s,e={}){let{appKey:r,memberId:n}=s,o=await this.config.request({url:`${e.baseUrl||N}/1/members/${n}/?key=${r}&token=${e.token||this.config.token}`});return{data:Cs(o.body)}}async getAccountsForTrelloBoard(s,e={}){let{appKey:r,boardId:n}=s;return{data:(await this.config.request({url:`${e.baseUrl||N}/1/boards/${n}/members?key=${r}&token=${e.token||this.config.token}`,headers:R(e.token||this.config.token)})).body.map(a=>({id:a.id,name:a.fullName,username:a.username,email:null,avatarUrl:null,url:null}))}}async getIssuesForBoard(s,e={}){let r=["-is:archived","sort:edited"],{appKey:n,boardId:o,filterText:a,assigneeLogins:i,labelNamesOrColors:u,trelloBoardListsById:l}=s||{};i&&r.push("@me"),u&&u.forEach(c=>r.push(`label:"${c}"`));let p=`${a?`${a}`:""}${r.join(" ")} board:${o}`;return{data:(await this.config.request({url:`${e.baseUrl||N}/1/search?key=${n}&query=${p}&cards_limit=${qs}&token=${e.token||this.config.token}&card_members=true`,headers:R(e.token||this.config.token)})).body.cards.map(c=>Ds(c,l||{}))}}async updateIssue(s,e,r,n){return await this.config.request({method:"PUT",url:`${n.baseUrl||N}/1/cards/${e.id}?key=${s}&token=${n.token||this.config.token}&${r}`,headers:R(n.token||this.config.token)})}async setIssueStatus(s,e={}){let{appKey:r,issue:n,status:o}=s;if(!o.id)throw new Error('Trello requires a status "id" for this function.');let a=`idList=${o.id}`;if(!(await this.updateIssue(r,n,a,e)).body.id)throw new Error("Could not set issue status")}async setIssueAssignees(s,e={}){let{appKey:r,issue:n,assignees:o}=s,a=o.map(l=>l.id),i=`idMembers=${encodeURIComponent(a.join(","))}`;if(!(await this.updateIssue(r,n,i,e)).body.id)throw new Error("Could not set issue status")}async setIssueLabels(s,e={}){let{appKey:r,issue:n,labels:o}=s,a=o.map(u=>u.id).join(",");if(!(await this.config.request({method:"PUT",url:`${e.baseUrl||N}/1/cards/${n.id}?key=${r}&token=${e.token||this.config.token}&idLabels=${encodeURIComponent(a)}`,headers:R(e.token||this.config.token)})).body.id)throw new Error("Could not set issue status")}async setIssueArchived(s,e={}){let{appKey:r,issue:n,archived:o}=s;if(!(await this.config.request({method:"PUT",url:`${e.baseUrl||N}/1/cards/${n.id}?key=${r}&token=${e.token||this.config.token}&closed=${o}`,headers:R(e.token||this.config.token)})).body.id)throw new Error("Could not update issue archived status")}async archiveIssue(s,e={}){await this.setIssueArchived({...s,archived:!0},e)}async unArchiveIssue(s,e={}){await this.setIssueArchived({...s,archived:!1},e)}async getLabelsForBoard(s,e={}){let{appKey:r,boardId:n}=s;return{data:(await this.config.request({url:`${e.baseUrl||N}/1/boards/${n}/labels?key=${r}&token=${e.token||this.config.token}`,headers:R(e.token||this.config.token)})).body.map(a=>({color:a.color,description:null,id:a.id,name:a.name}))}}};var _e=class{constructor(){this.set=new Set;this.arr=[]}push(...s){let e=s.filter(r=>!this.set.has(r.id));this.arr.push(...e),e.forEach(r=>this.set.add(r.id))}get length(){return this.arr.length}get items(){return this.arr}};var le=(a=>(a[a.None=0]="None",a[a.Assignee=1]="Assignee",a[a.Creator=2]="Creator",a[a.Mention=3]="Mention",a[a.MentionInDescription=4]="MentionInDescription",a[a.MentionInComments=5]="MentionInComments",a))(le||{});function Xt(t,s){return t?`${le[t]}:${s||""}`:s??null}function Zt(t){if(!t)return{category:0};let[s,e]=t.split(":");return s in le?{category:le[s],cursor:e||void 0}:{category:0,cursor:t}}var Yt=100;function Qe(t){return t?t instanceof Date?t:new Date(t):null}var rr=`
|
|
1126
1126
|
id
|
|
1127
1127
|
name
|
|
1128
1128
|
key
|
|
1129
1129
|
icon
|
|
1130
|
-
`;function Ls(t){return{id:t.id,name:t.name,key:t.key,iconUrl:t.icon}}var
|
|
1130
|
+
`;function Ls(t){return{id:t.id,name:t.name,key:t.key,iconUrl:t.icon}}var er=`
|
|
1131
1131
|
id
|
|
1132
1132
|
name
|
|
1133
1133
|
avatarUrl
|
|
1134
|
-
`;function
|
|
1134
|
+
`;function tr(t){return t?{id:t.id,name:t.name,username:t.name,email:null,avatarUrl:t.avatarUrl??null,url:null}:null}var $s=`
|
|
1135
1135
|
id
|
|
1136
1136
|
name
|
|
1137
1137
|
`;function Us(t,s){if(t)return{id:t.id,name:t.name,key:(s==null?void 0:s.key)||null,namespace:null,resourceId:(s==null?void 0:s.id)||null}}var As=`
|
|
@@ -1141,17 +1141,17 @@ OR comment ~ currentUser() OR summary ~ currentUser() OR description ~ currentUs
|
|
|
1141
1141
|
description
|
|
1142
1142
|
status
|
|
1143
1143
|
targetDate
|
|
1144
|
-
`;function Gs(t){return t?{id:t.id,number:t.sortOrder,title:t.name,description:t.description??null,isOpen:t.status!=="done",url:"",startDate:null,dueDate:
|
|
1144
|
+
`;function Gs(t){return t?{id:t.id,number:t.sortOrder,title:t.name,description:t.description??null,isOpen:t.status!=="done",url:"",startDate:null,dueDate:Qe(t.targetDate)}:null}function Ts(t){switch(t){case"completed":case"canceled":return"DONE";case"started":return"IN_PROGRESS";default:return"TO_DO"}}var Os=`
|
|
1145
1145
|
id
|
|
1146
1146
|
name
|
|
1147
1147
|
color
|
|
1148
1148
|
type
|
|
1149
|
-
`;function xs(t){return t?{id:t.id,name:t.name,color:t.color,category:Ts(t.type)}:null}var
|
|
1149
|
+
`;function xs(t){return t?{id:t.id,name:t.name,color:t.color,category:Ts(t.type)}:null}var yt=`
|
|
1150
1150
|
creator {
|
|
1151
|
-
${
|
|
1151
|
+
${er}
|
|
1152
1152
|
}
|
|
1153
1153
|
assignee {
|
|
1154
|
-
${
|
|
1154
|
+
${er}
|
|
1155
1155
|
}
|
|
1156
1156
|
archivedAt
|
|
1157
1157
|
createdAt
|
|
@@ -1162,7 +1162,7 @@ OR comment ~ currentUser() OR summary ~ currentUser() OR description ~ currentUs
|
|
|
1162
1162
|
${$s}
|
|
1163
1163
|
}
|
|
1164
1164
|
team {
|
|
1165
|
-
${
|
|
1165
|
+
${rr}
|
|
1166
1166
|
}
|
|
1167
1167
|
state {
|
|
1168
1168
|
${Os}
|
|
@@ -1173,18 +1173,18 @@ OR comment ~ currentUser() OR summary ~ currentUser() OR description ~ currentUs
|
|
|
1173
1173
|
projectMilestone {
|
|
1174
1174
|
${As}
|
|
1175
1175
|
}
|
|
1176
|
-
`;async function
|
|
1176
|
+
`;async function bt(t){return{author:tr(await t.creator),assignees:[tr(await t.assignee)].filter(s=>s!=null),commentCount:null,closedDate:Qe(t.archivedAt),createdDate:Qe(t.createdAt),description:t.description??null,id:t.id,labels:[],number:t.identifier,repository:null,project:Us(await t.project,await t.team),state:xs(await t.state),title:t.title,type:null,updatedDate:Qe(t.updatedAt),upvoteCount:null,url:t.url,milestone:Gs(await t.projectMilestone)}}var Fe=`
|
|
1177
1177
|
nodes {
|
|
1178
|
-
${
|
|
1178
|
+
${yt}
|
|
1179
1179
|
}
|
|
1180
1180
|
pageInfo {
|
|
1181
1181
|
hasNextPage
|
|
1182
1182
|
endCursor
|
|
1183
1183
|
}
|
|
1184
|
-
`,
|
|
1184
|
+
`,je=class extends O{async makeGraphQLRequest(s,e,r){let n=s.token||this.config.token;if(!n)throw new Error("Linear API key is required");let o=await this.config.request({url:"https://api.linear.app/graphql",method:"POST",headers:{Authorization:n,"Content-Type":"application/json"},body:JSON.stringify({query:e,variables:r})});if(o.status>=400)throw new Error(`Linear API request failed: ${o.status} ${o.statusText}`);let a=o.body;if(a.errors)throw new Error(`Linear GraphQL errors: ${a.errors.map(i=>i.message).join(", ")}`);return a.data}async fetchIssue(s,e){let r=`
|
|
1185
1185
|
query GetIssue($identifier: String!) {
|
|
1186
1186
|
issue(id: $identifier) {
|
|
1187
|
-
${
|
|
1187
|
+
${yt}
|
|
1188
1188
|
}
|
|
1189
1189
|
}
|
|
1190
1190
|
`;return(await this.makeGraphQLRequest(e,r,{identifier:s})).issue}async fetchOrganization(s){let e=`
|
|
@@ -1199,7 +1199,7 @@ OR comment ~ currentUser() OR summary ~ currentUser() OR description ~ currentUs
|
|
|
1199
1199
|
query GetTeams {
|
|
1200
1200
|
teams {
|
|
1201
1201
|
nodes {
|
|
1202
|
-
${
|
|
1202
|
+
${rr}
|
|
1203
1203
|
}
|
|
1204
1204
|
}
|
|
1205
1205
|
}
|
|
@@ -1212,23 +1212,23 @@ OR comment ~ currentUser() OR summary ~ currentUser() OR description ~ currentUs
|
|
|
1212
1212
|
displayName
|
|
1213
1213
|
}
|
|
1214
1214
|
}
|
|
1215
|
-
`;return(await this.makeGraphQLRequest(s,e)).viewer}async getIssue(s,e={}){let r=await this.fetchIssue(s.number,e);return{data:await
|
|
1215
|
+
`;return(await this.makeGraphQLRequest(s,e)).viewer}async getIssue(s,e={}){let r=await this.fetchIssue(s.number,e);return{data:await bt(r)}}async getLinearOrganization(s={}){let e=await this.fetchOrganization(s);return{data:{id:e.id,name:e.name,key:e.urlKey,url:`https://linear.app/${e.urlKey}`}}}async getTeamsForCurrentUser(s={}){return{data:(await this.fetchTeams(s)).nodes.map(Ls)}}async getCurrentUser(s={}){return{data:await this.fetchViewer(s)}}async getIssuesForCurrentUser(s,e={}){let{cursor:r}=s,{category:n,cursor:o}=Zt(r),a=await this.fetchViewer(e),i,u,l=new _e,p=async(d,c)=>{if(u||n>d)return;let g=await c(Math.max(Yt-l.length,1),n===d?o:void 0);if(!g)return;let m=await Me(g.nodes.map(bt));l.push(...m),g.pageInfo.hasNextPage&&(i=d,u=g.pageInfo.endCursor)};return await p(1,async(d,c)=>{var m,f;return(f=(m=(await this.rawRequest(e,`
|
|
1216
1216
|
query GetAssignedIssues($first: Int!, $after: String) {
|
|
1217
1217
|
viewer {
|
|
1218
1218
|
issues: assignedIssues(first: $first, after: $after) {
|
|
1219
|
-
${
|
|
1219
|
+
${Fe}
|
|
1220
1220
|
}
|
|
1221
1221
|
}
|
|
1222
1222
|
}
|
|
1223
|
-
`,{first:d,after:c})).data)==null?void 0:m.viewer)==null?void 0:
|
|
1223
|
+
`,{first:d,after:c})).data)==null?void 0:m.viewer)==null?void 0:f.issues}),await p(2,async(d,c)=>{var m,f;return(f=(m=(await this.rawRequest(e,`
|
|
1224
1224
|
query GetCreatedIssues($first: Int!, $after: String) {
|
|
1225
1225
|
viewer {
|
|
1226
1226
|
issues: createdIssues(first: $first, after: $after) {
|
|
1227
|
-
${
|
|
1227
|
+
${Fe}
|
|
1228
1228
|
}
|
|
1229
1229
|
}
|
|
1230
1230
|
}
|
|
1231
|
-
`,{first:d,after:c})).data)==null?void 0:m.viewer)==null?void 0:
|
|
1231
|
+
`,{first:d,after:c})).data)==null?void 0:m.viewer)==null?void 0:f.issues}),await p(4,async(d,c)=>{var m;return(m=(await this.rawRequest(e,`
|
|
1232
1232
|
query GetMentionedIssues($first: Int!, $after: String) {
|
|
1233
1233
|
issues(
|
|
1234
1234
|
first: $first
|
|
@@ -1249,7 +1249,7 @@ OR comment ~ currentUser() OR summary ~ currentUser() OR description ~ currentUs
|
|
|
1249
1249
|
}]
|
|
1250
1250
|
}
|
|
1251
1251
|
){
|
|
1252
|
-
${
|
|
1252
|
+
${Fe}
|
|
1253
1253
|
}
|
|
1254
1254
|
}
|
|
1255
1255
|
`,{first:d,after:c})).data)==null?void 0:m.issues}),await p(5,async(d,c)=>{var h;let m=(h=(await this.rawRequest(e,`
|
|
@@ -1275,7 +1275,7 @@ OR comment ~ currentUser() OR summary ~ currentUser() OR description ~ currentUs
|
|
|
1275
1275
|
){
|
|
1276
1276
|
nodes {
|
|
1277
1277
|
issue {
|
|
1278
|
-
${
|
|
1278
|
+
${yt}
|
|
1279
1279
|
}
|
|
1280
1280
|
}
|
|
1281
1281
|
pageInfo {
|
|
@@ -1284,4 +1284,10 @@ OR comment ~ currentUser() OR summary ~ currentUser() OR description ~ currentUs
|
|
|
1284
1284
|
}
|
|
1285
1285
|
}
|
|
1286
1286
|
}
|
|
1287
|
-
`,{first:d,after:c})).data)==null?void 0:h.comments;return m?{nodes:m.nodes.map(P=>P.issue),pageInfo:m.pageInfo}:void 0}),{data:l.items,pageInfo:{hasNextPage:!!u,endCursor:
|
|
1287
|
+
`,{first:d,after:c})).data)==null?void 0:h.comments;return m?{nodes:m.nodes.map(P=>P.issue),pageInfo:m.pageInfo}:void 0}),{data:l.items,pageInfo:{hasNextPage:!!u,endCursor:Xt(i,u)}}}async getIssues(s,e={}){var g;let{teams:r,projects:n,labels:o,cursor:a}=s,i=[];if(r&&r.length>0){let m=r.map(f=>`"${f}"`).join(", ");i.push(`team: { id: { in: [${m}] } }`)}if(n&&n.length>0){let m=n.map(f=>`"${f}"`).join(", ");i.push(`project: { id: { in: [${m}] } }`)}if(o&&o.length>0){let m=o.map(f=>`"${f}"`).join(", ");i.push(`labels: { name: { in: [${m}] } }`)}let u=i.length>0?`filter: { ${i.join(", ")} }`:"",l=`
|
|
1288
|
+
query GetIssues($first: Int!, $after: String) {
|
|
1289
|
+
issues(first: $first, after: $after${u?", ":""}${u}) {
|
|
1290
|
+
${Fe}
|
|
1291
|
+
}
|
|
1292
|
+
}
|
|
1293
|
+
`,d=(g=(await this.rawRequest(e,l,{first:Yt,after:a})).data)==null?void 0:g.issues;return d?{data:await Me(d.nodes.map(bt)),pageInfo:{hasNextPage:d.pageInfo.hasNextPage,endCursor:d.pageInfo.endCursor??null}}:{data:[],pageInfo:{hasNextPage:!1,endCursor:null}}}};var sr=t=>{let s={request:t==null?void 0:t.request};return{azureDevOps:new K({...s,...t==null?void 0:t.azureDevOps}),bitbucket:new X({...s,...t==null?void 0:t.bitbucket}),bitbucketServer:new Z({...s,...t==null?void 0:t.bitbucketServer}),github:new ee({...s,...t==null?void 0:t.github}),gitlab:new re({...s,...t==null?void 0:t.gitlab}),jira:new se({...s,...t==null?void 0:t.jira}),jiraServer:new ne({...s,...t==null?void 0:t.jiraServer}),linear:new je({...s,...t==null?void 0:t.linear}),trello:new oe({...s,...t==null?void 0:t.trello})}};var nr=(a=>(a.Conflicts="conflicts",a.Failure="failure",a.NotSet="notSet",a.Queued="queued",a.RejectedByPolicy="rejectedByPolicy",a.Succeeded="succeeded",a))(nr||{});var or=(e=>(e.Zero="0",e.One="1",e))(or||{}),ar=(e=>(e.PullRequest="pr",e.Issue="issue",e))(ar||{}),ir=(c=>(c.Azure="azure",c.AzureDevOpsServer="azureDevOpsServer",c.Github="github",c.GithubEnterprise="githubEnterprise",c.Gitlab="gitlab",c.GitlabSelfHosted="gitlabSelfHosted",c.Bitbucket="bitbucket",c.BitbucketServer="bitbucketServer",c.Jira="jira",c.JiraServer="jiraServer",c.Linear="linear",c.Trello="trello",c))(ir||{});var ur=(e=>(e.Completed="COMPLETED",e.NotPlanned="NOT_PLANNED",e))(ur||{});var ks=sr;
|