Skip to content
This repository has been archived by the owner on Jan 26, 2018. It is now read-only.

First pr merge semver #27

Open
wants to merge 18 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@ bindata.go
web/react/node_modules
web/static/files/script.js
#web/static/files/*.css

.idea
37 changes: 37 additions & 0 deletions api/tags.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package api

import (
log "github.com/Sirupsen/logrus"
"github.com/gin-gonic/gin"
"github.com/lgtmco/lgtm/cache"
"github.com/lgtmco/lgtm/model"
"github.com/lgtmco/lgtm/router/middleware/session"
"github.com/lgtmco/lgtm/store"
)

func GetTags(c *gin.Context) {
var (
owner = c.Param("owner")
name = c.Param("repo")
user = session.User(c)
)
repo, err := store.GetRepoOwnerName(c, owner, name)
if err != nil {
log.Errorf("Error getting repository %s. %s", name, err)
c.AbortWithStatus(404)
return
}
tags, err := cache.GetTags(c, user, repo)
if err != nil {
log.Errorf("Error getting remote tag list. %s", err)
c.String(500, "Error getting remote tag list")
return
}

// copy the slice since we don't
// want any nasty data races if the slice came from the cache.
tagsc := make(model.TagList, len(tags))
copy(tagsc, tags)

c.JSON(200, tagsc)
}
19 changes: 19 additions & 0 deletions cache/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,3 +93,22 @@ func GetMembers(c context.Context, user *model.User, team string) ([]*model.Memb
FromContext(c).Set(key, members)
return members, nil
}

func GetTags(c context.Context, user *model.User, repo *model.Repo) (model.TagList, error) {
key := fmt.Sprintf("tags:%s",
user.Login,
)
// if we fetch from the cache we can return immediately
val, err := FromContext(c).Get(key)
if err == nil {
return val.(model.TagList), nil
}
// else we try to grab from the remote system and
// populate our cache.
tags, err := remote.GetTagList(c, user, repo)
if err != nil {
return nil, err
}
FromContext(c).Set(key, tags)
return tags, nil
}
3 changes: 3 additions & 0 deletions model/branch_status.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package model

type BranchStatus string
4 changes: 3 additions & 1 deletion model/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ type Config struct {
Pattern string `json:"pattern" toml:"pattern"`
Team string `json:"team" toml:"team"`
SelfApprovalOff bool `json:"self_approval_off" toml:"self_approval_off"`
DoMerge bool `json:"do_merge" toml:"do_merge"`
DoVersion bool `json:"do_version" toml:"do_version"`

re *regexp.Regexp
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is gofmt run on the code? I would expect it to remove the spacing after re

Expand All @@ -31,7 +33,7 @@ func ParseConfigStr(data string) (*Config, error) {
c.Approvals = 2
}
if len(c.Pattern) == 0 {
c.Pattern = "(?i)LGTM"
c.Pattern = `(?i)LGTM\s*(\S*)`
}
if len(c.Team) == 0 {
c.Team = "MAINTAINERS"
Expand Down
6 changes: 6 additions & 0 deletions model/hook.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
package model

type Hook struct {
Kind string
IssueComment *IssueCommentHook
Status *StatusHook
}

type IssueCommentHook struct {
Repo *Repo
Issue *Issue
Comment *Comment
Expand Down
17 changes: 17 additions & 0 deletions model/status_hook.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package model

type StatusHook struct {
SHA string
Repo *Repo
}

type PullRequest struct {
Issue
Branch Branch
}

type Branch struct {
Name string
Status string
Mergeable bool
}
33 changes: 33 additions & 0 deletions model/tag.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package model

import (
log "github.com/Sirupsen/logrus"
"github.com/hashicorp/go-version"
)

type Tag string

type TagList []Tag

func (tl TagList) GetMaxTag() (Tag, *version.Version) {
//find the previous largest semver value
var maxVer *version.Version
var maxTag Tag

for _, tag := range tl {
curVer, err := version.NewVersion(string(tag))
if err != nil {
continue
}
if maxVer == nil || curVer.GreaterThan(maxVer) {
maxVer = curVer
maxTag = tag
}
}

if maxVer == nil {
maxVer, _ = version.NewVersion("v0.0.0")
}
log.Debugf("maxVer found is %s", maxVer.String())
return maxTag, maxVer
}
Loading