Exemple #1
0
func GetRepos(c *gin.Context) {
	user := session.User(c)
	remote := remote.FromContext(c)
	var repos []*model.RepoLite

	// get the repository list from the cache
	reposv, ok := c.Get("repos")
	if ok {
		repos = reposv.([]*model.RepoLite)
	} else {
		var err error
		repos, err = remote.Repos(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.Set("repos", repos)
	c.IndentedJSON(http.StatusOK, repos_)
}
Exemple #2
0
func GetFeed(c *gin.Context) {
	user := session.User(c)
	remote := remote.FromContext(c)
	var repos []*model.RepoLite

	// get the repository list from the cache
	reposv, ok := c.Get("repos")
	if ok {
		repos = reposv.([]*model.RepoLite)
	} else {
		var err error
		repos, err = remote.Repos(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)
}
Exemple #3
0
// GetRepos returns the list of user repositories from the cache
// associated with the current context.
func GetRepos(c context.Context, user *model.User) ([]*model.RepoLite, error) {
	key := fmt.Sprintf("repos:%s",
		user.Login,
	)
	// if we fetch from the cache we can return immediately
	val, err := Get(c, key)
	if err == nil {
		return val.([]*model.RepoLite), nil
	}
	// else we try to grab from the remote system and
	// populate our cache.
	repos, err := remote.Repos(c, user)
	if err != nil {
		return nil, err
	}

	Set(c, key, repos)
	return repos, nil
}
Exemple #4
0
func GetRemoteRepos(c *gin.Context) {
	user := session.User(c)
	remote := remote.FromContext(c)

	reposv, ok := c.Get("repos")
	if ok {
		c.IndentedJSON(http.StatusOK, reposv)
		return
	}

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

	c.Set("repos", repos)
	c.IndentedJSON(http.StatusOK, repos)
}
Exemple #5
0
func ShowIndex(c *gin.Context) {
	remote := remote.FromContext(c)
	user := session.User(c)
	if user == nil {
		c.Redirect(http.StatusSeeOther, "/login")
		return
	}

	var err error
	var repos []*model.RepoLite

	// get the repository list from the cache
	reposv, ok := c.Get("repos")
	if ok {
		repos = reposv.([]*model.RepoLite)
	} else {
		repos, err = remote.Repos(user)
		if err != nil {
			log.Errorf("Failure to get remote repositories for %s. %s.",
				user.Login, err)
		} else {
			c.Set("repos", repos)
		}
	}

	// 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 {
		log.Errorf("Failure to get repository list for %s. %s.",
			user.Login, err)
	}

	c.HTML(200, "repos.html", gin.H{
		"User":  user,
		"Repos": repos_,
	})
}