Skip to content

Commit

Permalink
implement for brew and scoop support for Gitea-hosted repos
Browse files Browse the repository at this point in the history
  • Loading branch information
6543 committed May 22, 2020
1 parent 6b80d90 commit bed1af5
Showing 1 changed file with 39 additions and 2 deletions.
41 changes: 39 additions & 2 deletions internal/client/gitea.go
Expand Up @@ -2,6 +2,7 @@ package client

import (
"crypto/tls"
"encoding/base64"
"fmt"
"net/http"
"net/url"
Expand Down Expand Up @@ -61,8 +62,44 @@ func (c *giteaClient) CreateFile(
path,
message string,
) error {
//TODO: implement for brew and scoop support for Gitea-hosted repos
return nil
owner := repo.Owner
repoName := repo.Name

branchName := "master"

fileOptions := gitea.FileOptions{
Message: message,
BranchName: branchName,
Author: gitea.Identity{
Name: commitAuthor.Name,
Email: commitAuthor.Email,
},
Committer: gitea.Identity{
Name: commitAuthor.Name,
Email: commitAuthor.Email,
},
}

currentFile, err := c.client.GetContents(owner, repoName, branchName, path)
// file not exist, create it
if err != nil {
if err.Error() != "404 Not Found" {
return err
}
_, err = c.client.CreateFile(owner, repoName, path, gitea.CreateFileOptions{
FileOptions: fileOptions,
Content: base64.StdEncoding.EncodeToString(content),
})
return err
}

// update file
_, err = c.client.UpdateFile(owner, repoName, path, gitea.UpdateFileOptions{
FileOptions: fileOptions,
SHA: currentFile.SHA,
Content: base64.StdEncoding.EncodeToString(content),
})
return err
}

func (c *giteaClient) createRelease(ctx *context.Context, title, body string) (*gitea.Release, error) {
Expand Down

0 comments on commit bed1af5

Please sign in to comment.