Ejemplo n.º 1
0
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,
	})
}
Ejemplo n.º 2
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_)
}
Ejemplo n.º 3
0
Archivo: user.go Proyecto: 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)
}
Ejemplo n.º 4
0
Archivo: user.go Proyecto: tnaoto/drone
func GetRepos(c *gin.Context) {
	repos, err := cache.GetRepos(c, session.User(c))
	if err != nil {
		c.String(500, "Error fetching repository list. %s", err)
		return
	}

	repos_, err := store.GetRepoListOf(c, repos)
	if err != nil {
		c.String(500, "Error fetching repository list. %s", err)
		return
	}
	c.JSON(http.StatusOK, repos_)
}
Ejemplo n.º 5
0
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_)
}
Ejemplo n.º 6
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_,
	})
}