Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add files affected by a commit to gitea API -- similar to github #12413

Closed
wants to merge 10 commits into from
15 changes: 15 additions & 0 deletions modules/convert/git_commit.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,20 @@ func ToCommit(repo *models.Repository, commit *git.Commit, userCache map[string]
}
}

// Retrieve files affected by the commit
fileStatus, err := git.GetCommitFileStatus(repo.RepoPath(), commit.ID.String())
if err != nil {
return nil, err
}
affectedFiles := append(fileStatus.Added, fileStatus.Removed...)
affectedFiles = append(affectedFiles, fileStatus.Modified...)
affectedFileList := make([]*api.CommitAffectedFiles, len(affectedFiles))
for i := 0; i < len(affectedFiles); i++ {
affectedFileList[i] = &api.CommitAffectedFiles{
Filename: affectedFiles[i],
}
}

return &api.Commit{
CommitMeta: &api.CommitMeta{
URL: repo.APIURL() + "/git/commits/" + commit.ID.String(),
Expand Down Expand Up @@ -161,5 +175,6 @@ func ToCommit(repo *models.Repository, commit *git.Commit, userCache map[string]
Author: apiAuthor,
Committer: apiCommitter,
Parents: apiParents,
Files: affectedFileList,
}, nil
}
16 changes: 11 additions & 5 deletions modules/structs/repo_commit.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,12 @@ type RepoCommit struct {
// Commit contains information generated from a Git commit.
type Commit struct {
*CommitMeta
HTMLURL string `json:"html_url"`
RepoCommit *RepoCommit `json:"commit"`
Author *User `json:"author"`
Committer *User `json:"committer"`
Parents []*CommitMeta `json:"parents"`
HTMLURL string `json:"html_url"`
RepoCommit *RepoCommit `json:"commit"`
Author *User `json:"author"`
Committer *User `json:"committer"`
Parents []*CommitMeta `json:"parents"`
Files []*CommitAffectedFiles `json:"files"`
}

// CommitDateOptions store dates for GIT_AUTHOR_DATE and GIT_COMMITTER_DATE
Expand All @@ -54,3 +55,8 @@ type CommitDateOptions struct {
// swagger:strfmt date-time
Committer time.Time `json:"committer"`
}

// CommitAffectedFiles store information about files affected by the commit
type CommitAffectedFiles struct {
Filename string `json:"filename"`
}
18 changes: 18 additions & 0 deletions templates/swagger/v1_json.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -11129,6 +11129,13 @@
"committer": {
"$ref": "#/definitions/User"
},
"files": {
"type": "array",
"items": {
"$ref": "#/definitions/CommitAffectedFiles"
},
"x-go-name": "Files"
},
"html_url": {
"type": "string",
"x-go-name": "HTMLURL"
Expand All @@ -11151,6 +11158,17 @@
},
"x-go-package": "code.gitea.io/gitea/modules/structs"
},
"CommitAffectedFiles": {
"description": "CommitAffectedFiles store information about files affected by the commit",
"type": "object",
"properties": {
"filename": {
"type": "string",
"x-go-name": "Filename"
}
},
"x-go-package": "code.gitea.io/gitea/modules/structs"
},
"CommitDateOptions": {
"description": "CommitDateOptions store dates for GIT_AUTHOR_DATE and GIT_COMMITTER_DATE",
"type": "object",
Expand Down