GitHub Action:如何检查公关创建者是否是特定团队的一部分?
我想运行一个github动作,该动作检查公关创建者是否是Github团队“我的酷团队”的成员,如果是这样,请做某事。
我很难理解如何利用octokit
团队端点“获得用户的团队成员资格” https://octokit.github.io/rest.js/v18#teams
文档解释了 https://docs.github.com/en/rest/rest/teams/members#get-team -Membership-for-a-user
如果
{
"url": "https://api.github.com/teams/1/memberships/octocat",
"role": "maintainer",
"state": "active"
}
用户在团队中,否则它将返回404,我也不知道该如何处理?
这就是我写的:
on: pull_request_target
jobs:
my_job:
runs-on: ubuntu-latest
steps:
- uses: actions/github-script@v6
with:
script: |
// If user is member of my_team team do nothing else do something
// See: https://octokit.github.io/rest.js/v18#teams
const creator = context.payload.sender.login
const opts = github.rest.teams.getMembershipForUserInOrg.endpoint.merge({
org: 'my_org',
team_slug: 'My cool Team',
username: ???? #How do I get the username of who opened the PR?
})
const response = await github.paginate(opts)
if (response.state <> "active") {
return
}
// User is not in the team continue to do something...
有什么想法我该怎么做?
I want to run a Github action that checks if the PR creator is a member of GitHub team "My cool Team" and if so do something.
I'm having trouble understanding how I can leverage the octokit
team endpoint "Get team membership for a user" https://octokit.github.io/rest.js/v18#teams
The docs explain that the response for https://docs.github.com/en/rest/teams/members#get-team-membership-for-a-user
is
{
"url": "https://api.github.com/teams/1/memberships/octocat",
"role": "maintainer",
"state": "active"
}
if the user is in the team otherwise it returns 404 which i also don't know how to handle?
This is what I wrote:
on: pull_request_target
jobs:
my_job:
runs-on: ubuntu-latest
steps:
- uses: actions/github-script@v6
with:
script: |
// If user is member of my_team team do nothing else do something
// See: https://octokit.github.io/rest.js/v18#teams
const creator = context.payload.sender.login
const opts = github.rest.teams.getMembershipForUserInOrg.endpoint.merge({
org: 'my_org',
team_slug: 'My cool Team',
username: ???? #How do I get the username of who opened the PR?
})
const response = await github.paginate(opts)
if (response.state <> "active") {
return
}
// User is not in the team continue to do something...
Any thoughts how I can do that?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
从您的代码段中,
创建者
变量是打开PR的人的用户名。另外,等待GetMembershipforuserinorg()
可能足以满足您的需求。像:From your code snippet
The
creator
variable is the username of who opened the PR. Also, await for the result ofgetMembershipForUserInOrg()
could be enough for your need. Something like: