예제 #1
0
func FetchRepository(user string, repo string) Repository {
	var review Review
	key := "github-" + user + "-" + repo
	err, found := cache.Get(key, &review)

	r := Repository{Description: "", Name: repo, User: user}

	if err != nil || !found {
		return r
	}

	r.Review = &review
	return r
}
예제 #2
0
func (c App) ReportCard(user string, repo string) revel.Result {
	title := user + "/" + repo + "'s Report Card - Rotten Repositories"
	key := "github-" + user + "-" + repo
	partial := c.Request.Header.Get("X-PJAX") != ""

	// Create a review channel
	var review Review

	err, found := cache.Get(key, &review)

	if err != nil {
		return c.RenderError(err)
	}

	missing := !found

	if !found && partial {

		checks := make(chan Check)
		base := "https://api.github.com"

		go func() {
			repo_url := fmt.Sprintf("%s/repos/%s/%s", base, user, repo)
			resp, err := http.Get(repo_url)

			if err != nil {
				checks <- Check{Passed: false, Comment: "GitHub Error :("}
				return
			}

			log.Println(resp.StatusCode)

			if resp.StatusCode != 200 {
				checks <- Check{Passed: false, Comment: "Repository doesn't exist"}
				return
			}

			checks <- Check{Passed: true, Comment: "Repository exists"}
			return
		}()

		// Check for LICENSE
		go func() {
			if FindFiles(user, repo, "LICENSE", "LICENSE.txt") {
				checks <- Check{Passed: true, Comment: "LICENSE in repository"}
			} else {
				checks <- Check{Passed: false, Comment: "No LICENSE in repository"}
			}
		}()

		// Check for README
		go func() {
			readme_url := fmt.Sprintf("%s/repos/%s/%s/readme", base, user, repo)
			resp, err := http.Get(readme_url)

			if err != nil {
				checks <- Check{Passed: false, Comment: "GitHub error :("}
				return
			}

			log.Println(resp.StatusCode)

			if resp.StatusCode != 200 {
				checks <- Check{Passed: false, Comment: "No README in repository"}
				return
			}

			checks <- Check{Passed: true, Comment: "README in repository"}
		}()

		for i := 0; i < 3; i++ {
			review.Checks = append(review.Checks, <-checks)
		}

		go cache.Set(key, review, 24*time.Hour)
	}

	return c.Render(user, repo, title, partial, review, missing)
}