예제 #1
0
파일: repos.go 프로젝트: fclairamb/drone
// Repos is a middleware function that attempts to cache the
// user's list of remote repositories (ie in GitHub) to minimize
// remote calls that might be expensive, slow or rate-limited.
func Repos(c *gin.Context) {
	var user, _ = c.Get("user")

	if user == nil {
		c.Next()
		return
	}

	// if the item already exists in the cache
	// we can continue the middleware chain and
	// exit afterwards.
	v := cache.GetRepos(c, user.(*model.User))
	if v != nil {
		c.Set("repos", v)
		c.Next()
		return
	}

	// otherwise, if the item isn't cached we execute
	// the middleware chain and then cache the permissions
	// after the request is processed.
	c.Next()

	repos, ok := c.Get("repos")
	if ok {
		cache.SetRepos(c,
			user.(*model.User),
			repos.([]*model.RepoLite),
		)
	}
}
예제 #2
0
파일: pages.go 프로젝트: tnaoto/drone
func ShowIndex(c *gin.Context) {
	user := session.User(c)
	if user == nil {
		c.Redirect(http.StatusSeeOther, "/login")
		return
	}

	// get the repository list from the cache
	repos, err := cache.GetRepos(c, user)
	if err != nil {
		c.String(400, err.Error())
		return
	}

	// filter to only show the currently active ones
	activeRepos, err := store.GetRepoListOf(c, repos)
	if err != nil {
		c.String(400, err.Error())
		return
	}

	c.HTML(200, "index.html", gin.H{
		"User":  user,
		"Repos": activeRepos,
	})
}
예제 #3
0
파일: user.go 프로젝트: tnaoto/drone
func GetRemoteRepos(c *gin.Context) {
	repos, err := cache.GetRepos(c, session.User(c))
	if err != nil {
		c.String(500, "Error fetching repository list. %s", err)
		return
	}
	c.JSON(http.StatusOK, repos)
}
예제 #4
0
파일: user.go 프로젝트: clanstyles/drone
func GetRemoteRepos(c *gin.Context) {
	user := session.User(c)

	repos, err := cache.GetRepos(c, user)
	if err != nil {
		c.AbortWithStatus(http.StatusInternalServerError)
		return
	}

	c.IndentedJSON(http.StatusOK, repos)
}
예제 #5
0
파일: user.go 프로젝트: Ablu/drone
func GetRepos(c *gin.Context) {
	var (
		user     = session.User(c)
		all, _   = strconv.ParseBool(c.Query("all"))
		flush, _ = strconv.ParseBool(c.Query("flush"))
	)

	if flush {
		log.Debugf("Evicting repository cache for user %s.", user.Login)
		cache.DeleteRepos(c, user)
	}

	remote, err := cache.GetRepos(c, user)
	if err != nil {
		c.String(500, "Error fetching repository list. %s", err)
		return
	}

	repos, err := store.GetRepoListOf(c, remote)
	if err != nil {
		c.String(500, "Error fetching repository list. %s", err)
		return
	}

	if !all {
		c.JSON(http.StatusOK, repos)
		return
	}

	// below we combine the two lists to include both active and inactive
	// repositories. This is displayed on the settings screen to enable
	// toggling on / off repository settings.

	repom := map[string]bool{}
	for _, repo := range repos {
		repom[repo.FullName] = true
	}

	for _, repo := range remote {
		if repom[repo.FullName] {
			continue
		}
		repos = append(repos, &model.Repo{
			Avatar:   repo.Avatar,
			FullName: repo.FullName,
			Owner:    repo.Owner,
			Name:     repo.Name,
		})
	}
	c.JSON(http.StatusOK, repos)
}
예제 #6
0
파일: user.go 프로젝트: tnaoto/drone
func GetFeed(c *gin.Context) {
	repos, err := cache.GetRepos(c, session.User(c))
	if err != nil {
		c.String(500, "Error fetching repository list. %s", err)
		return
	}

	feed, err := store.GetUserFeed(c, repos)
	if err != nil {
		c.String(500, "Error fetching feed. %s", err)
		return
	}
	c.JSON(200, feed)
}
예제 #7
0
파일: user.go 프로젝트: Ablu/drone
func GetFeed(c *gin.Context) {
	latest, _ := strconv.ParseBool(c.Query("latest"))

	repos, err := cache.GetRepos(c, session.User(c))
	if err != nil {
		c.String(500, "Error fetching repository list. %s", err)
		return
	}

	feed, err := store.GetUserFeed(c, repos, latest)
	if err != nil {
		c.String(500, "Error fetching feed. %s", err)
		return
	}
	c.JSON(200, feed)
}
예제 #8
0
파일: user.go 프로젝트: clanstyles/drone
func GetFeed(c *gin.Context) {
	user := session.User(c)

	// get the repository list from the cache
	repos, err := cache.GetRepos(c, user)
	if err != nil {
		c.String(400, err.Error())
		return
	}

	feed, err := store.GetUserFeed(c, repos)
	if err != nil {
		c.String(400, err.Error())
		return
	}
	c.JSON(200, feed)
}
예제 #9
0
파일: pages.go 프로젝트: tnaoto/drone
func ShowAllRepos(c *gin.Context) {
	user := session.User(c)
	if user == nil {
		c.Redirect(http.StatusSeeOther, "/login")
		return
	}

	// get the repository list from the cache
	repos, err := cache.GetRepos(c, user)
	if err != nil {
		c.String(400, err.Error())
		return
	}

	c.HTML(200, "repos.html", gin.H{
		"User":  user,
		"Repos": repos,
	})
}
예제 #10
0
파일: user.go 프로젝트: clanstyles/drone
func GetRepos(c *gin.Context) {
	user := session.User(c)

	repos, err := cache.GetRepos(c, user)
	if err != nil {
		c.AbortWithStatus(http.StatusInternalServerError)
		return
	}

	// for each repository in the remote system we get
	// the intersection of those repostiories in Drone
	repos_, err := store.GetRepoListOf(c, repos)
	if err != nil {
		c.AbortWithStatus(http.StatusInternalServerError)
		return
	}

	c.IndentedJSON(http.StatusOK, repos_)
}