When github.actor is a member, not github.repo_owner

I encountered the following use case.

Certain actions in a workflow should activate, only when the actor is the owner. This condition is created in order to disable certain actions on a PR from a forked/feature to upstream/master, but be enabled in any other push or PR case:

if: github.repository_owner == github.actor

There is the possibility of a member of an organization to be the actor, which would mean that the above condition will return false, because the owner is the organization. However, if the actor in this case is a member, the desired outcome is for the condition to return true, since a member of an organization logically (in the context of the condition) is owner.

Is there a way to check if the actor is a member ? - something like:

if: (github.repo.members).contains(github.actor) // true
2 Likes

The solution I came up with is this:

Write a script that would compare github.actor against each member’s login name in an organization, taken from a request like this https://api.github.com/orgs/github/members and store the outcome in an output of that step, so it can be used in the original condition like this:

if: github.repository_owner == github.actor || isTheActorAlsoMember // false || true

The script should look something like this:

let data = (https://api.github.com/orgs/github/members);
let isActorAlsoMember = false;
const githubActor = github.actor;

for (member in data) {
  if (isActorAlsoMember) {
    break;
  }
  else {
    isActorAlsoMember = githubActor === member.login
  }
}
1 Like