1
1
mirror of https://github.com/drone-plugins/github-actions synced 2026-03-07 10:01:33 +01:00
github.com-drone-plugins-gi.../cloner/util.go
OP (oppenheimer) 11ed8bab1c
feat: [CI-15681]: Enhance Drone GitHub Action Plugin with Workflow Output Parsing (#18)
* 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
2025-01-10 20:01:59 +05:30

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
}