Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Highlight issues and PRs from org members #438

Closed
markspolakovs opened this issue May 24, 2017 · 8 comments · Fixed by #2351
Closed

Highlight issues and PRs from org members #438

markspolakovs opened this issue May 24, 2017 · 8 comments · Fixed by #2351

Comments

@markspolakovs
Copy link

Context: for example, in the React team, much of the work happens via PRs, even by the core team. However, these core team PRs are lost in the long, long list of contributions.

Proposal: highlight PRs that are from members of the repo owning org, Facebook in the example of React.

@fregante
Copy link
Member

fregante commented May 26, 2017

I think we'd need an API key for that. This works, but it needs pagination for orgs with 101+ members:

fetch('https://api.github.com/orgs/facebook/members?per_page=100')
.then(r => r.json()).then(members => {
    $('.opened-by a').each((i, contributor) => {
        if(members.some(m => m.login === contributor.textContent)) {
            contributor.closest('.Box-row').style.background = '#eee';
        }
    });
});

Once v4 goes public we can get a much lighter response (but still paginated):

query {
  organization(login:"facebook") {
    members(first: 100) {
      edges {
        node {
          login
        }
      }
    }
  }
}

graphql

@sindresorhus
Copy link
Member

I think we should wait for the GraphQL API. It will make this much simpler to implement.

@markspolakovs
Copy link
Author

If you mean "wait for it to come out of early access", see https://github.com/blog/2359-introducing-github-marketplace-and-more-tools-to-customize-your-workflow

@fregante
Copy link
Member

fregante commented May 26, 2017

It doesn't look like GraphQL simplifies things in this case, from what I understand the only advantage is getting only what's needed as opposed to a big JSON.

I hoped you could query the visible user names directly but I don't think that's possible.

@sindresorhus sindresorhus changed the title Feature request: Highlight issues and PRs from org members Highlight issues and PRs from org members Oct 18, 2017
@fregante
Copy link
Member

fregante commented Jan 16, 2018

This is actually sort of possible in a single GraphQL query:

query {
  sindresorhus: user(login:"sindresorhus") {
    organizations(first: 100) {
      edges {
        node {
          login
        }
      }
    }
  }
  bfredit: user(login:"bfred-it") {
    organizations(first: 100) {
      edges {
        node {
          login
        }
      }
    }
  }
  etc...
}

This lets you query multiple specific users at once for their organizations.

It still is paginated but I doubt that there are many users that joined more than 100 orgs.

However: I don't know how you can tell if the current repo is part of an organization, I see no clues in the HTML.

@dertieran
Copy link
Contributor

Just stumbled upon this and if I find the time I will take another look at it, but I see two ways to solve this.

1. Get all members of an organisation
This would be the best way if the members could be reused (maybe in the Author filter) and/or saved for that repository/organisation context so we only need to get them once.
A query could look like this:

query ($org: String!, $cursor: String) {
  organization(login: $org) {
    login
    members(first: 100, after: $cursor) {
      pageInfo{
        hasNextPage
        endCursor
      }
      nodes {
        login
      }
    }
  }
}

This would return a list of members and the page information

{
  "data": {
    "organization": {
      "login": "bfred-it-obsolete",
      "members": {
        "pageInfo": {
          "hasNextPage": false,
          "endCursor": "Y3Vyc29yOnYyOpHOABVlgQ=="
        },
        "nodes": [
          {
            "login": "bfred-it"
          }
        ]
      }
    }
  }
}

If the passed $org isn't an organization the response would be an error/empty.

{
  "data": {
    "organization": null
  },
  "errors": [
    {
      "message": "Could not resolve to an Organization with the login of 'bfred-it'.",
      "type": "NOT_FOUND",
      "path": [
        "organization"
      ],
      "locations": [
        {
          "line": 2,
          "column": 3
        }
      ]
    }
  ]
}

2. Test the organization connection for each user
This would mean that we have a list of users we want to test.
Instead of the suggested query of @bfred-it it would also be possible to test for that one organization.

query ($org: String!) {
  sindresorhus: user(login: "sindresorhus") {
    organization(login: $org) {
      login
    }
  }
  bfredit: user(login: "bfred-it") {
    organization(login: $org) {
      login
    }
  }
}

This would return the organization or null if the user isn't a member

{
  "data": {
    "sindresorhus": {
      "organization": null
    },
    "bfredit": {
      "organization": {
        "login": "bfred-it-obsolete"
      }
    }
  }
}

Two problems I can see here are that

  1. There is no indication if the $org is actually an organization
  2. The query can't be build that easily and could lead to problems, e.g. there is a limit to how many users could be request at once (something around 50 when I tested it)

@fregante
Copy link
Member

fregante commented Sep 5, 2018

  1. There is no indication if the $org is actually an organization

This might need a separate request for each user, perhaps cached forever.

  1. The query can't be build that easily and could lead to problems, e.g. there is a limit to how many users could be request at once (something around 50 when I tested it)

The PR list only shows 20 PRs at a time, so that's not much of an issue. I built this type of query for my other extension, perhaps you can just copy-paste most of it: https://github.com/bfred-it/github-issue-link-status/blob/a079c3db069e16374713708b521254cecc1329c1/source/content.js#L35-L60

@fregante
Copy link
Member

If anyone wants to pick this up:

.rgh-collaborator {
    border: 1px solid #c0d3eb;
    border-radius: 3px;
    padding: 2px 5px;
}
{
  repository(owner: "sindresorhus", name: "refined-github") {
    collaborators(first: 100) {
      nodes {
        login
      }
    }
  }
}
{
  "data": {
    "repository": {
      "collaborators": {
        "nodes": [
          {
            "login": "sindresorhus"
          },
          {
            "login": "hkdobrev"
          },
          {
            "login": "SpaceK33z"
          },
          {
            "login": "kevva"
          },
          {
            "login": "paulmolluzzo"
          },
          {
            "login": "busches"
          },
          {
            "login": "bfred-it"
          },
          {
            "login": "SamVerschueren"
          },
          {
            "login": "jgierer12"
          },
          {
            "login": "DrewML"
          }
        ]
      }
    }
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging a pull request may close this issue.

5 participants