Skip to content

Commit

Permalink
feat(yolo): Add osx release page staff/yolo
Browse files Browse the repository at this point in the history
  • Loading branch information
gfanton committed Apr 30, 2019
1 parent 61fdf3a commit be0027a
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 20 deletions.
86 changes: 75 additions & 11 deletions server/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ const (
IOS_STAFF_JOB = "client.rn.ios"
IOS_YOLO_JOB = "client.rn.ios-beta"
MAC_STAFF_JOB = "client.rn.mac"
MAC_YOLO_JOB = "client.rn.mac-beta"
ANDROID_STAFF_JOB = "client.rn.android"
ANDROID_YOLO_JOB = "client.rn.android-beta"
SLACK_WEBHOOK_URL = "https://hooks.slack.com/services/T2AJ2MM5Z/BFX8ZASKW/***REMOVED***"
Expand Down Expand Up @@ -278,6 +279,10 @@ func (s *Server) ListReleaseDMGJson(c echo.Context) error {
return s.ListReleaseJson(c, MAC_STAFF_JOB)
}

func (s *Server) ListReleaseDMGBetaJson(c echo.Context) error {
return s.ListReleaseJson(c, MAC_YOLO_JOB)
}

func (s *Server) ListReleaseIOSJson(c echo.Context) error {
return s.ListReleaseJson(c, IOS_STAFF_JOB)
}
Expand Down Expand Up @@ -322,7 +327,7 @@ func (s *Server) ListReleaseJson(c echo.Context, job string) error {
id := strconv.Itoa(build.BuildNum)
androidToken := s.getHash(id)
href = fmt.Sprintf(`%s/auth/apk/build/%s/%s`, s.hostUrl, androidToken, id)
case MAC_STAFF_JOB:
case MAC_STAFF_JOB, MAC_YOLO_JOB:
id := strconv.Itoa(build.BuildNum)
href = fmt.Sprintf(`%s/auth/dmg/build/%s/%s`, s.hostUrl, s.getHash(id), id)
default:
Expand All @@ -339,6 +344,7 @@ func (s *Server) ListReleaseJson(c echo.Context, job string) error {
ManifestURL: href,
}
}

for _, build := range s.cache.builds.Sorted() {
if build.BuildParameters["CIRCLE_JOB"] != job {
continue
Expand All @@ -352,22 +358,32 @@ func (s *Server) ListReleaseJson(c echo.Context, job string) error {
//out, _ := json.MarshalIndent(build, "", " ")
//fmt.Println(string(out))
oncePerBranch[build.Branch] = true

if build.Branch == "master" {
ret.Master = releaseFromBuild(build)
} else {
ret.LatestPRs = append(ret.LatestPRs, releaseFromBuild(build))
if len(ret.LatestPRs) > 5 {
break
}
break // we got what we want, exit
}

// skip these until we add some protection on json handler

// else {
// ret.LatestPRs = append(ret.LatestPRs, releaseFromBuild(build))
// if len(ret.LatestPRs) > 5 {
// break
// }
// }
}
return c.JSON(http.StatusOK, ret)
}

func (s *Server) ListReleaseDmg(c echo.Context) error {
func (s *Server) ListReleaseDMG(c echo.Context) error {
return s.ListRelease(c, MAC_STAFF_JOB)
}

func (s *Server) ListReleaseDMGBeta(c echo.Context) error {
return s.ListRelease(c, MAC_YOLO_JOB)
}

func (s *Server) ListReleaseAndroid(c echo.Context) error {
return s.ListRelease(c, ANDROID_STAFF_JOB)
}
Expand Down Expand Up @@ -400,14 +416,19 @@ func (s *Server) TVDash(c echo.Context) error {
if data["ios_yolo"], err = s.GetReleasesByDate(c, IOS_YOLO_JOB); err != nil {
return err
}
if data["mac_yolo"], err = s.GetReleasesByDate(c, MAC_STAFF_JOB); err != nil {
if data["mac_staff"], err = s.GetReleasesByDate(c, MAC_STAFF_JOB); err != nil {
return err
}
if data["mac_yolo"], err = s.GetReleasesByDate(c, MAC_YOLO_JOB); err != nil {
return err
}

data["android_staff_job"] = ANDROID_STAFF_JOB
data["android_yolo_job"] = ANDROID_YOLO_JOB
data["ios_staff_job"] = IOS_STAFF_JOB
data["ios_yolo_job"] = IOS_YOLO_JOB
data["mac_job"] = MAC_STAFF_JOB
data["mac_staff_job"] = MAC_STAFF_JOB
data["mac_yolo_job"] = MAC_YOLO_JOB

return c.Render(http.StatusOK, "tv-dash.tmpl", data)
}
Expand All @@ -427,13 +448,39 @@ type ReleaseEntry struct {
HREF string
}

type ReleasesByDate []ReleasesDay

type ReleasesDay struct {
Date string
Releases []ReleaseEntry
}

func (rd *ReleasesDay) FilterByBranch(branch string) *ReleasesDay {
filtered := make([]ReleaseEntry, 0)
for _, entry := range rd.Releases {
if entry.BranchKind == branch {
filtered = append(filtered, entry)
}
}

return &ReleasesDay{
Date: rd.Date,
Releases: filtered,
}
}

type ReleasesByDate []ReleasesDay

func (r *ReleasesByDate) FilterByBranch(branch string) *ReleasesByDate {
filtered := make(ReleasesByDate, 0)
for _, release := range *r {
rf := release.FilterByBranch(branch)
if len(rf.Releases) != 0 {
filtered = append(filtered, *rf)
}
}

return &filtered
}

func (s *Server) ga(c echo.Context, event interface{}) {
if s.NoGa {
return
Expand Down Expand Up @@ -488,6 +535,23 @@ func (s *Server) ListRelease(c echo.Context, job string) error {
return c.Render(http.StatusOK, "release-list.tmpl", data)
}

func (s *Server) ListReleaseByBranch(c echo.Context, job string, branch string) error {
s.ga(c, ga.NewPageview())
s.sendUserActionToSlack(c, fmt.Sprintf("List Releases (%s)", job), "#00ffff", "#yolologs", "#yolodebug")

data := map[string]interface{}{}

releases, err := s.GetReleasesByDate(c, job)
if err != nil {
return err
}

data["ReleasesByDate"] = releases.FilterByBranch(branch)
data["job"] = job

return c.Render(http.StatusOK, "release-list.tmpl", data)
}

func (s *Server) GetReleasesByDate(c echo.Context, job string) (*ReleasesByDate, error) {
s.ga(c, ga.NewPageview())
releasesByDateMap := map[string][]ReleaseEntry{}
Expand Down
10 changes: 5 additions & 5 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ func NewServer(cfg *ServerConfig) (*Server, error) {

release.GET("/ios", s.ListReleaseIOSBeta)
release.GET("/android", s.ListReleaseAndroidBeta)
release.GET("/mac", s.ListReleaseDMGBeta)

release.GET("/ios-staff.json", s.ListReleaseIOSJson)
release.GET("/ios.json", s.ListReleaseIOSBetaJson)
Expand Down Expand Up @@ -225,15 +226,14 @@ func NewServer(cfg *ServerConfig) (*Server, error) {
}))
staffRelease.GET("/ios/*", s.ReleaseIOS)
staffRelease.GET("/ios", s.ListReleaseIOS)
staffRelease.GET("/mac", s.ListReleaseDmg)
staffRelease.GET("/mac", s.ListReleaseDMG)
staffRelease.GET("/android", s.ListReleaseAndroid)
staffRelease.GET("/tv", s.TVDash)

auth := e.Group("/auth")
if cfg.Password != "" {
tokenPaths := regexp.MustCompile("^/auth/ipa/build/.+$|^/auth/dmg/build/.+$|^/auth/apk/build/.+$|^/auth/itms/release/.+$")
auth.Use((s.basicAuth(cfg.Username, cfg.Password, tokenPaths)))
}
tokenPaths := regexp.MustCompile("^/auth/ipa/build/.+$|^/auth/dmg/build/.+$|^/auth/apk/build/.+$|^/auth/itms/release/.+$")
auth.Use((s.basicAuth(cfg.Username, cfg.Password, tokenPaths)))

auth.GET("/build/:build_id", s.Build)
auth.GET("/builds/*", s.Builds)
auth.GET("/artifacts/:build_id", s.Artifacts)
Expand Down
6 changes: 3 additions & 3 deletions server/templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,16 @@ func (s *Server) getFuncmap() *ctxFuncmap {
return "ios"
case ANDROID_STAFF_JOB, ANDROID_YOLO_JOB:
return "android"
case MAC_STAFF_JOB:
case MAC_STAFF_JOB, MAC_YOLO_JOB:
return "mac"
}
return "other"
}
f.fm["jobToKind"] = func(job string) string {
switch job {
case IOS_STAFF_JOB, MAC_STAFF_JOB, ANDROID_STAFF_JOB:
case IOS_STAFF_JOB, ANDROID_STAFF_JOB, MAC_STAFF_JOB:
return "staff"
case IOS_YOLO_JOB, ANDROID_YOLO_JOB:
case IOS_YOLO_JOB, ANDROID_YOLO_JOB, MAC_YOLO_JOB:
return "yolo"
}
return "other"
Expand Down
2 changes: 1 addition & 1 deletion templates/tv-dash.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<div class="tv-col">
<div class="tv-col-inner">
{{block "tv-head-partial" (dict "platform" "mac" "version" "staff") }}{{end}}
{{block "release-list-partial" (dict "dates" .mac_yolo "job" .mac_yolo_job) }}{{end}}
{{block "release-list-partial" (dict "dates" .mac_staff "job" .mac_staff_job) }}{{end}}
</div>
</div><!-- /.tv-col -->
<div class="tv-col">
Expand Down

0 comments on commit be0027a

Please sign in to comment.