fix GitUpdater maybe
This commit is contained in:
+2
-2
@@ -2,8 +2,8 @@ FROM node:alpine
|
|||||||
RUN apk add git
|
RUN apk add git
|
||||||
|
|
||||||
WORKDIR /service
|
WORKDIR /service
|
||||||
RUN git clone https://gitea.frontblock.me/fb-dist/admin.git .
|
COPY dist /service/dist
|
||||||
COPY node_modules /service/node_modules
|
COPY node_modules /service/node_modules
|
||||||
|
|
||||||
EXPOSE 8080 20000
|
EXPOSE 8080 20000
|
||||||
ENTRYPOINT ["node", "FrontblockAdmin.js"]
|
ENTRYPOINT ["node", "dist/FrontblockAdmin.js"]
|
||||||
+22
-11
@@ -27,6 +27,7 @@ const rmrf = (path:string, options = {}) => {
|
|||||||
export type RepoFolderStatus = {
|
export type RepoFolderStatus = {
|
||||||
exists: boolean
|
exists: boolean
|
||||||
empty: boolean
|
empty: boolean
|
||||||
|
isRepo: boolean
|
||||||
currentTag?: string
|
currentTag?: string
|
||||||
tags?: string[]
|
tags?: string[]
|
||||||
latestTag?: string
|
latestTag?: string
|
||||||
@@ -34,11 +35,8 @@ export type RepoFolderStatus = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export class GitUpdater{
|
export class GitUpdater{
|
||||||
private readonly repo
|
private repo: git.SimpleGit
|
||||||
constructor(private readonly folderPath:string){
|
constructor(private readonly folderPath:string){
|
||||||
this.folderPath = folderPath;
|
|
||||||
mkdirSync(this.folderPath, { recursive: true });
|
|
||||||
this.repo = git(this.folderPath)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async getStatus():Promise<RepoFolderStatus>{
|
async getStatus():Promise<RepoFolderStatus>{
|
||||||
@@ -46,7 +44,15 @@ export class GitUpdater{
|
|||||||
await fs.access(this.folderPath);
|
await fs.access(this.folderPath);
|
||||||
}
|
}
|
||||||
catch (e) {
|
catch (e) {
|
||||||
return { exists: false, empty: true };
|
try{
|
||||||
|
await gyt.gitDescribe(this.folderPath, { match: "*" });
|
||||||
|
}catch(e2){
|
||||||
|
return { exists: false, empty: true, isRepo: false };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!this.repo){
|
||||||
|
this.repo = git(this.folderPath)
|
||||||
}
|
}
|
||||||
|
|
||||||
const files = await fs.readdir(this.folderPath)
|
const files = await fs.readdir(this.folderPath)
|
||||||
@@ -55,16 +61,18 @@ export class GitUpdater{
|
|||||||
await this.repo.fetch("origin", "master", {
|
await this.repo.fetch("origin", "master", {
|
||||||
"--tags": null
|
"--tags": null
|
||||||
});
|
});
|
||||||
const remoteInfo = await this.repo.getRemotes(true)
|
const remoteInfo = await this.repo.getRemotes(/* verbose for full url */true)
|
||||||
let remoteURL
|
let remoteURL
|
||||||
if(remoteInfo.length != 0){
|
if(remoteInfo.length != 0){
|
||||||
remoteURL = remoteInfo.find(i => i.name === "origin").refs.fetch
|
const filtered = remoteInfo.find(i => i.name === "origin")
|
||||||
|
remoteURL = filtered?filtered.refs.fetch:"origin unknown"
|
||||||
}
|
}
|
||||||
const remoteTags = await this.repo.tags();
|
const remoteTags = await this.repo.tags();
|
||||||
const desc = await gyt.gitDescribe(this.folderPath, { match: "*" });
|
const desc = await gyt.gitDescribe(this.folderPath, { match: "*" });
|
||||||
return {
|
return {
|
||||||
exists: true,
|
exists: true,
|
||||||
empty: empty,
|
empty: empty,
|
||||||
|
isRepo: true,
|
||||||
currentTag: !desc.tag?null:desc.tag,
|
currentTag: !desc.tag?null:desc.tag,
|
||||||
tags: !remoteTags.all?[]:remoteTags.all,
|
tags: !remoteTags.all?[]:remoteTags.all,
|
||||||
latestTag: remoteTags.latest,
|
latestTag: remoteTags.latest,
|
||||||
@@ -75,16 +83,19 @@ export class GitUpdater{
|
|||||||
async cloneRepo(from:string, force:boolean = false):Promise<RepoFolderStatus> {
|
async cloneRepo(from:string, force:boolean = false):Promise<RepoFolderStatus> {
|
||||||
if(force){
|
if(force){
|
||||||
await rmrf(this.folderPath)
|
await rmrf(this.folderPath)
|
||||||
await fs.mkdir(this.folderPath, { recursive: true });
|
await fs.mkdir(this.folderPath)
|
||||||
}
|
}
|
||||||
const status = await this.getStatus()
|
const status = await this.getStatus()
|
||||||
if(!status.exists || !status.empty){
|
if(!status.exists){
|
||||||
logger.error("The folder "+this.folderPath+" doesn't exist or is not empty. Not cloning! Pass the force parameter to override this check")
|
await fs.mkdir(this.folderPath)
|
||||||
|
}
|
||||||
|
if(!status.empty){
|
||||||
|
logger.error("The folder "+this.folderPath+" is not empty. Not cloning! Pass the force parameter to override this check")
|
||||||
logger.error(status)
|
logger.error(status)
|
||||||
return status
|
return status
|
||||||
}
|
}
|
||||||
|
|
||||||
await git(this.folderPath).clone(from, path.resolve(this.folderPath));
|
await git().clone(from, path.resolve(this.folderPath));
|
||||||
return await this.getStatus();
|
return await this.getStatus();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user