mirror of
https://github.com/drone-plugins/github-actions
synced 2026-03-07 10:01:33 +01:00
* feat: [CI-15681]: Enhance Drone GitHub Actions Plugin with Workflow Output Parsing * formatted parse_test.go * Removed 'drone/plugin' dependencies to reduce the binary size and copied the relevant code to this repo * Removed windows code * Updated plugin.go
36 lines
1020 B
Go
36 lines
1020 B
Go
// Copyright 2022 Harness Inc. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
package cloner
|
|
|
|
import (
|
|
"regexp"
|
|
"strings"
|
|
)
|
|
|
|
// regular expressions to test whether or not a string is
|
|
// a sha1 or sha256 commit hash.
|
|
var (
|
|
sha1 = regexp.MustCompile("^([a-f0-9]{40})$")
|
|
sha256 = regexp.MustCompile("^([a-f0-9]{64})$")
|
|
semver = regexp.MustCompile(`^v?((([0-9]+)(?:\.([0-9]+))?(?:\.([0-9]+))?(?:-([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?)(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?)$`)
|
|
)
|
|
|
|
// helper function returns true if the string is a commit hash.
|
|
func isHash(s string) bool {
|
|
return sha1.MatchString(s) || sha256.MatchString(s)
|
|
}
|
|
|
|
// helper function returns the branch name expanded to the
|
|
// fully qualified reference path (e.g refs/heads/master).
|
|
func expandRef(name string) string {
|
|
if strings.HasPrefix(name, "refs/") {
|
|
return name
|
|
}
|
|
if semver.MatchString(name) {
|
|
return "refs/tags/" + name
|
|
}
|
|
return "refs/heads/" + name
|
|
}
|