• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang github.GitHub类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/docker/leeroy/github.GitHub的典型用法代码示例。如果您正苦于以下问题:Golang GitHub类的具体用法?Golang GitHub怎么用?Golang GitHub使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了GitHub类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: handlePullRequestReviewComment

func handlePullRequestReviewComment(w http.ResponseWriter, r *http.Request) {
	hook, err := github.ParsePullRequestReviewCommentHook(r.Body)
	if err != nil {
		logrus.Error(err)
		w.WriteHeader(500)
		return
	}

	if !hook.IsOpen() {
		w.WriteHeader(200)
		return
	}

	g := github.GitHub{
		AuthToken: config.GHToken,
		User:      config.GHUser,
	}

	if err := g.MoveTriageForward(hook.Repo, hook.PullRequest.Number, hook.Comment); err != nil {
		logrus.Error(err)
		w.WriteHeader(500)
		return
	}

	w.WriteHeader(204)
	return
}
开发者ID:KrunoKnego,项目名称:leeroy,代码行数:27,代码来源:handlers.go


示例2: removeFailedBuildComment

func (c Config) removeFailedBuildComment(repoName, job string, pr int) error {
	// parse git repo for username
	// and repo name
	r := strings.SplitN(repoName, "/", 2)
	if len(r) < 2 {
		return fmt.Errorf("repo name could not be parsed: %s", repoName)
	}

	// initialize github client
	g := github.GitHub{
		AuthToken: c.GHToken,
		User:      c.GHUser,
	}
	repo := octokat.Repo{
		Name:     r[1],
		UserName: r[0],
	}

	content, err := g.GetContent(repo, pr, true)
	if err != nil {
		return fmt.Errorf("getting pull request content failed: %v", err)
	}

	// find the comments about failed builds and remove them
	if comment := content.FindComment(fmt.Sprintf("Job: %s [FAILED", job), c.GHUser); comment != nil {
		if err := g.Client().RemoveComment(repo, comment.Id); err != nil {
			return fmt.Errorf("removing comment from %s#%d for %s failed: %v", repoName, pr, job, err)
		}
	}

	return nil
}
开发者ID:vdemeester,项目名称:leeroy,代码行数:32,代码来源:utils.go


示例3: handlePullRequest

