Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
schbrain-archetype-initializer
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Metrics
Incidents
Environments
Packages & Registries
Packages & Registries
Package Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
tools
schbrain-archetype-initializer
Commits
2e1c48d2
Commit
2e1c48d2
authored
Dec 07, 2022
by
liaozan
🏀
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update MavenUtils to support update protect branches when generate
parent
df7991a6
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
55 additions
and
21 deletions
+55
-21
initializer-backend/pom.xml
initializer-backend/pom.xml
+0
-1
initializer-backend/src/main/java/com/schbrain/archetype/initializer/maven/MavenUtils.java
.../com/schbrain/archetype/initializer/maven/MavenUtils.java
+39
-13
initializer-ui/package.json
initializer-ui/package.json
+4
-4
initializer-ui/src/components/starter.vue
initializer-ui/src/components/starter.vue
+4
-1
pom.xml
pom.xml
+8
-2
No files found.
initializer-backend/pom.xml
View file @
2e1c48d2
...
...
@@ -49,7 +49,6 @@
<dependency>
<groupId>
org.gitlab4j
</groupId>
<artifactId>
gitlab4j-api
</artifactId>
<version>
5.0.1
</version>
</dependency>
</dependencies>
...
...
initializer-backend/src/main/java/com/schbrain/archetype/initializer/maven/MavenUtils.java
View file @
2e1c48d2
...
...
@@ -7,6 +7,7 @@ import com.schbrain.common.exception.BaseException;
import
com.schbrain.common.util.IdWorker
;
import
com.schbrain.common.util.JacksonUtils
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.collections4.CollectionUtils
;
import
org.apache.maven.cli.MavenCli
;
import
org.apache.maven.settings.*
;
import
org.apache.maven.settings.io.DefaultSettingsWriter
;
...
...
@@ -14,9 +15,8 @@ import org.eclipse.jgit.api.Git;
import
org.eclipse.jgit.api.errors.GitAPIException
;
import
org.eclipse.jgit.transport.CredentialsProvider
;
import
org.eclipse.jgit.transport.URIish
;
import
org.gitlab4j.api.GitLabApi
;
import
org.gitlab4j.api.GitLabApiException
;
import
org.gitlab4j.api.models.Group
;
import
org.gitlab4j.api.*
;
import
org.gitlab4j.api.models.*
;
import
java.io.File
;
import
java.io.IOException
;
...
...
@@ -77,35 +77,47 @@ public class MavenUtils {
Git
git
=
Git
.
init
().
setInitialBranch
(
"develop"
).
setDirectory
(
directory
.
toFile
()).
call
();
git
.
add
().
addFilepattern
(
"."
).
call
();
git
.
commit
().
setAllowEmpty
(
true
).
setAuthor
(
"initializer"
,
"no-reply@schbrain.com"
).
setMessage
(
"Initial Commit"
).
call
();
for
(
String
branch
:
ADDITIONAL_BRANCHES
)
{
git
.
checkout
().
setName
(
branch
).
setCreateBranch
(
true
).
call
();
}
boolean
pushToRemote
=
repoGroupId
!=
null
;
if
(
pushToRemote
)
{
if
(
repoGroupId
!=
null
)
{
GitLabApi
gitLabApi
=
SpringUtil
.
getBean
(
GitLabApi
.
class
);
Group
group
=
gitLabApi
.
getGroupApi
().
getGroup
(
repoGroupId
);
String
groupPath
=
group
.
getFullPath
();
String
repositoryUrl
=
String
.
format
(
"%s/%s/%s.git"
,
gitLabApi
.
getGitLabServerUrl
(),
groupPath
,
param
.
getArtifactId
());
String
projectName
=
param
.
getArtifactId
();
String
repositoryUrl
=
String
.
format
(
"%s/%s/%s.git"
,
gitLabApi
.
getGitLabServerUrl
(),
groupPath
,
projectName
);
URIish
urIish
=
new
URIish
(
repositoryUrl
);
git
.
remoteSetUrl
().
setRemoteName
(
"origin"
).
setRemoteUri
(
urIish
).
call
();
}
for
(
String
branch
:
ADDITIONAL_BRANCHES
)
{
git
.
checkout
().
setName
(
branch
).
setCreateBranch
(
true
).
call
();
}
if
(
pushToRemote
)
{
git
.
push
()
.
setRemote
(
"origin"
)
.
setCredentialsProvider
(
SpringUtil
.
getBean
(
CredentialsProvider
.
class
))
.
setPushAll
()
.
setForce
(
true
)
.
call
();
Project
project
=
getProject
(
gitLabApi
,
groupPath
,
projectName
);
if
(
project
==
null
)
{
return
;
}
updateProjectDefaultBranch
(
gitLabApi
,
project
);
updateProtectedBranches
(
gitLabApi
,
project
);
}
git
.
close
();
}
catch
(
GitAPIException
|
GitLabApiException
|
URISyntaxException
e
)
{
log
.
warn
(
"Git repo init failed"
,
e
);
throw
new
BaseException
(
"Git仓库初始化失败"
);
}
}
private
static
void
updateProjectDefaultBranch
(
GitLabApi
gitLabApi
,
Project
project
)
throws
GitLabApiException
{
project
.
setDefaultBranch
(
"main"
);
gitLabApi
.
getProjectApi
().
updateProject
(
project
);
}
private
static
Project
getProject
(
GitLabApi
gitLabApi
,
String
groupPath
,
String
projectName
)
throws
GitLabApiException
{
String
projectPath
=
String
.
format
(
"%s/%s"
,
groupPath
,
projectName
);
return
gitLabApi
.
getProjectApi
().
getProject
(
projectPath
);
}
private
static
File
getSettingsFile
()
{
if
(
SETTINGS_FILE
.
exists
())
{
return
SETTINGS_FILE
;
...
...
@@ -171,4 +183,18 @@ public class MavenUtils {
};
}
private
static
void
updateProtectedBranches
(
GitLabApi
gitlabApi
,
Project
project
)
throws
GitLabApiException
{
ProtectedBranchesApi
protectedBranchesApi
=
gitlabApi
.
getProtectedBranchesApi
();
String
projectPath
=
project
.
getPathWithNamespace
();
List
<
ProtectedBranch
>
protectedBranches
=
protectedBranchesApi
.
getProtectedBranches
(
projectPath
);
if
(
CollectionUtils
.
isNotEmpty
(
protectedBranches
))
{
for
(
ProtectedBranch
protectedBranch
:
protectedBranches
)
{
protectedBranchesApi
.
unprotectBranch
(
projectPath
,
protectedBranch
.
getName
());
}
}
for
(
String
additionalBranch
:
ADDITIONAL_BRANCHES
)
{
protectedBranchesApi
.
protectBranch
(
projectPath
,
additionalBranch
);
}
}
}
\ No newline at end of file
initializer-ui/package.json
View file @
2e1c48d2
...
...
@@ -7,15 +7,15 @@
},
"dependencies"
:
{
"vue"
:
"^3.2.45"
,
"axios"
:
"^1.2.
0
"
,
"axios"
:
"^1.2.
1
"
,
"ant-design-vue"
:
"^3.2.15"
,
"highlight.js"
:
"^11.
6
.0"
,
"highlight.js"
:
"^11.
7
.0"
,
"@highlightjs/vue-plugin"
:
"^2.1.0"
},
"devDependencies"
:
{
"@vitejs/plugin-vue"
:
"^3.2.0"
,
"typescript"
:
"^4.9.3"
,
"vite"
:
"^3.2.
4
"
,
"vue-tsc"
:
"^1.0.
9
"
"vite"
:
"^3.2.
5
"
,
"vue-tsc"
:
"^1.0.
11
"
}
}
\ No newline at end of file
initializer-ui/src/components/starter.vue
View file @
2e1c48d2
...
...
@@ -101,13 +101,16 @@ const groupOptions = ref<SelectProps['options']>([
"
value
"
:
"
com.schbrain.kp
"
,
"
label
"
:
"
com.schbrain.kp
"
},
{
"
value
"
:
"
com.schbrain.rs
"
,
"
label
"
:
"
com.schbrain.rs
"
},
{
"
value
"
:
"
com.schbrain.xb
"
,
"
label
"
:
"
com.schbrain.xb
"
},
])
const
formState
=
reactive
<
FormState
>
({
groupId
:
''
,
artifactId
:
''
,
...
...
pom.xml
View file @
2e1c48d2
...
...
@@ -18,9 +18,10 @@
<properties>
<revision>
0.0.1-SNAPSHOT
</revision>
<frontend-maven-plugin.version>
1.12.1
</frontend-maven-plugin.version>
<maven-embedder.version>
3.8.5
</maven-embedder.version>
<aether.version>
1.1.0
</aether.version>
<gitlab4j-api.version>
5.0.1
</gitlab4j-api.version>
<maven-embedder.version>
3.8.5
</maven-embedder.version>
<frontend-maven-plugin.version>
1.12.1
</frontend-maven-plugin.version>
</properties>
<modules>
...
...
@@ -60,6 +61,11 @@
<artifactId>
aether-transport-http
</artifactId>
<version>
${aether.version}
</version>
</dependency>
<dependency>
<groupId>
org.gitlab4j
</groupId>
<artifactId>
gitlab4j-api
</artifactId>
<version>
${gitlab4j-api.version}
</version>
</dependency>
</dependencies>
</dependencyManagement>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment