Compare commits
	
		
			No commits in common. "bc99681992115b7603c35be4bed4b8a9790c0037" and "0dd91c5ce717d818fedb6472db504b9682890fc3" have entirely different histories.
		
	
	
		
			bc99681992
			...
			0dd91c5ce7
		
	
		
| @ -30,7 +30,7 @@ steps: | |||||||
|         from_secret: docker_username |         from_secret: docker_username | ||||||
|       password: |       password: | ||||||
|         from_secret: docker_password |         from_secret: docker_password | ||||||
|   - image: gitea.dikurium.ch/innopeak/drone-gitea-release:0.7 |   - image: gitea.dikurium.ch/innopeak/drone-gitea-release:0.6 | ||||||
|     name: create release |     name: create release | ||||||
|     settings: |     settings: | ||||||
|       gitea_password: |       gitea_password: | ||||||
|  | |||||||
| @ -26,8 +26,6 @@ type Args struct { | |||||||
| 	GiteaUrl          string `envconfig:"PLUGIN_GITEA_URL"` | 	GiteaUrl          string `envconfig:"PLUGIN_GITEA_URL"` | ||||||
| 	GiteaUsername     string `envconfig:"PLUGIN_GITEA_USERNAME"` | 	GiteaUsername     string `envconfig:"PLUGIN_GITEA_USERNAME"` | ||||||
| 	GiteaPassword     string `envconfig:"PLUGIN_GITEA_PASSWORD"` | 	GiteaPassword     string `envconfig:"PLUGIN_GITEA_PASSWORD"` | ||||||
| 	GitUsername       string `envconfig:"PLUGIN_GIT_USERNAME"` |  | ||||||
| 	GitPassword       string `envconfig:"PLUGIN_GIT_PASSWORD"` |  | ||||||
| 	Owner             string `envconfig:"PLUGIN_OWNER"` | 	Owner             string `envconfig:"PLUGIN_OWNER"` | ||||||
| 	Repo              string `envconfig:"PLUGIN_REPO"` | 	Repo              string `envconfig:"PLUGIN_REPO"` | ||||||
| 	TitleFormat       string `envconfig:"PLUGIN_TITLE_FORMAT"` | 	TitleFormat       string `envconfig:"PLUGIN_TITLE_FORMAT"` | ||||||
| @ -78,11 +76,8 @@ func Exec(ctx context.Context, args Args) error { | |||||||
| 
 | 
 | ||||||
| 	if args.UseLatestGitTag { | 	if args.UseLatestGitTag { | ||||||
| 		var options = make([]GetLatestGitTagOption, 0) | 		var options = make([]GetLatestGitTagOption, 0) | ||||||
| 		if args.GitUsername != "" && args.GitPassword != "" { |  | ||||||
| 			options = append(options, SetBasicAuth(args.GitUsername, args.GitPassword)) |  | ||||||
| 		} |  | ||||||
| 		if args.FetchGitTags { | 		if args.FetchGitTags { | ||||||
| 			options = append(options, FetchTags()) | 			options = append(options, FetchTags) | ||||||
| 		} | 		} | ||||||
| 		tag, err = getLatestGitTag(options...) | 		tag, err = getLatestGitTag(options...) | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -9,52 +9,22 @@ import ( | |||||||
| 	"encoding/json" | 	"encoding/json" | ||||||
| 	"fmt" | 	"fmt" | ||||||
| 	"io" | 	"io" | ||||||
| 	"net/http" |  | ||||||
| 	"os" | 	"os" | ||||||
| 	"strings" | 	"strings" | ||||||
| 
 | 
 | ||||||
| 	"github.com/go-git/go-git/v5" | 	"github.com/go-git/go-git/v5" | ||||||
| 	"github.com/go-git/go-git/v5/plumbing/transport/client" |  | ||||||
| 	githttp "github.com/go-git/go-git/v5/plumbing/transport/http" |  | ||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
| type GetLatestGitTagOption func(repo *git.Repository) error | type GetLatestGitTagOption func(repo *git.Repository) error | ||||||
| 
 | 
 | ||||||
| type BasicAuthTransport struct { | var FetchTags = func(repo *git.Repository) error { | ||||||
| 	Username    string | 	err := repo.Fetch(&git.FetchOptions{Tags: git.AllTags}) | ||||||
| 	Password    string |  | ||||||
| 	RoundTriper http.RoundTripper |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| func (bat BasicAuthTransport) RoundTrip(req *http.Request) (resp *http.Response, err error) { |  | ||||||
| 	creds := base64.StdEncoding.EncodeToString([]byte(fmt.Sprintf("%s:%s", bat.Username, bat.Password))) |  | ||||||
| 	req.Header.Set("Authorization", fmt.Sprintf("Basic %s", creds)) |  | ||||||
| 	return bat.RoundTriper.RoundTrip(req) |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| func SetBasicAuth(username, password string) func(repo *git.Repository) error { |  | ||||||
| 	return func(repo *git.Repository) error { |  | ||||||
| 		customClient := &http.Client{ |  | ||||||
| 			Transport: BasicAuthTransport{username, password, http.DefaultTransport}, |  | ||||||
| 		} |  | ||||||
| 
 |  | ||||||
| 		// Override http(s) default protocol to use our custom client
 |  | ||||||
| 		client.InstallProtocol("https", githttp.NewClient(customClient)) |  | ||||||
| 
 | 
 | ||||||
|  | 	if err == git.NoErrAlreadyUpToDate { | ||||||
| 		return nil | 		return nil | ||||||
| 	} | 	} | ||||||
| } |  | ||||||
| 
 | 
 | ||||||
| func FetchTags() func(repo *git.Repository) error { | 	return err | ||||||
| 	return func(repo *git.Repository) error { |  | ||||||
| 		err := repo.Fetch(&git.FetchOptions{Tags: git.AllTags}) |  | ||||||
| 
 |  | ||||||
| 		if err == git.NoErrAlreadyUpToDate { |  | ||||||
| 			return nil |  | ||||||
| 		} |  | ||||||
| 
 |  | ||||||
| 		return err |  | ||||||
| 	} |  | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func getLatestGitTag(options ...GetLatestGitTagOption) (tag string, err error) { | func getLatestGitTag(options ...GetLatestGitTagOption) (tag string, err error) { | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user