Skip to content

Commit

Permalink
feat: add more details in the table
Browse files Browse the repository at this point in the history
  • Loading branch information
moul committed Nov 22, 2018
1 parent 38d3c5e commit 7e5c501
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 17 deletions.
31 changes: 18 additions & 13 deletions server/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,9 @@ func (s *Server) ListReleaseIOS(c echo.Context) error {
continue
}

//out, _ := json.MarshalIndent(build, "", " ")
//fmt.Println(string(out))

updateTime := build.StartTime
if build.StopTime != nil {
updateTime = build.StopTime
Expand All @@ -198,27 +201,30 @@ func (s *Server) ListReleaseIOS(c echo.Context) error {

previousDate = currentDate

branchLink := fmt.Sprintf("https://github.com/berty/berty/tree/%s", build.Branch)
branchURL := fmt.Sprintf("https://github.com/berty/berty/tree/%s", build.Branch)
if strings.HasPrefix(build.Branch, "pull/") {
branchLink = fmt.Sprintf("https://github.com/berty/berty/%s", build.Branch)
branchURL = fmt.Sprintf("https://github.com/berty/berty/%s", build.Branch)
}

prBranch := build.Branch
branchName := build.Branch
hover := ""
subject := build.Subject
if build.Branch == "master" {
matches := masterMerge.FindAllStringSubmatch(build.Subject, -1)
if len(matches) == 1 && len(matches[0]) == 3 {
subject = matches[0][2]
pr := matches[0][1]
prBranch = "pull/" + pr
oncePerBranch[prBranch] = true
branchName = fmt.Sprintf("%s (%s)", build.Branch, pr)
hover = matches[0][2]
branchLink = "https://github.com/berty/berty/pull/" + pr
branchURL = "https://github.com/berty/berty/pull/" + pr
}

}
token := s.getHash(prBranch)
if subject == "" {
subject = "n/a"
}

//out, _ := json.Marshal(build)
//fmt.Println(string(out))
Expand Down Expand Up @@ -251,15 +257,14 @@ func (s *Server) ListReleaseIOS(c echo.Context) error {
durafmt.ParseShort(time.Duration(*build.BuildTimeMillis)*time.Millisecond),
)
}
commitLink := fmt.Sprintf(`<a href="https://github.com/berty/berty/commit/%s">%s</a>`, build.VcsRevision, build.VcsRevision[:8])
branchLink := fmt.Sprintf(`<a href="%s">%s</a>`, branchURL, branchName)
buildLink := fmt.Sprintf(`<a href="%s">%d</a>`, build.BuildURL, build.BuildNum)
age := durafmt.ParseShort(time.Since(*updateTime))

elems := []string{
fmt.Sprintf(`<td class="td-title"><a href="%s" title="%s">%s</a><br />%s</td>`, branchLink, hover, branchName, build.User.Login),
fmt.Sprintf(`<td class="td-build"><a href="%s">%d</a><br />%s ago %s</td>`,
build.BuildURL,
build.BuildNum,
durafmt.ParseShort(time.Since(*updateTime)),
duration,
),
//status,
fmt.Sprintf(`<td class="td-title">%s<br/>%s</td>`, branchLink, build.User.Login),
fmt.Sprintf(`<td class="td-build">%s %s<br />%s %s %s</td>`, commitLink, subject, buildLink, age, duration),
fmt.Sprintf(`<td class="td-diff">%s</td>`, diff),
fmt.Sprintf(`<td class="td-download"><a class="btn" href="itms-services://?action=download-manifest&url=https://%s/itms/release/%s/%[3]s">%s</a></td>`, s.hostname, token, prBranch, dlIcon),
// FIXME: create a link /itms/release/TOKEN/ID instead of /itms/release/TOKEN/BRANCH (this way we can handle multiple artifacts per branch)
Expand Down
12 changes: 8 additions & 4 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ func (s *Server) refreshCache() error {
)

if s.cache.mostRecentBuild.IsZero() { // first fill
log.Print("fetch all builds")
log.Print("initial builds fetch")
for page := 0; page < 20; page++ {
builds, err := s.client.Builds("", "", 100, page*100)
if err != nil {
Expand All @@ -191,16 +191,19 @@ func (s *Server) refreshCache() error {
if len(builds) < 100 {
break
}
buildMapMutex.Lock()
s.cache.builds = allBuilds
buildMapMutex.Unlock()
}
log.Printf("fetched %d initial builds", len(s.cache.builds))
} else { // just the difference
allBuilds = s.cache.builds
previousMostRecentBuild := mostRecentBuild
builds, err := s.client.Builds("", "", 100, 0)
if err != nil {
return err
}
hasChanged := false
changed := 0
for i := len(builds) - 1; i >= 0; i-- {
build := builds[i]
if build.StartTime == nil && build.StopTime == nil {
Expand All @@ -215,12 +218,13 @@ func (s *Server) refreshCache() error {
}
if updateTime.After(previousMostRecentBuild) {
allBuilds[build.BuildNum] = build
hasChanged = true
changed++
}
}
if !hasChanged {
if changed == 0 {
return nil
}
log.Printf("fetched %d new builds", changed)
}

buildMapMutex.Lock()
Expand Down

0 comments on commit 7e5c501

Please sign in to comment.