Skip to content

Commit

Permalink
Add draft contributors section
Browse files Browse the repository at this point in the history
	Fixes: fluxcd#349

Signed-off-by: Daniel Holbach <[email protected]>
  • Loading branch information
Daniel Holbach committed Jun 28, 2021
1 parent 96a9084 commit 68f6fd3
Show file tree
Hide file tree
Showing 6 changed files with 125 additions and 2 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,6 @@ static/install.sh

# Adopters logos
static/img/logos

# local GH token, used for some scripts
.gh-token
5 changes: 5 additions & 0 deletions content/en/.gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
# Generated
adopters.md
contributors_include.html


# Imported
community.md
contributing.md
governance.md
Expand Down
12 changes: 10 additions & 2 deletions content/en/_index.html
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ <h2 id='gitops'>GitOps at your fingertips</h2>
{{% /blocks/feature %}}

{{% blocks/feature icon="fas fa-cube fa-3x" title="Extensible" height="auto" color="blue" %}}
Easily create a continous delivery solution with only the components you need, or use the [GitOps Toolkit](#gitops-toolkit)
Easily create a continuous delivery solution with only the components you need, or use the [GitOps Toolkit](#gitops-toolkit)
to extend Flux.
{{% /blocks/feature %}}

Expand Down Expand Up @@ -165,12 +165,20 @@ <h2 class="section-label">Other Flux projects</h2>
<div class="section-community">
{{< blocks/lead color="dark" >}}

<h2 class="section-label">Community</h2>
<h2 class="section-label">Contributors</h2>

The Flux project aspires to be the vendor-neutral home for GitOps in a Cloud Native world.
What we achieved up until today is only possible because of our community.

<hr />

{{< blocks/contributors >}}

{{< /blocks/lead >}}

{{< blocks/lead color="dark" >}}
<h2 class="section-label">Community</h2>
{{< /blocks/lead >}}

{{< blocks/section color="dark" type="community-row">}}

Expand Down
102 changes: 102 additions & 0 deletions hack/contributors.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
#!/usr/bin/python

import os
import sys

from github import (Github, GithubException)

main_path = os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))

def github_login():
token = os.getenv('GITHUB_TOKEN')
if not token:
token_file = os.path.join(main_path, '.gh-token')
if not os.path.exists(token_file):
print('''GITHUB_TOKEN not set, and {} not found.
You either need to
- set the GITHUB_TOKEN environment variable, or
- specify it in {}
Please see https://github.com/settings/tokens for how to obtain token.'''.format(
token_file, token_file))
sys.exit(1)
token = open(token_file).read().strip()
return Github(token)

def get_contributions_from_gh():
repos = [
'.github',
'community',
'flux2',
'flux2-kustomize-helm-example',
'flux2-multi-tenancy',
'go-git-providers',
'helm-controller',
'image-automation-controller',
'image-reflector-controller',
'kustomize-controller',
'notification-controller',
'pkg',
'source-controller',
'source-watcher',
'terraform-provider-flux',
'website',
'webui'
]
bots = [
'fluxcdbot',
'dependabot[bot]'
]
contributors = {}

gh = github_login()
flux = gh.get_user('fluxcd')
for repo in repos:
try:
contribs = flux.get_repo(repo).get_contributors()
except GithubException:
print("Couldn't get contributors for {}.".format(repo))
continue
for contributor in contribs:
name = contributor.login
if name in bots:
continue
if name not in contributors:
contributors[name] = {'contributions': 0}
contributors[name]['contributions'] += contributor.contributions
contributors[name]['avatar_url'] = contributor.avatar_url
return contributors

def sort_contributions(contributors):
contribs = []
for c in contributors:
contribs += [
(c, contributors[c]['contributions'], contributors[c]['avatar_url'])
]
return sorted(contribs, key=lambda a: a[1], reverse=True)

def write_html(contributors):
html = ""
for contrib in contributors:
html += \
"""<a href="https://github.com/{}"><img src="{}" title="{}" width="80" height="80"></a>
""".format(contrib[0], contrib[2], contrib[0])

out_file = os.path.join(main_path, 'content/en/contributors_include.html')
if os.path.exists(out_file):
os.remove(out_file)
f = open(out_file, 'w')
f.write(html)
f.close()

def main():
contributors = get_contributions_from_gh()
write_html(sort_contributions(contributors))

if __name__ == '__main__':
try:
main()
except KeyboardInterrupt:
print("Aborted.", sys.stderr)
sys.exit(1)
4 changes: 4 additions & 0 deletions layouts/shortcodes/blocks/contributors.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{{ $_hugo_config := `{ "version": 1 }` }}
<div class="container">
{{ readFile "/content/en/contributors_include.html" | safeHTML }}
</div>
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
pathlib
pygithub
pyYaml

0 comments on commit 68f6fd3

Please sign in to comment.