@gitkraken/provider-apis 0.16.0 → 0.17.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +11 -0
- package/dist/index.js +41 -39
- package/dist/providers/azureDevops/azureDevOps.d.ts +33 -4
- package/dist/providers/azureDevops/azureDevOpsTypes.d.ts +8 -0
- package/dist/providers/gitProvider.d.ts +7 -1
- package/dist/providers/github/githubTypes.d.ts +9 -0
- package/package.json +1 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.17.0
|
|
4
|
+
|
|
5
|
+
- added `permissions` field to `GitPullRequest` (GitHub)
|
|
6
|
+
- added `getAccountFromAzureGraphAccount` (Azure DevOps)
|
|
7
|
+
- added `getAccountsFromAzureGraphAccounts (Azure DevOps)
|
|
8
|
+
|
|
9
|
+
### ⚠️ Breaking Changes
|
|
10
|
+
|
|
11
|
+
- GitLab normalizes "manual" build status states as `OPTIONAL_ACTION_REQUIRED` instead of `ACTION_REQUIRED`
|
|
12
|
+
- replaced `getAccountsForAzureProject` with `getAzureGraphAccountsForAzureProject`, which now returns `AzureGraphAccount[]`
|
|
13
|
+
|
|
3
14
|
## 0.16.0
|
|
4
15
|
|
|
5
16
|
- added paging to `getIssuesForProject` and `getIssuesForResourceForCurrentUser` (Jira and Jira Server)
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";var Pt=Object.create;var se=Object.defineProperty;var wt=Object.getOwnPropertyDescriptor;var St=Object.getOwnPropertyNames;var Dt=Object.getPrototypeOf,Et=Object.prototype.hasOwnProperty;var x=(t,s)=>{for(var e in s)se(t,e,{get:s[e],enumerable:!0})},Xe=(t,s,e,r)=>{if(s&&typeof s=="object"||typeof s=="function")for(let n of St(s))!Et.call(t,n)&&n!==e&&se(t,n,{get:()=>s[n],enumerable:!(r=wt(s,n))||r.enumerable});return t};var Ct=(t,s,e)=>(e=t!=null?Pt(Dt(t)):{},Xe(s||!t||!t.__esModule?se(e,"default",{value:t,enumerable:!0}):e,t)),Ut=t=>Xe(se({},"__esModule",{value:!0}),t);var Fs={};x(Fs,{AzureDevOps:()=>M,AzureDevopsUtils:()=>Ie,Bitbucket:()=>H,BitbucketServer:()=>W,BitbucketServerUtils:()=>ye,BitbucketUtils:()=>be,GitHub:()=>J,GitHubUtils:()=>Pe,GitLab:()=>V,GitLabUtils:()=>we,Jira:()=>Z,JiraServer:()=>Y,JiraUtils:()=>Se,Trello:()=>ee,TrelloUtils:()=>De,Utils:()=>js,default:()=>Qs});module.exports=Ut(Fs);var ot=require("js-base64");var E=100;var Ze=Ct(require("node-fetch")),Ye=globalThis.fetch||Ze.default;var et=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},Ee=t=>et(t)?async({url:s,...e})=>{let r=await t(s,e);return qt(r)}:t;var q=class{constructor(s){this.config={...s,request:Ee((s==null?void 0:s.request)||Ye)}}updateConfig(s){this.config={...this.config,...s,request:s.request?Ee(s.request):this.config.request}}},L=class extends q{};var R=(t,s)=>{let e={};return t&&(e.Authorization=`${s?"Basic":"Bearer"} ${t}`),e},tt=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),st=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 rt={APPROVED:0,COMMENTED:1,REVIEW_REQUESTED:2,CHANGES_REQUESTED:3},N=t=>!t||t.length===0?null:t.reduce((s,e)=>rt[e.state]>rt[s]?e.state:s,"APPROVED");var nt="https://app.vssps.visualstudio.com/_apis",S="https://dev.azure.com",vt={active:"OPEN",completed:"MERGED",abandoned:"CLOSED"},$t={10:"APPROVED",5:"APPROVED",0:"REVIEW_REQUESTED",[-5]:"CHANGES_REQUESTED",[-10]:"CHANGES_REQUESTED"},Ce=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:Ce(r),state:$t[r.vote]||"REVIEW_REQUESTED"}));return{id:t.pullRequestId.toString(),title:t.title,number:t.codeReviewId,state:vt[t.status],isDraft:t.isDraft,commentCount:null,upvoteCount:null,author:Ce(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:st(t),assignees:t.reviewers.map(Ce),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})))??[]}},at=(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}),Lt=(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()})))??[]}},M=class extends q{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:`${nt}/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:`${nt}/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",E.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:ot.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:at(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=>at(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",E.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=>Lt(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 U=(t,s={})=>R(s.token||t.token,s.isPAT||t.isPAT);var v="https://api.bitbucket.org/2.0",Gt={OPEN:"OPEN",MERGED:"MERGED",DECLINED:"CLOSED"},ut=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}),it=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:Gt[t.state],isDraft:!1,commentCount:t.comment_count,upvoteCount:null,author:ut(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"}},H=class extends q{async refreshToken(s){return{data:(await this.config.request({url:"https://bitbucket.org/site/oauth2/access_token",method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded",Authorization:`Basic ${s.base64ClientIDColonClientSecret}`},body:`grant_type=refresh_token&refresh_token=${s.refreshToken}`})).body}}async getCurrentUser(s={},e={}){let r=await this.config.request({url:`${v}/user`,headers:U(this.config,e)});return{data:ut(r.body)}}async getUserForCommit(s,e={}){var a;let n=(await this.config.request({url:`${v}/repositories/${s.repo.namespace}/${s.repo.name}/commit/${s.oid}`,headers:U(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:`${v}/repositories/${s.namespace}/${s.name}`,headers:U(this.config,e)});return{data:it(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(`${v}/repositories`);r.searchParams.set("role","member"),r.searchParams.set("pagelen",E.toString()),s.cursor&&r.searchParams.set("after",s.cursor);let n=await this.config.request({url:r.toString(),headers:U(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(it)}}async getBranches(s,e={}){var a;let r=new URL(`${v}/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",E.toString());let n=await this.config.request({url:r.toString(),headers:U(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(`${v}/repositories/${s.repo.namespace}/${s.repo.name}/refs/tags`);r.searchParams.set("pagelen",E.toString()),s.cursor&&r.searchParams.set("page",s.cursor);let n=await this.config.request({url:r.toString(),headers:U(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(`${v}/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:U(this.config,e)}),o=!!n.body.next;return{pageInfo:{hasNextPage:o,nextPage:o?n.body.page+1:null},data:n.body.values.map(qe)}}async getPullRequestsForRepoBase(s,e={}){var n;let r=new URL(`${v}/repositories/${encodeURI(s.repo.namespace)}/${encodeURI(s.repo.name)}/pullrequests?state=OPEN`);return r.searchParams.set("page",((n=s.page)==null?void 0:n.toString())||"1"),r.searchParams.set("pagelen","50"),await this.config.request({url:r.toString(),headers:U(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(qe(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(qe(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:`${v}/repositories/${r}/${n}/pullrequests/${o}/decline`,headers:U(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:`${v}/repositories/${r}/${n}/pullrequests/${o}/merge`,body:JSON.stringify(u),headers:{...U(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:`${v}/repositories/${r}/${n}/pullrequests/${o}`,body:JSON.stringify(i),headers:{...U(this.config,e),"Content-Type":"application/json"}})).body.title)throw new Error("Could not set pull request reviewers")}};var lt=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:lt(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:lt(t.author.user),assignees:null,reviews:r,reviewDecision:N(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"}},W=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",At=`${ie}/graphql`,ue=`
|
|
1
|
+
"use strict";var yt=Object.create;var se=Object.defineProperty;var Pt=Object.getOwnPropertyDescriptor;var wt=Object.getOwnPropertyNames;var St=Object.getPrototypeOf,Dt=Object.prototype.hasOwnProperty;var x=(t,s)=>{for(var e in s)se(t,e,{get:s[e],enumerable:!0})},Xe=(t,s,e,r)=>{if(s&&typeof s=="object"||typeof s=="function")for(let n of wt(s))!Dt.call(t,n)&&n!==e&&se(t,n,{get:()=>s[n],enumerable:!(r=Pt(s,n))||r.enumerable});return t};var Et=(t,s,e)=>(e=t!=null?yt(St(t)):{},Xe(s||!t||!t.__esModule?se(e,"default",{value:t,enumerable:!0}):e,t)),Ct=t=>Xe(se({},"__esModule",{value:!0}),t);var js={};x(js,{AzureDevOps:()=>M,AzureDevopsUtils:()=>Ie,Bitbucket:()=>W,BitbucketServer:()=>H,BitbucketServerUtils:()=>ye,BitbucketUtils:()=>be,GitHub:()=>J,GitHubUtils:()=>Pe,GitLab:()=>V,GitLabUtils:()=>we,Jira:()=>Z,JiraServer:()=>Y,JiraUtils:()=>Se,Trello:()=>ee,TrelloUtils:()=>De,Utils:()=>Fs,default:()=>Qs});module.exports=Ct(js);var E=100;var Ze=Et(require("node-fetch")),Ye=globalThis.fetch||Ze.default;var et=t=>t.name==="fetch";var Ut=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},Ee=t=>et(t)?async({url:s,...e})=>{let r=await t(s,e);return Ut(r)}:t;var q=class{constructor(s){this.config={...s,request:Ee((s==null?void 0:s.request)||Ye)}}updateConfig(s){this.config={...this.config,...s,request:s.request?Ee(s.request):this.config.request}}},L=class extends q{};var R=(t,s)=>{let e={};return t&&(e.Authorization=`${s?"Basic":"Bearer"} ${t}`),e},tt=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),st=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 rt={APPROVED:0,COMMENTED:1,REVIEW_REQUESTED:2,CHANGES_REQUESTED:3},N=t=>!t||t.length===0?null:t.reduce((s,e)=>rt[e.state]>rt[s]?e.state:s,"APPROVED");var nt="https://app.vssps.visualstudio.com/_apis",S="https://dev.azure.com",qt={active:"OPEN",completed:"MERGED",abandoned:"CLOSED"},vt={10:"APPROVED",5:"APPROVED",0:"REVIEW_REQUESTED",[-5]:"CHANGES_REQUESTED",[-10]:"CHANGES_REQUESTED"},Ce=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:Ce(r),state:vt[r.vote]||"REVIEW_REQUESTED"}));return{id:t.pullRequestId.toString(),title:t.title,number:t.codeReviewId,state:qt[t.status],isDraft:t.isDraft,commentCount:null,upvoteCount:null,author:Ce(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:st(t),assignees:t.reviewers.map(Ce),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})))??[],permissions:null}},at=(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}),$t=(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()})))??[]}},M=class extends q{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:`${nt}/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:`${nt}/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",E.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 getAzureGraphAccountsForAzureProject(s,e={}){let{namespace:r,projectScopeDescriptor:n,cursor:o}=s,a=new URL(`https://vssps.dev.azure.com/${encodeURIComponent(r)}/_apis/graph/users`);n&&a.searchParams.set("scopeDescriptor",n),o&&a.searchParams.set("continuationToken",o);let i=await this.config.request({url:a.toString(),headers:w(this.config,e)}),u=i.headers["x-ms-continuationtoken"];return{pageInfo:{endCursor:u||null,hasNextPage:!!u},data:i.body.value.map(l=>{var p;return{avatarUrl:((p=l._links.avatar)==null?void 0:p.href)??null,descriptor:l.descriptor,email:l.mailAddress,name:l.displayName,storageKeyURL:l._links.storageKey.href,username:l.displayName}})}}async getAccountFromAzureGraphAccount(s,e={}){let{azureGraphAccount:r}=s,n=await this.config.request({url:r.storageKeyURL,headers:w(this.config,e)});return{data:{avatarUrl:r.avatarUrl,email:r.email,id:n.body.value,name:r.name,username:r.username,url:null}}}async getAccountsFromAzureGraphAccounts(s,e={}){let r=[];for(let n of s.azureGraphAccounts){let o=await this.getAccountFromAzureGraphAccount({azureGraphAccount:n},e);r.push(o.data)}return{data:r}}async getRepo(s,e={}){if(!s.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let r=await this.config.request({url:`${S}/${encodeURIComponent(s.namespace)}/${encodeURIComponent(s.project)}/_apis/git/repositories/${encodeURIComponent(s.name)}`,headers:w(this.config,e)});return{data:at(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=>at(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",E.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=>$t(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 U=(t,s={})=>R(s.token||t.token,s.isPAT||t.isPAT);var v="https://api.bitbucket.org/2.0",Lt={OPEN:"OPEN",MERGED:"MERGED",DECLINED:"CLOSED"},it=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}),ot=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:Lt[t.state],isDraft:!1,commentCount:t.comment_count,upvoteCount:null,author:it(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",permissions:null}},W=class extends q{async refreshToken(s){return{data:(await this.config.request({url:"https://bitbucket.org/site/oauth2/access_token",method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded",Authorization:`Basic ${s.base64ClientIDColonClientSecret}`},body:`grant_type=refresh_token&refresh_token=${s.refreshToken}`})).body}}async getCurrentUser(s={},e={}){let r=await this.config.request({url:`${v}/user`,headers:U(this.config,e)});return{data:it(r.body)}}async getUserForCommit(s,e={}){var a;let n=(await this.config.request({url:`${v}/repositories/${s.repo.namespace}/${s.repo.name}/commit/${s.oid}`,headers:U(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:`${v}/repositories/${s.namespace}/${s.name}`,headers:U(this.config,e)});return{data:ot(r.body)}}async getRepos(s,e={}){let r=[],n=[];return await Promise.all(s.map(async o=>{try{let a=await this.getRepo(o,e);r.push(a.data)}catch(a){n.push({input:o,error:a})}})),{data:r,errors:n}}async getReposForCurrentUser(s={},e={}){let r=new URL(`${v}/repositories`);r.searchParams.set("role","member"),r.searchParams.set("pagelen",E.toString()),s.cursor&&r.searchParams.set("after",s.cursor);let n=await this.config.request({url:r.toString(),headers:U(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(ot)}}async getBranches(s,e={}){var a;let r=new URL(`${v}/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",E.toString());let n=await this.config.request({url:r.toString(),headers:U(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(`${v}/repositories/${s.repo.namespace}/${s.repo.name}/refs/tags`);r.searchParams.set("pagelen",E.toString()),s.cursor&&r.searchParams.set("page",s.cursor);let n=await this.config.request({url:r.toString(),headers:U(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(`${v}/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:U(this.config,e)}),o=!!n.body.next;return{pageInfo:{hasNextPage:o,nextPage:o?n.body.page+1:null},data:n.body.values.map(qe)}}async getPullRequestsForRepoBase(s,e={}){var n;let r=new URL(`${v}/repositories/${encodeURI(s.repo.namespace)}/${encodeURI(s.repo.name)}/pullrequests?state=OPEN`);return r.searchParams.set("page",((n=s.page)==null?void 0:n.toString())||"1"),r.searchParams.set("pagelen","50"),await this.config.request({url:r.toString(),headers:U(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(qe(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(qe(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:`${v}/repositories/${r}/${n}/pullrequests/${o}/decline`,headers:U(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:`${v}/repositories/${r}/${n}/pullrequests/${o}/merge`,body:JSON.stringify(u),headers:{...U(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:`${v}/repositories/${r}/${n}/pullrequests/${o}`,body:JSON.stringify(i),headers:{...U(this.config,e),"Content-Type":"application/json"}})).body.title)throw new Error("Could not set pull request reviewers")}};var ut=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:ut(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:ut(t.author.user),assignees:null,reviews:r,reviewDecision:N(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",permissions:null}},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",Gt=`${ie}/graphql`,ue=`
|
|
2
2
|
description
|
|
3
3
|
dueOn
|
|
4
4
|
id
|
|
@@ -6,7 +6,7 @@ number
|
|
|
6
6
|
state
|
|
7
7
|
title
|
|
8
8
|
url
|
|
9
|
-
`,
|
|
9
|
+
`,At=`
|
|
10
10
|
... on CheckRun {
|
|
11
11
|
completedAt
|
|
12
12
|
conclusion
|
|
@@ -20,7 +20,7 @@ color
|
|
|
20
20
|
description
|
|
21
21
|
id
|
|
22
22
|
name
|
|
23
|
-
`,
|
|
23
|
+
`,lt=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.")},Tt=(t,s)=>{let e=s.baseUrl||t.baseUrl;return e?(e=e.replace(/\/$/,""),lt(e),oe.test(e)&&(e=e.replace(oe,"")),`${e}/api/graphql`):Gt},pt=(t,s)=>{let e=s.baseUrl||t.baseUrl;return e?(e=e.replace(/\/$/,""),lt(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",r.Accept="application/vnd.github.merge-info-preview+json",t.request({url:Tt(t,e),method:"POST",headers:r,body:JSON.stringify(s)})},Ot={user:!0,"user:email":!0,"read:user":!0},Q=t=>t.some(s=>Ot[s]),$=(t=!1,s=!1,e)=>`
|
|
24
24
|
__typename
|
|
25
25
|
${k(e,["graphQLId"],"id")}
|
|
26
26
|
${k(e,["id"],"databaseId")}
|
|
@@ -29,7 +29,7 @@ ${k(e,["name","username"],"login")}
|
|
|
29
29
|
${s?k(e,["email"],"email"):""}
|
|
30
30
|
${k(e,["avatarUrl"],`avatarUrl${t?"(size: $avatarSize)":""}`)}
|
|
31
31
|
${k(e,["url"],"url")}
|
|
32
|
-
`,
|
|
32
|
+
`,xt=(t=!1)=>`
|
|
33
33
|
latestReviews(first: 100) {
|
|
34
34
|
nodes {
|
|
35
35
|
author {
|
|
@@ -40,14 +40,14 @@ latestReviews(first: 100) {
|
|
|
40
40
|
state
|
|
41
41
|
}
|
|
42
42
|
}
|
|
43
|
-
`,
|
|
43
|
+
`,dt=(t=!1)=>`
|
|
44
44
|
__typename
|
|
45
45
|
id
|
|
46
46
|
databaseId
|
|
47
47
|
login
|
|
48
48
|
avatarUrl${t?"(size: $avatarSize)":""}
|
|
49
49
|
url
|
|
50
|
-
`,
|
|
50
|
+
`,kt=(t,s=!1,e)=>`
|
|
51
51
|
id
|
|
52
52
|
databaseId
|
|
53
53
|
number
|
|
@@ -58,7 +58,7 @@ author {
|
|
|
58
58
|
${$(!1,s)}
|
|
59
59
|
}
|
|
60
60
|
... on Bot {
|
|
61
|
-
${
|
|
61
|
+
${dt(!1)}
|
|
62
62
|
}
|
|
63
63
|
}
|
|
64
64
|
commits(last: 1) {
|
|
@@ -71,7 +71,7 @@ commits(last: 1) {
|
|
|
71
71
|
contexts(first: 100) {
|
|
72
72
|
totalCount
|
|
73
73
|
nodes {
|
|
74
|
-
${e?
|
|
74
|
+
${e?At:""}
|
|
75
75
|
... on StatusContext {
|
|
76
76
|
context
|
|
77
77
|
createdAt
|
|
@@ -107,6 +107,7 @@ repository {
|
|
|
107
107
|
}
|
|
108
108
|
url
|
|
109
109
|
sshUrl
|
|
110
|
+
viewerPermission
|
|
110
111
|
}
|
|
111
112
|
headRepository {
|
|
112
113
|
id
|
|
@@ -145,7 +146,7 @@ reviewRequests(first: 100) {
|
|
|
145
146
|
}
|
|
146
147
|
}
|
|
147
148
|
}
|
|
148
|
-
${e?
|
|
149
|
+
${e?xt(s):""}
|
|
149
150
|
additions
|
|
150
151
|
deletions
|
|
151
152
|
changedFiles
|
|
@@ -159,7 +160,8 @@ labels(first: 100) {
|
|
|
159
160
|
${le}
|
|
160
161
|
}
|
|
161
162
|
}
|
|
162
|
-
|
|
163
|
+
viewerCanMergeAsAdmin
|
|
164
|
+
`,Nt=(t=!1)=>`
|
|
163
165
|
id
|
|
164
166
|
databaseId
|
|
165
167
|
title
|
|
@@ -168,7 +170,7 @@ author {
|
|
|
168
170
|
${$(!1,t)}
|
|
169
171
|
}
|
|
170
172
|
... on Bot {
|
|
171
|
-
${
|
|
173
|
+
${dt(!1)}
|
|
172
174
|
}
|
|
173
175
|
}
|
|
174
176
|
closedAt
|
|
@@ -204,7 +206,7 @@ labels(first: 100) {
|
|
|
204
206
|
${le}
|
|
205
207
|
}
|
|
206
208
|
}
|
|
207
|
-
`,
|
|
209
|
+
`,_t={"-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"},Qt=new RegExp('(([^\\s]+:)?\\"(?:[^\\"\\\\]|\\\\.)*\\"?)|([^\\"\\s]+)',"g"),$e=t=>{let s=[];return(t.match(Qt)??[]).forEach(r=>{if(r.includes(":")&&r!="is:closed"){let n=r.split(":")[0];_t[n]&&s.push(r)}}),s},Le=(t,s,e,r,n=!1,o=!1)=>{let a=t==="issue";return{query:`
|
|
208
210
|
query SearchIssuesOrPullRequests($query: String! $after: String) {
|
|
209
211
|
search(type:ISSUE query:$query first:100 after:$after) {
|
|
210
212
|
pageInfo {
|
|
@@ -213,13 +215,13 @@ query SearchIssuesOrPullRequests($query: String! $after: String) {
|
|
|
213
215
|
}
|
|
214
216
|
nodes {
|
|
215
217
|
... on ${a?"Issue":"PullRequest"} {
|
|
216
|
-
${a?
|
|
218
|
+
${a?Nt(r):kt(n,r,o)}
|
|
217
219
|
}
|
|
218
220
|
}
|
|
219
221
|
}
|
|
220
|
-
}`,variables:{query:`is:${t} is:open ${s}`,after:e}}},Ft="Field 'isDraft' doesn't exist on type 'PullRequest'",
|
|
222
|
+
}`,variables:{query:`is:${t} is:open ${s}`,after:e}}},Ft="Field 'isDraft' doesn't exist on type 'PullRequest'",ct=(t=[])=>t.some(s=>(s==null?void 0:s.message)===Ft),jt=/@@ -(\d+)(?:,\d+ | )\+(\d+)(?:,\d+ | )@@(?:\\n)?/,Bt=`
|
|
221
223
|
\
|
|
222
|
-
+`,
|
|
224
|
+
+`,gt=(t,s,e,r)=>{let n=jt.exec(t);if(!n||!n[0]||!n[1])return[];let o=parseInt(n[1],10),a=parseInt(n[2],10),i=t.replace(Bt,`
|
|
223
225
|
+`).split(`
|
|
224
226
|
`).slice(1),u=o-1,l=a-1,p=i.map(g=>{let m,f;switch(g[0]){case"-":{m="DELETED",u+=1,f=`${g.slice(1)}
|
|
225
227
|
`;break}case"+":{m="ADDED",l+=1,f=`${g.slice(1)}
|
|
@@ -237,7 +239,7 @@ defaultBranchRef {
|
|
|
237
239
|
name
|
|
238
240
|
}
|
|
239
241
|
viewerPermission
|
|
240
|
-
`,Te={__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"},
|
|
242
|
+
`,Te={__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"},zt={APPROVED:"APPROVED",CHANGES_REQUESTED:"CHANGES_REQUESTED",COMMENTED:"COMMENTED",REVIEW_REQUESTED:"REVIEW_REQUESTED"},Wt={MERGEABLE:"MERGEABLE",CONFLICTING:"CONFLICTS",UNKNOWN:"UNKNOWN"},Ht={BEHIND:"BEHIND",BLOCKED:"BLOCKED",UNKNOWN:"UNKNOWN_AND_BLOCKED",UNSTABLE:"UNSTABLE",CLEAN:null,DIRTY:null,DRAFT:null,HAS_HOOKS:null},Jt={OPEN:"OPEN",CLOSED:"CLOSED"},Kt=["ADMIN","MAINTAIN","TRIAGE","WRITE"],Oe=t=>({color:t.color,description:t.description,graphQLId:t.id,id:null,name:t.name}),Ae=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}),Vt={OPEN:"OPEN",CLOSED:"CLOSED",MERGED:"MERGED"},Xt={id:!0,graphQLId:!0,name:!0,username:!0,email:!0,avatarUrl:!0,url:!0},G=(t,s=Xt)=>{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},Zt=(t,s)=>{let e={IN_PROGRESS:"RUNNING",PENDING:"PENDING",QUEUED:"PENDING",REQUESTED:"PENDING",WAITING:"PENDING"};return t!=="COMPLETED"?e[t]:{ACTION_REQUIRED:"ACTION_REQUIRED",CANCELLED:"CANCELLED",FAILURE:"FAILED",NEUTRAL:null,SKIPPED:"SKIPPED",STALE:"FAILED",STARTUP_FAILURE:"FAILED",SUCCESS:"SUCCESS",TIMED_OUT:"ERROR"}[s]},Yt=t=>({ERROR:"ERROR",EXPECTED:"PENDING",FAILURE:"FAILED",PENDING:"PENDING",SUCCESS:"SUCCESS"})[t],es=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=Te;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||Te;return{reviewer:G(P),state:zt[h.state]}}));return{id:t.databaseId.toString(),graphQLId:t.id,title:t.title,number:t.number,state:Vt[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:Yt(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:Zt(h.status,h.conclusion),startedAt:h.startedAt?new Date(h.startedAt):null,stage:null,url:h.permalink}))??[]},headRef:t.headRef?{name:t.headRef.name,oid:((g=t.headRef.target)==null?void 0:g.oid)??null}:null,baseRef:t.baseRef?{name:t.baseRef.name,oid:((m=t.baseRef.target)==null?void 0:m.oid)??null}:null,url:t.url,updatedDate:new Date(t.updatedAt),closedDate:t.closedAt?new Date(t.closedAt):null,mergedDate:t.mergedAt?new Date(t.mergedAt):null,assignees:t.assignees.nodes?t.assignees.nodes.map(h=>G(h)):null,reviews:o,reviewDecision:N(o),additions:t.additions,deletions:t.deletions,fileCount:t.changedFiles,commitCount:t.commits.totalCount,mergeableState:Ht[t.mergeStateStatus]??Wt[t.mergeable],milestone:t.milestone?xe(t.milestone):null,labels:((y=(f=t.labels)==null?void 0:f.nodes)==null?void 0:y.map(Oe))??[],permissions:{canMerge:Kt.includes(t.repository.viewerPermission),canMergeAndBypassProtections:t.viewerCanMergeAsAdmin}}},ts=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:gt(s.nodes[0].diffHunk,n,o,a),id:l,isOutdated:e,isResolved:r,graphQLId:p,filename:d,replies:s.nodes.slice(1).map(ss),url:g}},ss=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}),rs=t=>{var e,r;let s=null;return t.author?s=(t.author.__typename==="Bot",t.author):s=Te,{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:Jt[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?xe(t.milestone):null,labels:((r=(e=t.labels)==null?void 0:e.nodes)==null?void 0:r.map(Oe))??[]}},xe=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}),J=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:`${pt(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=tt(e.fields),o=await this.getScopes(r),i=(u=(await I(this.config,{query:`
|
|
241
243
|
query getCurrentUser {
|
|
242
244
|
viewer {
|
|
243
245
|
${$(!1,Q(o),n)}
|
|
@@ -400,7 +402,7 @@ query getBlame($owner: String!, $name: String!, $ref: String!, $path: String!) {
|
|
|
400
402
|
}
|
|
401
403
|
}
|
|
402
404
|
}
|
|
403
|
-
`,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 Le("pr",m,e.cursor,a,g,i)},l=await I(this.config,u(!0),r);l.body.errors&&
|
|
405
|
+
`,variables:{owner:e.repo.namespace,name:e.repo.name,ref:e.ref,path:e.path}},r)).body.data)==null?void 0:i.repository;if(!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 Le("pr",m,e.cursor,a,g,i)},l=await I(this.config,u(!0),r);l.body.errors&&ct(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(es))||[]}}async searchIssues(e,r={}){var u,l;let n=await this.getScopes(r),o=Q(n),a=await I(this.config,Le("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(rs))||[]}}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=$e(l||"");return i.forEach(c=>{d.push(`repo:${c.namespace}/${c.name}`)}),n&&n.forEach(c=>{d.push(`assignee:${c}`)}),o&&d.push(`updated:<${o}`),a&&d.push(`author:${a}`),u&&d.push(`review-requested:${u}`),p&&d.push(`mentions:${p}`),this.searchPullRequests({query:`sort:updated ${d.join(" ")}`,isDraft:e.isDraft,cursor:e.cursor},r)}async closePullRequest(e,r={}){var i,u,l;let{pullRequestGraphQLId:n}=e,o=`mutation ClosePullRequest($pullRequestGraphQLId: ID!) {
|
|
404
406
|
closePullRequest(input: { pullRequestId: $pullRequestGraphQLId }) {
|
|
405
407
|
pullRequest {
|
|
406
408
|
id
|
|
@@ -572,7 +574,7 @@ query getLabelsForRepo($owner: String!, $name: String! $cursor: String, $first:
|
|
|
572
574
|
}
|
|
573
575
|
}
|
|
574
576
|
}
|
|
575
|
-
`,variables:{owner:n,name:o,cursor:a,first:E}},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(Oe))??[]}}};var ns="https://gitlab.com/api/v4",as="https://gitlab.com/api/graphql",
|
|
577
|
+
`,variables:{owner:n,name:o,cursor:a,first:E}},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(Oe))??[]}}};var ns="https://gitlab.com/api/v4",as="https://gitlab.com/api/graphql",mt=/\/api\/v\d+$/,ht=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.")},ke=(t,s)=>{let e=s.baseUrl||t.baseUrl;return e?(e=e.replace(/\/$/,""),ht(e),e):ns},os=(t,s)=>{let e=s.baseUrl||t.baseUrl;return e?(e=e.replace(/\/$/,""),ht(e),mt.test(e)&&(e=e.replace(mt,"")),`${e}/api/graphql`):as},b=(t,s,e)=>{let r=R(e.token||t.token);return t.request({url:os(t,e),method:"POST",headers:{...r,"Content-Type":"application/json"},body:JSON.stringify(s)})};var Me=t=>t.split("/").slice(0,-1).join("/"),ze=t=>t.split("/").at(-1)??"",K=t=>({id:t.id.replace(_,""),graphQLId:t.id,namespace:Me(t.fullPath),name:ze(t.fullPath),webUrl:t.webUrl}),ft=t=>({id:t.id.replace(_,""),graphQLId:t.id,httpsUrl:t.httpUrlToRepo,namespace:Me(t.fullPath),name:ze(t.fullPath),sshUrl:t.sshUrlToRepo,webUrl:t.webUrl}),is={assigned:"assignedMergeRequests",authored:"authoredMergeRequests",reviewRequested:"reviewRequestedMergeRequests"},us={CAN_BE_MERGED:"MERGEABLE",CANNOT_BE_MERGED:"CONFLICTS",CANNOT_BE_MERGED_RECHECK:"UNKNOWN",UNCHECKED:"UNKNOWN",CHECKING:"UNKNOWN"},ls="gid://gitlab/User/",_="gid://gitlab/Project/",ps="gid://gitlab/MergeRequest/",ds="gid://gitlab/Issue/",cs="gid://gitlab/ProjectLabel/",Rt="gid://gitlab/Milestone/",gs="gid://gitlab/Ci::Build/",We=`
|
|
576
578
|
description
|
|
577
579
|
dueDate
|
|
578
580
|
id
|
|
@@ -597,7 +599,7 @@ username
|
|
|
597
599
|
publicEmail
|
|
598
600
|
avatarUrl
|
|
599
601
|
webUrl
|
|
600
|
-
`,
|
|
602
|
+
`,He=`
|
|
601
603
|
color
|
|
602
604
|
description
|
|
603
605
|
id
|
|
@@ -619,7 +621,7 @@ id
|
|
|
619
621
|
iid
|
|
620
622
|
labels {
|
|
621
623
|
nodes {
|
|
622
|
-
${
|
|
624
|
+
${He}
|
|
623
625
|
}
|
|
624
626
|
}
|
|
625
627
|
state
|
|
@@ -630,7 +632,7 @@ upvotes
|
|
|
630
632
|
userNotesCount
|
|
631
633
|
webUrl
|
|
632
634
|
milestone {
|
|
633
|
-
${
|
|
635
|
+
${We}
|
|
634
636
|
}
|
|
635
637
|
`,ms=`
|
|
636
638
|
stages {
|
|
@@ -693,19 +695,19 @@ reviewers {
|
|
|
693
695
|
mergeStatusEnum
|
|
694
696
|
labels {
|
|
695
697
|
nodes {
|
|
696
|
-
${
|
|
698
|
+
${He}
|
|
697
699
|
}
|
|
698
700
|
}
|
|
699
701
|
${t?"project { id httpUrlToRepo fullPath sshUrlToRepo webUrl } sourceProject { id httpUrlToRepo fullPath sshUrlToRepo webUrl }":""}
|
|
700
|
-
${s?`milestone { ${
|
|
702
|
+
${s?`milestone { ${We} }`:""}
|
|
701
703
|
${e?`headPipeline { ${ms} }`:""}
|
|
702
|
-
`,
|
|
704
|
+
`,F=t=>`${t.namespace}/${t.name}`,hs=t=>`${t.namespace}/${t.name}`,Fe=t=>{var s;return{id:t.id.replace(_,""),graphQLId:t.id,namespace:Me(t.fullPath),name:ze(t.fullPath),webUrl:t.webUrl,httpsUrl:t.httpUrlToRepo,sshUrl:t.sshUrlToRepo,defaultBranch:(s=t.repository)!=null&&s.rootRef?{name:t.repository.rootRef}:null,permission:null}},fs={opened:"OPEN",merged:"MERGED",closed:"CLOSED"},T=(t,s)=>{let e=t.avatarUrl;return!s&&(e!=null&&e.startsWith("/"))&&(e=`https://gitlab.com${e}`),{id:t.id.replace(ls,""),graphQLId:t.id,name:t.name,username:t.username,email:t.publicEmail??null,avatarUrl:e,url:t.webUrl}},Je=t=>({color:t.color,description:t.description,id:t.id.replace(cs,""),graphQLId:t.id,name:t.title}),Rs=(t,s)=>t?t==="FAILED"&&s?"WARNING":{CANCELED:"CANCELLED",CREATED:"PENDING",FAILED:"FAILED",MANUAL:"OPTIONAL_ACTION_REQUIRED",PENDING:"PENDING",PREPARING:"RUNNING",RUNNING:"RUNNING",SCHEDULED:"PENDING",SKIPPED:"SKIPPED",SUCCESS:"SUCCESS",WAITING_FOR_CALLBACK:"PENDING",WAITING_FOR_RESOURCE:"PENDING"}[t]:null,je=(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,D;return{reviewer:T(h,r),state:(P=h.mergeRequestInteraction)!=null&&P.approved?"APPROVED":((D=h.mergeRequestInteraction)==null?void 0:D.reviewState)==="REVIEWED"?"CHANGES_REQUESTED":"CHANGES_REQUESTED"}}):null;return{id:t.id.replace(ps,""),graphQLId:t.id,title:t.title,number:parseInt(t.iid,10),state:fs[t.state],commentCount:t.userNotesCount||0,upvoteCount:t.upvotes,author:t.author?T(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,D;return((D=(P=h.jobs)==null?void 0:P.nodes)==null?void 0:D.map(C=>({completedAt:C.finishedAt?new Date(C.finishedAt):null,description:null,name:C.name??null,state:Rs(C.status,C.allowFailure),stage:h.name??null,startedAt:new Date(C.createdAt),url:`${s.webUrl}/-/jobs/${C.id.replace(gs,"")}`})))??[]}))??[]},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=>T(h,r)):null,reviews:n,reviewDecision:t.approved?"APPROVED":N(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:us[t.mergeStatusEnum],milestone:t.milestone?Ke(t.milestone,s.webUrl):null,labels:((y=(f=t.labels)==null?void 0:f.nodes)==null?void 0:y.map(Je))??[],permissions:null}},Be=(t,s,e)=>{var r,n;return{author:T(t.author,e),assignees:t.assignees.nodes.map(o=>T(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(ds,""),labels:((n=(r=t.labels)==null?void 0:r.nodes)==null?void 0:n.map(Je))??[],number:t.iid,repository:{id:s.id.replace(_,""),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?Ke(t.milestone,s.webUrl):null}},Ke=(t,s)=>({id:t.id.replace(Rt,""),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:`
|
|
703
705
|
query getCurrentUser {
|
|
704
706
|
currentUser {
|
|
705
707
|
${A}
|
|
706
708
|
}
|
|
707
709
|
}
|
|
708
|
-
`},e)).body.data)==null?void 0:o.currentUser;if(!n)throw new Error("Current user not found.");return{data:T(n,this.getIsSelfHosted(e))}}async getUserForCommit(s,e={}){var a,i,u,l;let r=
|
|
710
|
+
`},e)).body.data)==null?void 0:o.currentUser;if(!n)throw new Error("Current user not found.");return{data:T(n,this.getIsSelfHosted(e))}}async getUserForCommit(s,e={}){var a,i,u,l;let r=F(s.repo),o=(l=(u=(i=(a=(await b(this.config,{query:`
|
|
709
711
|
query getUserForCommit($fullPath: ID!, $oid: String!) {
|
|
710
712
|
project(fullPath: $fullPath) {
|
|
711
713
|
repository {
|
|
@@ -754,13 +756,13 @@ query getAccountsForRepo(
|
|
|
754
756
|
}
|
|
755
757
|
}
|
|
756
758
|
}
|
|
757
|
-
`,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=>T(f,this.getIsSelfHosted(e))))??[]}}async getRepo(s,e={}){var o;let r=
|
|
759
|
+
`,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=>T(f,this.getIsSelfHosted(e))))??[]}}async getRepo(s,e={}){var o;let r=F(s),n=await b(this.config,{query:`
|
|
758
760
|
query getRepo($fullPath: ID!) {
|
|
759
761
|
project(fullPath: $fullPath) {
|
|
760
762
|
${Ne}
|
|
761
763
|
}
|
|
762
764
|
}
|
|
763
|
-
`,variables:{fullPath:r}},e);if(!((o=n.body.data)!=null&&o.project))throw new Error(`Repository ${r} not found`);return{data:
|
|
765
|
+
`,variables:{fullPath:r}},e);if(!((o=n.body.data)!=null&&o.project))throw new Error(`Repository ${r} not found`);return{data:Fe(n.body.data.project)}}async getRepos(s,e={}){let n=s.map(F).map((u,l)=>`
|
|
764
766
|
getRepo_${l}: project(fullPath: "${u}") {
|
|
765
767
|
${Ne}
|
|
766
768
|
}
|
|
@@ -769,7 +771,7 @@ query getRepo($fullPath: ID!) {
|
|
|
769
771
|
query batchGetRepos {
|
|
770
772
|
${n}
|
|
771
773
|
}
|
|
772
|
-
`},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(
|
|
774
|
+
`},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(Fe(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:`
|
|
773
775
|
query getReposForCurrentUser($after: String) {
|
|
774
776
|
projects(membership: true first: 100 after: $after) {
|
|
775
777
|
pageInfo {
|
|
@@ -781,7 +783,7 @@ query getReposForCurrentUser($after: String) {
|
|
|
781
783
|
}
|
|
782
784
|
}
|
|
783
785
|
}
|
|
784
|
-
`,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(
|
|
786
|
+
`,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(Fe)}}async getRefs(s,e,r={}){var u;let n=F(e.repo),o=new URL(`${ke(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",E.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=F(s.repo),n=new URL(`${ke(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=is[s.association],n=await b(this.config,{query:`
|
|
785
787
|
query getPullRequestsForUser($username: String! $cursor: String) {
|
|
786
788
|
user(username: $username) {
|
|
787
789
|
${r}(state:opened first:100 after:$cursor) {
|
|
@@ -795,7 +797,7 @@ query getPullRequestsForUser($username: String! $cursor: String) {
|
|
|
795
797
|
}
|
|
796
798
|
}
|
|
797
799
|
}
|
|
798
|
-
`,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=>
|
|
800
|
+
`,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=>je(u,ft(u.project),ft(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=F(n),{variables:a,variableTypes:i,mergeRequestArguments:u}=this.getVariablesForPullRequests(s),l={fullPath:o,...a},p=await b(this.config,{query:`
|
|
799
801
|
query getPullRequestsForRepo(
|
|
800
802
|
$fullPath: ID!
|
|
801
803
|
$after: String
|
|
@@ -824,7 +826,7 @@ query getPullRequestsForRepo(
|
|
|
824
826
|
}
|
|
825
827
|
}
|
|
826
828
|
}
|
|
827
|
-
`,variables:{...l,after:r}},e),d=[],c=(f=p.body.data)==null?void 0:f.project,g=K(c||{id:"",fullPath:"",webUrl:""});return(((y=c==null?void 0:c.mergeRequests)==null?void 0:y.nodes)||[]).forEach(P=>{d.push(
|
|
829
|
+
`,variables:{...l,after:r}},e),d=[],c=(f=p.body.data)==null?void 0:f.project,g=K(c||{id:"",fullPath:"",webUrl:""});return(((y=c==null?void 0:c.mergeRequests)==null?void 0:y.nodes)||[]).forEach(P=>{d.push(je(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(_)?h:`${_}${h}`),{variables:o,variableTypes:a,mergeRequestArguments:i}=this.getVariablesForPullRequests(s),u={projectIds:n,...o},l=await b(this.config,{query:`
|
|
828
830
|
query getPullRequests(
|
|
829
831
|
$projectIds: [ID!]
|
|
830
832
|
$after: String
|
|
@@ -855,7 +857,7 @@ query getPullRequests(
|
|
|
855
857
|
}
|
|
856
858
|
}
|
|
857
859
|
}
|
|
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=K(h);(((C=h.mergeRequests)==null?void 0:C.nodes)||[]).forEach(te=>{p.push(
|
|
860
|
+
`,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=K(h);(((C=h.mergeRequests)==null?void 0:C.nodes)||[]).forEach(te=>{p.push(je(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!) {
|
|
859
861
|
mergeRequestUpdate(input: { projectPath: $fullPath, iid: $pullRequestId, state: CLOSED }) {
|
|
860
862
|
errors,
|
|
861
863
|
mergeRequest {
|
|
@@ -924,7 +926,7 @@ query GetSingleIssue($projectId: ID!, $issueId: String!) {
|
|
|
924
926
|
}
|
|
925
927
|
}
|
|
926
928
|
}
|
|
927
|
-
`,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:Be(n.body.data.project.issue,K(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=
|
|
929
|
+
`,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:Be(n.body.data.project.issue,K(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=F(n),{variables:a,variableTypes:i,issueArguments:u}=this.getVariablesForIssues(s),l={fullPath:o,...a},p=`
|
|
928
930
|
query GetIssuesFromProject(
|
|
929
931
|
$fullPath: ID!
|
|
930
932
|
$after: String
|
|
@@ -982,7 +984,7 @@ query GetSingleIssue($projectId: ID!, $issueId: String!) {
|
|
|
982
984
|
}
|
|
983
985
|
}
|
|
984
986
|
}
|
|
985
|
-
}`,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 D=K(P);(((te=P.issues)==null?void 0:te.nodes)||[]).forEach(
|
|
987
|
+
}`,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 D=K(P);(((te=P.issues)==null?void 0:te.nodes)||[]).forEach(bt=>d.push(Be(bt,D,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,D)=>(P.updatedDate||P.createdDate).getTime()-(D.updatedDate||D.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!) {
|
|
986
988
|
updateIssue(input: { projectPath: $fullPath, iid: $issueId, stateEvent: $status }) {
|
|
987
989
|
issue {
|
|
988
990
|
id
|
|
@@ -994,7 +996,7 @@ query GetSingleIssue($projectId: ID!, $issueId: String!) {
|
|
|
994
996
|
id
|
|
995
997
|
}
|
|
996
998
|
}
|
|
997
|
-
}`;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(
|
|
999
|
+
}`;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(Rt,""))??"",i=`mutation SetIssueMilestone($fullPath: ID!, $issueId: String!, $milestoneGraphQLId: ID) {
|
|
998
1000
|
updateIssue(input: { projectPath: $fullPath, iid: $issueId, milestoneId: $milestoneGraphQLId }) {
|
|
999
1001
|
errors
|
|
1000
1002
|
issue {
|
|
@@ -1022,7 +1024,7 @@ query getLabelsForRepo(
|
|
|
1022
1024
|
webUrl
|
|
1023
1025
|
milestones(after: $after) {
|
|
1024
1026
|
nodes {
|
|
1025
|
-
${
|
|
1027
|
+
${We}
|
|
1026
1028
|
}
|
|
1027
1029
|
pageInfo {
|
|
1028
1030
|
endCursor
|
|
@@ -1041,7 +1043,7 @@ query getLabelsForRepo(
|
|
|
1041
1043
|
) {
|
|
1042
1044
|
labels(after: $after) {
|
|
1043
1045
|
nodes {
|
|
1044
|
-
${
|
|
1046
|
+
${He}
|
|
1045
1047
|
}
|
|
1046
1048
|
pageInfo {
|
|
1047
1049
|
endCursor
|
|
@@ -1050,5 +1052,5 @@ query getLabelsForRepo(
|
|
|
1050
1052
|
}
|
|
1051
1053
|
}
|
|
1052
1054
|
}
|
|
1053
|
-
`,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(Je))??[]}}};var Is="https://api.atlassian.com/ex/jira",pe=100,
|
|
1054
|
-
OR comment ~ currentUser() OR summary ~ currentUser() OR description ~ currentUser())`,l=(await t.request({url:`${F(t,r,o)}/rest/api/2/search?jql=${i}&startAt=${a}&maxResults=${pe}&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=>bt(d,e,!o)),p=l.length==pe;return{data:l,pageInfo:{hasNextPage:p,nextPage:p?a+l.length:null}}},ge=async(t,s,e,r={})=>{let{assigneeLogins:n,authorLogin:o,mentionLogin:a,page:i,project:u,resourceId:l}=s||{},p=i??0,d=[`project = "${u}"`,"statusCategory != Done"];o&&d.push(`creator in ("${o}")`),n&&n.length!==0&&d.push(`assignee in ("${n.join('", "')}")`),a&&d.push(`comment ~ "${a}"`);let g=(await t.request({url:`${F(t,r,l)}/rest/api/2/search?jql=${d.join(" AND ")}&startAt=${p}&maxResults=${pe}&fields=${["assignee","comment","summary","created","creator","updated","votes","issuetype","status","labels","components"].join(",")}&expand=transitions`,headers:R(r.token||t.token)})).body.issues.map(f=>bt(f,e,!l)),m=g.length==pe;return{data:g,pageInfo:{hasNextPage:m,nextPage:m?p+g.length:null}}},me=async(t,s,e={})=>{let{resourceId:r,issueId:n,labelNames:o}=s,a={fields:{labels:o}};await t.request({method:"PUT",url:`${F(t,e,r)}/rest/api/2/issue/${n}`,body:JSON.stringify(a),headers:{...R(e.token||t.token),"Content-Type":"application/json"}})},he=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:`${F(t,e,r)}/rest/api/2/issue/${n}`,body:JSON.stringify(a),headers:{...R(e.token||t.token),"Content-Type":"application/json"}})},fe=async(t,s,e={})=>{let{resourceId:r,issueId:n,status:o}=s,a={transition:{id:o}};await t.request({method:"POST",url:`${F(t,e,r)}/rest/api/2/issue/${n}/transitions`,body:JSON.stringify(a),headers:{...R(e.token||t.token),"Content-Type":"application/json"}})},Re=async(t,s,e={})=>{let{resourceId:r,projectIdOrKey:n}=s,o=new URL(`${F(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",Ve=100,Z=class extends q{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",Ve.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",Ve.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=>de(p,i,!1))}}async getComponentsForJiraProject(e,r={}){return await Re(this.config,e,r)}async getIssuesForProject(e,r={}){let n=await this.getResourceUrl({resourceId:e.resourceId},r);return await ge(this.config,e,n,r)}async getIssuesForResourceForCurrentUser(e,r={}){let n=await this.getResourceUrl({resourceId:e.resourceId},r);return await ce(this.config,e,n,r)}async setIssueStatus(e,r={}){await fe(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 he(this.config,e,r)}async setIssueLabels(e,r={}){await me(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",Ve.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 ge(this.config,s,e.baseUrl,e)}async getIssuesForResourceForCurrentUser(s,e={}){if(!e.baseUrl)throw new Error('Jira Server requires a "baseUrl" for this function.');return await ce(this.config,s,e.baseUrl,e)}async setIssueStatus(s,e={}){await fe(this.config,s,e)}async setIssueLabels(s,e={}){await me(this.config,s,e)}async setIssueComponents(s,e={}){await he(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 Re(this.config,s,e)}};var O="https://api.trello.com",Ss=1e3,Ds=(t,s)=>{let e=new Date(1e3*parseInt(t.id.substring(0,8),16));return{id:t.id,commentCount:t.badges.comments,number:t.idShort.toString(),title:t.name,url:t.url,closedDate:null,createdDate:new Date(e.toISOString()),author:null,updatedDate:new Date(t.dateLastActivity),assignees:t.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 q{async getCurrentUser(s,e={}){let r=await this.config.request({url:`${e.baseUrl||O}/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||O}/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||O}/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||O}/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||O}/1/search?key=${n}&query=${l}&cards_limit=${Ss}&token=${e.token||this.config.token}`,headers:R(e.token||this.config.token)})).body.cards.map(d=>Ds(d,u||{}))}}async updateIssue(s,e,r,n){return await this.config.request({method:"PUT",url:`${n.baseUrl||O}/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||O}/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||O}/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||O}/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 Ie={};x(Ie,{getIssueUniqueId:()=>Es,getPullRequestUniqueId:()=>Cs});var Es=(t,s,e,r="")=>{let n=[];return n.push(r),n.push(t),n.push(s),n.push(e),JSON.stringify(n)},Cs=(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 be={};x(be,{getIssueUniqueId:()=>Us,getPullRequestUniqueId:()=>qs});var Us=(t,s)=>JSON.stringify(["",t,s]),qs=(t,s)=>JSON.stringify(["",t,s]);var ye={};x(ye,{getIssueUniqueId:()=>vs,getPullRequestUniqueId:()=>$s});var vs=(t,s,e)=>JSON.stringify([e,t,s]),$s=(t,s,e)=>JSON.stringify([e,t,s]);var Pe={};x(Pe,{getIssueUniqueId:()=>Ls,getPullRequestRank:()=>As,getPullRequestUniqueId:()=>Gs});var Ls=(t,s="")=>{let e=[];return e.push(s),e.push(t),JSON.stringify(e)},Gs=(t,s="")=>{let e=[];return e.push(s),e.push(t),JSON.stringify(e)},As=(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 we={};x(we,{getIssueUniqueId:()=>Ts,getPullRequestUniqueId:()=>Os});var Ts=(t,s="")=>{let e=[];return e.push(s),e.push(t),JSON.stringify(e)},Os=(t,s="")=>{let e=[];return e.push(s),e.push(t),JSON.stringify(e)};var Se={};x(Se,{getIssueUniqueId:()=>xs,getJiraServerIssueUniqueId:()=>ks});var xs=(t,s,e)=>{let r=[];return r.push(""),r.push(t),r.push(s),r.push(e),JSON.stringify(r)},ks=(t,s,e)=>{let r=[];return r.push(e),r.push(""),r.push(t),r.push(s),JSON.stringify(r)};var De={};x(De,{getIssueUniqueId:()=>Ns});var Ns=(t,s,e,r="")=>{let n=[];return n.push(r),n.push(t),n.push(s),n.push(e),JSON.stringify(n)};var _s=t=>{let s={request:t==null?void 0:t.request};return{azureDevOps:new M({...s,...t==null?void 0:t.azureDevOps}),bitbucket:new H({...s,...t==null?void 0:t.bitbucket}),bitbucketServer:new W({...s,...t==null?void 0:t.bitbucketServer}),github:new J({...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})}},Qs=_s;var js={azureDevOps:Ie,bitbucket:be,bitbucketServer:ye,github:Pe,gitlab:we,jira:Se,trello:De};
|
|
1055
|
+
`,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(Je))??[]}}};var Is="https://api.atlassian.com/ex/jira",pe=100,It=(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:de(t.fields.creator,s,e),updatedDate:new Date(t.fields.updated),assignees:r?[de(r,s,e)]:[],description:null,repository:null,state:ws(t.fields.status),statusTransitions:((n=t.transitions)==null?void 0:n.map(bs))??[],components:((o=t.fields.components)==null?void 0:o.map(ys))??[],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})))??[]}},bs=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}}},ys=t=>({description:t.description??null,id:t.id,name:t.name}),Ps=(t,s,e)=>e&&t.name?`${s}/secure/ViewProfile.jspa?name=${encodeURIComponent(t.name)}`:`${s}/jira/people/${t.accountId}`,de=(t,s,e)=>({id:(e?t.key:t.accountId)??"",name:t.displayName,email:t.emailAddress,avatarUrl:t.avatarUrls["48x48"],username:t.displayName,url:Ps(t,s,e)}),ws=t=>{let s;switch(t.statusCategory.name){case"To Do":s="TO_DO";break;case"In Progress":s="IN_PROGRESS";break;default:s="DONE";break}return{id:t.id,name:t.name,color:t.statusCategory.colorName,category:s}},j=(t,s,e)=>e?`${s.baseUrl||Is}/${e}`:`${(s==null?void 0:s.baseUrl)||t.baseUrl}`,ce=async(t,s,e,r={})=>{let{page:n,resourceId:o}=s||{},a=n??0,i=`statusCategory != Done AND (creator = currentUser() OR assignee = currentUser()
|
|
1056
|
+
OR comment ~ currentUser() OR summary ~ currentUser() OR description ~ currentUser())`,l=(await t.request({url:`${j(t,r,o)}/rest/api/2/search?jql=${i}&startAt=${a}&maxResults=${pe}&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=>It(d,e,!o)),p=l.length==pe;return{data:l,pageInfo:{hasNextPage:p,nextPage:p?a+l.length:null}}},ge=async(t,s,e,r={})=>{let{assigneeLogins:n,authorLogin:o,mentionLogin:a,page:i,project:u,resourceId:l}=s||{},p=i??0,d=[`project = "${u}"`,"statusCategory != Done"];o&&d.push(`creator in ("${o}")`),n&&n.length!==0&&d.push(`assignee in ("${n.join('", "')}")`),a&&d.push(`comment ~ "${a}"`);let g=(await t.request({url:`${j(t,r,l)}/rest/api/2/search?jql=${d.join(" AND ")}&startAt=${p}&maxResults=${pe}&fields=${["assignee","comment","summary","created","creator","updated","votes","issuetype","status","labels","components"].join(",")}&expand=transitions`,headers:R(r.token||t.token)})).body.issues.map(f=>It(f,e,!l)),m=g.length==pe;return{data:g,pageInfo:{hasNextPage:m,nextPage:m?p+g.length:null}}},me=async(t,s,e={})=>{let{resourceId:r,issueId:n,labelNames:o}=s,a={fields:{labels:o}};await t.request({method:"PUT",url:`${j(t,e,r)}/rest/api/2/issue/${n}`,body:JSON.stringify(a),headers:{...R(e.token||t.token),"Content-Type":"application/json"}})},he=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:`${j(t,e,r)}/rest/api/2/issue/${n}`,body:JSON.stringify(a),headers:{...R(e.token||t.token),"Content-Type":"application/json"}})},fe=async(t,s,e={})=>{let{resourceId:r,issueId:n,status:o}=s,a={transition:{id:o}};await t.request({method:"POST",url:`${j(t,e,r)}/rest/api/2/issue/${n}/transitions`,body:JSON.stringify(a),headers:{...R(e.token||t.token),"Content-Type":"application/json"}})},Re=async(t,s,e={})=>{let{resourceId:r,projectIdOrKey:n}=s,o=new URL(`${j(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",Ve=100,Z=class extends q{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",Ve.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",Ve.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=>de(p,i,!1))}}async getComponentsForJiraProject(e,r={}){return await Re(this.config,e,r)}async getIssuesForProject(e,r={}){let n=await this.getResourceUrl({resourceId:e.resourceId},r);return await ge(this.config,e,n,r)}async getIssuesForResourceForCurrentUser(e,r={}){let n=await this.getResourceUrl({resourceId:e.resourceId},r);return await ce(this.config,e,n,r)}async setIssueStatus(e,r={}){await fe(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 he(this.config,e,r)}async setIssueLabels(e,r={}){await me(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",Ve.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 ge(this.config,s,e.baseUrl,e)}async getIssuesForResourceForCurrentUser(s,e={}){if(!e.baseUrl)throw new Error('Jira Server requires a "baseUrl" for this function.');return await ce(this.config,s,e.baseUrl,e)}async setIssueStatus(s,e={}){await fe(this.config,s,e)}async setIssueLabels(s,e={}){await me(this.config,s,e)}async setIssueComponents(s,e={}){await he(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 Re(this.config,s,e)}};var O="https://api.trello.com",Ss=1e3,Ds=(t,s)=>{let e=new Date(1e3*parseInt(t.id.substring(0,8),16));return{id:t.id,commentCount:t.badges.comments,number:t.idShort.toString(),title:t.name,url:t.url,closedDate:null,createdDate:new Date(e.toISOString()),author:null,updatedDate:new Date(t.dateLastActivity),assignees:t.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 q{async getCurrentUser(s,e={}){let r=await this.config.request({url:`${e.baseUrl||O}/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||O}/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||O}/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||O}/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||O}/1/search?key=${n}&query=${l}&cards_limit=${Ss}&token=${e.token||this.config.token}`,headers:R(e.token||this.config.token)})).body.cards.map(d=>Ds(d,u||{}))}}async updateIssue(s,e,r,n){return await this.config.request({method:"PUT",url:`${n.baseUrl||O}/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||O}/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||O}/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||O}/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 Ie={};x(Ie,{getIssueUniqueId:()=>Es,getPullRequestUniqueId:()=>Cs});var Es=(t,s,e,r="")=>{let n=[];return n.push(r),n.push(t),n.push(s),n.push(e),JSON.stringify(n)},Cs=(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 be={};x(be,{getIssueUniqueId:()=>Us,getPullRequestUniqueId:()=>qs});var Us=(t,s)=>JSON.stringify(["",t,s]),qs=(t,s)=>JSON.stringify(["",t,s]);var ye={};x(ye,{getIssueUniqueId:()=>vs,getPullRequestUniqueId:()=>$s});var vs=(t,s,e)=>JSON.stringify([e,t,s]),$s=(t,s,e)=>JSON.stringify([e,t,s]);var Pe={};x(Pe,{getIssueUniqueId:()=>Ls,getPullRequestRank:()=>As,getPullRequestUniqueId:()=>Gs});var Ls=(t,s="")=>{let e=[];return e.push(s),e.push(t),JSON.stringify(e)},Gs=(t,s="")=>{let e=[];return e.push(s),e.push(t),JSON.stringify(e)},As=(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 we={};x(we,{getIssueUniqueId:()=>Ts,getPullRequestUniqueId:()=>Os});var Ts=(t,s="")=>{let e=[];return e.push(s),e.push(t),JSON.stringify(e)},Os=(t,s="")=>{let e=[];return e.push(s),e.push(t),JSON.stringify(e)};var Se={};x(Se,{getIssueUniqueId:()=>xs,getJiraServerIssueUniqueId:()=>ks});var xs=(t,s,e)=>{let r=[];return r.push(""),r.push(t),r.push(s),r.push(e),JSON.stringify(r)},ks=(t,s,e)=>{let r=[];return r.push(e),r.push(""),r.push(t),r.push(s),JSON.stringify(r)};var De={};x(De,{getIssueUniqueId:()=>Ns});var Ns=(t,s,e,r="")=>{let n=[];return n.push(r),n.push(t),n.push(s),n.push(e),JSON.stringify(n)};var _s=t=>{let s={request:t==null?void 0:t.request};return{azureDevOps:new M({...s,...t==null?void 0:t.azureDevOps}),bitbucket:new W({...s,...t==null?void 0:t.bitbucket}),bitbucketServer:new H({...s,...t==null?void 0:t.bitbucketServer}),github:new J({...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})}},Qs=_s;var Fs={azureDevOps:Ie,bitbucket:be,bitbucketServer:ye,github:Pe,gitlab:we,jira:Se,trello:De};
|
|
@@ -2,7 +2,7 @@ import { PagedResult, Result } from '../../types';
|
|
|
2
2
|
import { CursorPageInput, EnterpriseOptions, GetRepoErrorData, GetRepoInput, GitMergeStrategy, GitProvider, GitPullRequest, GitRepository, NumberedPageInput, Options } from '../gitProvider';
|
|
3
3
|
import { Issue } from '../issueProvider';
|
|
4
4
|
import { Provider } from '../provider';
|
|
5
|
-
import { PullRequestAsyncStatus, WorkItemType } from './azureDevOpsTypes';
|
|
5
|
+
import { AzureGraphAccount, PullRequestAsyncStatus, WorkItemType } from './azureDevOpsTypes';
|
|
6
6
|
export interface AzureGetRepoInput extends GetRepoInput {
|
|
7
7
|
project: string;
|
|
8
8
|
}
|
|
@@ -73,16 +73,45 @@ export declare class AzureDevOps extends Provider implements GitProvider {
|
|
|
73
73
|
scope: string;
|
|
74
74
|
};
|
|
75
75
|
}>;
|
|
76
|
-
|
|
76
|
+
getAzureGraphAccountsForAzureProject(input: {
|
|
77
77
|
namespace: string;
|
|
78
78
|
projectScopeDescriptor?: string;
|
|
79
|
+
} & CursorPageInput, options?: Options): Promise<{
|
|
80
|
+
pageInfo: {
|
|
81
|
+
endCursor: string | null;
|
|
82
|
+
hasNextPage: boolean;
|
|
83
|
+
};
|
|
84
|
+
data: {
|
|
85
|
+
avatarUrl: string | null;
|
|
86
|
+
descriptor: string;
|
|
87
|
+
email: string;
|
|
88
|
+
name: string;
|
|
89
|
+
storageKeyURL: string;
|
|
90
|
+
username: string;
|
|
91
|
+
}[];
|
|
92
|
+
}>;
|
|
93
|
+
getAccountFromAzureGraphAccount(input: {
|
|
94
|
+
azureGraphAccount: AzureGraphAccount;
|
|
79
95
|
}, options?: Options): Promise<{
|
|
80
96
|
data: {
|
|
97
|
+
avatarUrl: string | null;
|
|
98
|
+
email: string | null;
|
|
81
99
|
id: string;
|
|
82
100
|
name: string;
|
|
83
101
|
username: string;
|
|
84
|
-
|
|
85
|
-
|
|
102
|
+
url: null;
|
|
103
|
+
};
|
|
104
|
+
}>;
|
|
105
|
+
getAccountsFromAzureGraphAccounts(input: {
|
|
106
|
+
azureGraphAccounts: AzureGraphAccount[];
|
|
107
|
+
}, options?: Options): Promise<{
|
|
108
|
+
data: {
|
|
109
|
+
avatarUrl: string | null;
|
|
110
|
+
email: string | null;
|
|
111
|
+
id: string;
|
|
112
|
+
name: string;
|
|
113
|
+
username: string;
|
|
114
|
+
url: null;
|
|
86
115
|
}[];
|
|
87
116
|
}>;
|
|
88
117
|
getRepo(input: AzureGetRepoInput, options?: Options): Promise<{
|
|
@@ -232,6 +232,14 @@ export interface WorkItemType {
|
|
|
232
232
|
states: WorkItemState[];
|
|
233
233
|
url: string;
|
|
234
234
|
}
|
|
235
|
+
export interface AzureGraphAccount {
|
|
236
|
+
avatarUrl: string | null;
|
|
237
|
+
descriptor: string;
|
|
238
|
+
email: string | null;
|
|
239
|
+
name: string;
|
|
240
|
+
storageKeyURL: string;
|
|
241
|
+
username: string;
|
|
242
|
+
}
|
|
235
243
|
export interface UpdatePullRequestResponse {
|
|
236
244
|
status: string;
|
|
237
245
|
}
|
|
@@ -40,7 +40,8 @@ export declare enum GitBuildStatusState {
|
|
|
40
40
|
Running = "RUNNING",
|
|
41
41
|
Skipped = "SKIPPED",
|
|
42
42
|
Success = "SUCCESS",
|
|
43
|
-
Warning = "WARNING"
|
|
43
|
+
Warning = "WARNING",
|
|
44
|
+
OptionalActionRequired = "OPTIONAL_ACTION_REQUIRED"
|
|
44
45
|
}
|
|
45
46
|
export interface GitBuildStatus {
|
|
46
47
|
completedAt: Date | null;
|
|
@@ -137,6 +138,10 @@ export declare enum GitPullRequestMergeableState {
|
|
|
137
138
|
UnknownAndBlocked = "UNKNOWN_AND_BLOCKED",
|
|
138
139
|
Unstable = "UNSTABLE"
|
|
139
140
|
}
|
|
141
|
+
export interface GitPullRequestPermissions {
|
|
142
|
+
canMerge: boolean;
|
|
143
|
+
canMergeAndBypassProtections: boolean;
|
|
144
|
+
}
|
|
140
145
|
export interface GitPullRequest {
|
|
141
146
|
id: string;
|
|
142
147
|
graphQLId?: string;
|
|
@@ -196,6 +201,7 @@ export interface GitPullRequest {
|
|
|
196
201
|
mergeableState: GitPullRequestMergeableState;
|
|
197
202
|
milestone?: GitMilestone | null;
|
|
198
203
|
labels?: GitLabel[];
|
|
204
|
+
permissions: GitPullRequestPermissions | null;
|
|
199
205
|
}
|
|
200
206
|
export interface GitComment {
|
|
201
207
|
author: Account | User | null;
|
|
@@ -51,6 +51,13 @@ export declare enum GitHubPullRequestMergeStateStatus {
|
|
|
51
51
|
Unknown = "UNKNOWN",
|
|
52
52
|
Unstable = "UNSTABLE"
|
|
53
53
|
}
|
|
54
|
+
export declare enum GitHubRepositoryPermission {
|
|
55
|
+
Admin = "ADMIN",
|
|
56
|
+
Maintain = "MAINTAIN",
|
|
57
|
+
Read = "READ",
|
|
58
|
+
Triage = "TRIAGE",
|
|
59
|
+
Write = "WRITE"
|
|
60
|
+
}
|
|
54
61
|
export interface GraphQLUser {
|
|
55
62
|
__typename: 'User';
|
|
56
63
|
id: string;
|
|
@@ -187,6 +194,7 @@ export interface GraphQLPullRequest {
|
|
|
187
194
|
};
|
|
188
195
|
sshUrl: string;
|
|
189
196
|
url: string;
|
|
197
|
+
viewerPermission: GitHubRepositoryPermission;
|
|
190
198
|
};
|
|
191
199
|
reviewRequests: {
|
|
192
200
|
nodes: {
|
|
@@ -208,6 +216,7 @@ export interface GraphQLPullRequest {
|
|
|
208
216
|
labels: {
|
|
209
217
|
nodes: GraphQLLabel[] | null;
|
|
210
218
|
} | null;
|
|
219
|
+
viewerCanMergeAsAdmin: boolean;
|
|
211
220
|
}
|
|
212
221
|
export interface GraphQLIssue {
|
|
213
222
|
id: string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gitkraken/provider-apis",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.17.0",
|
|
4
4
|
"description": "An SDK around different third-party APIs that accepts and returns data in a common format.",
|
|
5
5
|
"author": "Axosoft, LLC dba GitKraken",
|
|
6
6
|
"license": "SEE LICENSE IN LICENSE",
|
|
@@ -29,7 +29,6 @@
|
|
|
29
29
|
"watch": "yarn clean && node ./scripts/build.mjs --watch & tsc -w"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"js-base64": "3.7.5",
|
|
33
32
|
"node-fetch": "2.7.0"
|
|
34
33
|
},
|
|
35
34
|
"devDependencies": {
|