Skip to content

Commit

Permalink
Better organization support
Browse files Browse the repository at this point in the history
  • Loading branch information
lowlighter committed Jan 26, 2021
1 parent 1c8dcbc commit 5c3ecf9
Show file tree
Hide file tree
Showing 10 changed files with 201 additions and 126 deletions.
74 changes: 53 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -563,26 +563,26 @@ The default template is `classic`.

<table>
<tr>
<th>Template\Plugin</th>
<th><span title="Base content">🗃️</span></th>
<th><span title="PageSpeed">⏱️</span></th>
<th><span title="Isometric calendar">📅</span></th>
<th><span title="Music">🎼</span></th>
<th><span title="Languages">🈷️</span></th>
<th><span title="Follow-up">🎟️</span></th>
<th><span title="Topics">📌</span></th>
<th><span title="Projects">🗂️</span></th>
<th><span title="Lines">👨‍💻</span></th>
<th><span title="Traffic">🧮</span></th>
<th><span title="Tweets">🐤</span></th>
<th><span title="Posts">✒️</span></th>
<th><span title="Habits">💡</span></th>
<th><span title="Activity">📰</span></th>
<th><span title="Stars">🌟</span></th>
<th><span title="Stargazers">✨</span></th>
<th><span title="Gists">🎫</span></th>
<th><span title="People">🧑‍🤝‍🧑</span></th>
<th><span title="Anilist">🌸</span></th>
<th nowrap="nowrap">Template\Plugin</th>
<th nowrap="nowrap"><span title="Base content">🗃️<sup>Ø<sup>P</sup></sup></span></th>
<th nowrap="nowrap"><span title="PageSpeed">⏱️</span></th>
<th nowrap="nowrap"><span title="Isometric calendar">📅<sup>Ø</sup></span></th>
<th nowrap="nowrap"><span title="Music">🎼</span></th>
<th nowrap="nowrap"><span title="Languages">🈷️</span></th>
<th nowrap="nowrap"><span title="Follow-up">🎟️</span></th>
<th nowrap="nowrap"><span title="Topics">📌<sup>Ø</sup></span></th>
<th nowrap="nowrap"><span title="Projects">🗂️</span></th>
<th nowrap="nowrap"><span title="Lines">👨‍💻</span></th>
<th nowrap="nowrap"><span title="Traffic">🧮</span></th>
<th nowrap="nowrap"><span title="Tweets">🐤</span></th>
<th nowrap="nowrap"><span title="Posts">✒️</span></th>
<th nowrap="nowrap"><span title="Habits">💡</span></th>
<th nowrap="nowrap"><span title="Activity">📰</span></th>
<th nowrap="nowrap"><span title="Stars">🌟<sup>Ø</sup></span></th>
<th nowrap="nowrap"><span title="Stargazers">✨</span></th>
<th nowrap="nowrap"><span title="Gists">🎫<sup>Ø</sup></span></th>
<th nowrap="nowrap"><span title="People">🧑‍🤝‍🧑</span></th>
<th nowrap="nowrap"><span title="Anilist">🌸</span></th>
</tr>
<tr>
<th>Classic</th>
Expand Down Expand Up @@ -656,7 +656,9 @@ The default template is `classic`.
* **P**: Partial support *(Hover cell for more informations)*
* **M**: Feature is not released yet but is available on `@master`
* **N**: Feature is already released, but new ones are available on `@master`
* **R**: Repository template (all plugins content will be restricted to related repository)
* **R**: Repository template (all plugins content will be scoped to related repository)
* **Ø**: Feature is not supported for organization accounts
* **Ø<sup>P</sup>**: Feature is supported partially for organization accounts

<details>
<summary>💬 Using community templates</summary>
Expand Down Expand Up @@ -712,6 +714,36 @@ Add the following to your workflow:

</details>

<details>
<summary>💬 Generating metrics for organizations</summary>

🚧 This feature is available as pre-release on @master branch (unstable)

It is also possible to generate metrics for organization accounts.
Setup is the same as for user accounts (i.e. a personal token from an user account and use of `GITHUB_TOKEN` for commits) but you'll need to change `user` option to your organization name.

Additionally, you'll need to add the `read:org` scope to your personal token, *whether you're member of target organization or not*.

![Add read:org scope to personal token](.github/readme/imgs/setup_token_org_read_scope.png)

Resulting workflow should look like below:
```yaml
- uses: lowlighter/metrics@master
with:
# ... other options
token: ${{ secrets.METRICS_TOKEN }} # A personal token from an user account with read:org scope
committer_token: ${{ secrets.GITHUB_TOKEN }}
user: "organization-name"
```

You may also need to [authorize your personal token](https://docs.github.com/en/free-pro-team@latest/github/authenticating-to-github/authorizing-a-personal-access-token-for-use-with-saml-single-sign-on) if you're using single sign-on and are encounting errors.

Note that `repositories` option will be capped to 25 repositories to ensure that GraphQL queries does not timeout, so you may end up using more requests than for user accounts.

Although some plugins may be noted as compatible with an organization account, it may not be actually possible to run them successfully depending of your organization size. As some of plugins use a lot of requests, you'll eventually reach the rate-limiter before all of your metrics are generated for large organizations.

</details>

## 🧩 Plugins

Plugins are features which can provide additional metrics and features.
Expand Down
2 changes: 1 addition & 1 deletion source/app/metrics.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@
let pushed = 0
do {
console.debug(`metrics/compute/${login}/common > retrieving repositories after ${cursor}`)
const {[account]:{repositories:{edges, nodes}}} = await graphql(queries.repositories({login, account, after:cursor ? `after: "${cursor}"` : "", repositories:Math.min(repositories, 100), forks:forks ? "" : ", isFork: false"}))
const {[account]:{repositories:{edges, nodes}}} = await graphql(queries.repositories({login, account, after:cursor ? `after: "${cursor}"` : "", repositories:Math.min(repositories, {user:100, organization:25}[account]), forks:forks ? "" : ", isFork: false"}))
cursor = edges?.[edges?.length-1]?.cursor
data.user.repositories.nodes.push(...nodes)
pushed = nodes.length
Expand Down
4 changes: 3 additions & 1 deletion source/queries/common.organization.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ query MetricsOrganization {
sponsorshipsAsMaintainer {
totalCount
}

membersWithRole {
totalCount
}
}
}
4 changes: 3 additions & 1 deletion source/templates/classic/image.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 5c3ecf9

Please sign in to comment.