func handlePullRequest(w http.ResponseWriter, r *http.Request) {
	logrus.Debugf("Got a pull request hook")

	// parse the pull request
	body, err := ioutil.ReadAll(r.Body)
	if err != nil {
		logrus.Errorf("Error reading github pull request handler body: %v", err)
		w.WriteHeader(500)
		return
	}

	prHook, err := octokat.ParsePullRequestHook(body)
	if err != nil {
		logrus.Errorf("Error parsing pull request hook: %v", err)
		w.WriteHeader(500)
		return
	}

	pr := prHook.PullRequest
	baseRepo := fmt.Sprintf("%s/%s", pr.Base.Repo.Owner.Login, pr.Base.Repo.Name)

	logrus.Infof("Received GitHub pull request notification for %s %d (%s): %s", baseRepo, pr.Number, pr.URL, prHook.Action)

	// ignore everything we don't care about
	if prHook.Action != "opened" && prHook.Action != "reopened" && prHook.Action != "synchronize" {
		logrus.Debugf("Ignoring PR hook action %q", prHook.Action)
		return
	}

	g := github.GitHub{
		AuthToken: config.GHToken,
		User:      config.GHUser,
	}

	pullRequest, err := g.LoadPullRequest(prHook)
	if err != nil {
		logrus.Errorf("Error loading the pull request: %v", err)
		w.WriteHeader(500)
		return
	}

	valid, err := g.DcoVerified(pullRequest)

	if err != nil {
		logrus.Errorf("Error validating DCO: %v", err)
		w.WriteHeader(500)
		return
	}

	// DCO not valid, we don't start the build
	if !valid {
		logrus.Errorf("Invalid DCO for %s #%d. Aborting build", baseRepo, pr.Number)
		w.WriteHeader(200)
		return
	}

	mergeable, err := g.IsMergeable(pullRequest)
	if err != nil {
		logrus.Errorf("Error checking if PR is mergeable: %v", err)
		w.WriteHeader(500)
		return
	}

	// PR is not mergeable, so don't start the build
	if !mergeable {
		logrus.Errorf("Unmergeable PR for %s #%d. Aborting build", baseRepo, pr.Number)
		w.WriteHeader(200)
		return
	}

	var builds []Build
	// Only run full jobs if there are code related changes
	if !pullRequest.Content.IsNonCodeOnly() {
		// get the builds
		var err error
		builds, err = config.getBuilds(baseRepo, false)
		if err != nil {
			logrus.Warn(err)
		}
	}

	// If there are doc-changes validate them
	if pullRequest.Content.HasDocsChanges() {
		build, err := config.getBuildByContextAndRepo("doc", baseRepo)
		if err != nil {
			logrus.Warnf("Adding doc build to %s for %d failed: %v", baseRepo, pr.Number, err)
		} else {
			builds = append(builds, build)
		}
	}

	// If there are vendoring changes validate them
	if pullRequest.Content.HasVendoringChanges() {
		build, err := config.getBuildByContextAndRepo("vendor", baseRepo)
		if err != nil {
			logrus.Warnf("Adding vendor build to %s for %d failed: %v", baseRepo, pr.Number, err)
		} else {
			builds = append(builds, build)
		}
	}
//.........这里部分代码省略.........
开发者ID:KrunoKnego,项目名称:leeroy,代码行数:101,代码来源:handlers.go


示例4: handleIssue

func handleIssue(w http.ResponseWriter, r *http.Request) {
	logrus.Debugf("Got an issue hook")

	// parse the issue
	body, err := ioutil.ReadAll(r.Body)
	if err != nil {
		logrus.Errorf("Error reading github issue handler body: %v", err)
		w.WriteHeader(500)
		return
	}

	issueHook, err := octokat.ParseIssueHook(body)
	if err != nil {
		logrus.Errorf("Error parsing issue hook: %v", err)
		w.WriteHeader(500)
		return
	}

	// get the build
	baseRepo := fmt.Sprintf("%s/%s", issueHook.Repo.Owner.Login, issueHook.Repo.Name)
	logrus.Debugf("Issue is for repo: %s", baseRepo)
	build, err := config.getBuildByContextAndRepo("janky", baseRepo)
	if err != nil {
		logrus.Warnf("could not find build for repo %s for issue handler, skipping: %v", baseRepo, err)
		return
	}

	// if we do not handle issues for this build just return
	if !build.HandleIssues {
		logrus.Warnf("Not configured to handle issues for %s", baseRepo)
		return
	}

	g := github.GitHub{
		AuthToken: config.GHToken,
		User:      config.GHUser,
	}

	logrus.Infof("Received GitHub issue notification for %s %d (%s): %s", baseRepo, issueHook.Issue.Number, issueHook.Issue.URL, issueHook.Action)

	// if it is not a comment or an opened issue
	// return becuase we dont care
	if !issueHook.IsComment() && !issueHook.IsOpened() {
		logrus.Debugf("Ignoring issue hook action %q", issueHook.Action)
		return
	}

	// if the issue has just been opened
	// parse if ENEEDMOREINFO
	if issueHook.IsOpened() {
		logrus.Debug("Issue is opened, checking if we have correct info")
		if err := g.IssueInfoCheck(issueHook); err != nil {
			logrus.Errorf("Error checking if issue opened needs more info: %v", err)
			w.WriteHeader(500)
			return
		}

		w.WriteHeader(200)
		return
	}

	if issueHook.Issue.State != "open" {
		return
	}

	if issueHook.Issue.PullRequest.HTMLURL != "" {
		if err := g.MoveTriageForward(issueHook.Repo, issueHook.Issue.Number, issueHook.Comment); err != nil {
			logrus.Error(err)
			w.WriteHeader(500)
			return
		}

		w.WriteHeader(204)
		return
	}

	// handle if it is an issue comment
	// apply approproate labels
	if err := g.LabelIssueComment(issueHook); err != nil {
		logrus.Errorf("Error applying labels to issue comment: %v", err)
		w.WriteHeader(500)
		return
	}

	return
}
开发者ID:KrunoKnego,项目名称:leeroy,代码行数:86,代码来源:handlers.go


示例5: handlePullRequest

func handlePullRequest(w http.ResponseWriter, r *http.Request) {
	log.Debugf("Got a pull request hook")

	// parse the pull request
	body, err := ioutil.ReadAll(r.Body)
	if err != nil {
		log.Errorf("Error reading github pull request handler body: %v", err)
		w.WriteHeader(500)
		return
	}

	prHook, err := octokat.ParsePullRequestHook(body)
	if err != nil {
		log.Errorf("Error parsing pull request hook: %v", err)
		w.WriteHeader(500)
		return
	}

	pr := prHook.PullRequest
	baseRepo := fmt.Sprintf("%s/%s", pr.Base.Repo.Owner.Login, pr.Base.Repo.Name)

	log.Infof("Received GitHub pull request notification for %s %d (%s): %s", baseRepo, pr.Number, pr.URL, prHook.Action)

	// ignore everything we don't care about
	if prHook.Action != "opened" && prHook.Action != "reopened" && prHook.Action != "synchronize" {
		log.Debugf("Ignoring PR hook action %q", prHook.Action)
		return
	}

	g := github.GitHub{
		AuthToken: config.GHToken,
		User:      config.GHUser,
	}

	pullRequest, err := g.LoadPullRequest(prHook)
	if err != nil {
		log.Errorf("Error loading the pull request: %v", err)
		w.WriteHeader(500)
		return
	}

	valid, err := g.DcoVerified(pullRequest)

	if err != nil {
		log.Errorf("Error validating DCO: %v", err)
		w.WriteHeader(500)
		return
	}

	// DCO not valid, we don't start the build
	if !valid {
		log.Errorf("Invalid DCO for %s #%d. Aborting build", baseRepo, pr.Number)
		w.WriteHeader(200)
		return
	}

	mergeable, err := g.IsMergeable(pullRequest)
	if err != nil {
		log.Errorf("Error checking if PR is mergeable: %v", err)
		w.WriteHeader(500)
		return
	}

	// PR is not mergeable, so don't start the build
	if !mergeable {
		log.Errorf("Unmergeable PR for %s #%d. Aborting build", baseRepo, pr.Number)
		w.WriteHeader(200)
		return
	}

	// Only docs, don't start jenkins jobs
	if pullRequest.Content.IsDocsOnly() {
		w.WriteHeader(200)
		return
	}

	// get the builds
	builds, err := config.getBuilds(baseRepo, false)
	if err != nil {
		log.Error(err)
		w.WriteHeader(500)
		return
	}

	// schedule the jenkins builds
	for _, build := range builds {
		if err := config.scheduleJenkinsBuild(baseRepo, pr.Number, build); err != nil {
			log.Error(err)
			w.WriteHeader(500)
		}
	}

	return
}
开发者ID:RDurgaPrasad,项目名称:leeroy,代码行数:94,代码来源:handlers.go



注:本文中的github.com/docker/leeroy/github.GitHub类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang libchan.Pipe函数代码示例发布时间:2022-05-23
下一篇:
Golang gordon.Fatalf函数代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap