我正在尝试在提交后在一个或多个文件中创建一个或多个注释。
我现在执行POST请求的方式是通过PR的编号,传递正文,commit_id,路径和位置。并且它可以很好地对PR的编号进行硬编码,因为当我通过webhook发送PUSH事件时,我有一个commit_id,它在有效负载中返回。
如果我对https://api.github.com/repos/author/repo/pulls/number/comments
发出POST请求,它会根据需要在特定行内成功创建注释。但是我必须事先知道他们的PR号码。
问题是,如果我有commit_id或在有效载荷中收到的其他push事件,是否可以获取PR号?
当前有效负载如下:
{"ref"=>"refs/heads/third",
"before"=>"0000000000000000000000000000000000000000",
"after"=>"0000000000000000000000000000000000000001",
"created"=>true,
"deleted"=>false,
"forced"=>false,
"base_ref"=>nil,
"compare"=>"https://github.com/author/repo/commit/831a7cb888ab",
"commits"=>
[{"id"=>"0000000000000000000000000000000000000001",
"tree_id"=>"tree_id",
"distinct"=>true,
"message"=>"message",
"timestamp"=>"2018-08-12T03:22:31-03:00",
"url"=>"https://github.com/author/repo/commit/0000000000000000000000000000000000000001",
"author"=>{"name"=>"author_name", "email"=>"", "username"=>"author"},
"committer"=>{"name"=>"author_name", "email"=>"", "username"=>"author"},
"added"=>["filename"],
"removed"=>[],
"modified"=>[]}],
"head_commit"=>
{"id"=>"0000000000000000000000000000000000000001",
"tree_id"=>"tree_id",
"distinct"=>true,
"message"=>"#1",
"timestamp"=>"2018-08-12T03:22:31-03:00",
"url"=>"https://github.com/author/repo/commit/0000000000000000000000000000000000000001",
"author"=>{"name"=>"author_name", "email"=>"", "username"=>"author"},
"committer"=>{"name"=>"author_name", "email"=>"", "username"=>"author"},
"added"=>["filename"],
"removed"=>[],
"modified"=>[]},
"repository"=>
{"id"=>repository_id,
"node_id"=>"node_id==",
"name"=>"repo",
"full_name"=>"author/repo",
"owner"=>
{"name"=>"author",
"email"=>"",
"login"=>"author",
"id"=>id,
"node_id"=>"MDQ6VXNlcjExODg4MTkx",
"avatar_url"=>"https://avatars2.githubusercontent.com/u/id?v=4",
"gravatar_id"=>"",
"url"=>"https://api.github.com/users/author",
"html_url"=>"https://github.com/author",
"followers_url"=>"https://api.github.com/users/author/followers",
"following_url"=>"https://api.github.com/users/author/following{/other_user}",
"gists_url"=>"https://api.github.com/users/author/gists{/gist_id}",
"starred_url"=>"https://api.github.com/users/author/starred{/owner}{/repo}",
"subscriptions_url"=>"https://api.github.com/users/author/subscriptions",
"organizations_url"=>"https://api.github.com/users/author/orgs",
"repos_url"=>"https://api.github.com/users/author/repos",
"events_url"=>"https://api.github.com/users/author/events{/privacy}",
"received_events_url"=>"https://api.github.com/users/author/received_events",
"type"=>"User",
"site_admin"=>false},
"private"=>true,
"html_url"=>"https://github.com/author/repo",
"description"=>nil,
"fork"=>false,
"url"=>"https://github.com/author/repo",
"forks_url"=>"https://api.github.com/repos/author/repo/forks",
"keys_url"=>"https://api.github.com/repos/author/repo/keys{/key_id}",
"collaborators_url"=>"https://api.github.com/repos/author/repo/collaborators{/collaborator}",
"teams_url"=>"https://api.github.com/repos/author/repo/teams",
"hooks_url"=>"https://api.github.com/repos/author/repo/hooks",
"issue_events_url"=>"https://api.github.com/repos/author/repo/issues/events{/number}",
"events_url"=>"https://api.github.com/repos/author/repo/events",
"assignees_url"=>"https://api.github.com/repos/author/repo/assignees{/user}",
"branches_url"=>"https://api.github.com/repos/author/repo/branches{/branch}",
"tags_url"=>"https://api.github.com/repos/author/repo/tags",
"blobs_url"=>"https://api.github.com/repos/author/repo/git/blobs{/sha}",
"git_tags_url"=>"https://api.github.com/repos/author/repo/git/tags{/sha}",
"git_refs_url"=>"https://api.github.com/repos/author/repo/git/refs{/sha}",
"trees_url"=>"https://api.github.com/repos/author/repo/git/trees{/sha}",
"statuses_url"=>"https://api.github.com/repos/author/repo/statuses/{sha}",
"languages_url"=>"https://api.github.com/repos/author/repo/languages",
"stargazers_url"=>"https://api.github.com/repos/author/repo/stargazers",
"contributors_url"=>"https://api.github.com/repos/author/repo/contributors",
"subscribers_url"=>"https://api.github.com/repos/author/repo/subscribers",
"subscription_url"=>"https://api.github.com/repos/author/repo/subscription",
"commits_url"=>"https://api.github.com/repos/author/repo/commits{/sha}",
"git_commits_url"=>"https://api.github.com/repos/author/repo/git/commits{/sha}",
"comments_url"=>"https://api.github.com/repos/author/repo/comments{/number}",
"issue_comment_url"=>"https://api.github.com/repos/author/repo/issues/comments{/number}",
"contents_url"=>"https://api.github.com/repos/author/repo/contents/{+path}",
"compare_url"=>"https://api.github.com/repos/author/repo/compare/{base}...{head}",
"merges_url"=>"https://api.github.com/repos/author/repo/merges",
"archive_url"=>"https://api.github.com/repos/author/repo/{archive_format}{/ref}",
"downloads_url"=>"https://api.github.com/repos/author/repo/downloads",
"issues_url"=>"https://api.github.com/repos/author/repo/issues{/number}",
"pulls_url"=>"https://api.github.com/repos/author/repo/pulls{/number}",
"milestones_url"=>"https://api.github.com/repos/author/repo/milestones{/number}",
"notifications_url"=>"https://api.github.com/repos/author/repo/notifications{?since,all,participating}",
"labels_url"=>"https://api.github.com/repos/author/repo/labels{/name}",
"releases_url"=>"https://api.github.com/repos/author/repo/releases{/id}",
"deployments_url"=>"https://api.github.com/repos/author/repo/deployments",
"created_at"=>1501475657,
"updated_at"=>"2018-07-17T01:30:41Z",
"pushed_at"=>1534054956,
"git_url"=>"git://github.com/author/repo.git",
"ssh_url"=>"git@github.com:author/repo.git",
"clone_url"=>"https://github.com/author/repo.git",
"svn_url"=>"https://github.com/author/repo",
"homepage"=>nil,
"size"=>55534,
"stargazers_count"=>0,
"watchers_count"=>0,
"language"=>"JavaScript",
"has_issues"=>true,
"has_projects"=>true,
"has_downloads"=>true,
"has_wiki"=>true,
"has_pages"=>false,
"forks_count"=>0,
"mirror_url"=>nil,
"archived"=>false,
"open_issues_count"=>0,
"license"=>nil,
"forks"=>0,
"open_issues"=>0,
"watchers"=>0,
"default_branch"=>"master",
"stargazers"=>0,
"master_branch"=>"master"},
"pusher"=>{"name"=>"author", "email"=>""},
"sender"=>
{"login"=>"author",
"id"=>id,
"node_id"=>"MDQ6VXNlcjExODg4MTkx",
"avatar_url"=>"https://avatars2.githubusercontent.com/u/id?v=4",
"gravatar_id"=>"",
"url"=>"https://api.github.com/users/author",
"html_url"=>"https://github.com/author",
"followers_url"=>"https://api.github.com/users/author/followers",
"following_url"=>"https://api.github.com/users/author/following{/other_user}",
"gists_url"=>"https://api.github.com/users/author/gists{/gist_id}",
"starred_url"=>"https://api.github.com/users/author/starred{/owner}{/repo}",
"subscriptions_url"=>"https://api.github.com/users/author/subscriptions",
"organizations_url"=>"https://api.github.com/users/author/orgs",
"repos_url"=>"https://api.github.com/users/author/repos",
"events_url"=>"https://api.github.com/users/author/events{/privacy}",
"received_events_url"=>"https://api.github.com/users/author/received_events",
"type"=>"User",
"site_admin"=>false},
"installation"=>{"id"=>installation_id}}
请求的主体非常简单,看起来像:
{
"body": "body message",
"commit_id": "commit_id",
"path": "file",
"position": position_as_integer
}