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

community/: Display contributor statistics #269

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .ci/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ python manage.py fetch_deployed_data _site $ISSUES_JSON \

python manage.py migrate
python manage.py import_contributors_data
python manage.py create_org_cluster_map_and_activity_graph org_map
python manage.py import_issues_data
python manage.py import_merge_requests_data
python manage.py create_config_data
Expand Down
5 changes: 3 additions & 2 deletions .coafile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[all]
files = **.py, **.js, **.sh
ignore = .git/**, **/__pycache__/**, gci/client.py, */migrations/**, private/*
ignore = .git/**, **/__pycache__/**, gci/client.py, */migrations/**, private/*, openhub/**, **/leaflet_dist/**
max_line_length = 80
use_spaces = True
preferred_quotation = '
Expand Down Expand Up @@ -42,6 +42,7 @@ files = static/**/*.js
bears = JSHintBear
allow_unused_variables = True
javascript_strictness = False
environment_jquery = True

[all.yml]
bears = YAMLLintBear
Expand All @@ -58,7 +59,7 @@ shell = bash
# for use by other organizations.
files = **
# .coverage crashes AnnotationBear
ignore += .coafile, *requirements.txt, .travis.yml, LICENSE, .nocover.yaml, .moban.yaml, .moban.dt/community-*.jj2, public/**, _site/**, .ci/check_moban.sh, .coverage
ignore += .coafile, *requirements.txt, .travis.yml, LICENSE, .nocover.yaml, .moban.yaml, .moban.dt/community-*.jj2, public/**, _site/**, .ci/check_moban.sh, .coverage, static/js/main.js
bears = KeywordBear
language = python 3
keywords = coala
Expand Down
8 changes: 3 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ coverage.xml
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
Expand Down Expand Up @@ -272,6 +273,7 @@ flycheck_*.el

# Session
Session.vim
Sessionx.vim

# Temporary
.netrwhist
Expand Down Expand Up @@ -429,11 +431,7 @@ DerivedData/
*.perspectivev3
!default.perspectivev3

## Xcode Patch
*.xcodeproj/*
!*.xcodeproj/project.pbxproj
!*.xcodeproj/xcshareddata/
!*.xcworkspace/contents.xcworkspacedata
## Gcc Patch
/*.gcno

# Eclipse rules
Expand Down
4 changes: 2 additions & 2 deletions .moban.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ packages:
- gci
- gsoc
- gamification
- log
- ci_build
- meta_review
- model
- twitter
- unassigned_issues

dependencies:
- getorg~=0.3.1
- git+https://gitlab.com/coala/coala-utils.git
- git-url-parse
- django>2.1,<2.2
Expand Down
3 changes: 1 addition & 2 deletions .nocover.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@ nocover_file_globs:
- community/git.py
- gci/*.py
- gsoc/*.py
- log/*.py
- ci_build/*.py
- meta_review/handler.py
- model/*.py
- openhub/*.py
- twitter/*.py
# Optional coverage. Once off scripts.
- inactive_issues/inactive_issues_scraper.py
- unassigned_issues/unassigned_issues_scraper.py
Expand Down
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
language: python
python: 3.6
python: 3.6.3

cache:
pip: true
Expand Down
5 changes: 3 additions & 2 deletions activity/scraper.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ def get_data(self):
return self.data


def activity_json(request):
def activity_json(filename):

org_name = get_org_name()

Expand All @@ -152,4 +152,5 @@ def activity_json(request):
real_data = Scraper(parsed_json['issues'], datetime.datetime.today())
real_data = real_data.get_data()

return HttpResponse(json.dumps(real_data))
with open(filename, 'w+') as f:
json.dump(real_data, f, indent=4)
131 changes: 131 additions & 0 deletions ci_build/view_log.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
import re
import json
import os
import sys

from django.views.generic import TemplateView

from community.views import get_header_and_footer
from community.git import (
get_org_name,
get_owner,
get_deploy_url,
get_upstream_deploy_url
)


class BuildLogsView(TemplateView):
template_name = 'build_logs.html'

def copy_build_logs_json(self, ci_build_jsons):
"""
:param ci_build_jsons: A dict of directories path
:return: A boolean, whether the build file is copied
"""
if os.path.isfile(ci_build_jsons['public_path']):
if sys.platform == 'linux':
os.popen('cp {} {}'.format(
ci_build_jsons['site_path'],
ci_build_jsons['public_path']))
os.popen('cp {} {}'.format(
ci_build_jsons['site_path'],
ci_build_jsons['static_path']))
else:
os.popen('copy {} {}'.format(
ci_build_jsons['site_path'],
ci_build_jsons['public_path']))
os.popen('copy {} {}'.format(
ci_build_jsons['site_path'],
ci_build_jsons['static_path']))
return True
return False

def create_and_copy_build_logs_json(self, logs, level_specific_logs):
"""
Create a build logs detailed json file in ./_site directory and copy
that file in the ./static and ./public/static directories
:param logs: A list of all lines in build log file
:param level_specific_logs: A dict containing logs divided in their
respective categories
:return: A boolean, whether the files were copied or not
"""
ci_build_jsons = {
'site_path': './_site/ci-build-detailed-logs.json',
'public_path': './public/static/ci-build-detailed-logs.json',
'static_path': './static/ci-build-detailed-logs.json'
}
with open(ci_build_jsons['site_path'], 'w+') as build_logs_file:
data = {
'logs': logs,
'logs_level_Specific': level_specific_logs
}
json.dump(data, build_logs_file, indent=4)
return self.copy_build_logs_json(ci_build_jsons)

def get_build_logs(self, log_file_path):
"""
:param log_file_path: build logs file path
:return: a tuple of two where the first element in tuple refers to
a list of build logs in the file, and the second element is a dict
which categorizes the build logs into 5 categories - INFO, DEBUG,
WARNING, ERROR nad CRITICAL
"""
log_lines = []
log_level_specific_lines = {
'INFO': [],
'DEBUG': [],
'WARNING': [],
'ERROR': [],
'CRITICAL': []
}
with open(log_file_path) as log_file:
previous_found_level = None
for line in log_file:
log_lines.append(line)
levels = re.findall(r'\[[A-Z]+]', line)
if levels:
level = levels[0]
level = previous_found_level = level[1:-1]
log_level_specific_lines[level].append(line)
elif previous_found_level:
log_level_specific_lines[previous_found_level].append(
line)
return log_lines, log_level_specific_lines

def check_build_logs_stored(self):
"""
Check whether the build logs json file is copied to _site and public
directories or not
:return: A Boolean
"""
log_file_path = './_site/community.log'
log_file_exists = os.path.isfile(log_file_path)
if log_file_exists:
logs, level_specific_logs = self.get_build_logs(log_file_path)
return self.create_and_copy_build_logs_json(logs,
level_specific_logs)
return False

def get_build_info(self):
"""
Get the information about build, like who deployed the website i.e.
owner, name of the organization or user etc.
:return: A dict having information about build related details
"""
data = {
'Org name': get_org_name(),
'Owner': get_owner(),
'Deploy URL': get_deploy_url(),
}
try:
data['Upstream deploy URL'] = get_upstream_deploy_url()
except RuntimeError:
data['Upstream deploy URL'] = 'Not found'
return data

def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context = get_header_and_footer(context)
context['build_info'] = self.get_build_info()
context['logs_stored'] = self.check_build_logs_stored()
return context
82 changes: 82 additions & 0 deletions community/forms.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
from django import forms


class JoinCommunityForm(forms.Form):

github_username = forms.CharField(
max_length=50, label='GitHub Username',
widget=forms.TextInput(
attrs={
'placeholder': 'Make sure to NOT enter your github profile url',
'autocomplete': 'off'
}
)
)
gh_first_repo = forms.URLField(
required=False, label='GitHub Personal Repository',
widget=forms.URLInput(
attrs={
'placeholder': 'A valid github url of your personal repository',
'autocomplete': 'off'
}
)
)
gh_git_training_exercise = forms.URLField(
required=False, label='From which GitHub repository you have done git'
' training?',
widget=forms.URLInput(
attrs={
'placeholder': 'A valid github url of git training repository',
'autocomplete': 'off'
}
)
)
gh_most_contributed_repo = forms.URLField(
required=False,
label="GitHub Repository to which you've contributed most!",
widget=forms.URLInput(
attrs={
'placeholder': 'A valid github public repository url',
'autocomplete': 'off'
}
)
)

gitlab_user_id = forms.IntegerField(
label='GitLab User ID',
widget=forms.NumberInput(
attrs={
'placeholder': 'Make sure to NOT enter your gitlab profile url',
'autocomplete': 'off'
}
)
)
gl_first_repo_id = forms.IntegerField(
required=False, label='GitLab Personal Project ID',
widget=forms.NumberInput(
attrs={
'placeholder': 'Your personal gitlab project ID',
'autocomplete': 'off'
}
)
)
gl_git_training_exercise = forms.IntegerField(
required=False, label='From which GitLab project you have done git'
' training?',
widget=forms.NumberInput(
attrs={
'placeholder': 'A valid project ID of Git training project',
'autocomplete': 'off'
}
)
)
gl_most_contributed_repo_id = forms.IntegerField(
required=False,
label="GitLab Project to which you've contributed most!",
widget=forms.NumberInput(
attrs={
'placeholder': 'A valid ID of gitlab public project',
'autocomplete': 'off',
}
)
)
6 changes: 3 additions & 3 deletions community/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def get_config_remote(name='origin'):
raise KeyError('No git remotes found')


def get_remote_url():
def get_remote_url(name='origin'):
"""Obtain a parsed remote URL.

Uses CI environment variables or git remotes.
Expand All @@ -58,7 +58,7 @@ def get_remote_url():
# It only sets the REPOSITORY_URL
url = os.environ.get('REPOSITORY_URL')
if not url:
remote = get_config_remote()
remote = get_config_remote(name)
assert remote[0][0] == 'url'
url = remote[0][1]

Expand Down Expand Up @@ -146,7 +146,7 @@ def get_upstream_repo():
"""Obtain the parent slug of the repository.
"""
try:
remote = get_config_remote(name='upstream')
remote = get_remote_url(name='origin')
except KeyError:
remote = None

Expand Down
Loading