同步代码(readme匹配,webhook类型,gitdiff内容) #60
|
@ -130,6 +130,7 @@ const (
|
||||||
MSTEAMS HookType = "msteams"
|
MSTEAMS HookType = "msteams"
|
||||||
FEISHU HookType = "feishu"
|
FEISHU HookType = "feishu"
|
||||||
MATRIX HookType = "matrix"
|
MATRIX HookType = "matrix"
|
||||||
|
JIANMU HookType = "jianmu"
|
||||||
)
|
)
|
||||||
|
|
||||||
// HookStatus is the status of a web hook
|
// HookStatus is the status of a web hook
|
||||||
|
|
|
@ -217,6 +217,11 @@ func (repo *Repository) GetDiff(base, head string, w io.Writer) error {
|
||||||
RunInDirPipeline(repo.Path, w, nil)
|
RunInDirPipeline(repo.Path, w, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (repo *Repository) GetDiffStringByFilePath(base, head, filepath string) (string, error) {
|
||||||
|
return NewCommand("diff", "-p", base, head, "--", filepath).
|
||||||
|
RunInDir(repo.Path)
|
||||||
|
}
|
||||||
|
|
||||||
// GetPatch generates and returns format-patch data between given revisions.
|
// GetPatch generates and returns format-patch data between given revisions.
|
||||||
func (repo *Repository) GetPatch(base, head string, w io.Writer) error {
|
func (repo *Repository) GetPatch(base, head string, w io.Writer) error {
|
||||||
stderr := new(bytes.Buffer)
|
stderr := new(bytes.Buffer)
|
||||||
|
|
|
@ -24,6 +24,9 @@ func GetBatchFileResponseFromCommit(repo *models.Repository, commit *git.Commit,
|
||||||
}
|
}
|
||||||
for _, treeName := range treeNames {
|
for _, treeName := range treeNames {
|
||||||
fileContent, _ := GetContents(repo, treeName, branch, false)
|
fileContent, _ := GetContents(repo, treeName, branch, false)
|
||||||
|
if fileContent == nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
batchFileResponse.Contents = append(batchFileResponse.Contents, fileContent)
|
batchFileResponse.Contents = append(batchFileResponse.Contents, fileContent)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -58,7 +58,7 @@ type CreateHookOptionConfig map[string]string
|
||||||
// CreateHookOption options when create a hook
|
// CreateHookOption options when create a hook
|
||||||
type CreateHookOption struct {
|
type CreateHookOption struct {
|
||||||
// required: true
|
// required: true
|
||||||
// enum: dingtalk,discord,gitea,gogs,msteams,slack,telegram,feishu
|
// enum: dingtalk,discord,gitea,gogs,msteams,slack,telegram,feishu,jianmu
|
||||||
Type string `json:"type" binding:"Required"`
|
Type string `json:"type" binding:"Required"`
|
||||||
// required: true
|
// required: true
|
||||||
Config CreateHookOptionConfig `json:"config" binding:"Required"`
|
Config CreateHookOptionConfig `json:"config" binding:"Required"`
|
||||||
|
|
|
@ -761,8 +761,23 @@ func GetReadmeContents(ctx *context.APIContext) {
|
||||||
|
|
||||||
// treePath := ctx.Params("*")
|
// treePath := ctx.Params("*")
|
||||||
ref := ctx.QueryTrim("ref")
|
ref := ctx.QueryTrim("ref")
|
||||||
|
var readmePath string
|
||||||
|
filesListInterface, _ := repofiles.GetContentsOrList(ctx, ctx.Repo.Repository, "", ref)
|
||||||
|
filesList, ok := filesListInterface.([]*api.ContentsResponse)
|
||||||
|
if ok {
|
||||||
|
for _, file := range filesList {
|
||||||
|
if strings.ToLower(file.Name) == "readme.md" {
|
||||||
|
readmePath = file.Name
|
||||||
|
}
|
||||||
|
if readmePath != "" {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
readmePath = "README.md"
|
||||||
|
}
|
||||||
|
|
||||||
if fileList, err := repofiles.GetContentsOrList(ctx, ctx.Repo.Repository, "README.md", ref); err != nil {
|
if fileList, err := repofiles.GetContentsOrList(ctx, ctx.Repo.Repository, readmePath, ref); err != nil {
|
||||||
if git.IsErrNotExist(err) {
|
if git.IsErrNotExist(err) {
|
||||||
ctx.NotFound("GetContentsOrList", err)
|
ctx.NotFound("GetContentsOrList", err)
|
||||||
return
|
return
|
||||||
|
@ -816,7 +831,22 @@ func GetReadmeContentsByPath(ctx *context.APIContext) {
|
||||||
|
|
||||||
treePath := ctx.Params("*")
|
treePath := ctx.Params("*")
|
||||||
ref := ctx.QueryTrim("ref")
|
ref := ctx.QueryTrim("ref")
|
||||||
newTreePath := treePath + "/" + "README.md"
|
var readmePath string
|
||||||
|
filesListInterface, _ := repofiles.GetContentsOrList(ctx, ctx.Repo.Repository, treePath, ref)
|
||||||
|
filesList, ok := filesListInterface.([]*api.ContentsResponse)
|
||||||
|
if ok {
|
||||||
|
for _, file := range filesList {
|
||||||
|
if strings.ToLower(file.Name) == "readme.md" {
|
||||||
|
readmePath = file.Name
|
||||||
|
}
|
||||||
|
if readmePath != "" {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
readmePath = "README.md"
|
||||||
|
}
|
||||||
|
newTreePath := treePath + "/" + readmePath
|
||||||
if fileList, err := repofiles.GetContentsOrList(ctx, ctx.Repo.Repository, newTreePath, ref); err != nil {
|
if fileList, err := repofiles.GetContentsOrList(ctx, ctx.Repo.Repository, newTreePath, ref); err != nil {
|
||||||
if git.IsErrNotExist(err) {
|
if git.IsErrNotExist(err) {
|
||||||
ctx.NotFound("GetContentsOrList", err)
|
ctx.NotFound("GetContentsOrList", err)
|
||||||
|
|
|
@ -3,6 +3,7 @@ package repo
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"code.gitea.io/gitea/models"
|
"code.gitea.io/gitea/models"
|
||||||
"code.gitea.io/gitea/modules/context"
|
"code.gitea.io/gitea/modules/context"
|
||||||
|
@ -157,11 +158,39 @@ func GetPullRequestVersionDiff(ctx *context.APIContext) {
|
||||||
var targetDiffFile *gitdiff.DiffFile
|
var targetDiffFile *gitdiff.DiffFile
|
||||||
for _, file := range diffs.Files {
|
for _, file := range diffs.Files {
|
||||||
if file.Name == filepath {
|
if file.Name == filepath {
|
||||||
|
if diffString, err := ctx.Repo.GitRepo.GetDiffStringByFilePath(prv.BaseCommitID, prv.HeadCommitID, file.Name); err == nil {
|
||||||
|
stringArray := strings.Split(diffString, "\n")
|
||||||
|
for i, item := range stringArray {
|
||||||
|
switch {
|
||||||
|
case strings.HasPrefix(item, "diff --git"):
|
||||||
|
stringArray[i] = ""
|
||||||
|
case strings.HasPrefix(item, "index"):
|
||||||
|
stringArray[i] = ""
|
||||||
|
case strings.HasPrefix(item, "---"):
|
||||||
|
stringArray[i] = ""
|
||||||
|
case strings.HasPrefix(item, "+++"):
|
||||||
|
stringArray[i] = ""
|
||||||
|
case strings.HasPrefix(item, "new file mode"):
|
||||||
|
stringArray[i] = ""
|
||||||
|
case strings.HasPrefix(item, "deleted file mode"):
|
||||||
|
stringArray[i] = ""
|
||||||
|
case strings.HasSuffix(item, "No newline at end of file"):
|
||||||
|
stringArray[i] = ""
|
||||||
|
default:
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
file.Diff = strings.Join(stringArray, "\n")
|
||||||
|
}
|
||||||
targetDiffFile = file
|
targetDiffFile = file
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ctx.JSON(http.StatusOK, targetDiffFile)
|
if targetDiffFile == nil {
|
||||||
|
ctx.NotFound()
|
||||||
|
} else {
|
||||||
|
ctx.JSON(http.StatusOK, targetDiffFile)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -326,7 +326,12 @@ func ListWikiPages(ctx *context.APIContext) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if entry.IsRegular() {
|
if entry.IsRegular() {
|
||||||
c, err := wikiRepo.GetCommitByPath(fmt.Sprintf("%s/%s", filePath, entry.Name()))
|
var commit *git.Commit
|
||||||
|
if filePath == "" {
|
||||||
|
commit, err = wikiRepo.GetCommitByPath(entry.Name())
|
||||||
|
} else {
|
||||||
|
commit, err = wikiRepo.GetCommitByPath(fmt.Sprintf("%s/%s", filePath, entry.Name()))
|
||||||
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetCommit", err)
|
ctx.Error(http.StatusInternalServerError, "GetCommit", err)
|
||||||
return
|
return
|
||||||
|
@ -339,15 +344,20 @@ func ListWikiPages(ctx *context.APIContext) {
|
||||||
ctx.Error(http.StatusInternalServerError, "WikiFilenameToName", err)
|
ctx.Error(http.StatusInternalServerError, "WikiFilenameToName", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
lists = append(lists, convert.RegularToWikiPageMetaData(wikiName, c, ctx.Repo.Repository))
|
lists = append(lists, convert.RegularToWikiPageMetaData(wikiName, commit, ctx.Repo.Repository))
|
||||||
}
|
}
|
||||||
if entry.IsDir() {
|
if entry.IsDir() {
|
||||||
c, err := wikiRepo.GetCommitByPath(fmt.Sprintf("%s/%s", filePath, entry.Name()))
|
var commit *git.Commit
|
||||||
|
if filePath == "" {
|
||||||
|
commit, err = wikiRepo.GetCommitByPath(entry.Name())
|
||||||
|
} else {
|
||||||
|
commit, err = wikiRepo.GetCommitByPath(fmt.Sprintf("%s/%s", filePath, entry.Name()))
|
||||||
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "GetCommit", err)
|
ctx.Error(http.StatusInternalServerError, "GetCommit", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
lists = append(lists, convert.DirToWikiPageMetaData(entry.Name(), c, ctx.Repo.Repository))
|
lists = append(lists, convert.DirToWikiPageMetaData(entry.Name(), commit, ctx.Repo.Repository))
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -593,6 +593,7 @@ type DiffFile struct {
|
||||||
IsIncomplete bool
|
IsIncomplete bool
|
||||||
IsIncompleteLineTooLong bool
|
IsIncompleteLineTooLong bool
|
||||||
IsProtected bool
|
IsProtected bool
|
||||||
|
Diff string
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetType returns type of diff file.
|
// GetType returns type of diff file.
|
||||||
|
|
|
@ -65,6 +65,12 @@ func IsValidHookTaskType(name string) bool {
|
||||||
if name == models.GITEA || name == models.GOGS {
|
if name == models.GITEA || name == models.GOGS {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 建木devops
|
||||||
|
if name == models.JIANMU {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
_, ok := webhooks[models.HookType(name)]
|
_, ok := webhooks[models.HookType(name)]
|
||||||
return ok
|
return ok
|
||||||
}
|
}
|
||||||
|
@ -135,7 +141,7 @@ func prepareWebhook(w *models.Webhook, repo *models.Repository, event models.Hoo
|
||||||
// Avoid sending "0 new commits" to non-integration relevant webhooks (e.g. slack, discord, etc.).
|
// Avoid sending "0 new commits" to non-integration relevant webhooks (e.g. slack, discord, etc.).
|
||||||
// Integration webhooks (e.g. drone) still receive the required data.
|
// Integration webhooks (e.g. drone) still receive the required data.
|
||||||
if pushEvent, ok := p.(*api.PushPayload); ok &&
|
if pushEvent, ok := p.(*api.PushPayload); ok &&
|
||||||
w.Type != models.GITEA && w.Type != models.GOGS &&
|
w.Type != models.GITEA && w.Type != models.GOGS && w.Type != models.JIANMU &&
|
||||||
len(pushEvent.Commits) == 0 {
|
len(pushEvent.Commits) == 0 {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -14615,7 +14615,8 @@
|
||||||
"msteams",
|
"msteams",
|
||||||
"slack",
|
"slack",
|
||||||
"telegram",
|
"telegram",
|
||||||
"feishu"
|
"feishu",
|
||||||
|
"jianmu"
|
||||||
],
|
],
|
||||||
"x-go-name": "Type"
|
"x-go-name": "Type"
|
||||||
}
|
}
|
||||||
|
@ -15387,6 +15388,9 @@
|
||||||
"format": "int64",
|
"format": "int64",
|
||||||
"x-go-name": "Deletion"
|
"x-go-name": "Deletion"
|
||||||
},
|
},
|
||||||
|
"Diff": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
"Index": {
|
"Index": {
|
||||||
"type": "integer",
|
"type": "integer",
|
||||||
"format": "int64"
|
"format": "int64"
|
||||||
|
|
Loading…
Reference in New Issue