This repository was archived by the owner on Apr 12, 2019. It is now read-only.
forked from gogs/git-module
-
Notifications
You must be signed in to change notification settings - Fork 38
Add get tags info method for releases #27
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ package git | |
|
||
import ( | ||
"strings" | ||
"time" | ||
|
||
"github.com/mcuadros/go-version" | ||
) | ||
|
@@ -94,6 +95,85 @@ func (repo *Repository) GetTag(name string) (*Tag, error) { | |
return tag, nil | ||
} | ||
|
||
// TagOption describes tag options | ||
type TagOption struct { | ||
} | ||
|
||
// parseTag parse the line | ||
// 2016-10-14 20:54:25 +0200 (tag: translation/20161014.01) d3b76dcf2 Dirk Baeumer [email protected] Merge in translations | ||
func parseTag(line string, opt TagOption) (*Tag, error) { | ||
line = strings.TrimSpace(line) | ||
if len(line) < 40 { | ||
return nil, nil | ||
} | ||
|
||
var err error | ||
var tag Tag | ||
var sig Signature | ||
sig.When, err = time.Parse("2006-01-02 15:04:05 -0700", line[0:25]) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
left := strings.TrimSpace(line[25:]) | ||
start := strings.Index(left, "(tag: ") | ||
if start < 0 { | ||
return nil, nil | ||
} | ||
end := strings.IndexByte(left[start+1:], ')') | ||
if end < 0 { | ||
return nil, nil | ||
} | ||
end = end + start + 1 | ||
part := strings.IndexByte(left[start+6:end], ',') | ||
if part > 0 { | ||
tag.Name = strings.TrimSpace(left[start+6 : start+6+part]) | ||
} else { | ||
tag.Name = strings.TrimSpace(left[start+6 : end]) | ||
} | ||
next := strings.IndexByte(left[end+2:], ' ') | ||
if next < 0 { | ||
return nil, nil | ||
} | ||
tag.Object = MustIDFromString(strings.TrimSpace(left[end+2 : end+2+next])) | ||
next = end + 2 + next | ||
|
||
emailStart := strings.IndexByte(left[next:], '<') | ||
sig.Name = strings.TrimSpace(left[next:][:emailStart-1]) | ||
emailEnd := strings.IndexByte(left[next:], '>') | ||
sig.Email = strings.TrimSpace(left[next:][emailStart+1 : emailEnd]) | ||
tag.Tagger = &sig | ||
tag.Message = strings.TrimSpace(left[next+emailEnd+1:]) | ||
return &tag, nil | ||
} | ||
|
||
// GetTagInfos returns all tag infos of the repository. | ||
func (repo *Repository) GetTagInfos(opt TagOption) ([]*Tag, error) { | ||
cmd := NewCommand("log", "--tags", "--simplify-by-decoration", `--pretty=format:"%ci %d %H %cn<%ce> %s"`) | ||
stdout, err := cmd.RunInDir(repo.Path) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
tagSlices := strings.Split(stdout, "\n") | ||
var tags []*Tag | ||
for _, line := range tagSlices { | ||
line := strings.Trim(line, `"`) | ||
tag, err := parseTag(line, opt) | ||
if err != nil { | ||
return nil, err | ||
} | ||
if tag != nil { | ||
tag.repo = repo | ||
tags = append(tags, tag) | ||
} | ||
} | ||
|
||
sortTagsByTime(tags) | ||
|
||
return tags, nil | ||
} | ||
|
||
// GetTags returns all tags of the repository. | ||
func (repo *Repository) GetTags() ([]string, error) { | ||
cmd := NewCommand("tag", "-l") | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.