@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 +20 -1
- package/dist/public.js +2 -2
- package/package.json +1 -1
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
|
-
|
|
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
|
|
2
|
-
`))}}};import
|
|
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};
|