@gitkraken/provider-apis 0.14.2 → 0.15.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +30 -0
- package/dist/index.js +167 -147
- package/dist/providers/azureDevops/azureDevOps.d.ts +1 -1
- package/dist/providers/azureDevops/azureDevOpsTypes.d.ts +3 -1
- package/dist/providers/bitbucket/bitbucket.d.ts +1 -1
- package/dist/providers/bitbucketServer/bitbucketServer.d.ts +25 -1
- package/dist/providers/bitbucketServer/bitbucketServerTypes.d.ts +89 -0
- package/dist/providers/gitProvider.d.ts +9 -2
- package/dist/providers/github/github.d.ts +9 -5
- package/dist/providers/github/githubHelpers.d.ts +6 -5
- package/dist/providers/github/githubTypes.d.ts +13 -4
- package/dist/providers/gitlab/gitlab.d.ts +2 -1
- package/dist/providers/issueProvider.d.ts +9 -0
- package/dist/providers/jira/sharedTypes.d.ts +1 -0
- package/dist/types.d.ts +2 -0
- package/dist/utils.d.ts +10 -0
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";var dt=Object.create;var Y=Object.defineProperty;var ct=Object.getOwnPropertyDescriptor;var gt=Object.getOwnPropertyNames;var mt=Object.getPrototypeOf,ht=Object.prototype.hasOwnProperty;var T=(t,s)=>{for(var e in s)Y(t,e,{get:s[e],enumerable:!0})},ze=(t,s,e,r)=>{if(s&&typeof s=="object"||typeof s=="function")for(let n of gt(s))!ht.call(t,n)&&n!==e&&Y(t,n,{get:()=>s[n],enumerable:!(r=ct(s,n))||r.enumerable});return t};var ft=(t,s,e)=>(e=t!=null?dt(mt(t)):{},ze(s||!t||!t.__esModule?Y(e,"default",{value:t,enumerable:!0}):e,t)),Rt=t=>ze(Y({},"__esModule",{value:!0}),t);var $s={};T($s,{AzureDevOps:()=>j,AzureDevopsUtils:()=>ce,Bitbucket:()=>Q,BitbucketServer:()=>B,BitbucketServerUtils:()=>me,BitbucketUtils:()=>ge,GitHub:()=>F,GitHubUtils:()=>he,GitLab:()=>W,GitLabUtils:()=>fe,Jira:()=>K,JiraServer:()=>V,JiraUtils:()=>Re,Trello:()=>X,TrelloUtils:()=>Ie,Utils:()=>Ss,default:()=>Ds});module.exports=Rt($s);var Ye=require("js-base64");var C=100;var We=ft(require("node-fetch")),He=globalThis.fetch||We.default;var Je=t=>t.name==="fetch";var It=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 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=>Je(t)?async({url:s,...e})=>{let r=await t(s,e);return It(r)}:t;var E=class{constructor(s){this.config={...s,request:be((s==null?void 0:s.request)||He)}}updateConfig(s){this.config={...this.config,...s,request:s.request?be(s.request):this.config.request}}},v=class extends E{};var m=(t,s)=>{let e={};return t&&(e.Authorization=`${s?"Basic":"Bearer"} ${t}`),e};var w=(t,s={})=>m(s.token||t.token,s.isPAT||t.isPAT),Ke=t=>t.url.replace("/_apis/git/repositories/","/_git/").replace(`/${t.repository.project.id}/`,`/${encodeURIComponent(t.repository.project.name)}/`).replace(`/${t.repository.id}/`,`/${encodeURIComponent(t.repository.name)}/`).replace("/pullRequests/","/pullrequest/");var Ve={APPROVED:0,COMMENTED:1,REVIEW_REQUESTED:2,CHANGES_REQUESTED:3},N=t=>!t||t.length===0?null:t.reduce((s,e)=>Ve[e.state]>Ve[s]?e.state:s,"APPROVED");var Xe="https://app.vssps.visualstudio.com/_apis",q="https://dev.azure.com",bt={active:"OPEN",completed:"MERGED",abandoned:"CLOSED"},yt={10:"APPROVED",5:"APPROVED",0:"REVIEW_REQUESTED",[-5]:"CHANGES_REQUESTED",[-10]:"CHANGES_REQUESTED"},ye=t=>({id:t.id,name:t.displayName,username:t.uniqueName||t.displayName,email:null,avatarUrl:t.imageUrl,url:null}),se=t=>t.startsWith("refs/heads/")?t.replace("refs/heads/",""):t,te=t=>{var e;let s=t.reviewers.filter(r=>r.vote!==0).map(r=>({reviewer:ye(r),state:yt[r.vote]||"REVIEW_REQUESTED"}));return{id:t.pullRequestId.toString(),title:t.title,number:t.codeReviewId,state:bt[t.status],isDraft:t.isDraft,commentCount:null,upvoteCount:null,author:ye(t.createdBy),createdDate:new Date(t.creationDate),updatedDate:new Date(t.closedDate||t.creationDate),closedDate:t.closedDate?new Date(t.closedDate):null,mergedDate:t.closedDate&&t.status==="completed"?new Date(t.closedDate):null,repository:{name:t.repository.name,project:t.repository.project.name,owner:{login:void 0},remoteInfo:null},headCommit:{buildStatuses:null},baseRef:{name:se(t.targetRefName),oid:t.lastMergeTargetCommit.commitId},headRef:{name:se(t.sourceRefName),oid:t.lastMergeSourceCommit.commitId},url:Ke(t),assignees:t.reviewers.map(ye),reviews:s,reviewDecision:N(s),additions:null,deletions:null,fileCount:null,commitCount:null,headRepository:null,mergeableState:"UNKNOWN",labels:((e=t.labels)==null?void 0:e.map(r=>({color:null,description:null,id:r.id,name:r.name})))??[]}},Ze=(t,s)=>({id:s.id,name:s.name,namespace:t,project:s.project.name,webUrl:s.webUrl,httpsUrl:s.remoteUrl,sshUrl:s.sshUrl,defaultBranch:s.defaultBranch?{name:se(s.defaultBranch)}:null,permission:null}),Pt=(t,s)=>{var i,u;let e=t.fields,r=e["System.AssignedTo"],n=e["System.State"],a=e["System.WorkItemType"],o;return n&&a&&(o=(i=s[a])==null?void 0:i[n]),{id:t.id.toString(),number:t.id.toString(),title:e["System.Title"],commentCount:e["System.CommentCount"],author:{avatarUrl:e["System.CreatedBy"]._links.avatar.href,email:null,id:e["System.CreatedBy"].id,name:e["System.CreatedBy"].uniqueName,username:e["System.CreatedBy"].displayName,url:null},closedDate:e["Microsoft.VSTS.Common.ClosedDate"]?new Date(e["Microsoft.VSTS.Common.ClosedDate"]):null,createdDate:new Date(e["System.CreatedDate"]),updatedDate:new Date(e["System.ChangedDate"]),url:t._links.html.href,assignees:r?[{avatarUrl:r._links.avatar.href,email:null,id:r.id,name:r.uniqueName,username:r.displayName,url:null}]:[],description:null,state:{name:(o==null?void 0:o.title)||n,color:null},type:e["System.WorkItemType"],repository:null,upvoteCount:0,labels:((u=t.fields["System.Tags"])==null?void 0:u.split(";").map(l=>({color:null,description:null,id:null,name:l.trim()})))??[]}},j=class extends E{async getCurrentUser(s={}){if(s.isPAT||this.config.isPAT)throw new Error("Azure DevOps does not support PATs for this function.");let e=await this.config.request({url:`${Xe}/profile/profiles/me`,headers:w(this.config,s)});return{data:{id:e.body.id,name:e.body.displayName,username:e.body.displayName,email:e.body.emailAddress,avatarUrl:null,url:null}}}async getCurrentUserForInstance(s,e={}){let n=(await this.config.request({url:`${q}/${encodeURIComponent(s.namespace)}/_apis/ConnectionData`,headers:w(this.config,e)})).body.authorizedUser;if(n.providerDisplayName==="Anonymous")throw new Error("Current user not found.");return{data:{id:n.id,name:n.providerDisplayName,username:n.providerDisplayName,email:n.properties.Account.$value,avatarUrl:null}}}async getUserForCommit(s,e={}){if(!s.repo.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let n=(await this.config.request({url:`${q}/${encodeURIComponent(s.repo.namespace)}/${encodeURIComponent(s.repo.project)}/_apis/git/repositories/${encodeURIComponent(s.repo.name)}/commits/${s.oid}`,headers:w(this.config,e)})).body.author;return{data:{name:n.name,email:n.email,avatarUrl:n.imageUrl}}}async getOrgsForUser(s,e={}){return{data:(await this.config.request({url:`${Xe}/accounts?memberId=${s.userId}&api-version=6.0`,headers:w(this.config,e)})).body.value.map(n=>({id:n.accountId,name:n.accountName}))}}async getAzureProjects(s,e={}){let r=new URL(`${q}/${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:w(this.config,e)}),a=n.headers["x-ms-continuationtoken"];return{pageInfo:{hasNextPage:!!a,endCursor:a||null},data:n.body.value.map(o=>({id:o.id,name:o.name,namespace:s.namespace}))}}async getAzureProjectScopeDescriptor(s,e={}){let{namespace:r,projectId:n}=s;return{data:{scope:(await this.config.request({url:`https://vssps.dev.azure.com/${encodeURIComponent(r)}/_apis/graph/descriptors/${n}?api-version=6.0`,headers:w(this.config,e)})).body.value}}}async getAccountsForAzureProject(s,e={}){let{namespace:r,projectScopeDescriptor:n}=s,a=new URL(`https://vssps.dev.azure.com/${encodeURIComponent(r)}/_apis/graph/users`);return n&&a.searchParams.set("scopeDescriptor",n),{data:(await this.config.request({url:a.toString(),headers:w(this.config,e)})).body.value.map(i=>{var u;return{id:Ye.Base64.decode(i.descriptor.replace(/.+?\./,"")),name:i.displayName,username:i.displayName,email:i.mailAddress,avatarUrl:(u=i._links.avatar)==null?void 0:u.href}})}}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:`${q}/${encodeURIComponent(s.namespace)}/${encodeURIComponent(s.project)}/_apis/git/repositories/${encodeURIComponent(s.name)}`,headers:w(this.config,e)});return{data:Ze(s.namespace,r.body)}}async getRepos(s,e={}){let r=[],n=[];return await Promise.all(s.map(async a=>{try{let o=await this.getRepo(a,e);r.push(o.data)}catch(o){n.push({input:a,error:o})}})),{data:r,errors:n}}async getReposForAzureProject(s,e={}){if(!s.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');return{data:(await this.config.request({url:`${q}/${encodeURIComponent(s.namespace)}/${encodeURIComponent(s.project)}/_apis/git/repositories`,headers:w(this.config,e)})).body.value.map(n=>Ze(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(`${q}/${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 a=await this.config.request({url:n.toString(),headers:w(this.config,r)}),o=a.headers["x-ms-continuationtoken"];return{pageInfo:{hasNextPage:!!o,endCursor:o||null},data:a.body.value.map(i=>({name:se(i.name),commit:{oid:i.objectId,authoredDate:null,committedDate:null}}))}}async getBranches(s,e={}){return this.getRefs("heads",s,e)}async getTags(s,e={}){return this.getRefs("tags",s,e)}async getPullRequestsForRepoBase(s,e={},r=100){let{page:n,repo:a,assigneeLogins:o,authorLogin:i}=s||{},u=n||1;if(!a.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let l="searchCriteria.status=1";return o&&o.length&&(l+=`&searchCriteria.reviewerId=${o[0]}`),i&&(l+=`&searchCriteria.creatorId=${i}`),await this.config.request({url:`${e.baseUrl||q}/${encodeURIComponent(a.namespace)}/${encodeURIComponent(a.project||"")}/_apis/git/repositories/${encodeURIComponent(a.name)}/pullRequests?${l}&%24top=${r}&%24skip=${(u-1)*r}`,headers:w(this.config,e)})}async getPullRequestsForRepo(s,e={}){let n=s.page||1,a=await this.getPullRequestsForRepoBase(s,e,100);return{pageInfo:{hasNextPage:a.body.value.length===100,nextPage:n+1},data:a.body.value.map(te)}}async getPullRequestsForRepos(s,e={}){if(!s.repos.every(a=>a.project))throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let{repos:r}=s||{},n=[];return await Promise.all(r.map(async a=>{try{(await this.getPullRequestsForRepoBase({repo:a,...s},e)).body.value.forEach(i=>{n.push(te(i))})}catch(o){if(o.statusCode!==404&&o.statusCode!==401)throw o}})),{data:n}}async getPullRequestsForProjectBase(s,e={},r=100){let{namespace:n,project:a,page:o,assigneeLogins:i,authorLogin:u}=s,l=o||1,p=new URL(`${e.baseUrl||q}/${encodeURIComponent(n)}/${encodeURIComponent(a)}/_apis/git/pullRequests`);return p.searchParams.set("searchCriteria.status","1"),p.searchParams.set("$top",r.toString()),p.searchParams.set("$skip",((l-1)*r).toString()),i&&i.length&&p.searchParams.set("searchCriteria.reviewerId",i[0]),u&&p.searchParams.set("searchCriteria.creatorId",u),await this.config.request({url:p.toString(),headers:w(this.config,e)})}async getPullRequestsForProject(s,e={}){let n=s.page||1,a=await this.getPullRequestsForProjectBase(s,e,100);return{pageInfo:{hasNextPage:a.body.value.length===100,nextPage:n+1},data:a.body.value.map(te)}}async getPullRequestsForProjects(s,e={}){let{projects:r}=s||{},n=[];return await Promise.all(r.map(async a=>{try{(await this.getPullRequestsForProjectBase({...a,...s},e)).body.value.forEach(i=>{n.push(te(i))})}catch(o){if(o.statusCode!==404&&o.statusCode!==401)throw o}})),{data:n}}async getAzurePullRequestLastMergeStatus(s,e={}){if(!s.repo.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let{repo:{namespace:r,project:n,name:a},pullRequestId:o}=s,i=await this.config.request({url:`${e.baseUrl||q}/${encodeURIComponent(r)}/${encodeURIComponent(n||"")}/_apis/git/repositories/${a}/pullrequests/${o}?includeCommits=true?api-version=6.0`,headers:{...w(this.config,e)}});if(!i.body.mergeStatus)throw new Error("Could not fetch pull request");return{data:i.body.mergeStatus}}async updatePullRequest(s,e,r,n){let{namespace:a,project:o,name:i}=s;return await this.config.request({method:"PATCH",url:`${n.baseUrl||q}/${encodeURIComponent(a)}/${encodeURIComponent(o||"")}/_apis/git/repositories/${i}/pullrequests/${e}?api-version=6.0`,body:r,headers:{...w(this.config,n),"Content-Type":"application/json"}})}async closePullRequest(s,e={}){if(!s.repo.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let{repo:r,pullRequestId:n}=s,a={status:"abandoned"};if(!(await this.updatePullRequest(r,n,JSON.stringify(a),e)).body.status)throw new Error("Could not close pull request")}async mergePullRequest(s,e={}){if(!s.repo.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let{repo:r,pullRequestId:n,expectedSourceSha:a,mergeStrategy:o}=s,i;switch(o){case"MERGE_COMMIT":{i="noFastForward";break}case"REBASE":{i="rebase";break}case"REBASE_THEN_MERGE_COMMIT":{i="rebaseMerge";break}case"SQUASH":{i="squash";break}}let u={completionOptions:{mergeStrategy:i},lastMergeSourceCommit:{commitId:a},status:"completed"};if(!(await this.updatePullRequest(r,n,JSON.stringify(u),e)).body.status)throw new Error("Could not merge pull request")}async addPullRequestLabel(s,e={}){let{repo:{namespace:r,project:n,name:a},pullRequestId:o,labelName:i}=s;if(!n)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let u={name:i};if(!(await this.config.request({method:"POST",url:`${e.baseUrl||q}/${encodeURIComponent(r)}/${encodeURIComponent(n||"")}/_apis/git/repositories/${a}/pullrequests/${o}/labels?api-version=6.0`,body:JSON.stringify(u),headers:{...w(this.config,e),"Content-Type":"application/json"}})).body.id)throw new Error("Could not add pull request label")}async removePullRequestLabel(s,e={}){let{repo:{namespace:r,project:n,name:a},pullRequestId:o,labelNameOrId:i}=s;if(!n)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');await this.config.request({method:"DELETE",url:`${e.baseUrl||q}/${encodeURIComponent(r)}/${encodeURIComponent(n||"")}/_apis/git/repositories/${a}/pullrequests/${o}/labels/${encodeURIComponent(i)}?api-version=6.0`,headers:{...w(this.config,e)}})}async setPullRequestAsDraft(s,e={}){if(!s.repo.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let{repo:r,pullRequestId:n,isDraft:a}=s,o={isDraft:a};if(!(await this.updatePullRequest(r,n,JSON.stringify(o),e)).body.status)throw new Error("Could not set the pull request as draft")}async addPullRequestReviewer(s,e={}){if(!s.repo.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let{repo:{namespace:r,project:n,name:a},pullRequestId:o,reviewerId:i,isRequired:u}=s,l={id:i,isRequired:u};if(!(await this.config.request({method:"PUT",url:`${e.baseUrl||q}/${encodeURIComponent(r)}/${encodeURIComponent(n||"")}/_apis/git/repositories/${a}/pullrequests/${o}/reviewers/${i}?api-version=6.0`,body:JSON.stringify(l),headers:{...w(this.config,e),"Content-Type":"application/json"}})).body.id)throw new Error("Could not add pull request reviewer")}async removePullRequestReviewer(s,e={}){if(!s.repo.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let{repo:{namespace:r,project:n,name:a},pullRequestId:o,reviewerId:i}=s;await this.config.request({method:"DELETE",url:`${e.baseUrl||q}/${encodeURIComponent(r)}/${encodeURIComponent(n||"")}/_apis/git/repositories/${a}/pullrequests/${o}/reviewers/${i}?api-version=6.0`,headers:{...w(this.config,e),Accept:"application/json"}})}async getIssuesForAzureProject(s,e={}){let{page:r,assigneeLogins:n,authorLogin:a,mentionLogin:o,statusByWorkItemIdByStatusId:i}=s||{},u=r||1,l=200,p=["[Microsoft.VSTS.Common.ClosedDate] = ''","[System.TeamProject] = @project","[Microsoft.VSTS.Common.ResolvedDate] = ''"];a&&p.push(`[System.CreatedBy] = '${a.replace("'","''")}'`),n&&n[0]&&p.push(`[System.AssignedTo] = '${n[0].replace("'","''")}'`),o&&p.push("[System.Id] IN (@recentMentions)");let d=`Select [Microsoft.VSTS.Common.ClosedDate], [Microsoft.VSTS.Common.ResolvedDate] From WorkItems Where ${p.join(" AND ")} order by [System.CreatedDate] desc`,c=await this.config.request({url:`${e.baseUrl||q}/${encodeURIComponent(s.namespace)}/${encodeURIComponent(s.project)}/_apis/wit/wiql?api-version=6.0`,body:JSON.stringify({query:d}),method:"POST",headers:{...w(this.config,e),"Content-Type":"application/json"}}),g=c.body.workItems.slice((u-1)*l,l*u).map(h=>h.id);if(g.length==0)return{pageInfo:{hasNextPage:!1,nextPage:null},data:[]};let R=await this.config.request({url:`${e.baseUrl||q}/${encodeURIComponent(s.namespace)}/${encodeURIComponent(s.project)}/_apis/wit/workitemsbatch?api-version=6.0`,body:JSON.stringify({ids:g,$expand:"Links"}),method:"POST",headers:{...w(this.config,e),"Content-Type":"application/json"}});return{pageInfo:{hasNextPage:c.body.workItems.length>l*u,nextPage:u+1},data:R.body.value.map(h=>Pt(h,i||{}))}}async updateIssue(s,e,r,n,a={}){return await this.config.request({method:"PATCH",url:`${a.baseUrl||q}/${encodeURIComponent(s)}/${encodeURIComponent(e||"")}/_apis/wit/workitems/${r}?api-version=6.0`,body:JSON.stringify(n),headers:{...w(this.config,a),"Content-Type":"application/json-patch+json"}})}async setIssueStatus(s,e={}){var l;if(!s.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let{namespace:r,project:n,issueId:a,status:o}=s,i=[{op:"add",path:"/fields/System.State",value:o}];if(!((l=(await this.updateIssue(r,n,a,i,e)).body.fields)!=null&&l["System.State"]))throw new Error("Could not set issue status")}async setIssueAssignee(s,e={}){var l;if(!s.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let{namespace:r,project:n,issueId:a,assigneeNameOrEmail:o}=s,i=[{op:"add",path:"/fields/System.AssignedTo",value:o??""}];if(!((l=(await this.updateIssue(r,n,a,i,e)).body.fields)!=null&&l["System.State"]))throw new Error("Could not set issue assignee")}async setIssueLabels(s,e={}){var l;let{namespace:r,project:n,issueId:a,tagNames:o}=s,i=[{op:"replace",path:"/fields/System.Tags",value:o.join(";")}];if(!((l=(await this.updateIssue(r,n,a,i,e)).body.fields)!=null&&l["System.Tags"]))throw new Error("Could not set issue tags")}async getIssueTypesForAzureProject(s,e={}){if(!s.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let{namespace:r,project:n}=s;return{data:(await this.config.request({url:`${e.baseUrl||q}/${encodeURIComponent(r)}/${encodeURIComponent(n||"")}/_apis/wit/workitemtypes?api-version=6.0`,headers:{...w(this.config,e)}})).body.value}}async getLabelsForProject(s,e={}){let{namespace:r,project:n}=s;return{data:(await this.config.request({url:`${e.baseUrl||q}/${encodeURIComponent(r)}/${encodeURIComponent(n||"")}/_apis/wit/tags?api-version=6.0`,headers:{...w(this.config,e)}})).body.value.map(o=>({color:null,description:null,id:o.id,name:o.name}))}}};var S=(t,s={})=>m(s.token||t.token,s.isPAT||t.isPAT);var $="https://api.bitbucket.org/2.0",wt={OPEN:"OPEN",MERGED:"MERGED",DECLINED:"CLOSED"},tt=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}),et=t=>{var s,e;return{id:t.uuid,namespace:t.workspace.slug,name:t.slug,webUrl:t.links.html.href,httpsUrl:((s=t.links.clone.find(r=>r.name==="https"))==null?void 0:s.href)??null,sshUrl:((e=t.links.clone.find(r=>r.name==="ssh"))==null?void 0:e.href)??null,defaultBranch:{name:t.mainbranch.name},permission:null}},qe=t=>{let s=t.id;return{id:s.toString(),title:t.title,number:s,state:wt[t.state],isDraft:!1,commentCount:t.comment_count,upvoteCount:null,author:tt(t.author),createdDate:new Date(t.created_on),updatedDate:new Date(t.updated_on),closedDate:null,mergedDate:null,repository:{name:t.source.repository.name,owner:{login:void 0},remoteInfo:null},headCommit:{buildStatuses:null},baseRef:{name:t.destination.branch.name,oid:t.destination.commit.hash},headRef:{name:t.source.branch.name,oid:t.source.commit.hash},url:t.links.html.href,assignees:null,reviews:null,reviewDecision:null,additions:null,deletions:null,fileCount:null,commitCount:null,headRepository:null,mergeableState:"UNKNOWN"}},Q=class extends E{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={}){let e=await this.config.request({url:`${$}/user`,headers:S(this.config,s)});return{data:tt(e.body)}}async getUserForCommit(s,e={}){var o;let n=(await this.config.request({url:`${$}/repositories/${s.repo.namespace}/${s.repo.name}/commit/${s.oid}`,headers:S(this.config,e)})).body.author,a=n.raw.match(/([^<]+)<(.+)>/);return{data:{name:a?a[1].trim():null,email:a?a[2]:null,avatarUrl:((o=n.user)==null?void 0:o.links.avatar.href)||null}}}async getRepo(s,e={}){let r=await this.config.request({url:`${$}/repositories/${s.namespace}/${s.name}`,headers:S(this.config,e)});return{data:et(r.body)}}async getRepos(s,e={}){let r=[],n=[];return await Promise.all(s.map(async a=>{try{let o=await this.getRepo(a,e);r.push(o.data)}catch(o){n.push({input:a,error:o})}})),{data:r,errors:n}}async getReposForCurrentUser(s={},e={}){let r=new URL(`${$}/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:S(this.config,e)}),a=!!n.body.next,o=null;return n.body.next&&(o=new URL(n.body.next).searchParams.get("after")),{pageInfo:{hasNextPage:a,endCursor:o},data:n.body.values.map(et)}}async getBranches(s,e={}){var o;let r=new URL(`${$}/repositories/${s.repo.namespace}/${s.repo.name}/refs/branches`);r.searchParams.set("page",((o=s.page)==null?void 0:o.toString())||"1"),r.searchParams.set("pagelen",C.toString());let n=await this.config.request({url:r.toString(),headers:S(this.config,e)}),a=!!n.body.next;return{pageInfo:{hasNextPage:a,nextPage:a?n.body.page+1:null},data:n.body.values.map(i=>{let u=new Date(i.target.date);return{name:i.name,commit:{oid:i.target.hash,authoredDate:u,committedDate:u}}})}}async getTags(s,e={}){let r=new URL(`${$}/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:S(this.config,e)}),a=!!n.body.next,o=null;return n.body.next&&(o=new URL(n.body.next).searchParams.get("page")),{pageInfo:{hasNextPage:a,endCursor:o},data:n.body.values.map(i=>{let u=new Date(i.target.date);return{name:i.name,commit:{oid:i.target.hash,authoredDate:u,committedDate:u}}})}}async getPullRequestsForUser(s,e={}){var o;let r=new URL(`${$}/pullrequests/${s.userId}`);r.searchParams.set("page",((o=s.page)==null?void 0:o.toString())||"1"),r.searchParams.set("pagelen","50");let n=await this.config.request({url:`${$}/pullrequests/${s.userId}`,headers:S(this.config,e)}),a=!!n.body.next;return{pageInfo:{hasNextPage:a,nextPage:a?n.body.page+1:null},data:n.body.values.map(qe)}}async getPullRequestsForRepoBase(s,e={}){var n;let r=new URL(`${$}/repositories/${encodeURI(s.repo.namespace)}/${encodeURI(s.repo.name)}/pullrequests?state=OPEN`);return r.searchParams.set("page",((n=s.page)==null?void 0:n.toString())||"1"),r.searchParams.set("pagelen","50"),await this.config.request({url:r.toString(),headers:S(this.config,e)})}async getPullRequestsForRepo(s,e={}){let r=[],n=await this.getPullRequestsForRepoBase(s,e);n.body.values.forEach(o=>{if(s.authorLogin&&o.author.uuid!==s.authorLogin)return null;r.push(qe(o))});let a=!!n.body.next;return{pageInfo:{hasNextPage:a,nextPage:a?n.body.page+1:null},data:r}}async getPullRequestsForRepos(s,e={}){let r=[];return await Promise.all(s.repos.map(async n=>{try{(await this.getPullRequestsForRepoBase({repo:n,...s},e)).body.values.forEach(o=>{if(s.authorLogin&&o.author.uuid!==s.authorLogin)return null;r.push(qe(o))})}catch(a){if(a.statusCode!==404&&a.statusCode!==401)throw a}})),{data:r}}async closePullRequest(s,e={}){let{repo:{namespace:r,name:n},pullRequestId:a}=s;if(!(await this.config.request({method:"POST",url:`${$}/repositories/${r}/${n}/pullrequests/${a}/decline`,headers:S(this.config,e)})).body.title)throw new Error("Could not close pull request")}async mergePullRequest(s,e={}){let{repo:{namespace:r,name:n},pullRequestId:a,mergeStrategy:o}=s,i;switch(o){case"MERGE_COMMIT":{i="merge_commit";break}case"FAST_FORWARD":{i="fast_forward";break}case"SQUASH":{i="squash";break}}let u={merge_strategy:i,type:"pullrequest"};if(!(await this.config.request({method:"POST",url:`${$}/repositories/${r}/${n}/pullrequests/${a}/merge`,body:JSON.stringify(u),headers:{...S(this.config,e),"Content-Type":"application/json"}})).body.title)throw new Error("Could not merge pull request")}async setPullRequestReviewers(s,e={}){let{repo:{namespace:r,name:n},pullRequestId:a,reviewerUsernames:o}=s,i={reviewers:o.map(l=>({username:l}))};if(!(await this.config.request({method:"PUT",url:`${$}/repositories/${r}/${n}/pullrequests/${a}`,body:JSON.stringify(i),headers:{...S(this.config,e),"Content-Type":"application/json"}})).body.title)throw new Error("Could not set pull request reviewers")}};var B=class extends v{getBaseUrl(s){let e=s.baseUrl||this.config.baseUrl;if(!e)throw new Error('Bitbucket Server requires "baseUrl"');return e}getRequestHeaders(s){return m(s.token||this.config.token)}async getRepo(s,e={}){var n,a,o;let r=await this.config.request({url:`${this.getBaseUrl(e)}/projects/${s.namespace}/repos/${s.name}`,headers:this.getRequestHeaders(e)});return{data:{id:r.body.id.toString(),namespace:r.body.project.key,name:r.body.slug,webUrl:((n=r.body.links.self[0])==null?void 0:n.href)??null,httpsUrl:((a=r.body.links.clone.find(i=>i.name==="https"))==null?void 0:a.href)??null,sshUrl:((o=r.body.links.clone.find(i=>i.name==="ssh"))==null?void 0:o.href)??null,defaultBranch:null,permission:null}}}async getRepos(s,e={}){let r=[],n=[];return await Promise.all(s.map(async a=>{try{let o=await this.getRepo(a,e);r.push(o.data)}catch(o){n.push({input:a,error:o})}})),{data:r,errors:n}}async closePullRequest(s,e){let{repo:{namespace:r,name:n},pullRequestId:a,version:o}=s;if(!(await this.config.request({method:"POST",url:`${this.getBaseUrl(e)}/projects/${r}/repos/${n}/pull-requests/${a}/decline`,body:JSON.stringify({version:o}),headers:{...this.getRequestHeaders(e),"Content-Type":"application/json"}})).body.title)throw new Error("Could not close pull request")}async mergePullRequest(s,e){let{repo:{namespace:r,name:n},pullRequestId:a,mergeStrategyId:o,version:i}=s;if(!(await this.config.request({method:"POST",url:`${this.getBaseUrl(e)}/projects/${r}/repos/${n}/pull-requests/${a}/merge`,body:JSON.stringify({strategyId:o,version:i}),headers:{...this.getRequestHeaders(e),"Content-Type":"application/json"}})).body.title)throw new Error("Could not merge pull request")}async getMergeStrategies(s){let e=await this.config.request({url:`${this.getBaseUrl(s)}/admin/pull-requests/git`,headers:{...this.getRequestHeaders(s),"Content-Type":"application/json"}});return{data:{defaultStrategy:e.body.mergeConfig.defaultStrategy,strategies:e.body.mergeConfig.strategies}}}async setPullRequestReviewers(s,e={}){let{repo:{namespace:r,name:n},pullRequestId:a,reviewerUsernames:o,version:i}=s,u={reviewers:o.map(p=>({user:{name:p}})),version:i};if(!(await this.config.request({method:"PUT",url:`${this.getBaseUrl(e)}/projects/${r}/repos/${n}/pull-requests/${a}`,body:JSON.stringify(u),headers:{...this.getRequestHeaders(e),"Content-Type":"application/json"}})).body.title)throw new Error("Could not set pull request reviewers")}};var Ce="https://api.github.com",qt=`${Ce}/graphql`,ne=`
|
|
1
|
+
"use strict";var Rt=Object.create;var se=Object.defineProperty;var It=Object.getOwnPropertyDescriptor;var bt=Object.getOwnPropertyNames;var yt=Object.getPrototypeOf,Pt=Object.prototype.hasOwnProperty;var x=(t,s)=>{for(var e in s)se(t,e,{get:s[e],enumerable:!0})},Je=(t,s,e,r)=>{if(s&&typeof s=="object"||typeof s=="function")for(let n of bt(s))!Pt.call(t,n)&&n!==e&&se(t,n,{get:()=>s[n],enumerable:!(r=It(s,n))||r.enumerable});return t};var wt=(t,s,e)=>(e=t!=null?Rt(yt(t)):{},Je(s||!t||!t.__esModule?se(e,"default",{value:t,enumerable:!0}):e,t)),St=t=>Je(se({},"__esModule",{value:!0}),t);var Ts={};x(Ts,{AzureDevOps:()=>B,AzureDevopsUtils:()=>fe,Bitbucket:()=>z,BitbucketServer:()=>H,BitbucketServerUtils:()=>Ie,BitbucketUtils:()=>Re,GitHub:()=>W,GitHubUtils:()=>be,GitLab:()=>V,GitLabUtils:()=>ye,Jira:()=>Z,JiraServer:()=>Y,JiraUtils:()=>Pe,Trello:()=>ee,TrelloUtils:()=>we,Utils:()=>Os,default:()=>As});module.exports=St(Ts);var rt=require("js-base64");var D=100;var Ve=wt(require("node-fetch")),Ke=globalThis.fetch||Ve.default;var Xe=t=>t.name==="fetch";var qt=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 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},Se=t=>Xe(t)?async({url:s,...e})=>{let r=await t(s,e);return qt(r)}:t;var U=class{constructor(s){this.config={...s,request:Se((s==null?void 0:s.request)||Ke)}}updateConfig(s){this.config={...this.config,...s,request:s.request?Se(s.request):this.config.request}}},L=class extends U{};var R=(t,s)=>{let e={};return t&&(e.Authorization=`${s?"Basic":"Bearer"} ${t}`),e},Ze=t=>t?t.reduce((s,e)=>(s[e]=!0,s),{}):void 0,k=(t,s,e)=>!t||s.some(r=>t[r])?e:"";var w=(t,s={})=>R(s.token||t.token,s.isPAT||t.isPAT),Ye=t=>t.url.replace("/_apis/git/repositories/","/_git/").replace(`/${t.repository.project.id}/`,`/${encodeURIComponent(t.repository.project.name)}/`).replace(`/${t.repository.id}/`,`/${encodeURIComponent(t.repository.name)}/`).replace("/pullRequests/","/pullrequest/");var et={APPROVED:0,COMMENTED:1,REVIEW_REQUESTED:2,CHANGES_REQUESTED:3},_=t=>!t||t.length===0?null:t.reduce((s,e)=>et[e.state]>et[s]?e.state:s,"APPROVED");var tt="https://app.vssps.visualstudio.com/_apis",S="https://dev.azure.com",Dt={active:"OPEN",completed:"MERGED",abandoned:"CLOSED"},Ct={10:"APPROVED",5:"APPROVED",0:"REVIEW_REQUESTED",[-5]:"CHANGES_REQUESTED",[-10]:"CHANGES_REQUESTED"},qe=t=>({id:t.id,name:t.displayName,username:t.uniqueName||t.displayName,email:null,avatarUrl:t.imageUrl,url:null}),ne=t=>t.startsWith("refs/heads/")?t.replace("refs/heads/",""):t,re=t=>{var e;let s=t.reviewers.filter(r=>r.vote!==0).map(r=>({reviewer:qe(r),state:Ct[r.vote]||"REVIEW_REQUESTED"}));return{id:t.pullRequestId.toString(),title:t.title,number:t.codeReviewId,state:Dt[t.status],isDraft:t.isDraft,commentCount:null,upvoteCount:null,author:qe(t.createdBy),createdDate:new Date(t.creationDate),updatedDate:new Date(t.closedDate||t.creationDate),closedDate:t.closedDate?new Date(t.closedDate):null,mergedDate:t.closedDate&&t.status==="completed"?new Date(t.closedDate):null,repository:{id:t.repository.id,name:t.repository.name,project:t.repository.project.name,owner:{login:void 0},remoteInfo:null},headCommit:{buildStatuses:null},baseRef:{name:ne(t.targetRefName),oid:t.lastMergeTargetCommit.commitId},headRef:{name:ne(t.sourceRefName),oid:t.lastMergeSourceCommit.commitId},url:Ye(t),assignees:t.reviewers.map(qe),reviews:s,reviewDecision:_(s),additions:null,deletions:null,fileCount:null,commitCount:null,headRepository:null,mergeableState:"UNKNOWN",labels:((e=t.labels)==null?void 0:e.map(r=>({color:null,description:null,id:r.id,name:r.name})))??[]}},st=(t,s)=>({id:s.id,name:s.name,namespace:t,project:s.project.name,webUrl:s.webUrl,httpsUrl:s.remoteUrl,sshUrl:s.sshUrl,defaultBranch:s.defaultBranch?{name:ne(s.defaultBranch)}:null,permission:null}),vt=(t,s)=>{var i,u;let e=t.fields,r=e["System.AssignedTo"],n=e["System.State"],o=e["System.WorkItemType"],a;return n&&o&&(a=(i=s[o])==null?void 0:i[n]),{id:t.id.toString(),number:t.id.toString(),title:e["System.Title"],commentCount:e["System.CommentCount"],author:{avatarUrl:e["System.CreatedBy"]._links.avatar.href,email:null,id:e["System.CreatedBy"].id,name:e["System.CreatedBy"].uniqueName,username:e["System.CreatedBy"].displayName,url:null},closedDate:e["Microsoft.VSTS.Common.ClosedDate"]?new Date(e["Microsoft.VSTS.Common.ClosedDate"]):null,createdDate:new Date(e["System.CreatedDate"]),updatedDate:new Date(e["System.ChangedDate"]),url:t._links.html.href,assignees:r?[{avatarUrl:r._links.avatar.href,email:null,id:r.id,name:r.uniqueName,username:r.displayName,url:null}]:[],description:null,state:{name:(a==null?void 0:a.title)||n,color:null},type:e["System.WorkItemType"],repository:null,upvoteCount:0,labels:((u=t.fields["System.Tags"])==null?void 0:u.split(";").map(l=>({color:null,description:null,id:null,name:l.trim()})))??[]}},B=class extends U{async getCurrentUser(s={},e={}){if(e.isPAT||this.config.isPAT)throw new Error("Azure DevOps does not support PATs for this function.");let r=await this.config.request({url:`${tt}/profile/profiles/me`,headers:w(this.config,e)});return{data:{id:r.body.id,name:r.body.displayName,username:r.body.displayName,email:r.body.emailAddress,avatarUrl:null,url:null}}}async getCurrentUserForInstance(s,e={}){let n=(await this.config.request({url:`${S}/${encodeURIComponent(s.namespace)}/_apis/ConnectionData`,headers:w(this.config,e)})).body.authorizedUser;if(n.providerDisplayName==="Anonymous")throw new Error("Current user not found.");return{data:{id:n.id,name:n.providerDisplayName,username:n.providerDisplayName,email:n.properties.Account.$value,avatarUrl:null}}}async getUserForCommit(s,e={}){if(!s.repo.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let n=(await this.config.request({url:`${S}/${encodeURIComponent(s.repo.namespace)}/${encodeURIComponent(s.repo.project)}/_apis/git/repositories/${encodeURIComponent(s.repo.name)}/commits/${s.oid}`,headers:w(this.config,e)})).body.author;return{data:{name:n.name,email:n.email,avatarUrl:n.imageUrl}}}async getOrgsForUser(s,e={}){return{data:(await this.config.request({url:`${tt}/accounts?memberId=${s.userId}&api-version=6.0`,headers:w(this.config,e)})).body.value.map(n=>({id:n.accountId,name:n.accountName}))}}async getAzureProjects(s,e={}){let r=new URL(`${S}/${encodeURIComponent(s.namespace)}/_apis/projects`);r.searchParams.set("$top",D.toString()),s.cursor&&r.searchParams.set("$skip",s.cursor);let n=await this.config.request({url:r.toString(),headers:w(this.config,e)}),o=n.headers["x-ms-continuationtoken"];return{pageInfo:{hasNextPage:!!o,endCursor:o||null},data:n.body.value.map(a=>({id:a.id,name:a.name,namespace:s.namespace}))}}async getAzureProjectScopeDescriptor(s,e={}){let{namespace:r,projectId:n}=s;return{data:{scope:(await this.config.request({url:`https://vssps.dev.azure.com/${encodeURIComponent(r)}/_apis/graph/descriptors/${n}?api-version=6.0`,headers:w(this.config,e)})).body.value}}}async getAccountsForAzureProject(s,e={}){let{namespace:r,projectScopeDescriptor:n}=s,o=new URL(`https://vssps.dev.azure.com/${encodeURIComponent(r)}/_apis/graph/users`);return n&&o.searchParams.set("scopeDescriptor",n),{data:(await this.config.request({url:o.toString(),headers:w(this.config,e)})).body.value.map(i=>{var u;return{id:rt.Base64.decode(i.descriptor.replace(/.+?\./,"")),name:i.displayName,username:i.displayName,email:i.mailAddress,avatarUrl:(u=i._links.avatar)==null?void 0:u.href}})}}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:`${S}/${encodeURIComponent(s.namespace)}/${encodeURIComponent(s.project)}/_apis/git/repositories/${encodeURIComponent(s.name)}`,headers:w(this.config,e)});return{data:st(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:`${S}/${encodeURIComponent(s.namespace)}/${encodeURIComponent(s.project)}/_apis/git/repositories`,headers:w(this.config,e)})).body.value.map(n=>st(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(`${S}/${encodeURIComponent(e.repo.namespace)}/${encodeURIComponent(e.repo.project)}/_apis/git/repositories/${encodeURIComponent(e.repo.name)}/refs`);n.searchParams.set("filter",s),n.searchParams.set("$top",D.toString()),e.cursor&&n.searchParams.set("continuationToken",e.cursor);let o=await this.config.request({url:n.toString(),headers:w(this.config,r)}),a=o.headers["x-ms-continuationtoken"];return{pageInfo:{hasNextPage:!!a,endCursor:a||null},data:o.body.value.map(i=>({name:ne(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:`${e.baseUrl||S}/${encodeURIComponent(o.namespace)}/${encodeURIComponent(o.project||"")}/_apis/git/repositories/${encodeURIComponent(o.name)}/pullRequests?${l}&%24top=${r}&%24skip=${(u-1)*r}`,headers:w(this.config,e)})}async getPullRequestsForRepo(s,e={}){let n=s.page||1,o=await this.getPullRequestsForRepoBase(s,e,100);return{pageInfo:{hasNextPage:o.body.value.length===100,nextPage:n+1},data:o.body.value.map(re)}}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(re(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}=s,l=a||1,p=new URL(`${e.baseUrl||S}/${encodeURIComponent(n)}/${encodeURIComponent(o)}/_apis/git/pullRequests`);return p.searchParams.set("searchCriteria.status","1"),p.searchParams.set("$top",r.toString()),p.searchParams.set("$skip",((l-1)*r).toString()),i&&i.length&&p.searchParams.set("searchCriteria.reviewerId",i[0]),u&&p.searchParams.set("searchCriteria.creatorId",u),await this.config.request({url:p.toString(),headers:w(this.config,e)})}async getPullRequestsForProject(s,e={}){let n=s.page||1,o=await this.getPullRequestsForProjectBase(s,e,100);return{pageInfo:{hasNextPage:o.body.value.length===100,nextPage:n+1},data:o.body.value.map(re)}}async getPullRequestsForProjects(s,e={}){let{projects:r}=s||{},n=[];return await Promise.all(r.map(async o=>{try{(await this.getPullRequestsForProjectBase({...o,...s},e)).body.value.forEach(i=>{n.push(re(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:`${e.baseUrl||S}/${encodeURIComponent(r)}/${encodeURIComponent(n||"")}/_apis/git/repositories/${o}/pullrequests/${a}?includeCommits=true?api-version=6.0`,headers:{...w(this.config,e)}});if(!i.body.mergeStatus)throw new Error("Could not fetch pull request");return{data:i.body.mergeStatus}}async updatePullRequest(s,e,r,n){let{namespace:o,project:a,name:i}=s;return await this.config.request({method:"PATCH",url:`${n.baseUrl||S}/${encodeURIComponent(o)}/${encodeURIComponent(a||"")}/_apis/git/repositories/${i}/pullrequests/${e}?api-version=6.0`,body:r,headers:{...w(this.config,n),"Content-Type":"application/json"}})}async closePullRequest(s,e={}){if(!s.repo.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let{repo:r,pullRequestId:n}=s,o={status:"abandoned"};if(!(await this.updatePullRequest(r,n,JSON.stringify(o),e)).body.status)throw new Error("Could not close pull request")}async mergePullRequest(s,e={}){if(!s.repo.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let{repo:r,pullRequestId:n,expectedSourceSha:o,mergeStrategy:a}=s,i;switch(a){case"MERGE_COMMIT":{i="noFastForward";break}case"REBASE":{i="rebase";break}case"REBASE_THEN_MERGE_COMMIT":{i="rebaseMerge";break}case"SQUASH":{i="squash";break}}let u={completionOptions:{mergeStrategy:i},lastMergeSourceCommit:{commitId:o},status:"completed"};if(!(await this.updatePullRequest(r,n,JSON.stringify(u),e)).body.status)throw new Error("Could not merge pull request")}async addPullRequestLabel(s,e={}){let{repo:{namespace:r,project:n,name:o},pullRequestId:a,labelName:i}=s;if(!n)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let u={name:i};if(!(await this.config.request({method:"POST",url:`${e.baseUrl||S}/${encodeURIComponent(r)}/${encodeURIComponent(n||"")}/_apis/git/repositories/${o}/pullrequests/${a}/labels?api-version=6.0`,body:JSON.stringify(u),headers:{...w(this.config,e),"Content-Type":"application/json"}})).body.id)throw new Error("Could not add pull request label")}async removePullRequestLabel(s,e={}){let{repo:{namespace:r,project:n,name:o},pullRequestId:a,labelNameOrId:i}=s;if(!n)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');await this.config.request({method:"DELETE",url:`${e.baseUrl||S}/${encodeURIComponent(r)}/${encodeURIComponent(n||"")}/_apis/git/repositories/${o}/pullrequests/${a}/labels/${encodeURIComponent(i)}?api-version=6.0`,headers:{...w(this.config,e)}})}async setPullRequestAsDraft(s,e={}){if(!s.repo.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let{repo:r,pullRequestId:n,isDraft:o}=s,a={isDraft:o};if(!(await this.updatePullRequest(r,n,JSON.stringify(a),e)).body.status)throw new Error("Could not set the pull request as draft")}async addPullRequestReviewer(s,e={}){if(!s.repo.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let{repo:{namespace:r,project:n,name:o},pullRequestId:a,reviewerId:i,isRequired:u}=s,l={id:i,isRequired:u};if(!(await this.config.request({method:"PUT",url:`${e.baseUrl||S}/${encodeURIComponent(r)}/${encodeURIComponent(n||"")}/_apis/git/repositories/${o}/pullrequests/${a}/reviewers/${i}?api-version=6.0`,body:JSON.stringify(l),headers:{...w(this.config,e),"Content-Type":"application/json"}})).body.id)throw new Error("Could not add pull request reviewer")}async removePullRequestReviewer(s,e={}){if(!s.repo.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let{repo:{namespace:r,project:n,name:o},pullRequestId:a,reviewerId:i}=s;await this.config.request({method:"DELETE",url:`${e.baseUrl||S}/${encodeURIComponent(r)}/${encodeURIComponent(n||"")}/_apis/git/repositories/${o}/pullrequests/${a}/reviewers/${i}?api-version=6.0`,headers:{...w(this.config,e),Accept:"application/json"}})}async getIssuesForAzureProject(s,e={}){let{page:r,assigneeLogins:n,authorLogin:o,mentionLogin:a,statusByWorkItemIdByStatusId:i}=s||{},u=r||1,l=200,p=["[Microsoft.VSTS.Common.ClosedDate] = ''","[System.TeamProject] = @project","[Microsoft.VSTS.Common.ResolvedDate] = ''"];o&&p.push(`[System.CreatedBy] = '${o.replace("'","''")}'`),n&&n[0]&&p.push(`[System.AssignedTo] = '${n[0].replace("'","''")}'`),a&&p.push("[System.Id] IN (@recentMentions)");let d=`Select [Microsoft.VSTS.Common.ClosedDate], [Microsoft.VSTS.Common.ResolvedDate] From WorkItems Where ${p.join(" AND ")} order by [System.CreatedDate] desc`,c=await this.config.request({url:`${e.baseUrl||S}/${encodeURIComponent(s.namespace)}/${encodeURIComponent(s.project)}/_apis/wit/wiql?api-version=6.0`,body:JSON.stringify({query:d}),method:"POST",headers:{...w(this.config,e),"Content-Type":"application/json"}}),g=c.body.workItems.slice((u-1)*l,l*u).map(f=>f.id);if(g.length==0)return{pageInfo:{hasNextPage:!1,nextPage:null},data:[]};let m=await this.config.request({url:`${e.baseUrl||S}/${encodeURIComponent(s.namespace)}/${encodeURIComponent(s.project)}/_apis/wit/workitemsbatch?api-version=6.0`,body:JSON.stringify({ids:g,$expand:"Links"}),method:"POST",headers:{...w(this.config,e),"Content-Type":"application/json"}});return{pageInfo:{hasNextPage:c.body.workItems.length>l*u,nextPage:u+1},data:m.body.value.map(f=>vt(f,i||{}))}}async updateIssue(s,e,r,n,o={}){return await this.config.request({method:"PATCH",url:`${o.baseUrl||S}/${encodeURIComponent(s)}/${encodeURIComponent(e||"")}/_apis/wit/workitems/${r}?api-version=6.0`,body:JSON.stringify(n),headers:{...w(this.config,o),"Content-Type":"application/json-patch+json"}})}async setIssueStatus(s,e={}){var l;if(!s.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let{namespace:r,project:n,issueId:o,status:a}=s,i=[{op:"add",path:"/fields/System.State",value:a}];if(!((l=(await this.updateIssue(r,n,o,i,e)).body.fields)!=null&&l["System.State"]))throw new Error("Could not set issue status")}async setIssueAssignee(s,e={}){var l;if(!s.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let{namespace:r,project:n,issueId:o,assigneeNameOrEmail:a}=s,i=[{op:"add",path:"/fields/System.AssignedTo",value:a??""}];if(!((l=(await this.updateIssue(r,n,o,i,e)).body.fields)!=null&&l["System.State"]))throw new Error("Could not set issue assignee")}async setIssueLabels(s,e={}){var l;let{namespace:r,project:n,issueId:o,tagNames:a}=s,i=[{op:"replace",path:"/fields/System.Tags",value:a.join(";")}];if(!((l=(await this.updateIssue(r,n,o,i,e)).body.fields)!=null&&l["System.Tags"]))throw new Error("Could not set issue tags")}async getIssueTypesForAzureProject(s,e={}){if(!s.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let{namespace:r,project:n}=s;return{data:(await this.config.request({url:`${e.baseUrl||S}/${encodeURIComponent(r)}/${encodeURIComponent(n||"")}/_apis/wit/workitemtypes?api-version=6.0`,headers:{...w(this.config,e)}})).body.value}}async getLabelsForProject(s,e={}){let{namespace:r,project:n}=s;return{data:(await this.config.request({url:`${e.baseUrl||S}/${encodeURIComponent(r)}/${encodeURIComponent(n||"")}/_apis/wit/tags?api-version=6.0`,headers:{...w(this.config,e)}})).body.value.map(a=>({color:null,description:null,id:a.id,name:a.name}))}}};var v=(t,s={})=>R(s.token||t.token,s.isPAT||t.isPAT);var E="https://api.bitbucket.org/2.0",Ut={OPEN:"OPEN",MERGED:"MERGED",DECLINED:"CLOSED"},at=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}),nt=t=>{var s,e;return{id:t.uuid,namespace:t.workspace.slug,name:t.slug,webUrl:t.links.html.href,httpsUrl:((s=t.links.clone.find(r=>r.name==="https"))==null?void 0:s.href)??null,sshUrl:((e=t.links.clone.find(r=>r.name==="ssh"))==null?void 0:e.href)??null,defaultBranch:{name:t.mainbranch.name},permission:null}},Ce=t=>{let s=t.id;return{id:s.toString(),title:t.title,number:s,state:Ut[t.state],isDraft:!1,commentCount:t.comment_count,upvoteCount:null,author:at(t.author),createdDate:new Date(t.created_on),updatedDate:new Date(t.updated_on),closedDate:null,mergedDate:null,repository:{id:t.source.repository.uuid,name:t.source.repository.name,owner:{login:void 0},remoteInfo:null},headCommit:{buildStatuses:null},baseRef:{name:t.destination.branch.name,oid:t.destination.commit.hash},headRef:{name:t.source.branch.name,oid:t.source.commit.hash},url:t.links.html.href,assignees:null,reviews:null,reviewDecision:null,additions:null,deletions:null,fileCount:null,commitCount:null,headRepository:null,mergeableState:"UNKNOWN"}},z=class extends U{async refreshToken(s){return{data:(await this.config.request({url:"https://bitbucket.org/site/oauth2/access_token",method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded",Authorization:`Basic ${s.base64ClientIDColonClientSecret}`},body:`grant_type=refresh_token&refresh_token=${s.refreshToken}`})).body}}async getCurrentUser(s={},e={}){let r=await this.config.request({url:`${E}/user`,headers:v(this.config,e)});return{data:at(r.body)}}async getUserForCommit(s,e={}){var a;let n=(await this.config.request({url:`${E}/repositories/${s.repo.namespace}/${s.repo.name}/commit/${s.oid}`,headers:v(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:`${E}/repositories/${s.namespace}/${s.name}`,headers:v(this.config,e)});return{data:nt(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(`${E}/repositories`);r.searchParams.set("role","member"),r.searchParams.set("pagelen",D.toString()),s.cursor&&r.searchParams.set("after",s.cursor);let n=await this.config.request({url:r.toString(),headers:v(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(nt)}}async getBranches(s,e={}){var a;let r=new URL(`${E}/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",D.toString());let n=await this.config.request({url:r.toString(),headers:v(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(`${E}/repositories/${s.repo.namespace}/${s.repo.name}/refs/tags`);r.searchParams.set("pagelen",D.toString()),s.cursor&&r.searchParams.set("page",s.cursor);let n=await this.config.request({url:r.toString(),headers:v(this.config,e)}),o=!!n.body.next,a=null;return n.body.next&&(a=new URL(n.body.next).searchParams.get("page")),{pageInfo:{hasNextPage:o,endCursor:a},data:n.body.values.map(i=>{let u=new Date(i.target.date);return{name:i.name,commit:{oid:i.target.hash,authoredDate:u,committedDate:u}}})}}async getPullRequestsForUser(s,e={}){var a;let r=new URL(`${E}/pullrequests/${s.userId}`);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:v(this.config,e)}),o=!!n.body.next;return{pageInfo:{hasNextPage:o,nextPage:o?n.body.page+1:null},data:n.body.values.map(Ce)}}async getPullRequestsForRepoBase(s,e={}){var n;let r=new URL(`${E}/repositories/${encodeURI(s.repo.namespace)}/${encodeURI(s.repo.name)}/pullrequests?state=OPEN`);return r.searchParams.set("page",((n=s.page)==null?void 0:n.toString())||"1"),r.searchParams.set("pagelen","50"),await this.config.request({url:r.toString(),headers:v(this.config,e)})}async getPullRequestsForRepo(s,e={}){let r=[],n=await this.getPullRequestsForRepoBase(s,e);n.body.values.forEach(a=>{if(s.authorLogin&&a.author.uuid!==s.authorLogin)return null;r.push(Ce(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=>{if(s.authorLogin&&a.author.uuid!==s.authorLogin)return null;r.push(Ce(a))})}catch(o){if(o.statusCode!==404&&o.statusCode!==401)throw o}})),{data:r}}async closePullRequest(s,e={}){let{repo:{namespace:r,name:n},pullRequestId:o}=s;if(!(await this.config.request({method:"POST",url:`${E}/repositories/${r}/${n}/pullrequests/${o}/decline`,headers:v(this.config,e)})).body.title)throw new Error("Could not close pull request")}async mergePullRequest(s,e={}){let{repo:{namespace:r,name:n},pullRequestId:o,mergeStrategy:a}=s,i;switch(a){case"MERGE_COMMIT":{i="merge_commit";break}case"FAST_FORWARD":{i="fast_forward";break}case"SQUASH":{i="squash";break}}let u={merge_strategy:i,type:"pullrequest"};if(!(await this.config.request({method:"POST",url:`${E}/repositories/${r}/${n}/pullrequests/${o}/merge`,body:JSON.stringify(u),headers:{...v(this.config,e),"Content-Type":"application/json"}})).body.title)throw new Error("Could not merge pull request")}async setPullRequestReviewers(s,e={}){let{repo:{namespace:r,name:n},pullRequestId:o,reviewerUsernames:a}=s,i={reviewers:a.map(l=>({username:l}))};if(!(await this.config.request({method:"PUT",url:`${E}/repositories/${r}/${n}/pullrequests/${o}`,body:JSON.stringify(i),headers:{...v(this.config,e),"Content-Type":"application/json"}})).body.title)throw new Error("Could not set pull request reviewers")}};var ot=t=>({name:t.displayName,email:t.emailAddress,avatarUrl:null,id:t.id.toString(),username:t.name,url:t.links.self[0].href}),ve=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:ot(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:ot(t.author.user),assignees:null,reviews:r,reviewDecision:_(r),repository:{id:t.toRef.repository.id.toString(),name:t.toRef.repository.name,owner:{login:t.toRef.repository.project.name},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.name},remoteInfo:i&&a?{cloneUrlHTTPS:i,cloneUrlSSH:a}:null},headCommit:null,mergeableState:"UNKNOWN"}},H=class extends L{getBaseUrl(s){let e=s.baseUrl||this.config.baseUrl;if(!e)throw new Error('Bitbucket Server requires "baseUrl"');return e}getRequestHeaders(s){return R(s.token||this.config.token)}async getRepo(s,e={}){var n,o,a;let r=await this.config.request({url:`${this.getBaseUrl(e)}/projects/${s.namespace}/repos/${s.name}`,headers:this.getRequestHeaders(e)});return{data:{id:r.body.id.toString(),namespace:r.body.project.key,name:r.body.slug,webUrl:((n=r.body.links.self[0])==null?void 0:n.href)??null,httpsUrl:((o=r.body.links.clone.find(i=>i.name==="https"))==null?void 0:o.href)??null,sshUrl:((a=r.body.links.clone.find(i=>i.name==="ssh"))==null?void 0:a.href)??null,defaultBranch:null,permission:null}}}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 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(ve(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(ve(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(ve)}}async closePullRequest(s,e){let{repo:{namespace:r,name:n},pullRequestId:o,version:a}=s;if(!(await this.config.request({method:"POST",url:`${this.getBaseUrl(e)}/projects/${r}/repos/${n}/pull-requests/${o}/decline`,body:JSON.stringify({version:a}),headers:{...this.getRequestHeaders(e),"Content-Type":"application/json"}})).body.title)throw new Error("Could not close pull request")}async mergePullRequest(s,e){let{repo:{namespace:r,name:n},pullRequestId:o,mergeStrategyId:a,version:i}=s;if(!(await this.config.request({method:"POST",url:`${this.getBaseUrl(e)}/projects/${r}/repos/${n}/pull-requests/${o}/merge`,body:JSON.stringify({strategyId:a,version:i}),headers:{...this.getRequestHeaders(e),"Content-Type":"application/json"}})).body.title)throw new Error("Could not merge pull request")}async getMergeStrategies(s){let e=await this.config.request({url:`${this.getBaseUrl(s)}/admin/pull-requests/git`,headers:{...this.getRequestHeaders(s),"Content-Type":"application/json"}});return{data:{defaultStrategy:e.body.mergeConfig.defaultStrategy,strategies:e.body.mergeConfig.strategies}}}async setPullRequestReviewers(s,e={}){let{repo:{namespace:r,name:n},pullRequestId:o,reviewerUsernames:a,version:i}=s,u={reviewers:a.map(p=>({user:{name:p}})),version:i};if(!(await this.config.request({method:"PUT",url:`${this.getBaseUrl(e)}/projects/${r}/repos/${n}/pull-requests/${o}`,body:JSON.stringify(u),headers:{...this.getRequestHeaders(e),"Content-Type":"application/json"}})).body.title)throw new Error("Could not set pull request reviewers")}};var ie="https://api.github.com",Et=`${ie}/graphql`,ue=`
|
|
2
2
|
description
|
|
3
3
|
dueOn
|
|
4
4
|
id
|
|
@@ -6,28 +6,47 @@ number
|
|
|
6
6
|
state
|
|
7
7
|
title
|
|
8
8
|
url
|
|
9
|
-
|
|
9
|
+
`,$t=`
|
|
10
|
+
... on CheckRun {
|
|
11
|
+
completedAt
|
|
12
|
+
name
|
|
13
|
+
status
|
|
14
|
+
permalink
|
|
15
|
+
startedAt
|
|
16
|
+
}
|
|
17
|
+
`,oe=/\/api\/v\d+$/,le=`
|
|
10
18
|
color
|
|
11
19
|
description
|
|
12
20
|
id
|
|
13
21
|
name
|
|
14
|
-
`,
|
|
22
|
+
`,it=t=>{if(t.endsWith("/api/graphql"))throw new Error("The graphql endpoint is being used as the baseUrl. This package uses both GraphQL and REST APIs, and the REST version cannot be assumed. Use the REST endpoint as the baseUrl instead.")},Lt=(t,s)=>{let e=s.baseUrl||t.baseUrl;return e?(e=e.replace(/\/$/,""),it(e),oe.test(e)&&(e=e.replace(oe,"")),`${e}/api/graphql`):Et},ut=(t,s)=>{let e=s.baseUrl||t.baseUrl;return e?(e=e.replace(/\/$/,""),it(e),oe.test(e)&&(e=e.replace(oe,"")),e):ie},I=(t,s,e)=>{let r=R(e.token||t.token);return r["X-Github-Next-Global-ID"]="1",r["Content-Type"]="application/json",t.request({url:Lt(t,e),method:"POST",headers:r,body:JSON.stringify(s)})},Gt={user:!0,"user:email":!0,"read:user":!0},Q=t=>t.some(s=>Gt[s]),$=(t=!1,s=!1,e)=>`
|
|
15
23
|
__typename
|
|
16
|
-
id
|
|
17
|
-
databaseId
|
|
18
|
-
name
|
|
19
|
-
login
|
|
20
|
-
${s?"email":""}
|
|
21
|
-
avatarUrl${t?"(size: $avatarSize)":""}
|
|
22
|
-
url
|
|
23
|
-
`,
|
|
24
|
+
${k(e,["graphQLId"],"id")}
|
|
25
|
+
${k(e,["id"],"databaseId")}
|
|
26
|
+
${k(e,["name"],"name")}
|
|
27
|
+
${k(e,["name","username"],"login")}
|
|
28
|
+
${s?k(e,["email"],"email"):""}
|
|
29
|
+
${k(e,["avatarUrl"],`avatarUrl${t?"(size: $avatarSize)":""}`)}
|
|
30
|
+
${k(e,["url"],"url")}
|
|
31
|
+
`,At=(t=!1)=>`
|
|
32
|
+
latestReviews(first: 100) {
|
|
33
|
+
nodes {
|
|
34
|
+
author {
|
|
35
|
+
... on User {
|
|
36
|
+
${$(!1,t)}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
state
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
`,lt=(t=!1)=>`
|
|
24
43
|
__typename
|
|
25
44
|
id
|
|
26
45
|
databaseId
|
|
27
46
|
login
|
|
28
47
|
avatarUrl${t?"(size: $avatarSize)":""}
|
|
29
48
|
url
|
|
30
|
-
|
|
49
|
+
`,Ot=(t,s=!1,e)=>`
|
|
31
50
|
id
|
|
32
51
|
databaseId
|
|
33
52
|
number
|
|
@@ -35,10 +54,10 @@ title
|
|
|
35
54
|
state
|
|
36
55
|
author {
|
|
37
56
|
... on User {
|
|
38
|
-
${
|
|
57
|
+
${$(!1,s)}
|
|
39
58
|
}
|
|
40
59
|
... on Bot {
|
|
41
|
-
${
|
|
60
|
+
${lt(!1)}
|
|
42
61
|
}
|
|
43
62
|
}
|
|
44
63
|
commits(last: 1) {
|
|
@@ -51,13 +70,10 @@ commits(last: 1) {
|
|
|
51
70
|
contexts(first: 100) {
|
|
52
71
|
totalCount
|
|
53
72
|
nodes {
|
|
54
|
-
|
|
55
|
-
name
|
|
56
|
-
status
|
|
57
|
-
permalink
|
|
58
|
-
}
|
|
73
|
+
${e?$t:""}
|
|
59
74
|
... on StatusContext {
|
|
60
75
|
context
|
|
76
|
+
createdAt
|
|
61
77
|
description
|
|
62
78
|
state
|
|
63
79
|
targetUrl
|
|
@@ -82,6 +98,8 @@ headRef {
|
|
|
82
98
|
}
|
|
83
99
|
}
|
|
84
100
|
repository {
|
|
101
|
+
id
|
|
102
|
+
databaseId
|
|
85
103
|
name
|
|
86
104
|
owner {
|
|
87
105
|
login
|
|
@@ -90,6 +108,8 @@ repository {
|
|
|
90
108
|
sshUrl
|
|
91
109
|
}
|
|
92
110
|
headRepository {
|
|
111
|
+
id
|
|
112
|
+
databaseId
|
|
93
113
|
name
|
|
94
114
|
owner {
|
|
95
115
|
login
|
|
@@ -111,51 +131,42 @@ closedAt
|
|
|
111
131
|
mergedAt
|
|
112
132
|
assignees(first: 100) {
|
|
113
133
|
nodes {
|
|
114
|
-
${
|
|
134
|
+
${$(!1,s)}
|
|
115
135
|
}
|
|
116
136
|
}
|
|
117
137
|
reviewRequests(first: 100) {
|
|
118
138
|
nodes {
|
|
119
|
-
asCodeOwner
|
|
139
|
+
${e?"asCodeOwner":""}
|
|
120
140
|
requestedReviewer {
|
|
121
141
|
... on User {
|
|
122
|
-
${
|
|
142
|
+
${$(!1,s)}
|
|
123
143
|
}
|
|
124
144
|
}
|
|
125
145
|
}
|
|
126
146
|
}
|
|
127
|
-
|
|
128
|
-
nodes {
|
|
129
|
-
author {
|
|
130
|
-
... on User {
|
|
131
|
-
${U(!1,s)}
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
state
|
|
135
|
-
}
|
|
136
|
-
}
|
|
147
|
+
${e?At(s):""}
|
|
137
148
|
additions
|
|
138
149
|
deletions
|
|
139
150
|
changedFiles
|
|
140
151
|
mergeable
|
|
141
152
|
milestone {
|
|
142
|
-
${
|
|
153
|
+
${ue}
|
|
143
154
|
}
|
|
144
155
|
labels(first: 100) {
|
|
145
156
|
nodes {
|
|
146
|
-
${
|
|
157
|
+
${le}
|
|
147
158
|
}
|
|
148
159
|
}
|
|
149
|
-
`,
|
|
160
|
+
`,Tt=(t=!1)=>`
|
|
150
161
|
id
|
|
151
162
|
databaseId
|
|
152
163
|
title
|
|
153
164
|
author {
|
|
154
165
|
... on User {
|
|
155
|
-
${
|
|
166
|
+
${$(!1,t)}
|
|
156
167
|
}
|
|
157
168
|
... on Bot {
|
|
158
|
-
${
|
|
169
|
+
${lt(!1)}
|
|
159
170
|
}
|
|
160
171
|
}
|
|
161
172
|
closedAt
|
|
@@ -167,6 +178,8 @@ reactions(content: THUMBS_UP) {
|
|
|
167
178
|
totalCount
|
|
168
179
|
}
|
|
169
180
|
repository {
|
|
181
|
+
databaseId
|
|
182
|
+
id
|
|
170
183
|
name
|
|
171
184
|
owner {
|
|
172
185
|
login
|
|
@@ -177,19 +190,19 @@ comments {
|
|
|
177
190
|
}
|
|
178
191
|
assignees(first: 100) {
|
|
179
192
|
nodes {
|
|
180
|
-
${
|
|
193
|
+
${$(!1,t)}
|
|
181
194
|
}
|
|
182
195
|
}
|
|
183
196
|
state
|
|
184
197
|
milestone {
|
|
185
|
-
${
|
|
198
|
+
${ue}
|
|
186
199
|
}
|
|
187
200
|
labels(first: 100) {
|
|
188
201
|
nodes {
|
|
189
|
-
${
|
|
202
|
+
${le}
|
|
190
203
|
}
|
|
191
204
|
}
|
|
192
|
-
`,
|
|
205
|
+
`,xt={"-linked":"-linked",archived:"archived",assignee:"assignee",author:"author",base:"base",closed:"closed",commenter:"commenter",comments:"comments",created:"created",draft:"draft",head:"head",label:"label",language:"language",linked:"linked",in:"in",interactions:"interactions",involves:"involves",is:"is",mentions:"mentions",merged:"merged",milestone:"milestone",no:"no",org:"org",project:"project",reactions:"reactions",repo:"repo",review:"review","reviewed-by":"reviewed-by","review-requested":"review-requested",state:"state",status:"status",team:"team","team-review-requested":"team-review-requested",type:"type",updated:"updated",user:"user","user-review-requested":"user-review-requested"},kt=new RegExp('(([^\\s]+:)?\\"(?:[^\\"\\\\]|\\\\.)*\\"?)|([^\\"\\s]+)',"g"),Ue=t=>{let s=[];return(t.match(kt)??[]).forEach(r=>{if(r.includes(":")&&r!="is:closed"){let n=r.split(":")[0];xt[n]&&s.push(r)}}),s},Ee=(t,s,e,r,n=!1,o=!1)=>{let a=t==="issue";return{query:`
|
|
193
206
|
query SearchIssuesOrPullRequests($query: String! $after: String) {
|
|
194
207
|
search(type:ISSUE query:$query first:100 after:$after) {
|
|
195
208
|
pageInfo {
|
|
@@ -198,18 +211,18 @@ query SearchIssuesOrPullRequests($query: String! $after: String) {
|
|
|
198
211
|
}
|
|
199
212
|
nodes {
|
|
200
213
|
... on ${a?"Issue":"PullRequest"} {
|
|
201
|
-
${a?
|
|
214
|
+
${a?Tt(r):Ot(n,r,o)}
|
|
202
215
|
}
|
|
203
216
|
}
|
|
204
217
|
}
|
|
205
|
-
}`,variables:{query:`is:${t} is:open ${s}`,after:e}}},
|
|
218
|
+
}`,variables:{query:`is:${t} is:open ${s}`,after:e}}},_t="Field 'isDraft' doesn't exist on type 'PullRequest'",pt=(t=[])=>t.some(s=>(s==null?void 0:s.message)===_t),Nt=/@@ -(\d+)(?:,\d+ | )\+(\d+)(?:,\d+ | )@@(?:\\n)?/,Qt=`
|
|
206
219
|
\
|
|
207
|
-
+`,
|
|
220
|
+
+`,dt=(t,s,e,r)=>{let n=Nt.exec(t);if(!n||!n[0]||!n[1])return[];let o=parseInt(n[1],10),a=parseInt(n[2],10),i=t.replace(Qt,`
|
|
208
221
|
+`).split(`
|
|
209
|
-
`).slice(1),u=
|
|
210
|
-
`;break}case"+":{
|
|
211
|
-
`;break}default:
|
|
212
|
-
`}return{line:
|
|
222
|
+
`).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)}
|
|
223
|
+
`;break}case"+":{m="ADDED",l+=1,f=`${g.slice(1)}
|
|
224
|
+
`;break}default:m="UNMODIFIED",l+=1,u+=1,f=`${g}
|
|
225
|
+
`}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 y=0;y<p.length;y++){let P=p[y][f];P===d?g=y:P===c&&(m=y)}p=p.slice(g,m+1)}return p};var $e=`
|
|
213
226
|
id
|
|
214
227
|
databaseId
|
|
215
228
|
owner {
|
|
@@ -222,18 +235,18 @@ defaultBranchRef {
|
|
|
222
235
|
name
|
|
223
236
|
}
|
|
224
237
|
viewerPermission
|
|
225
|
-
`,
|
|
238
|
+
`,Ge={__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"},jt={APPROVED:"APPROVED",CHANGES_REQUESTED:"CHANGES_REQUESTED",COMMENTED:"COMMENTED",REVIEW_REQUESTED:"REVIEW_REQUESTED"},Ft={MERGEABLE:"MERGEABLE",CONFLICTING:"CONFLICTS",UNKNOWN:"UNKNOWN"},Bt={OPEN:"OPEN",CLOSED:"CLOSED"},Ae=t=>({color:t.color,description:t.description,graphQLId:t.id,id:null,name:t.name}),Le=t=>({id:t.databaseId.toString(),graphQLId:t.id,namespace:t.owner.login,name:t.name,webUrl:t.url,httpsUrl:t.url.endsWith(".git")?t.url:`${t.url}.git`,sshUrl:t.sshUrl,defaultBranch:t.defaultBranchRef,permission:t.viewerPermission}),Mt={OPEN:"OPEN",CLOSED:"CLOSED",MERGED:"MERGED"},zt={id:!0,graphQLId:!0,name:!0,username:!0,email:!0,avatarUrl:!0,url:!0},G=(t,s=zt)=>{let e={};return s.id&&(e.id=t.databaseId.toString()),s.graphQLId&&(e.graphQLId=t.id),s.name&&(e.name=t.name??t.login),s.username&&(e.username=t.login),s.email&&(e.email=t.email??null),s.avatarUrl&&(e.avatarUrl=t.avatarUrl),s.url&&(e.url=t.url),e},Ht=t=>{var a,i,u,l,p,d,c,g,m,f,y;let s=null;t.author?s=(t.author.__typename==="Bot",t.author):s=Ge;let e=(((a=t.reviewRequests)==null?void 0:a.nodes)||[]).filter(h=>!h.asCodeOwner),r=(i=t.headRepository)==null?void 0:i.url;r&&!r.endsWith(".git")&&(r=`${r}.git`);let n=(u=t.repository)==null?void 0:u.url;n&&!n.endsWith(".git")&&(n=`${n}.git`);let o=e.filter(h=>h.requestedReviewer&&"__typename"in h.requestedReviewer).map(h=>({reviewer:G(h.requestedReviewer),state:"REVIEW_REQUESTED"})).concat((((l=t.latestReviews)==null?void 0:l.nodes)||[]).map(h=>{let P=h.author||Ge;return{reviewer:G(P),state:jt[h.state]}}));return{id:t.databaseId.toString(),graphQLId:t.id,title:t.title,number:t.number,state:Mt[t.state],commentCount:t.comments.totalCount,upvoteCount:t.reactions.totalCount,author:s?G(s):null,createdDate:new Date(t.createdAt),isDraft:t.isDraft,repository:{id:t.repository.databaseId,graphQLId:t.repository.id,name:t.repository.name,owner:{login:t.repository.owner.login},remoteInfo:{cloneUrlHTTPS:n,cloneUrlSSH:t.repository.sshUrl}},headRepository:t.headRepository?{id:t.headRepository.databaseId,graphQLId:t.headRepository.id,name:t.headRepository.name,owner:{login:t.headRepository.owner.login},remoteInfo:{cloneUrlHTTPS:r,cloneUrlSSH:t.headRepository.sshUrl}}:null,headCommit:{buildStatuses:((c=(d=(p=t.commits.nodes)==null?void 0:p[0].commit.statusCheckRollup)==null?void 0:d.contexts.nodes)==null?void 0:c.map(h=>"context"in h?{completedAt:null,description:h.description,name:h.context,state:h.state,startedAt:new Date(h.createdAt),stage:null,url:h.targetUrl}:{completedAt:h.completedAt?new Date(h.completedAt):null,description:null,name:h.name,state:h.status,startedAt:h.startedAt?new Date(h.startedAt):null,stage:null,url:h.permalink}))??[]},headRef:t.headRef?{name:t.headRef.name,oid:((g=t.headRef.target)==null?void 0:g.oid)??null}:null,baseRef:t.baseRef?{name:t.baseRef.name,oid:((m=t.baseRef.target)==null?void 0:m.oid)??null}:null,url:t.url,updatedDate:new Date(t.updatedAt),closedDate:t.closedAt?new Date(t.closedAt):null,mergedDate:t.mergedAt?new Date(t.mergedAt):null,assignees:t.assignees.nodes?t.assignees.nodes.map(h=>G(h)):null,reviews:o,reviewDecision:_(o),additions:t.additions,deletions:t.deletions,fileCount:t.changedFiles,commitCount:t.commits.totalCount,mergeableState:Ft[t.mergeable],milestone:t.milestone?Oe(t.milestone):null,labels:((y=(f=t.labels)==null?void 0:f.nodes)==null?void 0:y.map(Ae))??[]}},Wt=t=>{let{comments:s,isOutdated:e,isResolved:r,originalLine:n,originalStartLine:o,startDiffSide:a}=t,{author:i,body:u,databaseId:l,id:p,path:d,publishedAt:c,url:g}=s.nodes[0];return{author:i?{avatarUrl:i.avatarUrl,email:null,name:i.login}:null,body:u,createdAt:c?new Date(c):null,diffLines:dt(s.nodes[0].diffHunk,n,o,a),id:l,isOutdated:e,isResolved:r,graphQLId:p,filename:d,replies:s.nodes.slice(1).map(Jt),url:g}},Jt=t=>({author:t.author?{avatarUrl:t.author.avatarUrl,email:null,name:t.author.login}:null,body:t.body,createdAt:t.publishedAt?new Date(t.publishedAt):null,graphQLId:t.id,id:t.databaseId,url:t.url}),Vt=t=>{var e,r;let s=null;return t.author?s=(t.author.__typename==="Bot",t.author):s=Ge,{id:t.databaseId.toString(),graphQLId:t.id,number:t.number,title:t.title,author:G(s),commentCount:t.comments.totalCount,closedDate:t.closedAt?new Date(t.closedAt):null,createdDate:new Date(t.createdAt),description:null,state:{name:Bt[t.state],color:null},type:null,repository:{id:t.repository.databaseId,graphQLId:t.repository.id,name:t.repository.name,owner:{login:t.repository.owner.login}},url:t.url,updatedDate:new Date(t.updatedAt),assignees:t.assignees.nodes?t.assignees.nodes.map(n=>G(n)):[],upvoteCount:t.reactions.totalCount,milestone:t.milestone?Oe(t.milestone):null,labels:((r=(e=t.labels)==null?void 0:e.nodes)==null?void 0:r.map(Ae))??[]}},Oe=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}),W=class extends L{constructor(){super(...arguments);this._scopesCache={};this._enterpriseVersionsCache={}}async getScopes(e){let r=e.token||this.config.token;if(!r)return[];let n=this._scopesCache[r];if(!n){let a=(await I(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:`${ut(this.config,e)}/api/v3/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(ie)?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=Ze(e.fields),o=await this.getScopes(r),i=(u=(await I(this.config,{query:`
|
|
226
239
|
query getCurrentUser {
|
|
227
240
|
viewer {
|
|
228
|
-
${
|
|
241
|
+
${$(!1,Q(o),n)}
|
|
229
242
|
}
|
|
230
243
|
}
|
|
231
|
-
`},
|
|
244
|
+
`},r)).body.data)==null?void 0:u.viewer;if(!i)throw new Error("Current user not found.");return{data:G(i,n)}}async getAccountsForRepo(e,r={}){var l,p,d,c,g,m;let n=await this.getScopes(r),{repo:{namespace:o,name:a},cursor:i}=e,u=await I(this.config,{query:`
|
|
232
245
|
query getAccountsForRepo($owner: String!, $name: String! $cursor: String, $first: Int!) {
|
|
233
246
|
repository(owner: $owner, name: $name) {
|
|
234
247
|
assignableUsers(first: $first, after: $cursor) {
|
|
235
248
|
nodes {
|
|
236
|
-
${
|
|
249
|
+
${$(!1,Q(n))}
|
|
237
250
|
}
|
|
238
251
|
pageInfo {
|
|
239
252
|
endCursor
|
|
@@ -242,7 +255,7 @@ query getAccountsForRepo($owner: String!, $name: String! $cursor: String, $first
|
|
|
242
255
|
}
|
|
243
256
|
}
|
|
244
257
|
}
|
|
245
|
-
`,variables:{owner:
|
|
258
|
+
`,variables:{owner:o,name:a,cursor:i,first:D}},r);if(!u.body.data)throw new Error(((l=u.body.errors)==null?void 0:l[0].message)||u.statusText||"Unknown error");return{pageInfo:((d=(p=u.body.data.repository)==null?void 0:p.assignableUsers)==null?void 0:d.pageInfo)??{endCursor:null,hasNextPage:!1},data:((m=(g=(c=u.body.data.repository)==null?void 0:c.assignableUsers)==null?void 0:g.nodes)==null?void 0:m.map(f=>G(f)))??[]}}async getUserForCommit(e,r={}){var i,u;let o=(i=(await I(this.config,{query:`
|
|
246
259
|
query getUserForCommit(
|
|
247
260
|
$owner: String!
|
|
248
261
|
$name: String!
|
|
@@ -261,23 +274,23 @@ query getUserForCommit(
|
|
|
261
274
|
}
|
|
262
275
|
}
|
|
263
276
|
}
|
|
264
|
-
`,variables:{owner:e.repo.namespace,name:e.repo.name,oid:e.oid,avatarSize:e.avatarSize}},r)).body.data)==null?void 0:i.repository;if(!
|
|
277
|
+
`,variables:{owner:e.repo.namespace,name:e.repo.name,oid:e.oid,avatarSize:e.avatarSize}},r)).body.data)==null?void 0:i.repository;if(!o)throw new Error("Repository not found.");let a=(u=o.object)==null?void 0:u.author;if(!a)throw new Error("Commit not found.");return{data:{name:a.name,email:a.email,avatarUrl:this.getEnterpriseAvatarUrlIfNeeded(a.avatarUrl,a.email,r)}}}async getAccountForEmail(e,r={}){var i,u,l;let n=await this.getScopes(r),a=(l=(u=(i=(await I(this.config,{query:`
|
|
265
278
|
query getAccountForEmail($query: String! $avatarSize: Int) {
|
|
266
279
|
search(query: $query, type: USER, first: 1) {
|
|
267
280
|
nodes {
|
|
268
281
|
... on User {
|
|
269
|
-
${
|
|
282
|
+
${$(!0,Q(n))}
|
|
270
283
|
}
|
|
271
284
|
}
|
|
272
285
|
}
|
|
273
286
|
}
|
|
274
|
-
`,variables:{query:`in:email ${e.email}`,avatarSize:e.avatarSize}},r)).body.data)==null?void 0:i.search)==null?void 0:u.nodes)==null?void 0:l[0];if(!
|
|
287
|
+
`,variables:{query:`in:email ${e.email}`,avatarSize:e.avatarSize}},r)).body.data)==null?void 0:i.search)==null?void 0:u.nodes)==null?void 0:l[0];if(!a)throw new Error("User not found.");return{data:G({...a,avatarUrl:this.getEnterpriseAvatarUrlIfNeeded(a.avatarUrl,a.email,r)})}}async getAccountForUsername(e,r={}){var i;let n=await this.getScopes(r),a=(i=(await I(this.config,{query:`
|
|
275
288
|
query getUserForUsername($login: String! $avatarSize: Int) {
|
|
276
289
|
user(login: $login) {
|
|
277
|
-
${
|
|
290
|
+
${$(!0,Q(n))}
|
|
278
291
|
}
|
|
279
292
|
}
|
|
280
|
-
`,variables:{login:e.username,avatarSize:e.avatarSize}},r)).body.data)==null?void 0:i.user;if(!
|
|
293
|
+
`,variables:{login:e.username,avatarSize:e.avatarSize}},r)).body.data)==null?void 0:i.user;if(!a)throw new Error("User not found.");return{data:G({...a,avatarUrl:this.getEnterpriseAvatarUrlIfNeeded(a.avatarUrl,a.email,r)})}}async getOrgsForCurrentUser(e={},r={}){var a,i;let n=await I(this.config,{query:`
|
|
281
294
|
query getOrgsForCurrentUser($cursor: String, $first: Int!) {
|
|
282
295
|
viewer {
|
|
283
296
|
organizations(first: $first after: $cursor) {
|
|
@@ -296,22 +309,22 @@ query getOrgsForCurrentUser($cursor: String, $first: Int!) {
|
|
|
296
309
|
}
|
|
297
310
|
}
|
|
298
311
|
}
|
|
299
|
-
`,variables:{cursor:e.cursor,first:
|
|
312
|
+
`,variables:{cursor:e.cursor,first:D}},r);if(!((a=n.body.data)!=null&&a.viewer.organizations))throw new Error(((i=n.body.errors)==null?void 0:i[0].message)||n.statusText||"Unknown error");let o=n.body.data.viewer.organizations.nodes||[];return{pageInfo:n.body.data.viewer.organizations.pageInfo,data:o.map(u=>({id:u.databaseId.toString(),graphQLId:u.id,username:u.login,name:u.name||null,email:u.email||null,avatarUrl:u.avatarUrl}))}}async getRepo(e,r={}){var o;let n=await I(this.config,{query:`
|
|
300
313
|
query getRepo($owner: String!, $name: String!) {
|
|
301
314
|
repository(owner: $owner, name: $name) {
|
|
302
315
|
${$e}
|
|
303
316
|
}
|
|
304
317
|
}
|
|
305
|
-
`,variables:{owner:e.namespace,name:e.name}},r);if(!((
|
|
318
|
+
`,variables:{owner:e.namespace,name:e.name}},r);if(!((o=n.body.data)!=null&&o.repository))throw new Error(`Repository ${e.namespace}/${e.name} not found`);return{data:Le(n.body.data.repository)}}async getRepos(e,r={}){let n=e.map(({namespace:u,name:l},p)=>`
|
|
306
319
|
getRepo_${p}: repository(owner: "${u}", name: "${l}") {
|
|
307
320
|
${$e}
|
|
308
321
|
}
|
|
309
322
|
`).join(`
|
|
310
|
-
`),
|
|
323
|
+
`),o=await I(this.config,{query:`
|
|
311
324
|
query batchGetRepos {
|
|
312
325
|
${n}
|
|
313
326
|
}
|
|
314
|
-
`},r);if(!
|
|
327
|
+
`},r);if(!o.body.data)throw new Error(o.statusText||"Unknown error");let a=[],i=[];return e.forEach((u,l)=>{let p=o.body.data[`getRepo_${l}`];p?a.push(Le(p)):i.push({input:u})}),{data:a,errors:i}}async getReposForUsernames(e,r={}){var a;if(!e.usernames.length)return{pageInfo:{endCursor:null,hasNextPage:!1},data:[]};let n=await I(this.config,{query:`
|
|
315
328
|
query getReposForUsernames($query: String!, $cursor: String, $first: Int!) {
|
|
316
329
|
search(query: $query, type: REPOSITORY, first: $first, after: $cursor) {
|
|
317
330
|
pageInfo {
|
|
@@ -325,7 +338,7 @@ query getReposForUsernames($query: String!, $cursor: String, $first: Int!) {
|
|
|
325
338
|
}
|
|
326
339
|
}
|
|
327
340
|
}
|
|
328
|
-
`,variables:{query:`fork:true ${e.usernames.map(i=>`user:${i}`).join(" ")}`,cursor:e.cursor,first:
|
|
341
|
+
`,variables:{query:`fork:true ${e.usernames.map(i=>`user:${i}`).join(" ")}`,cursor:e.cursor,first:D}},r);if(!n.body.data)throw new Error(((a=n.body.errors)==null?void 0:a[0].message)||n.statusText||"Unknown error");let o=n.body.data.search.nodes||[];return{pageInfo:n.body.data.search.pageInfo,data:o.map(Le)}}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 a=(u=(await I(this.config,{query:`
|
|
329
342
|
query getRefs($owner: String!, $name: String!, $refPrefix: String!, $cursor: String, $first: Int!) {
|
|
330
343
|
repository(owner: $owner, name: $name) {
|
|
331
344
|
refs(refPrefix: $refPrefix first: $first after: $cursor) {
|
|
@@ -346,7 +359,7 @@ query getRefs($owner: String!, $name: String!, $refPrefix: String!, $cursor: Str
|
|
|
346
359
|
}
|
|
347
360
|
}
|
|
348
361
|
}
|
|
349
|
-
`,variables:{owner:r.repo.namespace,name:r.repo.name,refPrefix:e,cursor:r.cursor,first:
|
|
362
|
+
`,variables:{owner:r.repo.namespace,name:r.repo.name,refPrefix:e,cursor:r.cursor,first:D}},n)).body.data)==null?void 0:u.repository;if(!a)throw new Error("Repository not found.");let i=a.refs;return i?{pageInfo:i.pageInfo,data:(i.nodes||[]).map(l=>{var d;let p=(d=l.target)!=null&&d.oid?l.target:null;return{name:l.name,commit:p?{oid:p.oid,authoredDate:new Date(p.authoredDate),committedDate:new Date(p.committedDate)}:null}})}:{pageInfo:{endCursor:null,hasNextPage:!1},data:[]}}async getBranches(e,r={}){return this.getRefs("refs/heads/",e,r)}async getTags(e,r={}){return this.getRefs("refs/tags/",e,r)}async getBlame(e,r={}){var i;let o=(i=(await I(this.config,{query:`
|
|
350
363
|
query getBlame($owner: String!, $name: String!, $ref: String!, $path: String!) {
|
|
351
364
|
repository(owner: $owner, name: $name) {
|
|
352
365
|
object(expression: $ref) {
|
|
@@ -385,13 +398,13 @@ query getBlame($owner: String!, $name: String!, $ref: String!, $path: String!) {
|
|
|
385
398
|
}
|
|
386
399
|
}
|
|
387
400
|
}
|
|
388
|
-
`,variables:{owner:e.repo.namespace,name:e.repo.name,ref:e.ref,path:e.path}},r)).body.data)==null?void 0:i.repository;if(!
|
|
401
|
+
`,variables:{owner:e.repo.namespace,name:e.repo.name,ref:e.ref,path:e.path}},r)).body.data)==null?void 0:i.repository;if(!o)throw new Error("Repository not found.");let a=o.object;if(!a||!("blame"in a))throw new Error("Ref not found.");if(a.blame.ranges.length===0)throw new Error("File not found.");return{data:{ranges:a.blame.ranges.map(u=>{var l;return{startingLine:u.startingLine,endingLine:u.endingLine,commit:{oid:u.commit.oid,parentOids:((l=u.commit.parents.nodes)==null?void 0:l.map(p=>p.oid))||[],authoredDate:new Date(u.commit.authoredDate),author:u.commit.author?{name:u.commit.author.name,email:u.commit.author.email,avatarUrl:u.commit.author.avatarUrl}:null,committedDate:new Date(u.commit.committedDate),committer:u.commit.committer?{name:u.commit.committer.name,email:u.commit.committer.email,avatarUrl:u.commit.committer.avatarUrl}:null,message:u.commit.message,fileCount:u.commit.changedFilesIfAvailable,additions:u.commit.additions,deletions:u.commit.deletions}}})}}}async searchPullRequests(e,r={}){var d,c;let n=await this.getEnterpriseVersion(r),o=await this.getScopes(r),a=Q(o),i=n?n[0]>=3:!0,u=g=>{let m=g&&typeof e.isDraft=="boolean"?`${e.query} draft:${e.isDraft}`:e.query;return Ee("pr",m,e.cursor,a,g,i)},l=await I(this.config,u(!0),r);l.body.errors&&pt(l.body.errors)&&(this.config.baseUrl||r.baseUrl)&&(l=await I(this.config,u(!1),r));let{data:p}=l.body;if(!p)throw new Error(((d=l.body.errors)==null?void 0:d[0].message)||l.statusText||"Unknown error");return{pageInfo:{hasNextPage:p.search.pageInfo.hasNextPage,endCursor:p.search.pageInfo.endCursor},data:((c=p.search.nodes)==null?void 0:c.map(Ht))||[]}}async searchIssues(e,r={}){var u,l;let n=await this.getScopes(r),o=Q(n),a=await I(this.config,Ee("issue",e.query,e.cursor,o),r),{data:i}=a.body;if(!i)throw new Error(((u=a.body.errors)==null?void 0:u[0].message)||a.statusText||"Unknown error");return{pageInfo:{hasNextPage:i.search.pageInfo.hasNextPage,endCursor:i.search.pageInfo.endCursor},data:((l=i.search.nodes)==null?void 0:l.map(Vt))||[]}}async getPullRequestsAssociatedWithUser(e,r={}){return this.searchPullRequests({query:`involves:${e.username}`,cursor:e.cursor},r)}async getPullRequestsForRepos(e,r={}){let{assigneeLogins:n,updatedBefore:o,authorLogin:a,repos:i,reviewRequestedLogin:u,startQuery:l,mentionLogin:p}=e,d=Ue(l||"");return i.forEach(c=>{d.push(`repo:${c.namespace}/${c.name}`)}),n&&n.forEach(c=>{d.push(`assignee:${c}`)}),o&&d.push(`updated:<${o}`),a&&d.push(`author:${a}`),u&&d.push(`review-requested:${u}`),p&&d.push(`mentions:${p}`),this.searchPullRequests({query:`sort:updated ${d.join(" ")}`,isDraft:e.isDraft,cursor:e.cursor},r)}async closePullRequest(e,r={}){var i,u,l;let{pullRequestGraphQLId:n}=e,o=`mutation ClosePullRequest($pullRequestGraphQLId: ID!) {
|
|
389
402
|
closePullRequest(input: { pullRequestId: $pullRequestGraphQLId }) {
|
|
390
403
|
pullRequest {
|
|
391
404
|
id
|
|
392
405
|
}
|
|
393
406
|
}
|
|
394
|
-
}`;if(!((l=(u=(i=(await I(this.config,{query:`${
|
|
407
|
+
}`;if(!((l=(u=(i=(await I(this.config,{query:`${o}`,variables:{pullRequestGraphQLId:n}},r)).body.data)==null?void 0:i.closePullRequest)==null?void 0:u.pullRequest)!=null&&l.id))throw new Error("Could not close pull request")}async mergePullRequest(e,r={}){var p,d,c;let{pullRequestGraphQLId:n,expectedSourceSha:o,mergeStrategy:a}=e,i;switch(a){case"MERGE_COMMIT":{i="MERGE";break}case"REBASE":{i="REBASE";break}case"SQUASH":{i="SQUASH";break}}let u=`mutation MergePullRequest(
|
|
395
408
|
$pullRequestGraphQLId: ID!,
|
|
396
409
|
$expectedSourceSha: GitObjectID!,
|
|
397
410
|
$mergeStrategy: PullRequestMergeMethod,
|
|
@@ -405,37 +418,37 @@ query getBlame($owner: String!, $name: String!, $ref: String!, $path: String!) {
|
|
|
405
418
|
id
|
|
406
419
|
}
|
|
407
420
|
}
|
|
408
|
-
}`;if(!((c=(d=(p=(await I(this.config,{query:`${u}`,variables:{pullRequestGraphQLId:n,expectedSourceSha:
|
|
421
|
+
}`;if(!((c=(d=(p=(await I(this.config,{query:`${u}`,variables:{pullRequestGraphQLId:n,expectedSourceSha:o,mergeStrategy:i}},r)).body.data)==null?void 0:p.mergePullRequest)==null?void 0:d.pullRequest)!=null&&c.id))throw new Error("Could not merge pull request")}async setPullRequestMilestone(e,r={}){var u,l,p;let{pullRequestGraphQLId:n,milestoneGraphQLId:o}=e,a=`mutation SetPullRequestMilestone($pullRequestGraphQLId: ID!, $milestoneGraphQLId: ID) {
|
|
409
422
|
updatePullRequest(input: { pullRequestId: $pullRequestGraphQLId, milestoneId: $milestoneGraphQLId }) {
|
|
410
423
|
pullRequest {
|
|
411
424
|
id
|
|
412
425
|
}
|
|
413
426
|
}
|
|
414
|
-
}`;if(!((p=(l=(u=(await I(this.config,{query:`${
|
|
427
|
+
}`;if(!((p=(l=(u=(await I(this.config,{query:`${a}`,variables:{pullRequestGraphQLId:n,milestoneGraphQLId:o}},r)).body.data)==null?void 0:u.updatePullRequest)==null?void 0:l.pullRequest)!=null&&p.id))throw new Error("Could not set milestone of pull request")}async markPullRequestReadyForReview(e,r){var a,i,u;let n=`mutation MarkReadyToReview($pullRequestGraphQLId: ID!) {
|
|
415
428
|
markPullRequestReadyForReview(input: { pullRequestId: $pullRequestGraphQLId }) {
|
|
416
429
|
pullRequest {
|
|
417
430
|
id
|
|
418
431
|
}
|
|
419
432
|
}
|
|
420
|
-
}`;if(!((u=(i=(
|
|
433
|
+
}`;if(!((u=(i=(a=(await I(this.config,{query:n,variables:{pullRequestGraphQLId:e}},r)).body.data)==null?void 0:a.markPullRequestReadyForReview)==null?void 0:i.pullRequest)!=null&&u.id))throw new Error("Could not mark pull request ready to review")}async convertPullRequestToDraft(e,r){var a,i,u;let n=`mutation ConvertToDraft($pullRequestGraphQLId: ID!) {
|
|
421
434
|
convertPullRequestToDraft(input: { pullRequestId: $pullRequestGraphQLId }) {
|
|
422
435
|
pullRequest {
|
|
423
436
|
id
|
|
424
437
|
}
|
|
425
438
|
}
|
|
426
|
-
}`;if(!((u=(i=(
|
|
439
|
+
}`;if(!((u=(i=(a=(await I(this.config,{query:n,variables:{pullRequestGraphQLId:e}},r)).body.data)==null?void 0:a.convertPullRequestToDraft)==null?void 0:i.pullRequest)!=null&&u.id))throw new Error("Could not convert pull request to draft")}async setPullRequestAsDraft(e,r={}){let{pullRequestGraphQLId:n,isDraft:o}=e;if(o){await this.convertPullRequestToDraft(n,r);return}await this.markPullRequestReadyForReview(n,r)}async setPullRequestReviewers(e,r={}){var u,l,p;let{pullRequestGraphQLId:n,reviewerGraphQLIds:o}=e,a=`mutation SetPullRequestReviewers($pullRequestGraphQLId: ID!, $reviewerGraphQLIds: [ID!]!) {
|
|
427
440
|
requestReviews(input: { pullRequestId: $pullRequestGraphQLId, userIds: $reviewerGraphQLIds }) {
|
|
428
441
|
pullRequest {
|
|
429
442
|
id
|
|
430
443
|
}
|
|
431
444
|
}
|
|
432
|
-
}`;if(!((p=(l=(u=(await I(this.config,{query:
|
|
445
|
+
}`;if(!((p=(l=(u=(await I(this.config,{query:a,variables:{pullRequestGraphQLId:n,reviewerGraphQLIds:o}},r)).body.data)==null?void 0:u.requestReviews)==null?void 0:l.pullRequest)!=null&&p.id))throw new Error("Could not set pull request reviewers")}async setPullRequestAssignees(e,r={}){var u,l,p;let{pullRequestGraphQLId:n,assigneeGraphQLIds:o}=e,a=`mutation SetPullRequestAssignees($pullRequestGraphQLId: ID!, $assigneeGraphQLIds: [ID!]!) {
|
|
433
446
|
updatePullRequest(input: { pullRequestId: $pullRequestGraphQLId, assigneeIds: $assigneeGraphQLIds }) {
|
|
434
447
|
pullRequest {
|
|
435
448
|
id
|
|
436
449
|
}
|
|
437
450
|
}
|
|
438
|
-
}`;if(!((p=(l=(u=(await I(this.config,{query:
|
|
451
|
+
}`;if(!((p=(l=(u=(await I(this.config,{query:a,variables:{pullRequestGraphQLId:n,assigneeGraphQLIds:o}},r)).body.data)==null?void 0:u.updatePullRequest)==null?void 0:l.pullRequest)!=null&&p.id))throw new Error("Could not set pull request assignees")}async getReviewsForPullRequest(e,r={}){var d,c;let{repo:{namespace:n,name:o},pullRequestId:a}=e,i=`query getPullRequests(
|
|
439
452
|
$namespace: String!
|
|
440
453
|
$name: String!
|
|
441
454
|
$pullRequestId: Int!
|
|
@@ -487,54 +500,54 @@ query getBlame($owner: String!, $name: String!, $ref: String!, $path: String!) {
|
|
|
487
500
|
}
|
|
488
501
|
}
|
|
489
502
|
}
|
|
490
|
-
}`,u=await I(this.config,{query:i,variables:{namespace:n,name:
|
|
503
|
+
}`,u=await I(this.config,{query:i,variables:{namespace:n,name:o,pullRequestId:a}},r),l=((d=u.body.data)==null?void 0:d.repository.pullRequest.reviewThreads.nodes.reduce((g,m)=>{let f=m.comments.nodes[0].pullRequestReview;return f&&(g[f.id]||(g[f.id]=[]),g[f.id].push(Wt(m))),g},{}))??{};return{data:((c=u.body.data)==null?void 0:c.repository.pullRequest.reviews.nodes.filter(g=>l[g.id]).map(g=>({author:g.author?{avatarUrl:g.author.avatarUrl,email:null,name:g.author.login}:null,body:g.body,createdAt:g.publishedAt?new Date(g.publishedAt):null,id:g.databaseId,graphQLId:g.id,reviewComments:l[g.id],url:g.url})))??[]}}async getIssuesAssociatedWithUser(e,r={}){var d;let[n,o]=((d=e.cursor)==null?void 0:d.split(";"))||[void 0,void 0],[a,i]=await Promise.all([n==="null"?null:this.searchIssues({query:`author:${e.username}`,cursor:n},r),o==="null"?null:this.searchIssues({query:`assignee:${e.username}`,cursor:o},r)]),u={},l=[],p=c=>{u[c.id]||(u[c.id]=!0,l.push(c))};return a==null||a.data.forEach(p),i==null||i.data.forEach(p),{pageInfo:{hasNextPage:(a==null?void 0:a.pageInfo.hasNextPage)||(i==null?void 0:i.pageInfo.hasNextPage)||!1,endCursor:`${(a==null?void 0:a.pageInfo.hasNextPage)&&(a==null?void 0:a.pageInfo.endCursor)||"null"};${(i==null?void 0:i.pageInfo.hasNextPage)&&(i==null?void 0:i.pageInfo.endCursor)||"null"}`},data:l}}async setPullRequestLabels(e,r={}){var u,l,p;let{pullRequestGraphQLId:n,labelGraphQLIds:o}=e,a=`mutation SetPullRequestLabels($pullRequestGraphQLId: ID!, $labelGraphQLIds: [ID!]) {
|
|
491
504
|
updatePullRequest(input: { pullRequestId: $pullRequestGraphQLId, labelIds: $labelGraphQLIds }) {
|
|
492
505
|
pullRequest {
|
|
493
506
|
id
|
|
494
507
|
}
|
|
495
508
|
}
|
|
496
|
-
}`;if(!((p=(l=(u=(await I(this.config,{query:
|
|
509
|
+
}`;if(!((p=(l=(u=(await I(this.config,{query:a,variables:{pullRequestGraphQLId:n,labelGraphQLIds:o}},r)).body.data)==null?void 0:u.updatePullRequest)==null?void 0:l.pullRequest)!=null&&p.id))throw new Error("Could not set pull request labels")}async getIssuesForRepos(e,r={}){let n=Ue(e.startQuery||""),{cursor:o,assigneeLogins:a,updatedBefore:i,authorLogin:u,mentionLogin:l}=e;return e.repos.forEach(p=>{n.push(`repo:${p.namespace}/${p.name}`)}),a&&a.forEach(p=>{n.push(`assignee:${p}`)}),i&&n.push(`updated:<${i}`),u&&n.push(`author:${u}`),l&&n.push(`mentions:${l}`),this.searchIssues({query:`sort:updated ${n.join(" ")}`,cursor:o},r)}async closeIssueWithReason(e,r,n){var i,u,l;let o=`mutation CloseIssueWithReason($issueGraphQLId: ID!, $closeReason: IssueClosedStateReason!) {
|
|
497
510
|
closeIssue(input: { issueId: $issueGraphQLId, stateReason: $closeReason }) {
|
|
498
511
|
issue {
|
|
499
512
|
id
|
|
500
513
|
}
|
|
501
514
|
}
|
|
502
|
-
}`;if(!((l=(u=(i=(await I(this.config,{query:
|
|
515
|
+
}`;if(!((l=(u=(i=(await I(this.config,{query:o,variables:{issueGraphQLId:e,closeReason:r}},n)).body.data)==null?void 0:i.closeIssue)==null?void 0:u.issue)!=null&&l.id))throw new Error("Could not close issue with reason")}async closeIssueWithoutReason(e,r){var a,i,u;let n=`mutation SetIssueState($issueGraphQLId: ID!) {
|
|
503
516
|
updateIssue(input: { id: $issueGraphQLId, state: CLOSED }) {
|
|
504
517
|
issue {
|
|
505
518
|
id
|
|
506
519
|
}
|
|
507
520
|
}
|
|
508
|
-
}`;if(!((u=(i=(
|
|
521
|
+
}`;if(!((u=(i=(a=(await I(this.config,{query:n,variables:{issueGraphQLId:e}},r)).body.data)==null?void 0:a.updateIssue)==null?void 0:i.issue)!=null&&u.id))throw new Error("Could not close issue")}async reopenIssue(e,r){var a,i,u;let n=`mutation ReOpenIssue($issueGraphQLId: ID!) {
|
|
509
522
|
reopenIssue(input: { issueId: $issueGraphQLId }) {
|
|
510
523
|
issue {
|
|
511
524
|
id
|
|
512
525
|
}
|
|
513
526
|
}
|
|
514
|
-
}`;if(!((u=(i=(
|
|
527
|
+
}`;if(!((u=(i=(a=(await I(this.config,{query:n,variables:{issueGraphQLId:e}},r)).body.data)==null?void 0:a.reopenIssue)==null?void 0:i.issue)!=null&&u.id))throw new Error("Could not reopen issue")}async setIssueStatus(e,r={}){let{issueGraphQLId:n,status:o,closeReason:a}=e;if(a&&o=="OPEN")throw new Error("Did not expect closeReason to be set when trying to reopen issue");o=="OPEN"?await this.reopenIssue(n,r):o=="CLOSED"&&!a?await this.closeIssueWithoutReason(n,r):a&&await this.closeIssueWithReason(n,a,r)}async setIssueLabels(e,r={}){var u,l,p;let{issueGraphQLId:n,labelGraphQLIds:o}=e,a=`mutation SetIssueLabels($issueGraphQLId: ID!, $labelGraphQLIds: [ID!]) {
|
|
515
528
|
updateIssue(input: { id: $issueGraphQLId, labelIds: $labelGraphQLIds }) {
|
|
516
529
|
issue {
|
|
517
530
|
id
|
|
518
531
|
}
|
|
519
532
|
}
|
|
520
|
-
}`;if(!((p=(l=(u=(await I(this.config,{query:
|
|
533
|
+
}`;if(!((p=(l=(u=(await I(this.config,{query:a,variables:{issueGraphQLId:n,labelGraphQLIds:o}},r)).body.data)==null?void 0:u.updateIssue)==null?void 0:l.issue)!=null&&p.id))throw new Error("Could not set issue labels")}async setIssueMilestone(e,r={}){var u,l,p;let{issueGraphQLId:n,milestoneGraphQLId:o}=e,a=`mutation SetIssueMilestone($issueGraphQLId: ID!, $milestoneGraphQLId: ID) {
|
|
521
534
|
updateIssue(input: { id: $issueGraphQLId, milestoneId: $milestoneGraphQLId }) {
|
|
522
535
|
issue {
|
|
523
536
|
id
|
|
524
537
|
}
|
|
525
538
|
}
|
|
526
|
-
}`;if(!((p=(l=(u=(await I(this.config,{query:`${
|
|
539
|
+
}`;if(!((p=(l=(u=(await I(this.config,{query:`${a}`,variables:{issueGraphQLId:n,milestoneGraphQLId:o}},r)).body.data)==null?void 0:u.updateIssue)==null?void 0:l.issue)!=null&&p.id))throw new Error("Could not set milestone of issue")}async setIssueAssignees(e,r={}){var u,l,p;let{issueGraphQLId:n,assigneeGraphQLIds:o}=e,a=`mutation SetIssueAssignees($issueGraphQLId: ID!, $assigneeGraphQLIds: [ID!]!) {
|
|
527
540
|
updateIssue(input: { id: $issueGraphQLId, assigneeIds: $assigneeGraphQLIds }) {
|
|
528
541
|
issue {
|
|
529
542
|
id
|
|
530
543
|
}
|
|
531
544
|
}
|
|
532
|
-
}`;if(!((p=(l=(u=(await I(this.config,{query:
|
|
545
|
+
}`;if(!((p=(l=(u=(await I(this.config,{query:a,variables:{issueGraphQLId:n,assigneeGraphQLIds:o}},r)).body.data)==null?void 0:u.updateIssue)==null?void 0:l.issue)!=null&&p.id))throw new Error("Could not set issue assignees")}async getMilestonesForRepo(e,r={}){var u,l,p,d;let{repo:{namespace:n,name:o},cursor:a}=e,i=await I(this.config,{query:`
|
|
533
546
|
query getLabelsForRepo($owner: String!, $name: String! $cursor: String, $first: Int!) {
|
|
534
547
|
repository(owner: $owner, name: $name) {
|
|
535
548
|
milestones(first: $first, after: $cursor) {
|
|
536
549
|
nodes {
|
|
537
|
-
${
|
|
550
|
+
${ue}
|
|
538
551
|
}
|
|
539
552
|
pageInfo {
|
|
540
553
|
endCursor
|
|
@@ -543,12 +556,12 @@ query getLabelsForRepo($owner: String!, $name: String! $cursor: String, $first:
|
|
|
543
556
|
}
|
|
544
557
|
}
|
|
545
558
|
}
|
|
546
|
-
`,variables:{owner:n,name:
|
|
559
|
+
`,variables:{owner:n,name:o,cursor:a,first:D}},r);if(!i.body.data)throw new Error(((u=i.body.errors)==null?void 0:u[0].message)||i.statusText||"Unknown error");return{pageInfo:((l=i.body.data.repository.milestones)==null?void 0:l.pageInfo)??{endCursor:null,hasNextPage:!1},data:((d=(p=i.body.data.repository.milestones)==null?void 0:p.nodes)==null?void 0:d.map(Oe))??[]}}async getLabelsForRepo(e,r={}){var u,l,p,d;let{repo:{namespace:n,name:o},cursor:a}=e,i=await I(this.config,{query:`
|
|
547
560
|
query getLabelsForRepo($owner: String!, $name: String! $cursor: String, $first: Int!) {
|
|
548
561
|
repository(owner: $owner, name: $name) {
|
|
549
562
|
labels(first: $first, after: $cursor) {
|
|
550
563
|
nodes {
|
|
551
|
-
${
|
|
564
|
+
${le}
|
|
552
565
|
}
|
|
553
566
|
pageInfo {
|
|
554
567
|
endCursor
|
|
@@ -557,7 +570,7 @@ query getLabelsForRepo($owner: String!, $name: String! $cursor: String, $first:
|
|
|
557
570
|
}
|
|
558
571
|
}
|
|
559
572
|
}
|
|
560
|
-
`,variables:{owner:n,name:
|
|
573
|
+
`,variables:{owner:n,name:o,cursor:a,first:D}},r);if(!i.body.data)throw new Error(((u=i.body.errors)==null?void 0:u[0].message)||i.statusText||"Unknown error");return{pageInfo:((l=i.body.data.repository.labels)==null?void 0:l.pageInfo)??{endCursor:null,hasNextPage:!1},data:((d=(p=i.body.data.repository.labels)==null?void 0:p.nodes)==null?void 0:d.map(Ae))??[]}}};var Kt="https://gitlab.com/api/v4",Xt="https://gitlab.com/api/graphql",ct=/\/api\/v\d+$/,gt=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.")},Te=(t,s)=>{let e=s.baseUrl||t.baseUrl;return e?(e=e.replace(/\/$/,""),gt(e),e):Kt},Zt=(t,s)=>{let e=s.baseUrl||t.baseUrl;return e?(e=e.replace(/\/$/,""),gt(e),ct.test(e)&&(e=e.replace(ct,"")),`${e}/api/graphql`):Xt},b=(t,s,e)=>{let r=R(e.token||t.token);return t.request({url:Zt(t,e),method:"POST",headers:{...r,"Content-Type":"application/json"},body:JSON.stringify(s)})};var Fe=t=>t.split("/").slice(0,-1).join("/"),J=t=>({id:t.id.replace(N,""),graphQLId:t.id,namespace:Fe(t.fullPath),name:t.path,webUrl:t.webUrl}),mt=t=>({id:t.id.replace(N,""),graphQLId:t.id,httpsUrl:t.httpUrlToRepo,namespace:Fe(t.fullPath),name:t.path,sshUrl:t.sshUrlToRepo,webUrl:t.webUrl}),Yt={assigned:"assignedMergeRequests",authored:"authoredMergeRequests",reviewRequested:"reviewRequestedMergeRequests"},es={CAN_BE_MERGED:"MERGEABLE",CANNOT_BE_MERGED:"CONFLICTS",CANNOT_BE_MERGED_RECHECK:"UNKNOWN",UNCHECKED:"UNKNOWN",CHECKING:"UNKNOWN"},ts="gid://gitlab/User/",N="gid://gitlab/Project/",ss="gid://gitlab/MergeRequest/",rs="gid://gitlab/Issue/",ns="gid://gitlab/ProjectLabel/",ht="gid://gitlab/Milestone/",as="gid://gitlab/Ci::Build/",Be=`
|
|
561
574
|
description
|
|
562
575
|
dueDate
|
|
563
576
|
id
|
|
@@ -566,7 +579,7 @@ startDate
|
|
|
566
579
|
state
|
|
567
580
|
title
|
|
568
581
|
webPath
|
|
569
|
-
`,
|
|
582
|
+
`,xe=`
|
|
570
583
|
id
|
|
571
584
|
path
|
|
572
585
|
fullPath
|
|
@@ -576,25 +589,25 @@ sshUrlToRepo
|
|
|
576
589
|
repository {
|
|
577
590
|
rootRef
|
|
578
591
|
}
|
|
579
|
-
`,
|
|
592
|
+
`,A=`
|
|
580
593
|
id
|
|
581
594
|
name
|
|
582
595
|
username
|
|
583
596
|
publicEmail
|
|
584
597
|
avatarUrl
|
|
585
598
|
webUrl
|
|
586
|
-
`,
|
|
599
|
+
`,Me=`
|
|
587
600
|
color
|
|
588
601
|
description
|
|
589
602
|
id
|
|
590
603
|
title
|
|
591
|
-
`,
|
|
604
|
+
`,ke=`
|
|
592
605
|
author {
|
|
593
|
-
${
|
|
606
|
+
${A}
|
|
594
607
|
}
|
|
595
608
|
assignees {
|
|
596
609
|
nodes {
|
|
597
|
-
${
|
|
610
|
+
${A}
|
|
598
611
|
}
|
|
599
612
|
}
|
|
600
613
|
closedAt
|
|
@@ -605,7 +618,7 @@ id
|
|
|
605
618
|
iid
|
|
606
619
|
labels {
|
|
607
620
|
nodes {
|
|
608
|
-
${
|
|
621
|
+
${Me}
|
|
609
622
|
}
|
|
610
623
|
}
|
|
611
624
|
state
|
|
@@ -616,13 +629,15 @@ upvotes
|
|
|
616
629
|
userNotesCount
|
|
617
630
|
webUrl
|
|
618
631
|
milestone {
|
|
619
|
-
${
|
|
632
|
+
${Be}
|
|
620
633
|
}
|
|
621
|
-
`,
|
|
634
|
+
`,os=`
|
|
622
635
|
stages {
|
|
623
636
|
nodes {
|
|
624
637
|
jobs {
|
|
625
638
|
nodes {
|
|
639
|
+
createdAt
|
|
640
|
+
finishedAt
|
|
626
641
|
id
|
|
627
642
|
name
|
|
628
643
|
status
|
|
@@ -631,12 +646,12 @@ stages {
|
|
|
631
646
|
name
|
|
632
647
|
}
|
|
633
648
|
}
|
|
634
|
-
`,
|
|
649
|
+
`,_e=(t,s,e)=>`
|
|
635
650
|
id
|
|
636
651
|
state
|
|
637
652
|
approved
|
|
638
653
|
author {
|
|
639
|
-
${
|
|
654
|
+
${A}
|
|
640
655
|
}
|
|
641
656
|
diffRefs {
|
|
642
657
|
baseSha
|
|
@@ -661,12 +676,12 @@ targetBranch
|
|
|
661
676
|
sourceBranch
|
|
662
677
|
assignees {
|
|
663
678
|
nodes {
|
|
664
|
-
${
|
|
679
|
+
${A}
|
|
665
680
|
}
|
|
666
681
|
}
|
|
667
682
|
reviewers {
|
|
668
683
|
nodes {
|
|
669
|
-
${
|
|
684
|
+
${A}
|
|
670
685
|
mergeRequestInteraction {
|
|
671
686
|
approved
|
|
672
687
|
reviewState
|
|
@@ -676,19 +691,19 @@ reviewers {
|
|
|
676
691
|
mergeStatusEnum
|
|
677
692
|
labels {
|
|
678
693
|
nodes {
|
|
679
|
-
${
|
|
694
|
+
${Me}
|
|
680
695
|
}
|
|
681
696
|
}
|
|
682
|
-
${t?"project { httpUrlToRepo path fullPath sshUrlToRepo webUrl } sourceProject { httpUrlToRepo path fullPath sshUrlToRepo webUrl }":""}
|
|
683
|
-
${s?`milestone { ${
|
|
684
|
-
${e?`headPipeline { ${
|
|
685
|
-
`,
|
|
697
|
+
${t?"project { id httpUrlToRepo path fullPath sshUrlToRepo webUrl } sourceProject { id httpUrlToRepo path fullPath sshUrlToRepo webUrl }":""}
|
|
698
|
+
${s?`milestone { ${Be} }`:""}
|
|
699
|
+
${e?`headPipeline { ${os} }`:""}
|
|
700
|
+
`,j=t=>`${t.namespace}/${t.name}`,is=t=>`${t.namespace}/${t.name}`,Ne=t=>{var s;return{id:t.id.replace(N,""),graphQLId:t.id,namespace:Fe(t.fullPath),name:t.path,webUrl:t.webUrl,httpsUrl:t.httpUrlToRepo,sshUrl:t.sshUrlToRepo,defaultBranch:(s=t.repository)!=null&&s.rootRef?{name:t.repository.rootRef}:null,permission:null}},us={opened:"OPEN",merged:"MERGED",closed:"CLOSED"},O=(t,s)=>{let e=t.avatarUrl;return!s&&(e!=null&&e.startsWith("/"))&&(e=`https://gitlab.com${e}`),{id:t.id.replace(ts,""),graphQLId:t.id,name:t.name,username:t.username,email:t.publicEmail??null,avatarUrl:e,url:t.webUrl}},ze=t=>({color:t.color,description:t.description,id:t.id.replace(ns,""),graphQLId:t.id,name:t.title}),Qe=(t,s,e,r)=>{var o,a,i,u,l,p,d,c,g,m,f,y;let n=(o=t.reviewers)!=null&&o.nodes?t.reviewers.nodes.map(h=>{var P,q;return{reviewer:O(h,r),state:(P=h.mergeRequestInteraction)!=null&&P.approved?"APPROVED":((q=h.mergeRequestInteraction)==null?void 0:q.reviewState)==="REVIEWED"?"CHANGES_REQUESTED":"CHANGES_REQUESTED"}}):null;return{id:t.id.replace(ss,""),graphQLId:t.id,title:t.title,number:parseInt(t.iid,10),state:us[t.state],commentCount:t.userNotesCount||0,upvoteCount:t.upvotes,author:t.author?O(t.author,r):null,createdDate:new Date(t.createdAt),isDraft:t.draft,repository:{id:s.id,graphQLId:s.graphQLId,name:s.name,owner:{login:s.namespace},remoteInfo:s.httpsUrl&&s.sshUrl?{cloneUrlHTTPS:s.httpsUrl,cloneUrlSSH:s.sshUrl}:null},headRepository:e?{id:e.id,graphQLId:e.graphQLId,name:e.name,owner:{login:e.namespace},remoteInfo:{cloneUrlHTTPS:e.httpsUrl,cloneUrlSSH:e.sshUrl}}:null,headCommit:{buildStatuses:((u=(i=(a=t.headPipeline)==null?void 0:a.stages)==null?void 0:i.nodes)==null?void 0:u.flatMap(h=>{var P,q;return((q=(P=h.jobs)==null?void 0:P.nodes)==null?void 0:q.map(C=>({completedAt:C.finishedAt?new Date(C.finishedAt):null,description:null,name:C.name??null,state:C.status??null,stage:h.name??null,startedAt:new Date(C.createdAt),url:`${s.webUrl}/-/jobs/${C.id.replace(as,"")}`})))??[]}))??[]},baseRef:{name:t.targetBranch,oid:((l=t.diffRefs)==null?void 0:l.baseSha)??null},headRef:{name:t.sourceBranch,oid:((p=t.diffRefs)==null?void 0:p.headSha)??null},url:t.webUrl,updatedDate:new Date(t.updatedAt),closedDate:t.mergedAt?new Date(t.mergedAt):null,mergedDate:t.mergedAt?new Date(t.mergedAt):null,assignees:(d=t.assignees)!=null&&d.nodes?t.assignees.nodes.map(h=>O(h,r)):null,reviews:n,reviewDecision:t.approved?"APPROVED":_(n),additions:((c=t.diffStatsSummary)==null?void 0:c.additions)||0,deletions:((g=t.diffStatsSummary)==null?void 0:g.deletions)||0,fileCount:((m=t.diffStatsSummary)==null?void 0:m.fileCount)||0,commitCount:t.commitCount||0,mergeableState:es[t.mergeStatusEnum],milestone:t.milestone?He(t.milestone,s.webUrl):null,labels:((y=(f=t.labels)==null?void 0:f.nodes)==null?void 0:y.map(ze))??[]}},je=(t,s,e)=>{var r,n;return{author:O(t.author,e),assignees:t.assignees.nodes.map(o=>O(o,e)),commentCount:t.userNotesCount,closedDate:t.closedAt?new Date(t.closedAt):null,createdDate:new Date(t.createdAt),description:t.description,graphQLId:t.id,id:t.id.replace(rs,""),labels:((n=(r=t.labels)==null?void 0:r.nodes)==null?void 0:n.map(ze))??[],number:t.iid,repository:{id:s.id.replace(N,""),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?He(t.milestone,s.webUrl):null}},He=(t,s)=>({id:t.id.replace(ht,""),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}),V=class extends L{getIsSelfHosted(s){return!!s.baseUrl||!!this.config.baseUrl}async getCurrentUser(s={},e={}){var o;let n=(o=(await b(this.config,{query:`
|
|
686
701
|
query getCurrentUser {
|
|
687
702
|
currentUser {
|
|
688
|
-
${
|
|
703
|
+
${A}
|
|
689
704
|
}
|
|
690
705
|
}
|
|
691
|
-
`},
|
|
706
|
+
`},e)).body.data)==null?void 0:o.currentUser;if(!n)throw new Error("Current user not found.");return{data:O(n,this.getIsSelfHosted(e))}}async getUserForCommit(s,e={}){var a,i,u,l;let r=j(s.repo),o=(l=(u=(i=(a=(await b(this.config,{query:`
|
|
692
707
|
query getUserForCommit($fullPath: ID!, $oid: String!) {
|
|
693
708
|
project(fullPath: $fullPath) {
|
|
694
709
|
repository {
|
|
@@ -702,21 +717,21 @@ query getUserForCommit($fullPath: ID!, $oid: String!) {
|
|
|
702
717
|
}
|
|
703
718
|
}
|
|
704
719
|
}
|
|
705
|
-
`,variables:{fullPath:r,oid:s.oid}},e)).body.data)==null?void 0:
|
|
720
|
+
`,variables:{fullPath:r,oid:s.oid}},e)).body.data)==null?void 0:a.project)==null?void 0:i.repository)==null?void 0:u.tree)==null?void 0:l.lastCommit;if(!o)throw new Error("Commit not found.");return{data:{name:o.authorName,email:o.authorEmail,avatarUrl:o.authorGravatar}}}async getAccountForEmail(s,e={}){var o,a,i;let n=(i=(a=(o=(await b(this.config,{query:`
|
|
706
721
|
query getAccountForEmail($email: String!) {
|
|
707
722
|
users(search: $email) {
|
|
708
723
|
nodes {
|
|
709
|
-
${
|
|
724
|
+
${A}
|
|
710
725
|
}
|
|
711
726
|
}
|
|
712
727
|
}
|
|
713
|
-
`,variables:{email:s.email}},e)).body.data)==null?void 0:
|
|
728
|
+
`,variables:{email:s.email}},e)).body.data)==null?void 0:o.users)==null?void 0:a.nodes)==null?void 0:i[0];if(!n)throw new Error("User not found.");return{data:O(n,this.getIsSelfHosted(e))}}async getAccountForUsername(s,e={}){var o;let n=(o=(await b(this.config,{query:`
|
|
714
729
|
query getAccountForUsername($username: String!) {
|
|
715
730
|
user(username: $username) {
|
|
716
|
-
${
|
|
731
|
+
${A}
|
|
717
732
|
}
|
|
718
733
|
}
|
|
719
|
-
`,variables:{username:s.username}},e)).body.data)==null?void 0:
|
|
734
|
+
`,variables:{username:s.username}},e)).body.data)==null?void 0:o.user;if(!n)throw new Error("User not found.");return{data:O(n,this.getIsSelfHosted(e))}}async getAccountsForRepo(s,e={}){var u,l,p,d,c,g,m;let{repo:{namespace:r,name:n},cursor:o}=s,a=await b(this.config,{query:`
|
|
720
735
|
query getAccountsForRepo(
|
|
721
736
|
$fullPath: ID!
|
|
722
737
|
$after: String
|
|
@@ -727,7 +742,7 @@ query getAccountsForRepo(
|
|
|
727
742
|
projectMembers(after: $after) {
|
|
728
743
|
nodes {
|
|
729
744
|
user {
|
|
730
|
-
${
|
|
745
|
+
${A}
|
|
731
746
|
}
|
|
732
747
|
}
|
|
733
748
|
pageInfo {
|
|
@@ -737,22 +752,22 @@ query getAccountsForRepo(
|
|
|
737
752
|
}
|
|
738
753
|
}
|
|
739
754
|
}
|
|
740
|
-
`,variables:{fullPath:`${r}/${n}`,after:
|
|
755
|
+
`,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=>O(f,this.getIsSelfHosted(e))))??[]}}async getRepo(s,e={}){var o;let r=j(s),n=await b(this.config,{query:`
|
|
741
756
|
query getRepo($fullPath: ID!) {
|
|
742
757
|
project(fullPath: $fullPath) {
|
|
743
|
-
${
|
|
758
|
+
${xe}
|
|
744
759
|
}
|
|
745
760
|
}
|
|
746
|
-
`,variables:{fullPath:r}},e);if(!((
|
|
761
|
+
`,variables:{fullPath:r}},e);if(!((o=n.body.data)!=null&&o.project))throw new Error(`Repository ${r} not found`);return{data:Ne(n.body.data.project)}}async getRepos(s,e={}){let n=s.map(j).map((u,l)=>`
|
|
747
762
|
getRepo_${l}: project(fullPath: "${u}") {
|
|
748
|
-
${
|
|
763
|
+
${xe}
|
|
749
764
|
}
|
|
750
765
|
`).join(`
|
|
751
|
-
`),
|
|
766
|
+
`),o=await b(this.config,{query:`
|
|
752
767
|
query batchGetRepos {
|
|
753
768
|
${n}
|
|
754
769
|
}
|
|
755
|
-
`},e);if(!
|
|
770
|
+
`},e);if(!o.body.data)throw new Error(o.statusText||"Unknown error");let a=[],i=[];return s.forEach((u,l)=>{let p=o.body.data[`getRepo_${l}`];p?a.push(Ne(p)):i.push({input:u})}),{data:a,errors:i}}async getReposForCurrentUser(s={},e={}){var o,a,i,u,l,p;let r=await b(this.config,{query:`
|
|
756
771
|
query getReposForCurrentUser($after: String) {
|
|
757
772
|
projects(membership: true first: 100 after: $after) {
|
|
758
773
|
pageInfo {
|
|
@@ -760,11 +775,11 @@ query getReposForCurrentUser($after: String) {
|
|
|
760
775
|
hasNextPage
|
|
761
776
|
}
|
|
762
777
|
nodes {
|
|
763
|
-
${
|
|
778
|
+
${xe}
|
|
764
779
|
}
|
|
765
780
|
}
|
|
766
781
|
}
|
|
767
|
-
`,variables:{after:s.cursor}},e);if(!((
|
|
782
|
+
`,variables:{after:s.cursor}},e);if(!((o=r.body.data)!=null&&o.projects))throw new Error(((a=r.body.errors)==null?void 0:a[0].message)||r.statusText||"Unknown error");let n=((u=(i=r.body.data)==null?void 0:i.projects)==null?void 0:u.nodes)||[];return{pageInfo:(p=(l=r.body.data)==null?void 0:l.projects)==null?void 0:p.pageInfo,data:n.map(Ne)}}async getRefs(s,e,r={}){var u;let n=j(e.repo),o=new URL(`${Te(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",D.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=j(s.repo),n=new URL(`${Te(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 a,i;let r=Yt[s.association],n=await b(this.config,{query:`
|
|
768
783
|
query getPullRequestsForUser($username: String! $cursor: String) {
|
|
769
784
|
user(username: $username) {
|
|
770
785
|
${r}(state:opened first:100 after:$cursor) {
|
|
@@ -773,12 +788,12 @@ query getPullRequestsForUser($username: String! $cursor: String) {
|
|
|
773
788
|
hasNextPage
|
|
774
789
|
}
|
|
775
790
|
nodes {
|
|
776
|
-
${
|
|
791
|
+
${_e(!0,!0,!0)}
|
|
777
792
|
}
|
|
778
793
|
}
|
|
779
794
|
}
|
|
780
795
|
}
|
|
781
|
-
`,variables:{username:s.username,cursor:s.cursor}},e);if(!n.body.data)throw new Error(((
|
|
796
|
+
`,variables:{username:s.username,cursor:s.cursor}},e);if(!n.body.data)throw new Error(((a=n.body.errors)==null?void 0:a[0].message)||n.statusText||"Unknown error");if(!n.body.data.user)throw new Error("User not found");let o=n.body.data.user[r];if(!o)throw new Error("Unexpected response");return{pageInfo:o.pageInfo,data:((i=o.nodes)==null?void 0:i.map(u=>Qe(u,mt(u.project),mt(u.sourceProject),this.getIsSelfHosted(e))))||[]}}async getPullRequestsAssociatedWithUser(s,e={}){var c;let[r,n,o]=((c=s.cursor)==null?void 0:c.split(";"))||[void 0,void 0,void 0],[a,i,u]=await Promise.all([r==="null"?null:this.getPullRequestsForUser({username:s.username,association:"authored",cursor:r},e),n==="null"?null:this.getPullRequestsForUser({username:s.username,association:"assigned",cursor:n},e),o==="null"?null:this.getPullRequestsForUser({username:s.username,association:"reviewRequested",cursor:o},e)]),l={},p=[],d=g=>{l[g.id]||(l[g.id]=!0,p.push(g))};return a==null||a.data.forEach(d),i==null||i.data.forEach(d),u==null||u.data.forEach(d),{pageInfo:{hasNextPage:(a==null?void 0:a.pageInfo.hasNextPage)||(i==null?void 0:i.pageInfo.hasNextPage)||(u==null?void 0:u.pageInfo.hasNextPage)||!1,endCursor:`${(a==null?void 0:a.pageInfo.hasNextPage)&&(a==null?void 0:a.pageInfo.endCursor)||"null"};${(i==null?void 0:i.pageInfo.hasNextPage)&&(i==null?void 0:i.pageInfo.endCursor)||"null"};${(u==null?void 0:u.pageInfo.hasNextPage)&&(u==null?void 0:u.pageInfo.endCursor)||"null"}`},data:p}}getVariablesForPullRequests(s){let{updatedBefore:e,isDraft:r,authorLogin:n,assigneeLogins:o,reviewRequestedLogin:a}=s||{},i={},u=[],l=[],p=(d,c,g)=>{u.push(`$${d}: ${g}`),l.push(`${d}: $${d}`),i[d]=c};return e&&p("updatedBefore",e,"Time"),n&&p("authorUsername",n,"String"),o&&p("assigneeUsername",o[0],"String"),r!=null&&p("draft",r,"Boolean"),a&&p("reviewerUsername",a,"String"),{variables:i,variableTypes:u,mergeRequestArguments:l}}async getPullRequestsForRepo(s,e={}){var f,y,h;let{cursor:r,repo:n}=s||{},o=j(n),{variables:a,variableTypes:i,mergeRequestArguments:u}=this.getVariablesForPullRequests(s),l={fullPath:o,...a},p=await b(this.config,{query:`
|
|
782
797
|
query getPullRequestsForRepo(
|
|
783
798
|
$fullPath: ID!
|
|
784
799
|
$after: String
|
|
@@ -787,6 +802,7 @@ query getPullRequestsForRepo(
|
|
|
787
802
|
project(
|
|
788
803
|
fullPath: $fullPath
|
|
789
804
|
) {
|
|
805
|
+
id
|
|
790
806
|
path
|
|
791
807
|
fullPath
|
|
792
808
|
webUrl
|
|
@@ -802,16 +818,16 @@ query getPullRequestsForRepo(
|
|
|
802
818
|
hasNextPage
|
|
803
819
|
}
|
|
804
820
|
nodes {
|
|
805
|
-
${
|
|
821
|
+
${_e(!1,!0,!0)}
|
|
806
822
|
}
|
|
807
823
|
}
|
|
808
824
|
}
|
|
809
825
|
}
|
|
810
|
-
`,variables:{...l,after:r}},e),d=[],c=(
|
|
826
|
+
`,variables:{...l,after:r}},e),d=[],c=(f=p.body.data)==null?void 0:f.project,g=J(c||{id:"",fullPath:"",path:"",webUrl:""});return(((y=c==null?void 0:c.mergeRequests)==null?void 0:y.nodes)||[]).forEach(P=>{d.push(Qe(P,g,null,this.getIsSelfHosted(e)))}),{pageInfo:(h=c==null?void 0:c.mergeRequests)==null?void 0:h.pageInfo,data:d}}async getPullRequestsForRepos(s,e={}){var c,g,m,f,y;let{cursor:r}=s||{},n=s.repoIds.map(h=>h.toString().startsWith(N)?h:`${N}${h}`),{variables:o,variableTypes:a,mergeRequestArguments:i}=this.getVariablesForPullRequests(s),u={projectIds:n,...o},l=await b(this.config,{query:`
|
|
811
827
|
query getPullRequests(
|
|
812
828
|
$projectIds: [ID!]
|
|
813
829
|
$after: String
|
|
814
|
-
${
|
|
830
|
+
${a.length?a.join(" "):""}
|
|
815
831
|
) {
|
|
816
832
|
projects(
|
|
817
833
|
ids: $projectIds
|
|
@@ -822,6 +838,7 @@ query getPullRequests(
|
|
|
822
838
|
hasNextPage
|
|
823
839
|
}
|
|
824
840
|
nodes {
|
|
841
|
+
id
|
|
825
842
|
path
|
|
826
843
|
fullPath
|
|
827
844
|
webUrl
|
|
@@ -832,20 +849,20 @@ query getPullRequests(
|
|
|
832
849
|
${i.length?i.join(" "):""}
|
|
833
850
|
) {
|
|
834
851
|
nodes {
|
|
835
|
-
${
|
|
852
|
+
${_e(!1,!1,!1)}
|
|
836
853
|
}
|
|
837
854
|
}
|
|
838
855
|
}
|
|
839
856
|
}
|
|
840
857
|
}
|
|
841
|
-
`,variables:{...u,after:r}},e),p=[];return(((g=(c=l.body.data)==null?void 0:c.projects)==null?void 0:g.nodes)||[]).forEach(
|
|
858
|
+
`,variables:{...u,after:r}},e),p=[];return(((g=(c=l.body.data)==null?void 0:c.projects)==null?void 0:g.nodes)||[]).forEach(h=>{var C;let P=J(h);(((C=h.mergeRequests)==null?void 0:C.nodes)||[]).forEach(te=>{p.push(Qe(te,P,null,this.getIsSelfHosted(e)))})}),{pageInfo:(y=(f=(m=l.body)==null?void 0:m.data)==null?void 0:f.projects)==null?void 0:y.pageInfo,data:p}}async closePullRequest(s,e={}){var l,p,d;let{repo:{namespace:r,name:n},pullRequestId:o}=s,a=`mutation ClosePullRequest($fullPath: ID!, $pullRequestId: String!) {
|
|
842
859
|
mergeRequestUpdate(input: { projectPath: $fullPath, iid: $pullRequestId, state: CLOSED }) {
|
|
843
860
|
errors,
|
|
844
861
|
mergeRequest {
|
|
845
862
|
id
|
|
846
863
|
}
|
|
847
864
|
}
|
|
848
|
-
}`,u=(l=(await
|
|
865
|
+
}`,u=(l=(await b(this.config,{query:a,variables:{fullPath:`${r}/${n}`,pullRequestId:o}},e)).body.data)==null?void 0:l.mergeRequestUpdate;if(!((p=u==null?void 0:u.mergeRequest)!=null&&p.id)||((d=u==null?void 0:u.errors)==null?void 0:d.length)!==0)throw new Error("Could not close pull request")}async mergePullRequest(s,e={}){var d,c,g;let{repo:{namespace:r,name:n},pullRequestId:o,expectedSourceSha:a,mergeStrategy:i}=s,u=`mutation MergePullRequest(
|
|
849
866
|
$fullPath: ID!,
|
|
850
867
|
$pullRequestId: String!,
|
|
851
868
|
$expectedSourceSha: String!,
|
|
@@ -862,52 +879,53 @@ query getPullRequests(
|
|
|
862
879
|
id
|
|
863
880
|
}
|
|
864
881
|
}
|
|
865
|
-
}`,p=(d=(await
|
|
882
|
+
}`,p=(d=(await b(this.config,{query:u,variables:{fullPath:`${r}/${n}`,pullRequestId:o,expectedSourceSha:a,squash:i==="SQUASH"}},e)).body.data)==null?void 0:d.mergeRequestAccept;if(!((c=p==null?void 0:p.mergeRequest)!=null&&c.id)||((g=p==null?void 0:p.errors)==null?void 0:g.length)!==0)throw new Error("Could not merge pull request")}async setPullRequestMilestone(s,e={}){var p,d,c;let{repo:{namespace:r,name:n},pullRequestId:o,milestoneGraphQLId:a}=s,i=`mutation SetPullRequestMilestone($fullPath: ID!, $pullRequestId: String!, $milestoneGraphQLId: MilestoneID) {
|
|
866
883
|
mergeRequestSetMilestone(input: { projectPath: $fullPath, iid: $pullRequestId, milestoneId: $milestoneGraphQLId }) {
|
|
867
884
|
errors,
|
|
868
885
|
mergeRequest {
|
|
869
886
|
id
|
|
870
887
|
}
|
|
871
888
|
}
|
|
872
|
-
}`,u=await
|
|
889
|
+
}`,u=await b(this.config,{query:i,variables:{fullPath:`${r}/${n}`,pullRequestId:o,milestoneGraphQLId:a}},e),l=(p=u.body.data)==null?void 0:p.mergeRequestSetMilestone;if(!((d=l==null?void 0:l.mergeRequest)!=null&&d.id)||u.body.errors||((c=l==null?void 0:l.errors)==null?void 0:c.length)!==0)throw new Error("Could not set milestone of pull request")}async setPullRequestAsDraft(s,e={}){var p,d,c;let{repo:{namespace:r,name:n},pullRequestId:o,isDraft:a}=s,i=`mutation MergeRequestSetDraft($fullPath: ID!, $pullRequestId: String!, $isDraft: Boolean!) {
|
|
873
890
|
mergeRequestSetDraft(input: { projectPath: $fullPath, iid: $pullRequestId, draft: $isDraft }) {
|
|
874
891
|
errors,
|
|
875
892
|
mergeRequest {
|
|
876
893
|
id
|
|
877
894
|
}
|
|
878
895
|
}
|
|
879
|
-
}`,l=(p=(await
|
|
896
|
+
}`,l=(p=(await b(this.config,{query:i,variables:{fullPath:`${r}/${n}`,pullRequestId:o,isDraft:a}},e)).body.data)==null?void 0:p.mergeRequestSetDraft;if(!((d=l==null?void 0:l.mergeRequest)!=null&&d.id)||((c=l==null?void 0:l.errors)==null?void 0:c.length)!==0)throw new Error("Could not set pull request as draft")}async setPullRequestReviewers(s,e={}){var p,d,c;let{repo:{namespace:r,name:n},pullRequestId:o,reviewerUsernames:a}=s,i=`mutation MergeRequestSetReviewers($fullPath: ID!, $pullRequestId: String!, $reviewerUsernames: [String!]!) {
|
|
880
897
|
mergeRequestSetReviewers(input: { projectPath: $fullPath, iid: $pullRequestId, reviewerUsernames: $reviewerUsernames }) {
|
|
881
898
|
errors,
|
|
882
899
|
mergeRequest {
|
|
883
900
|
id
|
|
884
901
|
}
|
|
885
902
|
}
|
|
886
|
-
}`,l=(p=(await
|
|
903
|
+
}`,l=(p=(await b(this.config,{query:i,variables:{fullPath:`${r}/${n}`,pullRequestId:o,reviewerUsernames:a}},e)).body.data)==null?void 0:p.mergeRequestSetReviewers;if(!((d=l==null?void 0:l.mergeRequest)!=null&&d.id)||((c=l==null?void 0:l.errors)==null?void 0:c.length)!==0)throw new Error("Could not set pull request reviewers")}async setPullRequestAssignees(s,e={}){var p,d,c;let{repo:{namespace:r,name:n},pullRequestId:o,assigneeUsernames:a}=s,i=`mutation MergeRequestSetAssignees($fullPath: ID!, $pullRequestId: String!, $assigneeUsernames: [String!]!) {
|
|
887
904
|
mergeRequestSetAssignees(input: { projectPath: $fullPath, iid: $pullRequestId, assigneeUsernames: $assigneeUsernames }) {
|
|
888
905
|
errors,
|
|
889
906
|
mergeRequest {
|
|
890
907
|
id
|
|
891
908
|
}
|
|
892
909
|
}
|
|
893
|
-
}`,l=(p=(await
|
|
910
|
+
}`,l=(p=(await b(this.config,{query:i,variables:{fullPath:`${r}/${n}`,pullRequestId:o,assigneeUsernames:a}},e)).body.data)==null?void 0:p.mergeRequestSetAssignees;if(!((d=l==null?void 0:l.mergeRequest)!=null&&d.id)||((c=l==null?void 0:l.errors)==null?void 0:c.length)!==0)throw new Error("Could not set pull request assignees")}async setPullRequestLabels(s,e={}){var l,p,d;let{repo:{namespace:r,name:n},pullRequestId:o,labelGraphQLIds:a}=s,i=`mutation SetPullRequestLabels($fullPath: ID!, $pullRequestId: String!, $labelGraphQLIds: [LabelID!]!) {
|
|
894
911
|
mergeRequestSetLabels(input: { projectPath: $fullPath, iid: $pullRequestId, labelIds: $labelGraphQLIds }) {
|
|
895
912
|
mergeRequest {
|
|
896
913
|
id
|
|
897
914
|
}
|
|
898
915
|
}
|
|
899
|
-
}`;if(!((d=(p=(l=(await
|
|
916
|
+
}`;if(!((d=(p=(l=(await b(this.config,{query:i,variables:{fullPath:`${r}/${n}`,pullRequestId:o,labelGraphQLIds:a}},e)).body.data)==null?void 0:l.mergeRequestSetLabels)==null?void 0:p.mergeRequest)!=null&&d.id))throw new Error("Could not set pull request labels")}async getIssue(s,e={}){var o,a,i;let r=is(s),n=await b(this.config,{query:`
|
|
900
917
|
query GetSingleIssue($projectId: ID!, $issueId: String!) {
|
|
901
918
|
project(fullPath: $projectId) {
|
|
919
|
+
id
|
|
902
920
|
path
|
|
903
921
|
fullPath
|
|
904
922
|
webUrl
|
|
905
923
|
issue(iid: $issueId) {
|
|
906
|
-
${
|
|
924
|
+
${ke}
|
|
907
925
|
}
|
|
908
926
|
}
|
|
909
927
|
}
|
|
910
|
-
`,variables:{issueId:s.id,projectId:r}},e);if(!((
|
|
928
|
+
`,variables:{issueId:s.id,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.id} not found`);return{data:je(n.body.data.project.issue,J(n.body.data.project),this.getIsSelfHosted(e))}}getVariablesForIssues(s){let{updatedBefore:e,authorLogin:r,assigneeLogins:n}=s||{},o={},a=[],i=[],u=(l,p,d)=>{a.push(`$${l}: ${d}`),i.push(`${l}: $${l}`),o[l]=p};return e&&u("updatedBefore",e,"Time"),r&&u("authorUsername",r,"String"),n&&u("assigneeUsername",n[0],"String"),{variables:o,variableTypes:a,issueArguments:i}}async getIssuesForRepo(s,e={}){var y,h,P;let{cursor:r,repo:n}=s||{},o=j(n),{variables:a,variableTypes:i,issueArguments:u}=this.getVariablesForIssues(s),l={fullPath:o,...a},p=`
|
|
911
929
|
query GetIssuesFromProject(
|
|
912
930
|
$fullPath: ID!
|
|
913
931
|
$after: String
|
|
@@ -916,6 +934,7 @@ query GetSingleIssue($projectId: ID!, $issueId: String!) {
|
|
|
916
934
|
project(
|
|
917
935
|
fullPath: $fullPath
|
|
918
936
|
) {
|
|
937
|
+
id
|
|
919
938
|
path
|
|
920
939
|
fullPath
|
|
921
940
|
webUrl
|
|
@@ -927,7 +946,7 @@ query GetSingleIssue($projectId: ID!, $issueId: String!) {
|
|
|
927
946
|
${u.length?u.join(" "):""}
|
|
928
947
|
) {
|
|
929
948
|
nodes {
|
|
930
|
-
${
|
|
949
|
+
${ke}
|
|
931
950
|
}
|
|
932
951
|
pageInfo {
|
|
933
952
|
endCursor
|
|
@@ -935,11 +954,11 @@ query GetSingleIssue($projectId: ID!, $issueId: String!) {
|
|
|
935
954
|
}
|
|
936
955
|
}
|
|
937
956
|
}
|
|
938
|
-
}`,d=await
|
|
957
|
+
}`,d=await b(this.config,{query:p,variables:{...l,after:r}},e),c=[],g=(y=d.body.data)==null?void 0:y.project,m=J(g||{id:"",fullPath:"",path:"",webUrl:""});return(((h=g==null?void 0:g.issues)==null?void 0:h.nodes)||[]).forEach(q=>{c.push(je(q,m,this.getIsSelfHosted(e)))}),{pageInfo:(P=g==null?void 0:g.issues)==null?void 0:P.pageInfo,data:c.sort((q,C)=>(q.updatedDate||q.createdDate).getTime()-(C.updatedDate||C.createdDate).getTime())}}async getIssuesForRepos(s,e={}){var g,m,f,y,h;let{cursor:r}=s||{},n=s.repoIds.map(P=>P.toString().startsWith(N)?P:`${N}${P}`),{variables:o,variableTypes:a,mergeRequestArguments:i}=this.getVariablesForPullRequests(s),u={projectIds:n,...o},l=`
|
|
939
958
|
query GetIssuesFromProject(
|
|
940
959
|
$projectIds: [ID!]
|
|
941
960
|
$after: String
|
|
942
|
-
${
|
|
961
|
+
${a.length?a.join(" "):""}
|
|
943
962
|
) {
|
|
944
963
|
projects(
|
|
945
964
|
ids: $projectIds
|
|
@@ -950,6 +969,7 @@ query GetSingleIssue($projectId: ID!, $issueId: String!) {
|
|
|
950
969
|
hasNextPage
|
|
951
970
|
}
|
|
952
971
|
nodes {
|
|
972
|
+
id
|
|
953
973
|
path
|
|
954
974
|
fullPath
|
|
955
975
|
webUrl
|
|
@@ -960,24 +980,24 @@ query GetSingleIssue($projectId: ID!, $issueId: String!) {
|
|
|
960
980
|
${i.length?i.join(" "):""}
|
|
961
981
|
) {
|
|
962
982
|
nodes {
|
|
963
|
-
${
|
|
983
|
+
${ke}
|
|
964
984
|
}
|
|
965
985
|
}
|
|
966
986
|
}
|
|
967
987
|
}
|
|
968
|
-
}`,p=await
|
|
988
|
+
}`,p=await b(this.config,{query:l,variables:{...u,after:r}},e),d=[];return(((m=(g=p.body.data)==null?void 0:g.projects)==null?void 0:m.nodes)||[]).forEach(P=>{var te;let q=J(P);(((te=P.issues)==null?void 0:te.nodes)||[]).forEach(ft=>d.push(je(ft,q,this.getIsSelfHosted(e))))}),{pageInfo:(h=(y=(f=p.body)==null?void 0:f.data)==null?void 0:y.projects)==null?void 0:h.pageInfo,data:d.sort((P,q)=>(P.updatedDate||P.createdDate).getTime()-(q.updatedDate||q.createdDate).getTime())}}async setIssueStatus(s,e={}){var l,p,d;let{repo:{namespace:r,name:n},issueId:o,status:a}=s,i=`mutation SetIssueState($fullPath: ID!, $issueId: String!, $status: IssueStateEvent!) {
|
|
969
989
|
updateIssue(input: { projectPath: $fullPath, iid: $issueId, stateEvent: $status }) {
|
|
970
990
|
issue {
|
|
971
991
|
id
|
|
972
992
|
}
|
|
973
993
|
}
|
|
974
|
-
}`;if(!((d=(p=(l=(await
|
|
994
|
+
}`;if(!((d=(p=(l=(await b(this.config,{query:i,variables:{fullPath:`${r}/${n}`,issueId:o,status:a}},e)).body.data)==null?void 0:l.updateIssue)==null?void 0:p.issue)!=null&&d.id))throw new Error("Could not set issue status")}async setIssueLabels(s,e={}){var l,p,d;let{repo:{namespace:r,name:n},issueId:o,labelGraphQLIds:a}=s,i=`mutation SetIssueLabels($fullPath: ID!, $issueId: String!, $labelGraphQLIds: [ID!]) {
|
|
975
995
|
updateIssue(input: { projectPath: $fullPath, iid: $issueId, labelIds: $labelGraphQLIds }) {
|
|
976
996
|
issue {
|
|
977
997
|
id
|
|
978
998
|
}
|
|
979
999
|
}
|
|
980
|
-
}`;if(!((d=(p=(l=(await
|
|
1000
|
+
}`;if(!((d=(p=(l=(await b(this.config,{query:i,variables:{fullPath:`${r}/${n}`,issueId:o,labelGraphQLIds:a}},e)).body.data)==null?void 0:l.updateIssue)==null?void 0:p.issue)!=null&&d.id))throw new Error("Could not set issue labels")}async setIssueMilestone(s,e={}){var p,d,c,g;let{repo:{namespace:r,name:n},issueId:o}=s,a=((p=s.milestoneGraphQLId)==null?void 0:p.replace(ht,""))??"",i=`mutation SetIssueMilestone($fullPath: ID!, $issueId: String!, $milestoneGraphQLId: ID) {
|
|
981
1001
|
updateIssue(input: { projectPath: $fullPath, iid: $issueId, milestoneId: $milestoneGraphQLId }) {
|
|
982
1002
|
errors
|
|
983
1003
|
issue {
|
|
@@ -987,14 +1007,14 @@ query GetSingleIssue($projectId: ID!, $issueId: String!) {
|
|
|
987
1007
|
}
|
|
988
1008
|
}
|
|
989
1009
|
}
|
|
990
|
-
}`,u=await
|
|
1010
|
+
}`,u=await b(this.config,{query:i,variables:{fullPath:`${r}/${n}`,issueId:o,milestoneGraphQLId:a}},e),l=(d=u.body.data)==null?void 0:d.updateIssue;if(!((c=l==null?void 0:l.issue)!=null&&c.id)||u.body.errors||((g=l==null?void 0:l.errors)==null?void 0:g.length)!==0)throw new Error("Could not set milestone of issue")}async setIssueAssignees(s,e={}){var p,d,c;let{repo:{namespace:r,name:n},issueId:o,assigneeUsernames:a}=s,i=`mutation SetIssueAssignees($fullPath: ID!, $issueId: String!, $assigneeUsernames: [String!]!) {
|
|
991
1011
|
issueSetAssignees(input: { projectPath: $fullPath, iid: $issueId, assigneeUsernames: $assigneeUsernames }) {
|
|
992
1012
|
errors,
|
|
993
1013
|
issue {
|
|
994
1014
|
id
|
|
995
1015
|
}
|
|
996
1016
|
}
|
|
997
|
-
}`,l=(p=(await
|
|
1017
|
+
}`,l=(p=(await b(this.config,{query:i,variables:{fullPath:`${r}/${n}`,issueId:o,assigneeUsernames:a}},e)).body.data)==null?void 0:p.issueSetAssignees;if(!((d=l==null?void 0:l.issue)!=null&&d.id)||((c=l==null?void 0:l.errors)==null?void 0:c.length)!==0)throw new Error("Could not set issue assignees")}async getMilestonesForRepo(s,e={}){var i,u,l,p,d,c,g;let{repo:{namespace:r,name:n},cursor:o}=s,a=await b(this.config,{query:`
|
|
998
1018
|
query getLabelsForRepo(
|
|
999
1019
|
$fullPath: ID!
|
|
1000
1020
|
$after: String
|
|
@@ -1005,7 +1025,7 @@ query getLabelsForRepo(
|
|
|
1005
1025
|
webUrl
|
|
1006
1026
|
milestones(after: $after) {
|
|
1007
1027
|
nodes {
|
|
1008
|
-
${
|
|
1028
|
+
${Be}
|
|
1009
1029
|
}
|
|
1010
1030
|
pageInfo {
|
|
1011
1031
|
endCursor
|
|
@@ -1014,7 +1034,7 @@ query getLabelsForRepo(
|
|
|
1014
1034
|
}
|
|
1015
1035
|
}
|
|
1016
1036
|
}
|
|
1017
|
-
`,variables:{fullPath:`${r}/${n}`,after:
|
|
1037
|
+
`,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,y;return He(m,((y=(f=a.body.data)==null?void 0:f.project)==null?void 0:y.webUrl)||"")}))??[]}}async getLabelsForRepo(s,e={}){var i,u,l,p,d,c,g;let{repo:{namespace:r,name:n},cursor:o}=s,a=await b(this.config,{query:`
|
|
1018
1038
|
query getLabelsForRepo(
|
|
1019
1039
|
$fullPath: ID!
|
|
1020
1040
|
$after: String
|
|
@@ -1024,7 +1044,7 @@ query getLabelsForRepo(
|
|
|
1024
1044
|
) {
|
|
1025
1045
|
labels(after: $after) {
|
|
1026
1046
|
nodes {
|
|
1027
|
-
${
|
|
1047
|
+
${Me}
|
|
1028
1048
|
}
|
|
1029
1049
|
pageInfo {
|
|
1030
1050
|
endCursor
|
|
@@ -1033,4 +1053,4 @@ query getLabelsForRepo(
|
|
|
1033
1053
|
}
|
|
1034
1054
|
}
|
|
1035
1055
|
}
|
|
1036
|
-
`,variables:{fullPath:`${r}/${n}`,after:a}},e);return{pageInfo:((l=(u=(i=o.body.data)==null?void 0:i.project)==null?void 0:u.labels)==null?void 0:l.pageInfo)??{endCursor:null,hasNextPage:!1},data:((g=(c=(d=(p=o.body.data)==null?void 0:p.project)==null?void 0:d.labels)==null?void 0:c.nodes)==null?void 0:g.map(Be))??[]}}};var ts="https://api.atlassian.com/ex/jira",ss=100,rs=(t,s,e)=>{var n,a,o,i;let r=t.fields.assignee;return{id:t.id,commentCount:t.fields.comment.comments.length,number:t.key,title:t.fields.summary,url:s?`${s}/browse/${t.key}`:null,closedDate:null,createdDate:new Date(t.fields.created),author:ae(t.fields.creator,s,e),updatedDate:new Date(t.fields.updated),assignees:r?[ae(r,s,e)]:[],description:null,repository:null,state:is(t.fields.status),statusTransitions:((n=t.transitions)==null?void 0:n.map(ns))??[],components:((a=t.fields.components)==null?void 0:a.map(os))??[],type:t.fields.issuetype.name,upvoteCount:((o=t.fields.votes)==null?void 0:o.votes)||0,labels:((i=t.fields.labels)==null?void 0:i.map(u=>({color:null,description:null,id:null,name:u})))??[]}},ns=t=>({name:t.name,id:t.id}),os=t=>({description:t.description??null,id:t.id,name:t.name}),as=(t,s,e)=>e&&t.name?`${s}/secure/ViewProfile.jspa?name=${encodeURIComponent(t.name)}`:`${s}/jira/people/${t.accountId}`,ae=(t,s,e)=>({id:(e?t.key:t.accountId)??"",name:t.displayName,email:t.emailAddress,avatarUrl:t.avatarUrls["48x48"],username:t.displayName,url:as(t,s,e)}),is=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{name:t.name,color:t.statusCategory.colorName,category:s}},H=(t,s,e)=>e?`${s.baseUrl||ts}/${e}`:`${(s==null?void 0:s.baseUrl)||t.baseUrl}`,ie=async(t,s,e,r={})=>{let{assigneeLogins:n,authorLogin:a,mentionLogin:o,project:i,resourceId:u}=s||{},l=[`project = "${i}"`,"statusCategory != Done"];return a&&l.push(`creator in ("${a}")`),n&&n.length!==0&&l.push(`assignee in ("${n.join('", "')}")`),o&&l.push(`comment ~ "${o}"`),{data:(await t.request({url:`${H(t,r,u)}/rest/api/2/search?jql=${l.join(" AND ")}&startAt=0&maxResults=${ss}&fields=${["assignee","comment","summary","created","creator","updated","votes","issuetype","status","labels","components"].join(",")}&expand=transitions`,headers:m(r.token||t.token)})).body.issues.map(d=>rs(d,e,!u))}},ue=async(t,s,e={})=>{let{resourceId:r,issueId:n,labelNames:a}=s,o={fields:{labels:a}};await t.request({method:"PUT",url:`${H(t,e,r)}/rest/api/2/issue/${n}`,body:JSON.stringify(o),headers:{...m(e.token||t.token),"Content-Type":"application/json"}})},le=async(t,s,e={})=>{let{resourceId:r,issueId:n,componentIds:a}=s,o={fields:{components:a.map(i=>({id:i}))}};await t.request({method:"PUT",url:`${H(t,e,r)}/rest/api/2/issue/${n}`,body:JSON.stringify(o),headers:{...m(e.token||t.token),"Content-Type":"application/json"}})},pe=async(t,s,e={})=>{let{resourceId:r,issueId:n,status:a}=s,o={transition:{id:a}};await t.request({method:"POST",url:`${H(t,e,r)}/rest/api/2/issue/${n}/transitions`,body:JSON.stringify(o),headers:{...m(e.token||t.token),"Content-Type":"application/json"}})},de=async(t,s,e={})=>{let{resourceId:r,projectIdOrKey:n}=s,a=new URL(`${H(t,e,r)}/rest/api/2/project/${n}/components`);return{data:(await t.request({url:a.toString(),headers:m(e.token||t.token)})).body}};var J="https://api.atlassian.com/ex/jira",Me=100,K=class extends E{constructor(){super(...arguments);this._resourceUrlCache={}}async getResourceUrl(e,r={}){var o;let n=r.token||this.config.token;if(!n)return null;let a=this._resourceUrlCache[n];return a?a[e.resourceId]??null:(await this.getJiraResourcesForCurrentUser(r),((o=this._resourceUrlCache[n])==null?void 0:o[e.resourceId])??null)}async getCurrentUserForResource(e,r={}){let n=await this.getResourceUrl({resourceId:e.resourceId},r),a=await this.config.request({url:`${r.baseUrl||J}/${e.resourceId}/rest/api/2/myself`,headers:m(r.token||this.config.token)});return{data:{name:a.body.displayName,email:a.body.emailAddress,avatarUrl:a.body.avatarUrls["48x48"],id:a.body.accountId,username:a.body.displayName,url:n?`${n}/jira/people/${a.body.accountId}`:null}}}async getJiraResourcesForCurrentUser(e={}){let r=await this.config.request({url:`${e.baseUrl||"https://api.atlassian.com/"}/oauth/token/accessible-resources`,headers:m(e.token||this.config.token)}),n=e.token||this.config.token,a=n?this._resourceUrlCache[n]||{}:void 0,o=r.body.map(i=>(a&&(a[i.id]=i.url),{avatarUrl:i.avatarUrl,id:i.id,name:i.name,url:i.url}));return n&&(this._resourceUrlCache[n]=a),{data:o}}async getJiraProjectsForResource(e,r={}){let n=new URL(`${r.baseUrl||J}/${e.resourceId}/rest/api/2/project/search`);n.searchParams.set("maxResults",Me.toString()),e.cursor&&n.searchParams.set("startAt",e.cursor);let a=await this.config.request({url:n.toString(),headers:m(r.token||this.config.token)});return{pageInfo:{hasNextPage:a.body.values.length!==0,endCursor:(a.body.startAt+a.body.values.length).toString()},data:a.body.values.map(o=>({id:o.id,key:o.key,name:o.name,resourceId:e.resourceId}))}}async getJiraProjectsForResources(e,r={}){let n=[];return await Promise.all(e.resourceIds.map(async a=>{let o=await this.getJiraProjectsForResource({resourceId:a},r);n.push(...o.data)})),{data:n}}async getAccountsForJiraProject(e,r={}){let{resourceId:n,projectKey:a,cursor:o}=e,i=await this.getResourceUrl({resourceId:n},r),u=new URL(`${r.baseUrl||J}/${n}/rest/api/2/user/assignable/search`);u.searchParams.set("maxResults",Me.toString()),o&&u.searchParams.set("startAt",o),u.searchParams.set("project",a);let l=await this.config.request({url:u.toString(),headers:m(r.token||this.config.token)});return{pageInfo:{hasNextPage:l.body.length!==0,endCursor:((o?parseInt(o):0)+l.body.length).toString()},data:l.body.filter(p=>p.accountType!=="app"&&p.active).map(p=>ae(p,i,!1))}}async getComponentsForJiraProject(e,r={}){return await de(this.config,e,r)}async getIssuesForProject(e,r={}){let n=await this.getResourceUrl({resourceId:e.resourceId},r);return await ie(this.config,e,n,r)}async setIssueStatus(e,r={}){await pe(this.config,e,r)}async setIssueAssignee(e,r={}){let{resourceId:n,issueId:a,assigneeId:o}=e,i={accountId:o};await this.config.request({method:"PUT",url:`${r.baseUrl||J}/${n}/rest/api/2/issue/${a}/assignee`,body:JSON.stringify(i),headers:{...m(r.token||this.config.token),"Content-Type":"application/json"}})}async setIssueComponents(e,r={}){await le(this.config,e,r)}async setIssueLabels(e,r={}){await ue(this.config,e,r)}async getLabelsForResource(e,r={}){let{resourceId:n,cursor:a}=e,o=new URL(`${r.baseUrl||J}/${n}/rest/api/2/label`);o.searchParams.set("maxResults",Me.toString()),a&&o.searchParams.set("startAt",a);let i=await this.config.request({url:o.toString(),headers:m(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 V=class extends v{async getCurrentUser(s={}){let e=await this.config.request({url:`${(s==null?void 0:s.baseUrl)||this.config.baseUrl}/rest/api/2/myself`,headers:m((s==null?void 0:s.token)||this.config.token)});return{data:{name:e.body.displayName,email:e.body.emailAddress,avatarUrl:e.body.avatarUrls["48x48"],id:e.body.key,username:e.body.displayName,url:null}}}async getJiraProjects(s={}){return{data:(await this.config.request({url:`${(s==null?void 0:s.baseUrl)||this.config.baseUrl}/rest/api/2/project`,headers:m((s==null?void 0:s.token)||this.config.token)})).body.map(r=>({id:r.id,name:r.name}))}}async getIssuesForProject(s,e={}){if(!e.baseUrl)throw new Error('Jira Server requires a "baseUrl" for this function.');return await ie(this.config,s,e.baseUrl,e)}async setIssueStatus(s,e={}){await pe(this.config,s,e)}async setIssueLabels(s,e={}){await ue(this.config,s,e)}async setIssueComponents(s,e={}){await le(this.config,s,e)}async getLabels(s={}){return{data:(await this.config.request({url:`${(s==null?void 0:s.baseUrl)||this.config.baseUrl}/rest/api/2/jql/autocompletedata/suggestions?fieldName=labels`,headers:m(s.token||this.config.token)})).body.results.map(({displayName:r})=>({color:null,description:null,id:null,name:r}))}}async getComponentsForJiraProject(s,e={}){return await de(this.config,s,e)}};var A="https://api.trello.com",us=1e3,ls=(t,s)=>{let e=new Date(1e3*parseInt(t.id.substring(0,8),16));return{id:t.id,commentCount:t.badges.comments,number:t.idShort.toString(),title:t.name,url:t.url,closedDate:null,createdDate:new Date(e.toISOString()),author:null,updatedDate:new Date(t.dateLastActivity),assignees:t.idMembers.map(r=>({id:r,username:null,name:null,email:null,avatarUrl:null,url:null})),description:null,state:s[t.idList??""]?{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}))}},X=class extends E{async getCurrentUser(s,e={}){let r=await this.config.request({url:`${e.baseUrl||A}/1/members/me?key=${s.appKey}&token=${e.token||this.config.token}`,headers:m(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||A}/1/members/me/boards?fields=name&key=${s.appKey}&token=${e.token||this.config.token}&filter=open`,headers:m(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||A}/1/boards/${n}/lists?key=${r}&token=${e.token||this.config.token}`,headers:m(e.token||this.config.token)})).body}}async getAccountsForTrelloBoard(s,e={}){let{appKey:r,boardId:n}=s;return{data:(await this.config.request({url:`${e.baseUrl||A}/1/boards/${n}/members?key=${r}&token=${e.token||this.config.token}`,headers:m(e.token||this.config.token)})).body.map(o=>({id:o.id,name:o.fullName,username:o.username,email:null,avatarUrl:null,url:null}))}}async getIssuesForBoard(s,e={}){let r=["-is:archived","sort:edited"],{appKey:n,boardId:a,filterText:o,assigneeLogins:i,trelloBoardListsById:u}=s||{};i&&r.push("@me");let l=`${o?`${o}`:""}${r.join(" ")} board:${a}`;return{data:(await this.config.request({url:`${e.baseUrl||A}/1/search?key=${n}&query=${l}&cards_limit=${us}&token=${e.token||this.config.token}`,headers:m(e.token||this.config.token)})).body.cards.map(d=>ls(d,u||{}))}}async updateIssue(s,e,r,n){return await this.config.request({method:"PUT",url:`${n.baseUrl||A}/1/cards/${e}?key=${s}&token=${n.token||this.config.token}&${r}`,headers:m(n.token||this.config.token)})}async setIssueStatus(s,e={}){let{appKey:r,cardId:n,status:a}=s,o=`idList=${a}`;if(!(await this.updateIssue(r,n,o,e)).body.id)throw new Error("Could not set issue status")}async setIssueAssignees(s,e={}){let{appKey:r,cardId:n,assigneeIds:a}=s,o=`idMembers=${encodeURIComponent(a.join(","))}`;if(!(await this.updateIssue(r,n,o,e)).body.id)throw new Error("Could not set issue status")}async setIssueLabels(s,e={}){let{appKey:r,cardId:n,labelIds:a}=s;if(!(await this.config.request({method:"PUT",url:`${e.baseUrl||A}/1/cards/${n}?key=${r}&token=${e.token||this.config.token}&idLabels=${encodeURIComponent(a.join(","))}`,headers:m(e.token||this.config.token)})).body.id)throw new Error("Could not set issue status")}async setIssueArchived(s,e={}){let{appKey:r,cardId:n,archived:a}=s;if(!(await this.config.request({method:"PUT",url:`${e.baseUrl||A}/1/cards/${n}?key=${r}&token=${e.token||this.config.token}&closed=${a}`,headers:m(e.token||this.config.token)})).body.id)throw new Error("Could not update issue archived status")}async getLabelsForBoard(s,e={}){let{appKey:r,boardId:n}=s;return{data:(await this.config.request({url:`${e.baseUrl||A}/1/boards/${n}/labels?key=${r}&token=${e.token||this.config.token}`,headers:m(e.token||this.config.token)})).body.map(o=>({color:o.color,description:null,id:o.id,name:o.name}))}}};var ce={};T(ce,{getIssueUniqueId:()=>ps,getPullRequestUniqueId:()=>ds});var ps=(t,s,e,r="")=>{let n=[];return n.push(r),n.push(t),n.push(s),n.push(e),JSON.stringify(n)},ds=(t,s,e,r,n="")=>{let a=[];return a.push(n),a.push(t),a.push(s),a.push(e),a.push(r),JSON.stringify(a)};var ge={};T(ge,{getIssueUniqueId:()=>cs,getPullRequestUniqueId:()=>gs});var cs=(t,s)=>JSON.stringify(["",t,s]),gs=(t,s)=>JSON.stringify(["",t,s]);var me={};T(me,{getIssueUniqueId:()=>ms,getPullRequestUniqueId:()=>hs});var ms=(t,s,e)=>JSON.stringify([e,t,s]),hs=(t,s,e)=>JSON.stringify([e,t,s]);var he={};T(he,{getIssueUniqueId:()=>fs,getPullRequestRank:()=>Is,getPullRequestUniqueId:()=>Rs});var fs=(t,s="")=>{let e=[];return e.push(s),e.push(t),JSON.stringify(e)},Rs=(t,s="")=>{let e=[];return e.push(s),e.push(t),JSON.stringify(e)},Is=(t,s,e)=>{var o,i,u;let r=0,n,a;return(o=t.reviews)==null||o.forEach(l=>{l.reviewer.id===s&&(n=l.state),l.state==="CHANGES_REQUESTED"?a="CHANGES_REQUESTED":l.state==="APPROVED"&&a!=="CHANGES_REQUESTED"&&(a="APPROVED")}),a||(a="REVIEW_REQUESTED"),((i=t.author)==null?void 0:i.id)===s?r+=1e3:(u=t.assignees)!=null&&u.find(l=>l.id===s)?r+=900:n==="REVIEW_REQUESTED"?r+=800:e&&(r+=700),a==="APPROVED"?t.mergeableState==="MERGEABLE"?r+=100:t.mergeableState==="CONFLICTS"?r+=90:r+=80:a=="CHANGES_REQUESTED"&&(r+=70),r};var fe={};T(fe,{getIssueUniqueId:()=>bs,getPullRequestUniqueId:()=>ys});var bs=(t,s="")=>{let e=[];return e.push(s),e.push(t),JSON.stringify(e)},ys=(t,s="")=>{let e=[];return e.push(s),e.push(t),JSON.stringify(e)};var Re={};T(Re,{getIssueUniqueId:()=>Ps,getJiraServerIssueUniqueId:()=>ws});var Ps=(t,s,e)=>{let r=[];return r.push(""),r.push(t),r.push(s),r.push(e),JSON.stringify(r)},ws=(t,s,e)=>{let r=[];return r.push(e),r.push(""),r.push(t),r.push(s),JSON.stringify(r)};var Ie={};T(Ie,{getIssueUniqueId:()=>qs});var qs=(t,s,e,r="")=>{let n=[];return n.push(r),n.push(t),n.push(s),n.push(e),JSON.stringify(n)};var Cs=t=>{let s={request:t==null?void 0:t.request};return{azureDevOps:new j({...s,...t==null?void 0:t.azureDevOps}),bitbucket:new Q({...s,...t==null?void 0:t.bitbucket}),bitbucketServer:new B({...s,...t==null?void 0:t.bitbucketServer}),github:new F({...s,...t==null?void 0:t.github}),gitlab:new W({...s,...t==null?void 0:t.gitlab}),jira:new K({...s,...t==null?void 0:t.jira}),jiraServer:new V({...s,...t==null?void 0:t.jiraServer}),trello:new X({...s,...t==null?void 0:t.trello})}},Ds=Cs;var Ss={azureDevOps:ce,bitbucket:ge,bitbucketServer:me,github:he,gitlab:fe,jira:Re,trello:Ie};
|
|
1056
|
+
`,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(ze))??[]}}};var ls="https://api.atlassian.com/ex/jira",ps=100,ds=(t,s,e)=>{var n,o,a,i;let r=t.fields.assignee;return{id:t.id,commentCount:t.fields.comment.comments.length,number:t.key,title:t.fields.summary,url:s?`${s}/browse/${t.key}`:null,closedDate:null,createdDate:new Date(t.fields.created),author:pe(t.fields.creator,s,e),updatedDate:new Date(t.fields.updated),assignees:r?[pe(r,s,e)]:[],description:null,repository:null,state:hs(t.fields.status),statusTransitions:((n=t.transitions)==null?void 0:n.map(cs))??[],components:((o=t.fields.components)==null?void 0:o.map(gs))??[],type:t.fields.issuetype.name,upvoteCount:((a=t.fields.votes)==null?void 0:a.votes)||0,labels:((i=t.fields.labels)==null?void 0:i.map(u=>({color:null,description:null,id:null,name:u})))??[]}},cs=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}}},gs=t=>({description:t.description??null,id:t.id,name:t.name}),ms=(t,s,e)=>e&&t.name?`${s}/secure/ViewProfile.jspa?name=${encodeURIComponent(t.name)}`:`${s}/jira/people/${t.accountId}`,pe=(t,s,e)=>({id:(e?t.key:t.accountId)??"",name:t.displayName,email:t.emailAddress,avatarUrl:t.avatarUrls["48x48"],username:t.displayName,url:ms(t,s,e)}),hs=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}},K=(t,s,e)=>e?`${s.baseUrl||ls}/${e}`:`${(s==null?void 0:s.baseUrl)||t.baseUrl}`,de=async(t,s,e,r={})=>{let{assigneeLogins:n,authorLogin:o,mentionLogin:a,project:i,resourceId:u}=s||{},l=[`project = "${i}"`,"statusCategory != Done"];return o&&l.push(`creator in ("${o}")`),n&&n.length!==0&&l.push(`assignee in ("${n.join('", "')}")`),a&&l.push(`comment ~ "${a}"`),{data:(await t.request({url:`${K(t,r,u)}/rest/api/2/search?jql=${l.join(" AND ")}&startAt=0&maxResults=${ps}&fields=${["assignee","comment","summary","created","creator","updated","votes","issuetype","status","labels","components"].join(",")}&expand=transitions`,headers:R(r.token||t.token)})).body.issues.map(d=>ds(d,e,!u))}},ce=async(t,s,e={})=>{let{resourceId:r,issueId:n,labelNames:o}=s,a={fields:{labels:o}};await t.request({method:"PUT",url:`${K(t,e,r)}/rest/api/2/issue/${n}`,body:JSON.stringify(a),headers:{...R(e.token||t.token),"Content-Type":"application/json"}})},ge=async(t,s,e={})=>{let{resourceId:r,issueId:n,componentIds:o}=s,a={fields:{components:o.map(i=>({id:i}))}};await t.request({method:"PUT",url:`${K(t,e,r)}/rest/api/2/issue/${n}`,body:JSON.stringify(a),headers:{...R(e.token||t.token),"Content-Type":"application/json"}})},me=async(t,s,e={})=>{let{resourceId:r,issueId:n,status:o}=s,a={transition:{id:o}};await t.request({method:"POST",url:`${K(t,e,r)}/rest/api/2/issue/${n}/transitions`,body:JSON.stringify(a),headers:{...R(e.token||t.token),"Content-Type":"application/json"}})},he=async(t,s,e={})=>{let{resourceId:r,projectIdOrKey:n}=s,o=new URL(`${K(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 X="https://api.atlassian.com/ex/jira",We=100,Z=class extends U{constructor(){super(...arguments);this._resourceUrlCache={}}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||X}/${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||X}/${e.resourceId}/rest/api/2/project/search`);n.searchParams.set("maxResults",We.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=>{let a=await this.getJiraProjectsForResource({resourceId:o},r);n.push(...a.data)})),{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||X}/${n}/rest/api/2/user/assignable/search`);u.searchParams.set("maxResults",We.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=>pe(p,i,!1))}}async getComponentsForJiraProject(e,r={}){return await he(this.config,e,r)}async getIssuesForProject(e,r={}){let n=await this.getResourceUrl({resourceId:e.resourceId},r);return await de(this.config,e,n,r)}async setIssueStatus(e,r={}){await me(this.config,e,r)}async setIssueAssignee(e,r={}){let{resourceId:n,issueId:o,assigneeId:a}=e,i={accountId:a};await this.config.request({method:"PUT",url:`${r.baseUrl||X}/${n}/rest/api/2/issue/${o}/assignee`,body:JSON.stringify(i),headers:{...R(r.token||this.config.token),"Content-Type":"application/json"}})}async setIssueComponents(e,r={}){await ge(this.config,e,r)}async setIssueLabels(e,r={}){await ce(this.config,e,r)}async getLabelsForResource(e,r={}){let{resourceId:n,cursor:o}=e,a=new URL(`${r.baseUrl||X}/${n}/rest/api/2/label`);a.searchParams.set("maxResults",We.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 Y=class extends L{async getCurrentUser(s={}){let e=await this.config.request({url:`${(s==null?void 0:s.baseUrl)||this.config.baseUrl}/rest/api/2/myself`,headers:R((s==null?void 0:s.token)||this.config.token)});return{data:{name:e.body.displayName,email:e.body.emailAddress,avatarUrl:e.body.avatarUrls["48x48"],id:e.body.key,username:e.body.displayName,url:null}}}async getJiraProjects(s={}){return{data:(await this.config.request({url:`${(s==null?void 0:s.baseUrl)||this.config.baseUrl}/rest/api/2/project`,headers:R((s==null?void 0:s.token)||this.config.token)})).body.map(r=>({id:r.id,name:r.name}))}}async getIssuesForProject(s,e={}){if(!e.baseUrl)throw new Error('Jira Server requires a "baseUrl" for this function.');return await de(this.config,s,e.baseUrl,e)}async setIssueStatus(s,e={}){await me(this.config,s,e)}async setIssueLabels(s,e={}){await ce(this.config,s,e)}async setIssueComponents(s,e={}){await ge(this.config,s,e)}async getLabels(s={}){return{data:(await this.config.request({url:`${(s==null?void 0:s.baseUrl)||this.config.baseUrl}/rest/api/2/jql/autocompletedata/suggestions?fieldName=labels`,headers:R(s.token||this.config.token)})).body.results.map(({displayName:r})=>({color:null,description:null,id:null,name:r}))}}async getComponentsForJiraProject(s,e={}){return await he(this.config,s,e)}};var T="https://api.trello.com",fs=1e3,Rs=(t,s)=>{let e=new Date(1e3*parseInt(t.id.substring(0,8),16));return{id:t.id,commentCount:t.badges.comments,number:t.idShort.toString(),title:t.name,url:t.url,closedDate:null,createdDate:new Date(e.toISOString()),author:null,updatedDate:new Date(t.dateLastActivity),assignees:t.idMembers.map(r=>({id:r,username:null,name:null,email:null,avatarUrl:null,url:null})),description:null,state:s[t.idList??""]?{id:t.idList,name:s[t.idList].name,color:null}:null,type:null,repository:null,upvoteCount:t.badges.votes,labels:t.labels.map(r=>({color:r.color,description:null,id:r.id,name:r.name}))}},ee=class extends U{async getCurrentUser(s,e={}){let r=await this.config.request({url:`${e.baseUrl||T}/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||T}/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||T}/1/boards/${n}/lists?key=${r}&token=${e.token||this.config.token}`,headers:R(e.token||this.config.token)})).body}}async getAccountsForTrelloBoard(s,e={}){let{appKey:r,boardId:n}=s;return{data:(await this.config.request({url:`${e.baseUrl||T}/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,trelloBoardListsById:u}=s||{};i&&r.push("@me");let l=`${a?`${a}`:""}${r.join(" ")} board:${o}`;return{data:(await this.config.request({url:`${e.baseUrl||T}/1/search?key=${n}&query=${l}&cards_limit=${fs}&token=${e.token||this.config.token}`,headers:R(e.token||this.config.token)})).body.cards.map(d=>Rs(d,u||{}))}}async updateIssue(s,e,r,n){return await this.config.request({method:"PUT",url:`${n.baseUrl||T}/1/cards/${e}?key=${s}&token=${n.token||this.config.token}&${r}`,headers:R(n.token||this.config.token)})}async setIssueStatus(s,e={}){let{appKey:r,cardId:n,status:o}=s,a=`idList=${o}`;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,cardId:n,assigneeIds:o}=s,a=`idMembers=${encodeURIComponent(o.join(","))}`;if(!(await this.updateIssue(r,n,a,e)).body.id)throw new Error("Could not set issue status")}async setIssueLabels(s,e={}){let{appKey:r,cardId:n,labelIds:o}=s;if(!(await this.config.request({method:"PUT",url:`${e.baseUrl||T}/1/cards/${n}?key=${r}&token=${e.token||this.config.token}&idLabels=${encodeURIComponent(o.join(","))}`,headers:R(e.token||this.config.token)})).body.id)throw new Error("Could not set issue status")}async setIssueArchived(s,e={}){let{appKey:r,cardId:n,archived:o}=s;if(!(await this.config.request({method:"PUT",url:`${e.baseUrl||T}/1/cards/${n}?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 getLabelsForBoard(s,e={}){let{appKey:r,boardId:n}=s;return{data:(await this.config.request({url:`${e.baseUrl||T}/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 fe={};x(fe,{getIssueUniqueId:()=>Is,getPullRequestUniqueId:()=>bs});var Is=(t,s,e,r="")=>{let n=[];return n.push(r),n.push(t),n.push(s),n.push(e),JSON.stringify(n)},bs=(t,s,e,r,n="")=>{let o=[];return o.push(n),o.push(t),o.push(s),o.push(e),o.push(r),JSON.stringify(o)};var Re={};x(Re,{getIssueUniqueId:()=>ys,getPullRequestUniqueId:()=>Ps});var ys=(t,s)=>JSON.stringify(["",t,s]),Ps=(t,s)=>JSON.stringify(["",t,s]);var Ie={};x(Ie,{getIssueUniqueId:()=>ws,getPullRequestUniqueId:()=>Ss});var ws=(t,s,e)=>JSON.stringify([e,t,s]),Ss=(t,s,e)=>JSON.stringify([e,t,s]);var be={};x(be,{getIssueUniqueId:()=>qs,getPullRequestRank:()=>Cs,getPullRequestUniqueId:()=>Ds});var qs=(t,s="")=>{let e=[];return e.push(s),e.push(t),JSON.stringify(e)},Ds=(t,s="")=>{let e=[];return e.push(s),e.push(t),JSON.stringify(e)},Cs=(t,s,e)=>{var a,i,u;let r=0,n,o;return(a=t.reviews)==null||a.forEach(l=>{l.reviewer.id===s&&(n=l.state),l.state==="CHANGES_REQUESTED"?o="CHANGES_REQUESTED":l.state==="APPROVED"&&o!=="CHANGES_REQUESTED"&&(o="APPROVED")}),o||(o="REVIEW_REQUESTED"),((i=t.author)==null?void 0:i.id)===s?r+=1e3:(u=t.assignees)!=null&&u.find(l=>l.id===s)?r+=900:n==="REVIEW_REQUESTED"?r+=800:e&&(r+=700),o==="APPROVED"?t.mergeableState==="MERGEABLE"?r+=100:t.mergeableState==="CONFLICTS"?r+=90:r+=80:o=="CHANGES_REQUESTED"&&(r+=70),r};var ye={};x(ye,{getIssueUniqueId:()=>vs,getPullRequestUniqueId:()=>Us});var vs=(t,s="")=>{let e=[];return e.push(s),e.push(t),JSON.stringify(e)},Us=(t,s="")=>{let e=[];return e.push(s),e.push(t),JSON.stringify(e)};var Pe={};x(Pe,{getIssueUniqueId:()=>Es,getJiraServerIssueUniqueId:()=>$s});var Es=(t,s,e)=>{let r=[];return r.push(""),r.push(t),r.push(s),r.push(e),JSON.stringify(r)},$s=(t,s,e)=>{let r=[];return r.push(e),r.push(""),r.push(t),r.push(s),JSON.stringify(r)};var we={};x(we,{getIssueUniqueId:()=>Ls});var Ls=(t,s,e,r="")=>{let n=[];return n.push(r),n.push(t),n.push(s),n.push(e),JSON.stringify(n)};var Gs=t=>{let s={request:t==null?void 0:t.request};return{azureDevOps:new B({...s,...t==null?void 0:t.azureDevOps}),bitbucket:new z({...s,...t==null?void 0:t.bitbucket}),bitbucketServer:new H({...s,...t==null?void 0:t.bitbucketServer}),github:new W({...s,...t==null?void 0:t.github}),gitlab:new V({...s,...t==null?void 0:t.gitlab}),jira:new Z({...s,...t==null?void 0:t.jira}),jiraServer:new Y({...s,...t==null?void 0:t.jiraServer}),trello:new ee({...s,...t==null?void 0:t.trello})}},As=Gs;var Os={azureDevOps:fe,bitbucket:Re,bitbucketServer:Ie,github:be,gitlab:ye,jira:Pe,trello:we};
|