0
0
mirror of https://github.com/thegeeklab/wp-git-clone.git synced 2024-11-21 14:10:38 +00:00

fix: enable tags fetching by default and remove event condition

This commit is contained in:
Robert Kaussow 2023-12-23 21:46:36 +01:00
parent 019f983e8f
commit 802772766b
Signed by: xoxys
GPG Key ID: 4E692A2EAECC03C0
7 changed files with 8 additions and 68 deletions

View File

@ -53,14 +53,6 @@ func settingsFlags(settings *plugin.Settings, category string) []cli.Flag {
Destination: &settings.Repo.CommitRef,
Category: category,
},
&cli.StringFlag{
Name: "event",
Value: "push",
Usage: "pipeline event",
EnvVars: []string{"CI_PIPELINE_EVENT"},
Destination: &settings.Pipeline.Event,
Category: category,
},
&cli.StringFlag{
Name: "netrc.machine",
Usage: "netrc machine",
@ -99,7 +91,7 @@ func settingsFlags(settings *plugin.Settings, category string) []cli.Flag {
},
&cli.BoolFlag{
Name: "tags",
Usage: "clone tags, if not explicitly set and event is tag its default is true else false",
Usage: "fetch git tags during clone",
EnvVars: []string{"PLUGIN_TAGS"},
Destination: &settings.Tags,
Category: category,

View File

@ -56,7 +56,6 @@ docker build --file Containerfile.multiarch --tag thegeeklab/wp-git-clone .
```Shell
docker run --rm \
-e CI_REPO_CLONE_URL=https://github.com/octocat/Hello-World.git \
-e CI_PIPELINE_EVENT=push \
-e CI_COMMIT_SHA=b3cbd5bbd7e81436d2eee04537ea2b4c0cad4cdf \
-e CI_COMMIT_REF=refs/heads/test \
-e CI_WORKSPACE=/tmp/wp_git_testrepo \

View File

@ -5,23 +5,6 @@ properties:
Change branch name.
defaultvalue: "main"
- name: ci_netrc_machine
description: |
Netrc machine.
- name: ci_netrc_password
description: |
Netrc password.
- name: ci_netrc_username
description: |
Metrc username.
- name: ci_pipeline_event
description: |
Pipeline event.
defaultvalue: "push"
- name: commit_ref
description: |
Git commit ref.
@ -90,8 +73,8 @@ properties:
- name: tags
description: |
Clone tags, if not explicitly set and event is tag its default is `true` else `false`.
defaultvalue: false
Fetch git tags during clone.
defaultvalue: true
- name: use_ssh
description: |

View File

@ -8,10 +8,10 @@ import (
// FetchSource fetches the source from remote.
func FetchSource(ref string, tags bool, depth int, filter string) *execabs.Cmd {
tagsOption := "--no-tags"
tagsOption := "--tags"
if tags {
tagsOption = "--tags"
if !tags {
tagsOption = "--no-tags"
}
args := []string{

View File

@ -59,19 +59,6 @@ func (p *Plugin) Validate() error {
}
}
if p.Settings.Pipeline.Event == "tag" && !p.Settings.Tags {
// tags clone not explicit set but pipeline is triggered by a tag
// auto set tags cloning to true
p.Settings.Tags = true
}
if p.Settings.Tags && p.Settings.Partial {
log.Warn().Msg("ignore partial clone as tags are fetched")
// if tag fetching is enabled per event or setting, disable partial clone
p.Settings.Partial = false
}
if p.Settings.Partial {
p.Settings.Depth = 1
p.Settings.Filter = "tree:0"

View File

@ -12,7 +12,6 @@ type testCommit struct {
name string
path string
clone string
event string
commit string
ref string
file string
@ -37,9 +36,6 @@ func TestClone(t *testing.T) {
CommitSha: tt.commit,
Branch: "main",
},
Pipeline: Pipeline{
Event: tt.event,
},
Home: "/tmp",
WorkDir: filepath.Join(dir, tt.path),
Recursive: tt.recursive,
@ -83,9 +79,6 @@ func TestCloneNonEmpty(t *testing.T) {
CommitSha: tt.commit,
Branch: "main",
},
Pipeline: Pipeline{
Event: tt.event,
},
Home: "/tmp",
WorkDir: filepath.Join(dir, tt.path),
Recursive: tt.recursive,
@ -150,7 +143,6 @@ func getCommits() []testCommit {
name: "first commit",
path: "octocat/Hello-World",
clone: "https://github.com/octocat/Hello-World.git",
event: "push",
commit: "553c2077f0edc3d5dc5d17262f6aa498e69d6f8e",
ref: "refs/heads/master",
file: "README",
@ -160,7 +152,6 @@ func getCommits() []testCommit {
name: "head commit",
path: "octocat/Hello-World",
clone: "https://github.com/octocat/Hello-World.git",
event: "push",
commit: "7fd1a60b01f91b314f59955a4e4d4e80d8edf11d",
ref: "refs/heads/master",
file: "README",
@ -170,7 +161,6 @@ func getCommits() []testCommit {
name: "pull request commit",
path: "octocat/Hello-World",
clone: "https://github.com/octocat/Hello-World.git",
event: "pull_request",
commit: "762941318ee16e59dabbacb1b4049eec22f0d303",
ref: "refs/pull/6/merge",
file: "README",
@ -180,7 +170,6 @@ func getCommits() []testCommit {
name: "branch",
path: "octocat/Hello-World",
clone: "https://github.com/octocat/Hello-World.git",
event: "push",
commit: "b3cbd5bbd7e81436d2eee04537ea2b4c0cad4cdf",
ref: "refs/heads/test",
file: "CONTRIBUTING.md",
@ -190,7 +179,6 @@ func getCommits() []testCommit {
name: "tags",
path: "github/mime-types",
clone: "https://github.com/github/mime-types.git",
event: "tag",
commit: "bf68d60215a167c935bc5976b7d06a7ffb290926",
ref: "refs/tags/v1.17",
file: ".gitignore",
@ -200,7 +188,6 @@ func getCommits() []testCommit {
name: "submodules",
path: "test-assets/woodpecker-git-test-submodule",
clone: "https://github.com/test-assets/woodpecker-git-test-submodule.git",
event: "push",
commit: "cc020eb6aaa601c13ca7b0d5db9d1ca694e7a003",
ref: "refs/heads/main",
file: "Hello-World/README",
@ -211,7 +198,6 @@ func getCommits() []testCommit {
name: "checkout with ref only",
path: "octocat/Hello-World",
clone: "https://github.com/octocat/Hello-World.git",
event: "push",
// commit: "a11fb45a696bf1d696fc9ab2c733f8f123aa4cf5",
ref: "pull/2403/head",
file: "README",
@ -222,7 +208,6 @@ func getCommits() []testCommit {
name: "checkout with lfs skip",
path: "test-assets/woodpecker-git-test-lfs",
clone: "https://github.com/test-assets/woodpecker-git-test-lfs.git",
event: "push",
commit: "69d4dadb4c2899efb73c0095bb58a6454d133cef",
ref: "refs/heads/main",
file: "4M.bin",
@ -232,7 +217,6 @@ func getCommits() []testCommit {
name: "checkout with lfs",
path: "test-assets/woodpecker-git-test-lfs",
clone: "https://github.com/test-assets/woodpecker-git-test-lfs.git",
event: "push",
commit: "69d4dadb4c2899efb73c0095bb58a6454d133cef",
ref: "refs/heads/main",
file: "4M.bin",

View File

@ -16,10 +16,6 @@ type Plugin struct {
Settings *Settings
}
type Pipeline struct {
Event string
}
type Netrc struct {
Machine string
Login string
@ -39,9 +35,8 @@ type Settings struct {
Home string
WorkDir string
Pipeline Pipeline
Netrc Netrc
Repo git.Repository
Netrc Netrc
Repo git.Repository
}
func New(options wp.Options, settings *Settings) *Plugin {