@tomsd/github-repo-js 0.2.3 → 0.2.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +14047 -504
- package/dist/index.iife.js +1 -1
- package/dist/index.mjs +1 -1
- package/dist/modules/github-classes.d.ts +17050 -642
- package/dist/modules/issue-comments.d.ts +470 -20
- package/dist/modules/issue.d.ts +2078 -83
- package/dist/modules/my-issues.d.ts +1890 -75
- package/dist/modules/organization-repositories.d.ts +270 -15
- package/dist/modules/pull-commits.d.ts +390 -30
- package/dist/modules/pull-reviewers.d.ts +330 -10
- package/dist/modules/repository-branch.d.ts +2620 -10
- package/dist/modules/repository-branches.d.ts +2100 -5
- package/dist/modules/repository-issues.d.ts +1894 -79
- package/dist/modules/repository-pull.d.ts +2985 -115
- package/dist/modules/repository-pulls.d.ts +2775 -100
- package/dist/modules/repository-releases.d.ts +375 -15
- package/dist/modules/repository-runs.d.ts +2000 -35
- package/dist/modules/repository.d.ts +12840 -467
- package/dist/modules/user-repositories.d.ts +160 -10
- package/dist/repl.mjs +1 -1
- package/package.json +5 -3
package/dist/index.iife.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var GitHubRepoJs=(function(e){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});async function loopPages(e,t){let n=t??10,r=[],i=1;for(;;){let{resultItems:t}=await e({per_page:n,page:i});if(r.push(t),t.length<n)break;i++}return r.flat()}var GitHubApiBase=class{token;constructor(e){this.token=e}get apiOrigin(){return`https://api.github.com`}get apiEndpoint(){return``}get requestHeaders(){return{accept:`application/vnd.github+json`,authorization:`Bearer ${this.token}`,"X-GitHub-Api-Version":`2022-11-28`}}get pageSizeForRequest(){return 10}async getPagedList(e){return await loopPages(async({per_page:t,page:n})=>{let r=new URL(this.apiEndpoint),i={...e??{},per_page:t,page:n};for(let[e,t]of Object.entries(i))r.searchParams.append(e,`${t}`);return{resultItems:await fetch(r,{headers:this.requestHeaders,cache:`no-store`}).then(e=>{if(!e.ok)throw Error(e.statusText,{cause:{response:e}});return e.json()})}},this.pageSizeForRequest)}async getList(e){let t=new URL(this.apiEndpoint);for(let[n,r]of Object.entries(e??{}))t.searchParams.append(n,`${r}`);return await fetch(t,{headers:this.requestHeaders,cache:`no-store`}).then(e=>{if(!e.ok)throw Error(e.statusText,{cause:{response:e}});return e.json()})}async get(){return await fetch(this.apiEndpoint,{headers:this.requestHeaders,cache:`no-store`}).then(e=>{if(!e.ok)throw Error(e.statusText,{cause:{response:e}});return e.json()})}async post(e){return await fetch(this.apiEndpoint,{method:`POST`,headers:this.requestHeaders,body:JSON.stringify(e)}).then(e=>{if(!e.ok)throw Error(e.statusText,{cause:{response:e}});return e.json()})}async patch(e){return await fetch(this.apiEndpoint,{method:`PATCH`,headers:this.requestHeaders,body:JSON.stringify(e)}).then(e=>{if(!e.ok)throw Error(e.statusText,{cause:{response:e}});return e.json()})}async delete(){let e=await fetch(this.apiEndpoint,{method:`DELETE`,headers:this.requestHeaders});if(!e.ok)throw Error(e.statusText,{cause:{response:e}})}},GitHubRepoApiBase=class extends GitHubApiBase{owner;repo;constructor(e,t,n){super(e),this.owner=t,this.repo=n}},GitHubIssueApiBase=class extends GitHubRepoApiBase{issueNumber;constructor(e,t,n,r){super(e,t,n),this.issueNumber=r}},GitHubPullApiBase=class extends GitHubRepoApiBase{pullNumber;constructor(e,t,n,r){super(e,t,n),this.pullNumber=r}};function readyGitHubMyIssues(e){return class extends GitHubApiBase{constructor(){super(e)}get apiEndpoint(){return`${this.apiOrigin}/issues`}get pageSizeForRequest(){return 100}async getList(e){return await this.getPagedList(e)}}}function readyGitHubOrganizationRepositories(e){return class extends GitHubApiBase{org;constructor(t){super(e),this.org=t}get apiEndpoint(){return`${this.apiOrigin}/orgs/${this.org}/repos`}}}function readyGitHubBlob(e){return class extends GitHubRepoApiBase{fileSha;constructor(t,n,r){super(e,t,n),this.fileSha=r}get apiEndpoint(){return`${this.apiOrigin}/repos/${this.owner}/${this.repo}/git/blobs/${this.fileSha}`}}}function readyGitHubBlobs(e){return class extends GitHubRepoApiBase{constructor(t,n){super(e,t,n)}get apiEndpoint(){return`${this.apiOrigin}/repos/${this.owner}/${this.repo}/git/blobs`}}}function readyGitHubIssueComments(e){return class extends GitHubIssueApiBase{constructor(t,n,r){super(e,t,n,r)}get apiEndpoint(){return`${this.apiOrigin}/repos/${this.owner}/${this.repo}/issues/${this.issueNumber}/comments`}get pageSizeForRequest(){return 100}async getList(e){return await this.getPagedList(e)}}}function readyGitHubIssue(e){let t=readyGitHubIssueComments(e);return class extends GitHubIssueApiBase{constructor(t,n,r){super(e,t,n,r)}get apiEndpoint(){return`${this.apiOrigin}/repos/${this.owner}/${this.repo}/issues/${this.issueNumber}`}async getComments(){return await new t(this.owner,this.repo,this.issueNumber).getList()}async postComment(...e){return await new t(this.owner,this.repo,this.issueNumber).post(...e)}}}function readyGitHubRepositoryArtifacts(e){return class extends GitHubRepoApiBase{constructor(t,n){super(e,t,n)}get apiEndpoint(){return`${this.apiOrigin}/repos/${this.owner}/${this.repo}/actions/artifacts`}get pageSizeForRequest(){return 100}async getList(e){return await loopPages(async({per_page:t,page:n})=>{let r=new URL(this.apiEndpoint),i={...e??{},per_page:t,page:n};for(let[e,t]of Object.entries(i))r.searchParams.append(e,`${t}`);return{resultItems:await fetch(r,{headers:this.requestHeaders,cache:`no-store`}).then(async e=>{if(!e.ok)throw Error(e.statusText,{cause:{response:e}});let{artifacts:t}=await e.json();return t})}},this.pageSizeForRequest)}}}function readyGitHubRepositoryArtifact(e){return class extends GitHubRepoApiBase{artifactId;constructor(t,n,r){super(e,t,n),this.artifactId=r}get apiEndpoint(){return`${this.apiOrigin}/repos/${this.owner}/${this.repo}/actions/artifacts/${this.artifactId}`}async downloadBlob(){let e=`${this.apiEndpoint}/zip`,t=await fetch(e,{headers:this.requestHeaders,cache:`no-store`});if(!t.ok)throw Error(t.statusText,{cause:{response:t}});return await t.blob()}}}function readyGitHubRepositoryBranch(e){return class extends GitHubRepoApiBase{branch;constructor(t,n,r){super(e,t,n),this.branch=r}get apiEndpoint(){return`${this.apiOrigin}/repos/${this.owner}/${this.repo}/branches/${this.branch}`}}}function readyGitHubRepositoryBranches(e){return class extends GitHubRepoApiBase{constructor(t,n){super(e,t,n)}get apiEndpoint(){return`${this.apiOrigin}/repos/${this.owner}/${this.repo}/branches`}get pageSizeForRequest(){return 100}async getList(e){return await this.getPagedList(e)}}}function readyGitHubRepositoryCommits(e){return class extends GitHubRepoApiBase{constructor(t,n){super(e,t,n)}get apiEndpoint(){return`${this.apiOrigin}/repos/${this.owner}/${this.repo}/git/commits`}}}function readyGitHubRepositoryIssues(e){return class extends GitHubRepoApiBase{constructor(t,n){super(e,t,n)}get apiEndpoint(){return`${this.apiOrigin}/repos/${this.owner}/${this.repo}/issues`}get pageSizeForRequest(){return 100}async getList(e){return await this.getPagedList(e)}}}function readyGitHubReference(e){return class extends GitHubRepoApiBase{ref;constructor(t,n,r){super(e,t,n),this.ref=r}get apiEndpoint(){return`${this.apiOrigin}/repos/${this.owner}/${this.repo}/git/refs/${this.ref}`}}}function readyGitHubReferenceForGet(e){return class extends GitHubRepoApiBase{ref;constructor(t,n,r){super(e,t,n),this.ref=r}get apiEndpoint(){return`${this.apiOrigin}/repos/${this.owner}/${this.repo}/git/ref/${this.ref}`}}}function readyGitHubPullCommits(e){return class extends GitHubPullApiBase{constructor(t,n,r){super(e,t,n,r)}get apiEndpoint(){return`${this.apiOrigin}/repos/${this.owner}/${this.repo}/pulls/${this.pullNumber}/commits`}get pageSizeForRequest(){return 100}async getList(e){return await this.getPagedList(e)}}}function readyGitHubPullReviewers(e){return class extends GitHubPullApiBase{constructor(t,n,r){super(e,t,n,r)}get apiEndpoint(){return`${this.apiOrigin}/repos/${this.owner}/${this.repo}/pulls/${this.pullNumber}/requested_reviewers`}}}function readyGitHubRepositoryPull(e){let t=readyGitHubPullCommits(e),n=readyGitHubPullReviewers(e);return class extends GitHubPullApiBase{constructor(t,n,r){super(e,t,n,r)}get apiEndpoint(){return`${this.apiOrigin}/repos/${this.owner}/${this.repo}/pulls/${this.pullNumber}`}async getCommits(){return await new t(this.owner,this.repo,this.pullNumber).getList()}async getReviewers(){return await new n(this.owner,this.repo,this.pullNumber).get()}async postReviewers(...e){return await new n(this.owner,this.repo,this.pullNumber).post(...e)}}}function readyGitHubRepositoryPulls(e){return class extends GitHubRepoApiBase{constructor(t,n){super(e,t,n)}get apiEndpoint(){return`${this.apiOrigin}/repos/${this.owner}/${this.repo}/pulls`}get pageSizeForRequest(){return 100}async getList(e){return await this.getPagedList(e)}}}function readyGitHubRepositoryReferences(e){class GitHubRepositoryMatchingReferences extends GitHubRepoApiBase{refName;constructor(t,n,r){super(e,t,n),this.refName=r}get apiEndpoint(){return`${this.apiOrigin}/repos/${this.owner}/${this.repo}/git/matching-refs/${this.refName}`}}return class extends GitHubRepoApiBase{constructor(t,n){super(e,t,n)}get apiEndpoint(){return`${this.apiOrigin}/repos/${this.owner}/${this.repo}/git/refs`}async getMatchingList(e){return await new GitHubRepositoryMatchingReferences(this.owner,this.repo,e).getList()}}}function readyGitHubRepositoryReleases(e){return class extends GitHubRepoApiBase{constructor(t,n){super(e,t,n)}get apiEndpoint(){return`${this.apiOrigin}/repos/${this.owner}/${this.repo}/releases`}get pageSizeForRequest(){return 100}async getList(e){return await this.getPagedList(e)}}}function readyGitHubRepositoryLatestRelease(e){return class extends GitHubRepoApiBase{constructor(t,n){super(e,t,n)}get apiEndpoint(){return`${this.apiOrigin}/repos/${this.owner}/${this.repo}/releases/latest`}}}function readyGitHubRepositoryRuns(e){return class extends GitHubRepoApiBase{constructor(t,n){super(e,t,n)}get apiEndpoint(){return`${this.apiOrigin}/repos/${this.owner}/${this.repo}/actions/runs`}get pageSizeForRequest(){return 100}async getList(e){return await loopPages(async({per_page:t,page:n})=>{let r=new URL(this.apiEndpoint),i={...e??{},per_page:t,page:n};for(let[e,t]of Object.entries(i))r.searchParams.append(e,`${t}`);return{resultItems:await fetch(r,{headers:this.requestHeaders,cache:`no-store`}).then(async e=>{if(!e.ok)throw Error(e.statusText,{cause:{response:e}});let{workflow_runs:t}=await e.json();return t})}},this.pageSizeForRequest)}}}function readyGitHubTree(e){return class extends GitHubRepoApiBase{treeSha;constructor(t,n,r){super(e,t,n),this.treeSha=r}get apiEndpoint(){return`${this.apiOrigin}/repos/${this.owner}/${this.repo}/git/trees/${this.treeSha}?recursive=true`}}}function readyGitHubRepositoryTrees(e){return class extends GitHubRepoApiBase{constructor(t,n){super(e,t,n)}get apiEndpoint(){return`${this.apiOrigin}/repos/${this.owner}/${this.repo}/git/trees`}}}function readyGitHubRepository(e){let t=readyGitHubBlob(e),n=readyGitHubBlobs(e),r=readyGitHubIssue(e),i=readyGitHubReference(e),a=readyGitHubReferenceForGet(e),o=readyGitHubRepositoryArtifacts(e),s=readyGitHubRepositoryArtifact(e),c=readyGitHubRepositoryIssues(e),l=readyGitHubRepositoryBranch(e),u=readyGitHubRepositoryBranches(e),d=readyGitHubRepositoryCommits(e),f=readyGitHubRepositoryPull(e),p=readyGitHubRepositoryPulls(e),m=readyGitHubRepositoryReferences(e),h=readyGitHubRepositoryReleases(e),g=readyGitHubRepositoryLatestRelease(e),_=readyGitHubRepositoryRuns(e),v=readyGitHubRepositoryTrees(e),y=readyGitHubTree(e);return class extends GitHubRepoApiBase{constructor(t,n){super(e,t,n)}get apiEndpoint(){return`${this.apiOrigin}/repos/${this.owner}/${this.repo}`}async getArtifacts(e){return await new o(this.owner,this.repo).getList(e)}async getArtifact(e){return await new s(this.owner,this.repo,e).get()}async getArtifactZipBlob(e){return await new s(this.owner,this.repo,e).downloadBlob()}async getBranches(){return await new u(this.owner,this.repo).getList()}async getBranch(e){return await new l(this.owner,this.repo,e).get()}async getReferences(e){return await new m(this.owner,this.repo).getMatchingList(e)}async getBranchReferences(){return await new m(this.owner,this.repo).getMatchingList(`heads/`)}async getTagReferences(){return await new m(this.owner,this.repo).getMatchingList(`tags/`)}async postReference(...e){return await new m(this.owner,this.repo).post(...e)}async getReference(e){return await new a(this.owner,this.repo,e).get()}async getBranchReference(e){return await new a(this.owner,this.repo,`heads/${e}`).get()}async getTagReference(e){return await new a(this.owner,this.repo,`tags/${e}`).get()}async patchReference(e,...t){return await new i(this.owner,this.repo,e).patch(...t)}async deleteReference(e){return await new i(this.owner,this.repo,e).delete()}async getBlob(e){return await new t(this.owner,this.repo,e).get()}async postBlob(...e){return await new n(this.owner,this.repo).post(...e)}async getTree(e){return await new y(this.owner,this.repo,e).get()}async postTree(...e){return await new v(this.owner,this.repo).post(...e)}async getIssues(e){return await new c(this.owner,this.repo).getList(e)}async postIssue(...e){return await new c(this.owner,this.repo).post(...e)}issue(e){return new r(this.owner,this.repo,e)}async getIssue(e){return await new r(this.owner,this.repo,e).get()}async patchIssue(e,...t){return await new r(this.owner,this.repo,e).patch(...t)}async getPulls(e){return await new p(this.owner,this.repo).getList(e)}async postPull(...e){return await new p(this.owner,this.repo).post(...e)}pull(e){return new f(this.owner,this.repo,e)}async getPull(e){return await new f(this.owner,this.repo,e).get()}async patchPull(e,...t){return await new f(this.owner,this.repo,e).patch(...t)}async getReleases(e){return await new h(this.owner,this.repo).getList(e)}async postRelease(...e){return await new h(this.owner,this.repo).post(...e)}async getLatestRelease(){return await new g(this.owner,this.repo).get()}async postCommit(...e){return await new d(this.owner,this.repo).post(...e)}async getRuns(e){return await new _(this.owner,this.repo).getList(e)}}}function readyGitHubUser(e){return class GitHubUser extends GitHubApiBase{constructor(){super(e)}get apiEndpoint(){return`${this.apiOrigin}/user`}}}function readyGitHubUserOrganizations(e){return class extends GitHubApiBase{constructor(){super(e)}get apiEndpoint(){return`${this.apiOrigin}/user/orgs`}get pageSizeForRequest(){return 100}async getList(e){return await this.getPagedList(e)}}}function readyGitHubUserRepositories(e){return class extends GitHubApiBase{constructor(){super(e)}get apiEndpoint(){return`${this.apiOrigin}/user/repos`}get pageSizeForRequest(){return 100}async getList(e){return await this.getPagedList(e)}}}function readyGitHubClasses(e){return{GitHubMyIssues:readyGitHubMyIssues(e),GitHubOrganizationRepositories:readyGitHubOrganizationRepositories(e),GitHubRepository:readyGitHubRepository(e),GitHubRepositoryIssues:readyGitHubRepositoryIssues(e),GitHubUser:readyGitHubUser(e),GitHubUserOrganizations:readyGitHubUserOrganizations(e),GitHubUserRepositories:readyGitHubUserRepositories(e)}}var GitHubFacade=class{token;githubClasses;constructor(e){this.token=e,this.githubClasses=readyGitHubClasses(e)}async getMe(){return await new this.githubClasses.GitHubUser().get()}async getMyOrganizations(){let{GitHubUserOrganizations:e,GitHubOrganizationRepositories:t}=this.githubClasses;return(await new e().getList()).map(e=>({...e,async getRepositories(){return await new t(e.login).getList()}}))}async getMyRepositories(){let{GitHubUserRepositories:e,GitHubRepositoryIssues:t}=this.githubClasses;return(await new e().getList()).map(e=>({...e,async getIssues(){return await new t(e.owner.login,e.name).getList()},async postIssue(...n){return await new t(e.owner.login,e.name).post(...n)}}))}async getMyIssues(){let{GitHubMyIssues:e}=this.githubClasses;return await new e().getList()}repo(e,t){let{GitHubRepository:n}=this.githubClasses;return new n(e,t)}};return e.GitHubFacade=GitHubFacade,e})({});
|
|
1
|
+
var GitHubRepoJs=(function(e){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});async function loopPages(e,t){let n=t??10,r=[],i=1;for(;;){let{resultItems:t}=await e({per_page:n,page:i});if(r.push(t),t.length<n)break;i++}return r.flat()}var GitHubApiBase=class{token;constructor(e){this.token=e}get apiOrigin(){return`https://api.github.com`}get apiEndpoint(){return``}get requestHeaders(){return{accept:`application/vnd.github+json`,authorization:`Bearer ${this.token}`,"X-GitHub-Api-Version":`2022-11-28`}}get pageSizeForRequest(){return 10}async getPagedList(e){return await loopPages(async({per_page:t,page:n})=>{let r=new URL(this.apiEndpoint),i={...e??{},per_page:t,page:n};for(let[e,t]of Object.entries(i))r.searchParams.append(e,`${t}`);return{resultItems:await fetch(r,{headers:this.requestHeaders,cache:`no-store`}).then(e=>{if(!e.ok)throw Error(e.statusText,{cause:{response:e}});return e.json()})}},this.pageSizeForRequest)}async getList(e){let t=new URL(this.apiEndpoint);for(let[n,r]of Object.entries(e??{}))t.searchParams.append(n,`${r}`);return await fetch(t,{headers:this.requestHeaders,cache:`no-store`}).then(e=>{if(!e.ok)throw Error(e.statusText,{cause:{response:e}});return e.json()})}async get(){return await fetch(this.apiEndpoint,{headers:this.requestHeaders,cache:`no-store`}).then(e=>{if(!e.ok)throw Error(e.statusText,{cause:{response:e}});return e.json()})}async post(e){return await fetch(this.apiEndpoint,{method:`POST`,headers:this.requestHeaders,body:JSON.stringify(e)}).then(e=>{if(!e.ok)throw Error(e.statusText,{cause:{response:e}});return e.json()})}async patch(e){return await fetch(this.apiEndpoint,{method:`PATCH`,headers:this.requestHeaders,body:JSON.stringify(e)}).then(e=>{if(!e.ok)throw Error(e.statusText,{cause:{response:e}});return e.json()})}async delete(){let e=await fetch(this.apiEndpoint,{method:`DELETE`,headers:this.requestHeaders});if(!e.ok)throw Error(e.statusText,{cause:{response:e}})}},GitHubRepoApiBase=class extends GitHubApiBase{owner;repo;constructor(e,t,n){super(e),this.owner=t,this.repo=n}},GitHubIssueApiBase=class extends GitHubRepoApiBase{issueNumber;constructor(e,t,n,r){super(e,t,n),this.issueNumber=r}},GitHubPullApiBase=class extends GitHubRepoApiBase{pullNumber;constructor(e,t,n,r){super(e,t,n),this.pullNumber=r}};function readyGitHubMyIssues(e){return class GitHubMyIssues extends GitHubApiBase{constructor(){super(e)}get apiEndpoint(){return`${this.apiOrigin}/issues`}get pageSizeForRequest(){return 100}async getList(e){return await this.getPagedList(e)}}}function readyGitHubOrganizationRepositories(e){return class GitHubOrganizationRepositories extends GitHubApiBase{org;constructor(t){super(e),this.org=t}get apiEndpoint(){return`${this.apiOrigin}/orgs/${this.org}/repos`}}}function readyGitHubBlob(e){return class GitHubBlob extends GitHubRepoApiBase{fileSha;constructor(t,n,r){super(e,t,n),this.fileSha=r}get apiEndpoint(){return`${this.apiOrigin}/repos/${this.owner}/${this.repo}/git/blobs/${this.fileSha}`}}}function readyGitHubBlobs(e){return class GitHubBlobs extends GitHubRepoApiBase{constructor(t,n){super(e,t,n)}get apiEndpoint(){return`${this.apiOrigin}/repos/${this.owner}/${this.repo}/git/blobs`}}}function readyGitHubIssueComments(e){return class GitHubIssueComments extends GitHubIssueApiBase{constructor(t,n,r){super(e,t,n,r)}get apiEndpoint(){return`${this.apiOrigin}/repos/${this.owner}/${this.repo}/issues/${this.issueNumber}/comments`}get pageSizeForRequest(){return 100}async getList(e){return await this.getPagedList(e)}}}function readyGitHubIssue(e){let t=readyGitHubIssueComments(e);return class GitHubIssue extends GitHubIssueApiBase{constructor(t,n,r){super(e,t,n,r)}get apiEndpoint(){return`${this.apiOrigin}/repos/${this.owner}/${this.repo}/issues/${this.issueNumber}`}async getComments(){return await new t(this.owner,this.repo,this.issueNumber).getList()}async postComment(...e){return await new t(this.owner,this.repo,this.issueNumber).post(...e)}}}function readyGitHubRepositoryArtifacts(e){return class GitHubRepositoryArtifacts extends GitHubRepoApiBase{constructor(t,n){super(e,t,n)}get apiEndpoint(){return`${this.apiOrigin}/repos/${this.owner}/${this.repo}/actions/artifacts`}get pageSizeForRequest(){return 100}async getList(e){return await loopPages(async({per_page:t,page:n})=>{let r=new URL(this.apiEndpoint),i={...e??{},per_page:t,page:n};for(let[e,t]of Object.entries(i))r.searchParams.append(e,`${t}`);return{resultItems:await fetch(r,{headers:this.requestHeaders,cache:`no-store`}).then(async e=>{if(!e.ok)throw Error(e.statusText,{cause:{response:e}});let{artifacts:t}=await e.json();return t})}},this.pageSizeForRequest)}}}function readyGitHubRepositoryArtifact(e){return class GitHubRepositoryArtifact extends GitHubRepoApiBase{artifactId;constructor(t,n,r){super(e,t,n),this.artifactId=r}get apiEndpoint(){return`${this.apiOrigin}/repos/${this.owner}/${this.repo}/actions/artifacts/${this.artifactId}`}async downloadBlob(){let e=`${this.apiEndpoint}/zip`,t=await fetch(e,{headers:this.requestHeaders,cache:`no-store`});if(!t.ok)throw Error(t.statusText,{cause:{response:t}});return await t.blob()}}}function readyGitHubRepositoryBranch(e){return class GitHubRepositoryBranch extends GitHubRepoApiBase{branch;constructor(t,n,r){super(e,t,n),this.branch=r}get apiEndpoint(){return`${this.apiOrigin}/repos/${this.owner}/${this.repo}/branches/${this.branch}`}}}function readyGitHubRepositoryBranches(e){return class GitHubRepositoryBranches extends GitHubRepoApiBase{constructor(t,n){super(e,t,n)}get apiEndpoint(){return`${this.apiOrigin}/repos/${this.owner}/${this.repo}/branches`}get pageSizeForRequest(){return 100}async getList(e){return await this.getPagedList(e)}}}function readyGitHubRepositoryCommits(e){return class GitHubRepositoryCommits extends GitHubRepoApiBase{constructor(t,n){super(e,t,n)}get apiEndpoint(){return`${this.apiOrigin}/repos/${this.owner}/${this.repo}/git/commits`}}}function readyGitHubRepositoryIssues(e){return class GitHubRepositoryIssues extends GitHubRepoApiBase{constructor(t,n){super(e,t,n)}get apiEndpoint(){return`${this.apiOrigin}/repos/${this.owner}/${this.repo}/issues`}get pageSizeForRequest(){return 100}async getList(e){return await this.getPagedList(e)}}}function readyGitHubReference(e){return class GitHubReference extends GitHubRepoApiBase{ref;constructor(t,n,r){super(e,t,n),this.ref=r}get apiEndpoint(){return`${this.apiOrigin}/repos/${this.owner}/${this.repo}/git/refs/${this.ref}`}}}function readyGitHubReferenceForGet(e){return class GitHubReferenceForGet extends GitHubRepoApiBase{ref;constructor(t,n,r){super(e,t,n),this.ref=r}get apiEndpoint(){return`${this.apiOrigin}/repos/${this.owner}/${this.repo}/git/ref/${this.ref}`}}}function readyGitHubPullCommits(e){return class GitHubPullCommits extends GitHubPullApiBase{constructor(t,n,r){super(e,t,n,r)}get apiEndpoint(){return`${this.apiOrigin}/repos/${this.owner}/${this.repo}/pulls/${this.pullNumber}/commits`}get pageSizeForRequest(){return 100}async getList(e){return await this.getPagedList(e)}}}function readyGitHubPullReviewers(e){return class GitHubPullReviewers extends GitHubPullApiBase{constructor(t,n,r){super(e,t,n,r)}get apiEndpoint(){return`${this.apiOrigin}/repos/${this.owner}/${this.repo}/pulls/${this.pullNumber}/requested_reviewers`}}}function readyGitHubRepositoryPull(e){let t=readyGitHubPullCommits(e),n=readyGitHubPullReviewers(e);return class GitHubRepositoryPull extends GitHubPullApiBase{constructor(t,n,r){super(e,t,n,r)}get apiEndpoint(){return`${this.apiOrigin}/repos/${this.owner}/${this.repo}/pulls/${this.pullNumber}`}async getCommits(){return await new t(this.owner,this.repo,this.pullNumber).getList()}async getReviewers(){return await new n(this.owner,this.repo,this.pullNumber).get()}async postReviewers(...e){return await new n(this.owner,this.repo,this.pullNumber).post(...e)}}}function readyGitHubRepositoryPulls(e){return class GitHubRepositoryPulls extends GitHubRepoApiBase{constructor(t,n){super(e,t,n)}get apiEndpoint(){return`${this.apiOrigin}/repos/${this.owner}/${this.repo}/pulls`}get pageSizeForRequest(){return 100}async getList(e){return await this.getPagedList(e)}}}function readyGitHubRepositoryReferences(e){class GitHubRepositoryMatchingReferences extends GitHubRepoApiBase{refName;constructor(t,n,r){super(e,t,n),this.refName=r}get apiEndpoint(){return`${this.apiOrigin}/repos/${this.owner}/${this.repo}/git/matching-refs/${this.refName}`}}return class GitHubRepositoryReferences extends GitHubRepoApiBase{constructor(t,n){super(e,t,n)}get apiEndpoint(){return`${this.apiOrigin}/repos/${this.owner}/${this.repo}/git/refs`}async getMatchingList(e){return await new GitHubRepositoryMatchingReferences(this.owner,this.repo,e).getList()}}}function readyGitHubRepositoryReleases(e){return class GitHubRepositoryReleases extends GitHubRepoApiBase{constructor(t,n){super(e,t,n)}get apiEndpoint(){return`${this.apiOrigin}/repos/${this.owner}/${this.repo}/releases`}get pageSizeForRequest(){return 100}async getList(e){return await this.getPagedList(e)}}}function readyGitHubRepositoryLatestRelease(e){return class GitHubRepositoryLatestRelease extends GitHubRepoApiBase{constructor(t,n){super(e,t,n)}get apiEndpoint(){return`${this.apiOrigin}/repos/${this.owner}/${this.repo}/releases/latest`}}}function readyGitHubRepositoryRuns(e){return class GitHubRepositoryRuns extends GitHubRepoApiBase{constructor(t,n){super(e,t,n)}get apiEndpoint(){return`${this.apiOrigin}/repos/${this.owner}/${this.repo}/actions/runs`}get pageSizeForRequest(){return 100}async getList(e){return await loopPages(async({per_page:t,page:n})=>{let r=new URL(this.apiEndpoint),i={...e??{},per_page:t,page:n};for(let[e,t]of Object.entries(i))r.searchParams.append(e,`${t}`);return{resultItems:await fetch(r,{headers:this.requestHeaders,cache:`no-store`}).then(async e=>{if(!e.ok)throw Error(e.statusText,{cause:{response:e}});let{workflow_runs:t}=await e.json();return t})}},this.pageSizeForRequest)}}}function readyGitHubTree(e){return class GitHubTree extends GitHubRepoApiBase{treeSha;constructor(t,n,r){super(e,t,n),this.treeSha=r}get apiEndpoint(){return`${this.apiOrigin}/repos/${this.owner}/${this.repo}/git/trees/${this.treeSha}?recursive=true`}}}function readyGitHubRepositoryTrees(e){return class GitHubRepositoryTrees extends GitHubRepoApiBase{constructor(t,n){super(e,t,n)}get apiEndpoint(){return`${this.apiOrigin}/repos/${this.owner}/${this.repo}/git/trees`}}}function readyGitHubRepository(e){let t=readyGitHubBlob(e),n=readyGitHubBlobs(e),r=readyGitHubIssue(e),i=readyGitHubReference(e),a=readyGitHubReferenceForGet(e),o=readyGitHubRepositoryArtifacts(e),s=readyGitHubRepositoryArtifact(e),c=readyGitHubRepositoryIssues(e),l=readyGitHubRepositoryBranch(e),u=readyGitHubRepositoryBranches(e),d=readyGitHubRepositoryCommits(e),f=readyGitHubRepositoryPull(e),p=readyGitHubRepositoryPulls(e),m=readyGitHubRepositoryReferences(e),h=readyGitHubRepositoryReleases(e),g=readyGitHubRepositoryLatestRelease(e),_=readyGitHubRepositoryRuns(e),v=readyGitHubRepositoryTrees(e),y=readyGitHubTree(e);return class GitHubRepository extends GitHubRepoApiBase{constructor(t,n){super(e,t,n)}get apiEndpoint(){return`${this.apiOrigin}/repos/${this.owner}/${this.repo}`}async getArtifacts(e){return await new o(this.owner,this.repo).getList(e)}async getArtifact(e){return await new s(this.owner,this.repo,e).get()}async getArtifactZipBlob(e){return await new s(this.owner,this.repo,e).downloadBlob()}async getBranches(){return await new u(this.owner,this.repo).getList()}async getBranch(e){return await new l(this.owner,this.repo,e).get()}async getReferences(e){return await new m(this.owner,this.repo).getMatchingList(e)}async getBranchReferences(){return await new m(this.owner,this.repo).getMatchingList(`heads/`)}async getTagReferences(){return await new m(this.owner,this.repo).getMatchingList(`tags/`)}async postReference(...e){return await new m(this.owner,this.repo).post(...e)}async getReference(e){return await new a(this.owner,this.repo,e).get()}async getBranchReference(e){return await new a(this.owner,this.repo,`heads/${e}`).get()}async getTagReference(e){return await new a(this.owner,this.repo,`tags/${e}`).get()}async patchReference(e,...t){return await new i(this.owner,this.repo,e).patch(...t)}async deleteReference(e){return await new i(this.owner,this.repo,e).delete()}async getBlob(e){return await new t(this.owner,this.repo,e).get()}async postBlob(...e){return await new n(this.owner,this.repo).post(...e)}async getTree(e){return await new y(this.owner,this.repo,e).get()}async postTree(...e){return await new v(this.owner,this.repo).post(...e)}async getIssues(e){return await new c(this.owner,this.repo).getList(e)}async postIssue(...e){return await new c(this.owner,this.repo).post(...e)}issue(e){return new r(this.owner,this.repo,e)}async getIssue(e){return await new r(this.owner,this.repo,e).get()}async patchIssue(e,...t){return await new r(this.owner,this.repo,e).patch(...t)}async getPulls(e){return await new p(this.owner,this.repo).getList(e)}async postPull(...e){return await new p(this.owner,this.repo).post(...e)}pull(e){return new f(this.owner,this.repo,e)}async getPull(e){return await new f(this.owner,this.repo,e).get()}async patchPull(e,...t){return await new f(this.owner,this.repo,e).patch(...t)}async getReleases(e){return await new h(this.owner,this.repo).getList(e)}async postRelease(...e){return await new h(this.owner,this.repo).post(...e)}async getLatestRelease(){return await new g(this.owner,this.repo).get()}async postCommit(...e){return await new d(this.owner,this.repo).post(...e)}async getRuns(e){return await new _(this.owner,this.repo).getList(e)}}}function readyGitHubUser(e){return class GitHubUser extends GitHubApiBase{constructor(){super(e)}get apiEndpoint(){return`${this.apiOrigin}/user`}}}function readyGitHubUserOrganizations(e){return class GitHubUserOrganizations extends GitHubApiBase{constructor(){super(e)}get apiEndpoint(){return`${this.apiOrigin}/user/orgs`}get pageSizeForRequest(){return 100}async getList(e){return await this.getPagedList(e)}}}function readyGitHubUserRepositories(e){return class GitHubUserRepositories extends GitHubApiBase{constructor(){super(e)}get apiEndpoint(){return`${this.apiOrigin}/user/repos`}get pageSizeForRequest(){return 100}async getList(e){return await this.getPagedList(e)}}}function readyGitHubClasses(e){return{GitHubMyIssues:readyGitHubMyIssues(e),GitHubOrganizationRepositories:readyGitHubOrganizationRepositories(e),GitHubRepository:readyGitHubRepository(e),GitHubRepositoryIssues:readyGitHubRepositoryIssues(e),GitHubUser:readyGitHubUser(e),GitHubUserOrganizations:readyGitHubUserOrganizations(e),GitHubUserRepositories:readyGitHubUserRepositories(e)}}var GitHubFacade=class{token;githubClasses;constructor(e){this.token=e,this.githubClasses=readyGitHubClasses(e)}async getMe(){return await new this.githubClasses.GitHubUser().get()}async getMyOrganizations(){let{GitHubUserOrganizations:e,GitHubOrganizationRepositories:t}=this.githubClasses;return(await new e().getList()).map(e=>({...e,async getRepositories(){return await new t(e.login).getList()}}))}async getMyRepositories(){let{GitHubUserRepositories:e,GitHubRepositoryIssues:t}=this.githubClasses;return(await new e().getList()).map(e=>({...e,async getIssues(){return await new t(e.owner.login,e.name).getList()},async postIssue(...n){return await new t(e.owner.login,e.name).post(...n)}}))}async getMyIssues(){let{GitHubMyIssues:e}=this.githubClasses;return await new e().getList()}repo(e,t){let{GitHubRepository:n}=this.githubClasses;return new n(e,t)}};return e.GitHubFacade=GitHubFacade,e})({});
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
async function loopPages(e,t){let n=t??10,r=[],i=1;for(;;){let{resultItems:t}=await e({per_page:n,page:i});if(r.push(t),t.length<n)break;i++}return r.flat()}var GitHubApiBase=class{token;constructor(e){this.token=e}get apiOrigin(){return`https://api.github.com`}get apiEndpoint(){return``}get requestHeaders(){return{accept:`application/vnd.github+json`,authorization:`Bearer ${this.token}`,"X-GitHub-Api-Version":`2022-11-28`}}get pageSizeForRequest(){return 10}async getPagedList(e){return await loopPages(async({per_page:t,page:n})=>{let r=new URL(this.apiEndpoint),i={...e??{},per_page:t,page:n};for(let[e,t]of Object.entries(i))r.searchParams.append(e,`${t}`);return{resultItems:await fetch(r,{headers:this.requestHeaders,cache:`no-store`}).then(e=>{if(!e.ok)throw Error(e.statusText,{cause:{response:e}});return e.json()})}},this.pageSizeForRequest)}async getList(e){let t=new URL(this.apiEndpoint);for(let[n,r]of Object.entries(e??{}))t.searchParams.append(n,`${r}`);return await fetch(t,{headers:this.requestHeaders,cache:`no-store`}).then(e=>{if(!e.ok)throw Error(e.statusText,{cause:{response:e}});return e.json()})}async get(){return await fetch(this.apiEndpoint,{headers:this.requestHeaders,cache:`no-store`}).then(e=>{if(!e.ok)throw Error(e.statusText,{cause:{response:e}});return e.json()})}async post(e){return await fetch(this.apiEndpoint,{method:`POST`,headers:this.requestHeaders,body:JSON.stringify(e)}).then(e=>{if(!e.ok)throw Error(e.statusText,{cause:{response:e}});return e.json()})}async patch(e){return await fetch(this.apiEndpoint,{method:`PATCH`,headers:this.requestHeaders,body:JSON.stringify(e)}).then(e=>{if(!e.ok)throw Error(e.statusText,{cause:{response:e}});return e.json()})}async delete(){let e=await fetch(this.apiEndpoint,{method:`DELETE`,headers:this.requestHeaders});if(!e.ok)throw Error(e.statusText,{cause:{response:e}})}},GitHubRepoApiBase=class extends GitHubApiBase{owner;repo;constructor(e,t,n){super(e),this.owner=t,this.repo=n}},GitHubIssueApiBase=class extends GitHubRepoApiBase{issueNumber;constructor(e,t,n,r){super(e,t,n),this.issueNumber=r}},GitHubPullApiBase=class extends GitHubRepoApiBase{pullNumber;constructor(e,t,n,r){super(e,t,n),this.pullNumber=r}};function readyGitHubMyIssues(e){return class extends GitHubApiBase{constructor(){super(e)}get apiEndpoint(){return`${this.apiOrigin}/issues`}get pageSizeForRequest(){return 100}async getList(e){return await this.getPagedList(e)}}}function readyGitHubOrganizationRepositories(e){return class extends GitHubApiBase{org;constructor(t){super(e),this.org=t}get apiEndpoint(){return`${this.apiOrigin}/orgs/${this.org}/repos`}}}function readyGitHubBlob(e){return class extends GitHubRepoApiBase{fileSha;constructor(t,n,r){super(e,t,n),this.fileSha=r}get apiEndpoint(){return`${this.apiOrigin}/repos/${this.owner}/${this.repo}/git/blobs/${this.fileSha}`}}}function readyGitHubBlobs(e){return class extends GitHubRepoApiBase{constructor(t,n){super(e,t,n)}get apiEndpoint(){return`${this.apiOrigin}/repos/${this.owner}/${this.repo}/git/blobs`}}}function readyGitHubIssueComments(e){return class extends GitHubIssueApiBase{constructor(t,n,r){super(e,t,n,r)}get apiEndpoint(){return`${this.apiOrigin}/repos/${this.owner}/${this.repo}/issues/${this.issueNumber}/comments`}get pageSizeForRequest(){return 100}async getList(e){return await this.getPagedList(e)}}}function readyGitHubIssue(e){let t=readyGitHubIssueComments(e);return class extends GitHubIssueApiBase{constructor(t,n,r){super(e,t,n,r)}get apiEndpoint(){return`${this.apiOrigin}/repos/${this.owner}/${this.repo}/issues/${this.issueNumber}`}async getComments(){return await new t(this.owner,this.repo,this.issueNumber).getList()}async postComment(...e){return await new t(this.owner,this.repo,this.issueNumber).post(...e)}}}function readyGitHubRepositoryArtifacts(e){return class extends GitHubRepoApiBase{constructor(t,n){super(e,t,n)}get apiEndpoint(){return`${this.apiOrigin}/repos/${this.owner}/${this.repo}/actions/artifacts`}get pageSizeForRequest(){return 100}async getList(e){return await loopPages(async({per_page:t,page:n})=>{let r=new URL(this.apiEndpoint),i={...e??{},per_page:t,page:n};for(let[e,t]of Object.entries(i))r.searchParams.append(e,`${t}`);return{resultItems:await fetch(r,{headers:this.requestHeaders,cache:`no-store`}).then(async e=>{if(!e.ok)throw Error(e.statusText,{cause:{response:e}});let{artifacts:t}=await e.json();return t})}},this.pageSizeForRequest)}}}function readyGitHubRepositoryArtifact(e){return class extends GitHubRepoApiBase{artifactId;constructor(t,n,r){super(e,t,n),this.artifactId=r}get apiEndpoint(){return`${this.apiOrigin}/repos/${this.owner}/${this.repo}/actions/artifacts/${this.artifactId}`}async downloadBlob(){let e=`${this.apiEndpoint}/zip`,t=await fetch(e,{headers:this.requestHeaders,cache:`no-store`});if(!t.ok)throw Error(t.statusText,{cause:{response:t}});return await t.blob()}}}function readyGitHubRepositoryBranch(e){return class extends GitHubRepoApiBase{branch;constructor(t,n,r){super(e,t,n),this.branch=r}get apiEndpoint(){return`${this.apiOrigin}/repos/${this.owner}/${this.repo}/branches/${this.branch}`}}}function readyGitHubRepositoryBranches(e){return class extends GitHubRepoApiBase{constructor(t,n){super(e,t,n)}get apiEndpoint(){return`${this.apiOrigin}/repos/${this.owner}/${this.repo}/branches`}get pageSizeForRequest(){return 100}async getList(e){return await this.getPagedList(e)}}}function readyGitHubRepositoryCommits(e){return class extends GitHubRepoApiBase{constructor(t,n){super(e,t,n)}get apiEndpoint(){return`${this.apiOrigin}/repos/${this.owner}/${this.repo}/git/commits`}}}function readyGitHubRepositoryIssues(e){return class extends GitHubRepoApiBase{constructor(t,n){super(e,t,n)}get apiEndpoint(){return`${this.apiOrigin}/repos/${this.owner}/${this.repo}/issues`}get pageSizeForRequest(){return 100}async getList(e){return await this.getPagedList(e)}}}function readyGitHubReference(e){return class extends GitHubRepoApiBase{ref;constructor(t,n,r){super(e,t,n),this.ref=r}get apiEndpoint(){return`${this.apiOrigin}/repos/${this.owner}/${this.repo}/git/refs/${this.ref}`}}}function readyGitHubReferenceForGet(e){return class extends GitHubRepoApiBase{ref;constructor(t,n,r){super(e,t,n),this.ref=r}get apiEndpoint(){return`${this.apiOrigin}/repos/${this.owner}/${this.repo}/git/ref/${this.ref}`}}}function readyGitHubPullCommits(e){return class extends GitHubPullApiBase{constructor(t,n,r){super(e,t,n,r)}get apiEndpoint(){return`${this.apiOrigin}/repos/${this.owner}/${this.repo}/pulls/${this.pullNumber}/commits`}get pageSizeForRequest(){return 100}async getList(e){return await this.getPagedList(e)}}}function readyGitHubPullReviewers(e){return class extends GitHubPullApiBase{constructor(t,n,r){super(e,t,n,r)}get apiEndpoint(){return`${this.apiOrigin}/repos/${this.owner}/${this.repo}/pulls/${this.pullNumber}/requested_reviewers`}}}function readyGitHubRepositoryPull(e){let t=readyGitHubPullCommits(e),n=readyGitHubPullReviewers(e);return class extends GitHubPullApiBase{constructor(t,n,r){super(e,t,n,r)}get apiEndpoint(){return`${this.apiOrigin}/repos/${this.owner}/${this.repo}/pulls/${this.pullNumber}`}async getCommits(){return await new t(this.owner,this.repo,this.pullNumber).getList()}async getReviewers(){return await new n(this.owner,this.repo,this.pullNumber).get()}async postReviewers(...e){return await new n(this.owner,this.repo,this.pullNumber).post(...e)}}}function readyGitHubRepositoryPulls(e){return class extends GitHubRepoApiBase{constructor(t,n){super(e,t,n)}get apiEndpoint(){return`${this.apiOrigin}/repos/${this.owner}/${this.repo}/pulls`}get pageSizeForRequest(){return 100}async getList(e){return await this.getPagedList(e)}}}function readyGitHubRepositoryReferences(e){class GitHubRepositoryMatchingReferences extends GitHubRepoApiBase{refName;constructor(t,n,r){super(e,t,n),this.refName=r}get apiEndpoint(){return`${this.apiOrigin}/repos/${this.owner}/${this.repo}/git/matching-refs/${this.refName}`}}return class extends GitHubRepoApiBase{constructor(t,n){super(e,t,n)}get apiEndpoint(){return`${this.apiOrigin}/repos/${this.owner}/${this.repo}/git/refs`}async getMatchingList(e){return await new GitHubRepositoryMatchingReferences(this.owner,this.repo,e).getList()}}}function readyGitHubRepositoryReleases(e){return class extends GitHubRepoApiBase{constructor(t,n){super(e,t,n)}get apiEndpoint(){return`${this.apiOrigin}/repos/${this.owner}/${this.repo}/releases`}get pageSizeForRequest(){return 100}async getList(e){return await this.getPagedList(e)}}}function readyGitHubRepositoryLatestRelease(e){return class extends GitHubRepoApiBase{constructor(t,n){super(e,t,n)}get apiEndpoint(){return`${this.apiOrigin}/repos/${this.owner}/${this.repo}/releases/latest`}}}function readyGitHubRepositoryRuns(e){return class extends GitHubRepoApiBase{constructor(t,n){super(e,t,n)}get apiEndpoint(){return`${this.apiOrigin}/repos/${this.owner}/${this.repo}/actions/runs`}get pageSizeForRequest(){return 100}async getList(e){return await loopPages(async({per_page:t,page:n})=>{let r=new URL(this.apiEndpoint),i={...e??{},per_page:t,page:n};for(let[e,t]of Object.entries(i))r.searchParams.append(e,`${t}`);return{resultItems:await fetch(r,{headers:this.requestHeaders,cache:`no-store`}).then(async e=>{if(!e.ok)throw Error(e.statusText,{cause:{response:e}});let{workflow_runs:t}=await e.json();return t})}},this.pageSizeForRequest)}}}function readyGitHubTree(e){return class extends GitHubRepoApiBase{treeSha;constructor(t,n,r){super(e,t,n),this.treeSha=r}get apiEndpoint(){return`${this.apiOrigin}/repos/${this.owner}/${this.repo}/git/trees/${this.treeSha}?recursive=true`}}}function readyGitHubRepositoryTrees(e){return class extends GitHubRepoApiBase{constructor(t,n){super(e,t,n)}get apiEndpoint(){return`${this.apiOrigin}/repos/${this.owner}/${this.repo}/git/trees`}}}function readyGitHubRepository(e){let t=readyGitHubBlob(e),n=readyGitHubBlobs(e),r=readyGitHubIssue(e),i=readyGitHubReference(e),a=readyGitHubReferenceForGet(e),o=readyGitHubRepositoryArtifacts(e),s=readyGitHubRepositoryArtifact(e),c=readyGitHubRepositoryIssues(e),l=readyGitHubRepositoryBranch(e),u=readyGitHubRepositoryBranches(e),d=readyGitHubRepositoryCommits(e),f=readyGitHubRepositoryPull(e),p=readyGitHubRepositoryPulls(e),m=readyGitHubRepositoryReferences(e),h=readyGitHubRepositoryReleases(e),g=readyGitHubRepositoryLatestRelease(e),_=readyGitHubRepositoryRuns(e),v=readyGitHubRepositoryTrees(e),y=readyGitHubTree(e);return class extends GitHubRepoApiBase{constructor(t,n){super(e,t,n)}get apiEndpoint(){return`${this.apiOrigin}/repos/${this.owner}/${this.repo}`}async getArtifacts(e){return await new o(this.owner,this.repo).getList(e)}async getArtifact(e){return await new s(this.owner,this.repo,e).get()}async getArtifactZipBlob(e){return await new s(this.owner,this.repo,e).downloadBlob()}async getBranches(){return await new u(this.owner,this.repo).getList()}async getBranch(e){return await new l(this.owner,this.repo,e).get()}async getReferences(e){return await new m(this.owner,this.repo).getMatchingList(e)}async getBranchReferences(){return await new m(this.owner,this.repo).getMatchingList(`heads/`)}async getTagReferences(){return await new m(this.owner,this.repo).getMatchingList(`tags/`)}async postReference(...e){return await new m(this.owner,this.repo).post(...e)}async getReference(e){return await new a(this.owner,this.repo,e).get()}async getBranchReference(e){return await new a(this.owner,this.repo,`heads/${e}`).get()}async getTagReference(e){return await new a(this.owner,this.repo,`tags/${e}`).get()}async patchReference(e,...t){return await new i(this.owner,this.repo,e).patch(...t)}async deleteReference(e){return await new i(this.owner,this.repo,e).delete()}async getBlob(e){return await new t(this.owner,this.repo,e).get()}async postBlob(...e){return await new n(this.owner,this.repo).post(...e)}async getTree(e){return await new y(this.owner,this.repo,e).get()}async postTree(...e){return await new v(this.owner,this.repo).post(...e)}async getIssues(e){return await new c(this.owner,this.repo).getList(e)}async postIssue(...e){return await new c(this.owner,this.repo).post(...e)}issue(e){return new r(this.owner,this.repo,e)}async getIssue(e){return await new r(this.owner,this.repo,e).get()}async patchIssue(e,...t){return await new r(this.owner,this.repo,e).patch(...t)}async getPulls(e){return await new p(this.owner,this.repo).getList(e)}async postPull(...e){return await new p(this.owner,this.repo).post(...e)}pull(e){return new f(this.owner,this.repo,e)}async getPull(e){return await new f(this.owner,this.repo,e).get()}async patchPull(e,...t){return await new f(this.owner,this.repo,e).patch(...t)}async getReleases(e){return await new h(this.owner,this.repo).getList(e)}async postRelease(...e){return await new h(this.owner,this.repo).post(...e)}async getLatestRelease(){return await new g(this.owner,this.repo).get()}async postCommit(...e){return await new d(this.owner,this.repo).post(...e)}async getRuns(e){return await new _(this.owner,this.repo).getList(e)}}}function readyGitHubUser(e){return class GitHubUser extends GitHubApiBase{constructor(){super(e)}get apiEndpoint(){return`${this.apiOrigin}/user`}}}function readyGitHubUserOrganizations(e){return class extends GitHubApiBase{constructor(){super(e)}get apiEndpoint(){return`${this.apiOrigin}/user/orgs`}get pageSizeForRequest(){return 100}async getList(e){return await this.getPagedList(e)}}}function readyGitHubUserRepositories(e){return class extends GitHubApiBase{constructor(){super(e)}get apiEndpoint(){return`${this.apiOrigin}/user/repos`}get pageSizeForRequest(){return 100}async getList(e){return await this.getPagedList(e)}}}function readyGitHubClasses(e){return{GitHubMyIssues:readyGitHubMyIssues(e),GitHubOrganizationRepositories:readyGitHubOrganizationRepositories(e),GitHubRepository:readyGitHubRepository(e),GitHubRepositoryIssues:readyGitHubRepositoryIssues(e),GitHubUser:readyGitHubUser(e),GitHubUserOrganizations:readyGitHubUserOrganizations(e),GitHubUserRepositories:readyGitHubUserRepositories(e)}}var GitHubFacade=class{token;githubClasses;constructor(e){this.token=e,this.githubClasses=readyGitHubClasses(e)}async getMe(){return await new this.githubClasses.GitHubUser().get()}async getMyOrganizations(){let{GitHubUserOrganizations:e,GitHubOrganizationRepositories:t}=this.githubClasses;return(await new e().getList()).map(e=>({...e,async getRepositories(){return await new t(e.login).getList()}}))}async getMyRepositories(){let{GitHubUserRepositories:e,GitHubRepositoryIssues:t}=this.githubClasses;return(await new e().getList()).map(e=>({...e,async getIssues(){return await new t(e.owner.login,e.name).getList()},async postIssue(...n){return await new t(e.owner.login,e.name).post(...n)}}))}async getMyIssues(){let{GitHubMyIssues:e}=this.githubClasses;return await new e().getList()}repo(e,t){let{GitHubRepository:n}=this.githubClasses;return new n(e,t)}};export{GitHubFacade};
|
|
1
|
+
async function loopPages(e,t){let n=t??10,r=[],i=1;for(;;){let{resultItems:t}=await e({per_page:n,page:i});if(r.push(t),t.length<n)break;i++}return r.flat()}var GitHubApiBase=class{token;constructor(e){this.token=e}get apiOrigin(){return`https://api.github.com`}get apiEndpoint(){return``}get requestHeaders(){return{accept:`application/vnd.github+json`,authorization:`Bearer ${this.token}`,"X-GitHub-Api-Version":`2022-11-28`}}get pageSizeForRequest(){return 10}async getPagedList(e){return await loopPages(async({per_page:t,page:n})=>{let r=new URL(this.apiEndpoint),i={...e??{},per_page:t,page:n};for(let[e,t]of Object.entries(i))r.searchParams.append(e,`${t}`);return{resultItems:await fetch(r,{headers:this.requestHeaders,cache:`no-store`}).then(e=>{if(!e.ok)throw Error(e.statusText,{cause:{response:e}});return e.json()})}},this.pageSizeForRequest)}async getList(e){let t=new URL(this.apiEndpoint);for(let[n,r]of Object.entries(e??{}))t.searchParams.append(n,`${r}`);return await fetch(t,{headers:this.requestHeaders,cache:`no-store`}).then(e=>{if(!e.ok)throw Error(e.statusText,{cause:{response:e}});return e.json()})}async get(){return await fetch(this.apiEndpoint,{headers:this.requestHeaders,cache:`no-store`}).then(e=>{if(!e.ok)throw Error(e.statusText,{cause:{response:e}});return e.json()})}async post(e){return await fetch(this.apiEndpoint,{method:`POST`,headers:this.requestHeaders,body:JSON.stringify(e)}).then(e=>{if(!e.ok)throw Error(e.statusText,{cause:{response:e}});return e.json()})}async patch(e){return await fetch(this.apiEndpoint,{method:`PATCH`,headers:this.requestHeaders,body:JSON.stringify(e)}).then(e=>{if(!e.ok)throw Error(e.statusText,{cause:{response:e}});return e.json()})}async delete(){let e=await fetch(this.apiEndpoint,{method:`DELETE`,headers:this.requestHeaders});if(!e.ok)throw Error(e.statusText,{cause:{response:e}})}},GitHubRepoApiBase=class extends GitHubApiBase{owner;repo;constructor(e,t,n){super(e),this.owner=t,this.repo=n}},GitHubIssueApiBase=class extends GitHubRepoApiBase{issueNumber;constructor(e,t,n,r){super(e,t,n),this.issueNumber=r}},GitHubPullApiBase=class extends GitHubRepoApiBase{pullNumber;constructor(e,t,n,r){super(e,t,n),this.pullNumber=r}};function readyGitHubMyIssues(e){return class GitHubMyIssues extends GitHubApiBase{constructor(){super(e)}get apiEndpoint(){return`${this.apiOrigin}/issues`}get pageSizeForRequest(){return 100}async getList(e){return await this.getPagedList(e)}}}function readyGitHubOrganizationRepositories(e){return class GitHubOrganizationRepositories extends GitHubApiBase{org;constructor(t){super(e),this.org=t}get apiEndpoint(){return`${this.apiOrigin}/orgs/${this.org}/repos`}}}function readyGitHubBlob(e){return class GitHubBlob extends GitHubRepoApiBase{fileSha;constructor(t,n,r){super(e,t,n),this.fileSha=r}get apiEndpoint(){return`${this.apiOrigin}/repos/${this.owner}/${this.repo}/git/blobs/${this.fileSha}`}}}function readyGitHubBlobs(e){return class GitHubBlobs extends GitHubRepoApiBase{constructor(t,n){super(e,t,n)}get apiEndpoint(){return`${this.apiOrigin}/repos/${this.owner}/${this.repo}/git/blobs`}}}function readyGitHubIssueComments(e){return class GitHubIssueComments extends GitHubIssueApiBase{constructor(t,n,r){super(e,t,n,r)}get apiEndpoint(){return`${this.apiOrigin}/repos/${this.owner}/${this.repo}/issues/${this.issueNumber}/comments`}get pageSizeForRequest(){return 100}async getList(e){return await this.getPagedList(e)}}}function readyGitHubIssue(e){let t=readyGitHubIssueComments(e);return class GitHubIssue extends GitHubIssueApiBase{constructor(t,n,r){super(e,t,n,r)}get apiEndpoint(){return`${this.apiOrigin}/repos/${this.owner}/${this.repo}/issues/${this.issueNumber}`}async getComments(){return await new t(this.owner,this.repo,this.issueNumber).getList()}async postComment(...e){return await new t(this.owner,this.repo,this.issueNumber).post(...e)}}}function readyGitHubRepositoryArtifacts(e){return class GitHubRepositoryArtifacts extends GitHubRepoApiBase{constructor(t,n){super(e,t,n)}get apiEndpoint(){return`${this.apiOrigin}/repos/${this.owner}/${this.repo}/actions/artifacts`}get pageSizeForRequest(){return 100}async getList(e){return await loopPages(async({per_page:t,page:n})=>{let r=new URL(this.apiEndpoint),i={...e??{},per_page:t,page:n};for(let[e,t]of Object.entries(i))r.searchParams.append(e,`${t}`);return{resultItems:await fetch(r,{headers:this.requestHeaders,cache:`no-store`}).then(async e=>{if(!e.ok)throw Error(e.statusText,{cause:{response:e}});let{artifacts:t}=await e.json();return t})}},this.pageSizeForRequest)}}}function readyGitHubRepositoryArtifact(e){return class GitHubRepositoryArtifact extends GitHubRepoApiBase{artifactId;constructor(t,n,r){super(e,t,n),this.artifactId=r}get apiEndpoint(){return`${this.apiOrigin}/repos/${this.owner}/${this.repo}/actions/artifacts/${this.artifactId}`}async downloadBlob(){let e=`${this.apiEndpoint}/zip`,t=await fetch(e,{headers:this.requestHeaders,cache:`no-store`});if(!t.ok)throw Error(t.statusText,{cause:{response:t}});return await t.blob()}}}function readyGitHubRepositoryBranch(e){return class GitHubRepositoryBranch extends GitHubRepoApiBase{branch;constructor(t,n,r){super(e,t,n),this.branch=r}get apiEndpoint(){return`${this.apiOrigin}/repos/${this.owner}/${this.repo}/branches/${this.branch}`}}}function readyGitHubRepositoryBranches(e){return class GitHubRepositoryBranches extends GitHubRepoApiBase{constructor(t,n){super(e,t,n)}get apiEndpoint(){return`${this.apiOrigin}/repos/${this.owner}/${this.repo}/branches`}get pageSizeForRequest(){return 100}async getList(e){return await this.getPagedList(e)}}}function readyGitHubRepositoryCommits(e){return class GitHubRepositoryCommits extends GitHubRepoApiBase{constructor(t,n){super(e,t,n)}get apiEndpoint(){return`${this.apiOrigin}/repos/${this.owner}/${this.repo}/git/commits`}}}function readyGitHubRepositoryIssues(e){return class GitHubRepositoryIssues extends GitHubRepoApiBase{constructor(t,n){super(e,t,n)}get apiEndpoint(){return`${this.apiOrigin}/repos/${this.owner}/${this.repo}/issues`}get pageSizeForRequest(){return 100}async getList(e){return await this.getPagedList(e)}}}function readyGitHubReference(e){return class GitHubReference extends GitHubRepoApiBase{ref;constructor(t,n,r){super(e,t,n),this.ref=r}get apiEndpoint(){return`${this.apiOrigin}/repos/${this.owner}/${this.repo}/git/refs/${this.ref}`}}}function readyGitHubReferenceForGet(e){return class GitHubReferenceForGet extends GitHubRepoApiBase{ref;constructor(t,n,r){super(e,t,n),this.ref=r}get apiEndpoint(){return`${this.apiOrigin}/repos/${this.owner}/${this.repo}/git/ref/${this.ref}`}}}function readyGitHubPullCommits(e){return class GitHubPullCommits extends GitHubPullApiBase{constructor(t,n,r){super(e,t,n,r)}get apiEndpoint(){return`${this.apiOrigin}/repos/${this.owner}/${this.repo}/pulls/${this.pullNumber}/commits`}get pageSizeForRequest(){return 100}async getList(e){return await this.getPagedList(e)}}}function readyGitHubPullReviewers(e){return class GitHubPullReviewers extends GitHubPullApiBase{constructor(t,n,r){super(e,t,n,r)}get apiEndpoint(){return`${this.apiOrigin}/repos/${this.owner}/${this.repo}/pulls/${this.pullNumber}/requested_reviewers`}}}function readyGitHubRepositoryPull(e){let t=readyGitHubPullCommits(e),n=readyGitHubPullReviewers(e);return class GitHubRepositoryPull extends GitHubPullApiBase{constructor(t,n,r){super(e,t,n,r)}get apiEndpoint(){return`${this.apiOrigin}/repos/${this.owner}/${this.repo}/pulls/${this.pullNumber}`}async getCommits(){return await new t(this.owner,this.repo,this.pullNumber).getList()}async getReviewers(){return await new n(this.owner,this.repo,this.pullNumber).get()}async postReviewers(...e){return await new n(this.owner,this.repo,this.pullNumber).post(...e)}}}function readyGitHubRepositoryPulls(e){return class GitHubRepositoryPulls extends GitHubRepoApiBase{constructor(t,n){super(e,t,n)}get apiEndpoint(){return`${this.apiOrigin}/repos/${this.owner}/${this.repo}/pulls`}get pageSizeForRequest(){return 100}async getList(e){return await this.getPagedList(e)}}}function readyGitHubRepositoryReferences(e){class GitHubRepositoryMatchingReferences extends GitHubRepoApiBase{refName;constructor(t,n,r){super(e,t,n),this.refName=r}get apiEndpoint(){return`${this.apiOrigin}/repos/${this.owner}/${this.repo}/git/matching-refs/${this.refName}`}}return class GitHubRepositoryReferences extends GitHubRepoApiBase{constructor(t,n){super(e,t,n)}get apiEndpoint(){return`${this.apiOrigin}/repos/${this.owner}/${this.repo}/git/refs`}async getMatchingList(e){return await new GitHubRepositoryMatchingReferences(this.owner,this.repo,e).getList()}}}function readyGitHubRepositoryReleases(e){return class GitHubRepositoryReleases extends GitHubRepoApiBase{constructor(t,n){super(e,t,n)}get apiEndpoint(){return`${this.apiOrigin}/repos/${this.owner}/${this.repo}/releases`}get pageSizeForRequest(){return 100}async getList(e){return await this.getPagedList(e)}}}function readyGitHubRepositoryLatestRelease(e){return class GitHubRepositoryLatestRelease extends GitHubRepoApiBase{constructor(t,n){super(e,t,n)}get apiEndpoint(){return`${this.apiOrigin}/repos/${this.owner}/${this.repo}/releases/latest`}}}function readyGitHubRepositoryRuns(e){return class GitHubRepositoryRuns extends GitHubRepoApiBase{constructor(t,n){super(e,t,n)}get apiEndpoint(){return`${this.apiOrigin}/repos/${this.owner}/${this.repo}/actions/runs`}get pageSizeForRequest(){return 100}async getList(e){return await loopPages(async({per_page:t,page:n})=>{let r=new URL(this.apiEndpoint),i={...e??{},per_page:t,page:n};for(let[e,t]of Object.entries(i))r.searchParams.append(e,`${t}`);return{resultItems:await fetch(r,{headers:this.requestHeaders,cache:`no-store`}).then(async e=>{if(!e.ok)throw Error(e.statusText,{cause:{response:e}});let{workflow_runs:t}=await e.json();return t})}},this.pageSizeForRequest)}}}function readyGitHubTree(e){return class GitHubTree extends GitHubRepoApiBase{treeSha;constructor(t,n,r){super(e,t,n),this.treeSha=r}get apiEndpoint(){return`${this.apiOrigin}/repos/${this.owner}/${this.repo}/git/trees/${this.treeSha}?recursive=true`}}}function readyGitHubRepositoryTrees(e){return class GitHubRepositoryTrees extends GitHubRepoApiBase{constructor(t,n){super(e,t,n)}get apiEndpoint(){return`${this.apiOrigin}/repos/${this.owner}/${this.repo}/git/trees`}}}function readyGitHubRepository(e){let t=readyGitHubBlob(e),n=readyGitHubBlobs(e),r=readyGitHubIssue(e),i=readyGitHubReference(e),a=readyGitHubReferenceForGet(e),o=readyGitHubRepositoryArtifacts(e),s=readyGitHubRepositoryArtifact(e),c=readyGitHubRepositoryIssues(e),l=readyGitHubRepositoryBranch(e),u=readyGitHubRepositoryBranches(e),d=readyGitHubRepositoryCommits(e),f=readyGitHubRepositoryPull(e),p=readyGitHubRepositoryPulls(e),m=readyGitHubRepositoryReferences(e),h=readyGitHubRepositoryReleases(e),g=readyGitHubRepositoryLatestRelease(e),_=readyGitHubRepositoryRuns(e),v=readyGitHubRepositoryTrees(e),y=readyGitHubTree(e);return class GitHubRepository extends GitHubRepoApiBase{constructor(t,n){super(e,t,n)}get apiEndpoint(){return`${this.apiOrigin}/repos/${this.owner}/${this.repo}`}async getArtifacts(e){return await new o(this.owner,this.repo).getList(e)}async getArtifact(e){return await new s(this.owner,this.repo,e).get()}async getArtifactZipBlob(e){return await new s(this.owner,this.repo,e).downloadBlob()}async getBranches(){return await new u(this.owner,this.repo).getList()}async getBranch(e){return await new l(this.owner,this.repo,e).get()}async getReferences(e){return await new m(this.owner,this.repo).getMatchingList(e)}async getBranchReferences(){return await new m(this.owner,this.repo).getMatchingList(`heads/`)}async getTagReferences(){return await new m(this.owner,this.repo).getMatchingList(`tags/`)}async postReference(...e){return await new m(this.owner,this.repo).post(...e)}async getReference(e){return await new a(this.owner,this.repo,e).get()}async getBranchReference(e){return await new a(this.owner,this.repo,`heads/${e}`).get()}async getTagReference(e){return await new a(this.owner,this.repo,`tags/${e}`).get()}async patchReference(e,...t){return await new i(this.owner,this.repo,e).patch(...t)}async deleteReference(e){return await new i(this.owner,this.repo,e).delete()}async getBlob(e){return await new t(this.owner,this.repo,e).get()}async postBlob(...e){return await new n(this.owner,this.repo).post(...e)}async getTree(e){return await new y(this.owner,this.repo,e).get()}async postTree(...e){return await new v(this.owner,this.repo).post(...e)}async getIssues(e){return await new c(this.owner,this.repo).getList(e)}async postIssue(...e){return await new c(this.owner,this.repo).post(...e)}issue(e){return new r(this.owner,this.repo,e)}async getIssue(e){return await new r(this.owner,this.repo,e).get()}async patchIssue(e,...t){return await new r(this.owner,this.repo,e).patch(...t)}async getPulls(e){return await new p(this.owner,this.repo).getList(e)}async postPull(...e){return await new p(this.owner,this.repo).post(...e)}pull(e){return new f(this.owner,this.repo,e)}async getPull(e){return await new f(this.owner,this.repo,e).get()}async patchPull(e,...t){return await new f(this.owner,this.repo,e).patch(...t)}async getReleases(e){return await new h(this.owner,this.repo).getList(e)}async postRelease(...e){return await new h(this.owner,this.repo).post(...e)}async getLatestRelease(){return await new g(this.owner,this.repo).get()}async postCommit(...e){return await new d(this.owner,this.repo).post(...e)}async getRuns(e){return await new _(this.owner,this.repo).getList(e)}}}function readyGitHubUser(e){return class GitHubUser extends GitHubApiBase{constructor(){super(e)}get apiEndpoint(){return`${this.apiOrigin}/user`}}}function readyGitHubUserOrganizations(e){return class GitHubUserOrganizations extends GitHubApiBase{constructor(){super(e)}get apiEndpoint(){return`${this.apiOrigin}/user/orgs`}get pageSizeForRequest(){return 100}async getList(e){return await this.getPagedList(e)}}}function readyGitHubUserRepositories(e){return class GitHubUserRepositories extends GitHubApiBase{constructor(){super(e)}get apiEndpoint(){return`${this.apiOrigin}/user/repos`}get pageSizeForRequest(){return 100}async getList(e){return await this.getPagedList(e)}}}function readyGitHubClasses(e){return{GitHubMyIssues:readyGitHubMyIssues(e),GitHubOrganizationRepositories:readyGitHubOrganizationRepositories(e),GitHubRepository:readyGitHubRepository(e),GitHubRepositoryIssues:readyGitHubRepositoryIssues(e),GitHubUser:readyGitHubUser(e),GitHubUserOrganizations:readyGitHubUserOrganizations(e),GitHubUserRepositories:readyGitHubUserRepositories(e)}}var GitHubFacade=class{token;githubClasses;constructor(e){this.token=e,this.githubClasses=readyGitHubClasses(e)}async getMe(){return await new this.githubClasses.GitHubUser().get()}async getMyOrganizations(){let{GitHubUserOrganizations:e,GitHubOrganizationRepositories:t}=this.githubClasses;return(await new e().getList()).map(e=>({...e,async getRepositories(){return await new t(e.login).getList()}}))}async getMyRepositories(){let{GitHubUserRepositories:e,GitHubRepositoryIssues:t}=this.githubClasses;return(await new e().getList()).map(e=>({...e,async getIssues(){return await new t(e.owner.login,e.name).getList()},async postIssue(...n){return await new t(e.owner.login,e.name).post(...n)}}))}async getMyIssues(){let{GitHubMyIssues:e}=this.githubClasses;return await new e().getList()}repo(e,t){let{GitHubRepository:n}=this.githubClasses;return new n(e,t)}};export{GitHubFacade};
|