@yukiakai/actions-git 2.0.2 → 2.1.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/dist/public.d.ts CHANGED
@@ -1,9 +1,17 @@
1
1
  type AbsoluteDirectoryPath = string;
2
2
 
3
+ interface GitInspectionResult {
4
+ exitCode: number;
5
+ }
3
6
  interface GitIdentity {
4
7
  readonly name: string;
5
8
  readonly email: string;
6
9
  }
10
+ declare enum GitInspectionOperation {
11
+ StagedChangesPresence = "stagedChangesPresence",
12
+ LocalBranchPresence = "localBranchPresence",
13
+ RemoteBranchPresence = "remoteBranchPresence"
14
+ }
7
15
 
8
16
  interface GitRepositoryOptions {
9
17
  workingDirectory: AbsoluteDirectoryPath;
@@ -39,4 +47,15 @@ declare function prepareGitRepository(options: PrepareGitRepositoryOptions): Pro
39
47
 
40
48
  declare const GITHUB_ACTIONS_IDENTITY: GitIdentity;
41
49
 
42
- export { type AbsoluteDirectoryPath, GITHUB_ACTIONS_IDENTITY, type GitIdentity, GitRepository, type PrepareGitRepositoryOptions, type PreparedGitRepository, prepareGitRepository };
50
+ interface UnexpectedGitInspectionResultErrorOptions {
51
+ readonly result: GitInspectionResult;
52
+ readonly operation: GitInspectionOperation;
53
+ }
54
+ type UnexpectedGitInspectionResultErrorDetails = UnexpectedGitInspectionResultErrorOptions;
55
+ declare class UnexpectedGitInspectionResultError extends Error {
56
+ private options;
57
+ readonly details: UnexpectedGitInspectionResultErrorDetails;
58
+ constructor(options: UnexpectedGitInspectionResultErrorOptions);
59
+ }
60
+
61
+ export { type AbsoluteDirectoryPath, GITHUB_ACTIONS_IDENTITY, type GitIdentity, GitInspectionOperation, type GitInspectionResult, GitRepository, type PrepareGitRepositoryOptions, type PreparedGitRepository, UnexpectedGitInspectionResultError, type UnexpectedGitInspectionResultErrorDetails, type UnexpectedGitInspectionResultErrorOptions, prepareGitRepository };
package/dist/public.js CHANGED
@@ -1,2 +1,2 @@
1
- import{exec as m}from"@actions/exec";var s=class{static async execute(t){let r=await m("git",[...t.args],{cwd:t.workingDirectory})}static async inspect(t){return{exitCode:await m("git",[...t.args],{cwd:t.workingDirectory,ignoreReturnCode:!0})}}};var n=class{constructor(t){this.options=t}execute(t){return s.execute({workingDirectory:this.options.workingDirectory,args:t})}executeInspectable(t){return s.inspect({workingDirectory:this.options.workingDirectory,args:t})}async wipe(t){await this.execute(["rm","-r","-f","--ignore-unmatch",...t]),await this.execute(["clean","-fdx","--",...t])}async setupIdentity(t){await this.execute(["config","user.name",t.name]),await this.execute(["config","user.email",t.email])}async checkout(t){await this.execute(["checkout",t])}async checkoutOrphan(t){await this.execute(["checkout","--orphan",t])}async pull(){await this.execute(["pull"])}async pullRebase(t){await this.execute(["pull","--rebase","origin",t])}async commit(t){await this.execute(["commit","-m",t])}async add(t){await this.execute(["add",...t])}async push(){await this.execute(["push","--set-upstream","origin","HEAD"])}async hasStagedChanges(){let t=await this.executeInspectable(["diff","--cached","--quiet"]);if(t.exitCode===0)return!1;if(t.exitCode===1)return!0;throw new Error(`git diff failed with exit code ${t.exitCode}`)}async hasLocalBranch(t){let r=await this.executeInspectable(["show-ref","--verify","--quiet",`refs/heads/${t}`]);if(r.exitCode===0)return!0;if(r.exitCode===1)return!1;throw new Error(`Failed to resolve local branch "${t}"`)}};var c=class{constructor(t){this.git=t}async initialize(t){if(await this.git.hasLocalBranch(t)){await this.git.checkout(t);return}await this.git.checkoutOrphan(t),await this.git.wipe(["."])}};var p=class{constructor(t){this.options=t}execInspectable(t){return s.inspect({workingDirectory:void 0,args:t})}async exists(t){let r=await this.execInspectable(["ls-remote","--exit-code","--heads",this.options.repositoryUrl,t]);switch(r.exitCode){case 0:return!0;case 2:return!1;default:throw new Error([`Failed to check remote branch "${t}"`,`Repository: ${this.options.repositoryUrl}`,`Exit code: ${r.exitCode}`].join(`
2
- `))}}};import h from"path";var y=class{constructor(t){this.options=t}execute(t){return s.execute({workingDirectory:h.dirname(this.options.destinationDirectory),args:t})}async clone(){await this.execute(["clone",this.options.repositoryUrl,this.options.destinationDirectory])}async cloneAtBranch(t){await this.execute(["clone","--depth=1","--branch",t,this.options.repositoryUrl,this.options.destinationDirectory])}};var u=class{static build(t){let{token:r,repository:a}=t;return`https://x-access-token:${r}@github.com/${a}.git`}};async function d(e){let t=u.build({repository:e.repository,token:e.token}),r=new p({repositoryUrl:t}),a=new y({repositoryUrl:t,destinationDirectory:e.directory});await r.exists(e.branch)?await a.cloneAtBranch(e.branch):await a.clone();let l=new n({workingDirectory:e.directory});return await new c(l).initialize(e.branch),await l.setupIdentity(e.identity),l}var x={name:"github-actions[bot]",email:"github-actions[bot]@users.noreply.github.com"};export{x as GITHUB_ACTIONS_IDENTITY,n as GitRepository,d as prepareGitRepository};
1
+ import{exec as x}from"@actions/exec";var n=class{static async execute(e){let r=await x("git",[...e.args],{cwd:e.workingDirectory})}static async inspect(e){return{exitCode:await x("git",[...e.args],{cwd:e.workingDirectory,ignoreReturnCode:!0})}}};var a=class t extends Error{constructor(r){super(["Unexpected git inspection result.",`Operation: ${r.operation}`,`Exit code: ${r.result.exitCode}`].join(`
2
+ `));this.options=r;this.name=t.name,this.details=r}details};var d=(s=>(s.StagedChangesPresence="stagedChangesPresence",s.LocalBranchPresence="localBranchPresence",s.RemoteBranchPresence="remoteBranchPresence",s))(d||{});var c=class{static hasStagedChanges(e){switch(e.exitCode){case 0:return!1;case 1:return!0;default:throw new a({result:e,operation:"stagedChangesPresence"})}}static hasLocalBranch(e){switch(e.exitCode){case 0:return!0;case 1:return!1;default:throw new a({result:e,operation:"localBranchPresence"})}}static hasRemoteBranch(e){switch(e.exitCode){case 0:return!0;case 2:return!1;default:throw new a({result:e,operation:"remoteBranchPresence"})}}};var p=class{constructor(e){this.options=e}execute(e){return n.execute({workingDirectory:this.options.workingDirectory,args:e})}executeInspectable(e){return n.inspect({workingDirectory:this.options.workingDirectory,args:e})}async wipe(e){await this.execute(["rm","-r","-f","--ignore-unmatch",...e]),await this.execute(["clean","-fdx","--",...e])}async setupIdentity(e){await this.execute(["config","user.name",e.name]),await this.execute(["config","user.email",e.email])}async checkout(e){await this.execute(["checkout",e])}async checkoutOrphan(e){await this.execute(["checkout","--orphan",e])}async pull(){await this.execute(["pull"])}async pullRebase(e){await this.execute(["pull","--rebase","origin",e])}async commit(e){await this.execute(["commit","-m",e])}async add(e){await this.execute(["add",...e])}async push(){await this.execute(["push","--set-upstream","origin","HEAD"])}async hasStagedChanges(){let e=await this.executeInspectable(["diff","--cached","--quiet"]);return c.hasStagedChanges(e)}async hasLocalBranch(e){let r=await this.executeInspectable(["show-ref","--verify","--quiet",`refs/heads/${e}`]);return c.hasLocalBranch(r)}};var l=class{constructor(e){this.git=e}async initialize(e){if(await this.git.hasLocalBranch(e)){await this.git.checkout(e);return}await this.git.checkoutOrphan(e),await this.git.wipe(["."])}};var u=class{constructor(e){this.options=e}execInspectable(e){return n.inspect({workingDirectory:void 0,args:e})}async exists(e){let r=await this.execInspectable(["ls-remote","--exit-code","--heads",this.options.repositoryUrl,e]);return c.hasRemoteBranch(r)}};import g from"path";var m=class{constructor(e){this.options=e}execute(e){return n.execute({workingDirectory:g.dirname(this.options.destinationDirectory),args:e})}async clone(){await this.execute(["clone",this.options.repositoryUrl,this.options.destinationDirectory])}async cloneAtBranch(e){await this.execute(["clone","--depth=1","--branch",e,this.options.repositoryUrl,this.options.destinationDirectory])}};var y=class{static build(e){let{token:r,repository:s}=e;return`https://x-access-token:${r}@github.com/${s}.git`}};async function f(t){let e=y.build({repository:t.repository,token:t.token}),r=new u({repositoryUrl:e}),s=new m({repositoryUrl:e,destinationDirectory:t.directory});await r.exists(t.branch)?await s.cloneAtBranch(t.branch):await s.clone();let h=new p({workingDirectory:t.directory});return await new l(h).initialize(t.branch),await h.setupIdentity(t.identity),h}var G={name:"github-actions[bot]",email:"github-actions[bot]@users.noreply.github.com"};export{G as GITHUB_ACTIONS_IDENTITY,d as GitInspectionOperation,p as GitRepository,a as UnexpectedGitInspectionResultError,f as prepareGitRepository};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yukiakai/actions-git",
3
- "version": "2.0.2",
3
+ "version": "2.1.0",
4
4
  "description": "Lightweight Git client for GitHub Actions and CI workflows.",
5
5
  "type": "module",
6
6
  "main": "./dist/public.js",