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

List: organization owners (v2) #38

Merged
merged 4 commits into from
Nov 17, 2017
Merged
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
2 changes: 2 additions & 0 deletions docs/_data/navigation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
url: "/repos-activity"
- title: "Total"
url: "/repos-total"
- title: "Organizations"
url: "/org-owners"
- title: "Housekeeping"
url: "/housekeeping-git-traffic"
subnavigation:
Expand Down
36 changes: 23 additions & 13 deletions docs/assets/js/charts.js
Original file line number Diff line number Diff line change
Expand Up @@ -362,20 +362,30 @@ function createTable(table)
.enter()
.append("td")
.each(function(d, i) {
var cell = d3.select(this);
switch (data.columns[i].toLowerCase()) {
case "user":
case "organization":
case "repository":
case "resource":
case "fork":
cell = cell
.append("a")
.attr("target", "_blank")
.attr("href", gheUrl() + "/" + d);
break;
const cell = d3.select(this);
const entries = d.split(/[\s,]+/);
const column = data.columns[i].toLowerCase();

for (let j = 0; j < entries.length; j++) {
if (j > 0)
cell.append().text(", ")
const entry = entries[j];
switch (column) {
case "fork":
case "organization":
case "owner(s)":
case "repository":
case "resource":
case "user":
cell.append("a")
.attr("target", "_blank")
.attr("href", gheUrl() + "/" + entry)
.text(entry);
break;
default:
cell.append().text(entry);
}
}
cell.text(function(d) { return d; })
});
});
}
Expand Down
10 changes: 10 additions & 0 deletions docs/demo-data/org-owners.tsv
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
organization owner(s)
Alpha user39, user72, user81, user20
Bravo user50, user39
Charlie user80
Delta user78, user59, user86
Echo user70
Foxtrot user24, user87
Golf user36, user90, user27, user40, user67
Hotel user67, user90
India user65
21 changes: 21 additions & 0 deletions docs/org-owners.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
---
layout: default
title: Organization Owners
permalink: /org-owners
---
<h3>
Organization Owners
</h3>

<div class="row">
<div class="col-main">
<div class="chart-container">
<table class="table" data-url="{{ site.dataURL }}/org-owners.tsv"></table>
</div>
</div>
<div class="col-aside">
<div class="info-box">
<p>Owners for each GitHub organization.</p>
</div>
</div>
</div>
26 changes: 15 additions & 11 deletions updater/reports/Report.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,15 @@ def executeScript(self, script, stdin = None):

return stdout

def executeGHEConsole(self, rubyCode):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🥇

escapedRubyCode = rubyCode.replace('\\t', '\\\\t') \
.replace('\\n', '\\\\n') \
.replace('"', '\\"')
return self.executeScript(
["bash -s", "--"],
"github-env bin/runner -e production \"'" + escapedRubyCode + "'\""
)

# Executes a database query, given as a string
def executeQuery(self, query):
return self.executeScript(self.configuration["databaseCommand"], stdin = query)
Expand Down Expand Up @@ -179,27 +188,22 @@ def update(self):
print("Finished update of " + self.name() + ".tsv (runtime: " + str(timeElapsed) + " s)", file = sys.stderr)
sys.stderr.flush()

def andExcludedEntities(self, org, repo):
def andExcludedEntities(self, column, delimiter = "AND"):
query = ""
if ("excludedEntities" in self.configuration and
len(self.configuration["excludedEntities"]) > 0):
if org:
query += ' AND ' + org + '.login not LIKE "' + \
self.configuration["excludedEntities"] + '" '
if repo:
query += ' AND ' + repo + '.name not LIKE "' + \
self.configuration["excludedEntities"] +'" '
query += " " + delimiter + " " + column + ' NOT LIKE "' + self.configuration["excludedEntities"] + '" '
return query

def andExcludedUsers(self, users, delimiter = "AND"):
def andExcludedUsers(self, column, delimiter = "AND"):
query = ""
for excludedUser in self.configuration["excludedUsers"]:
query += " " + delimiter + " " + users + '.login NOT LIKE "' + excludedUser + '" '
query += " " + delimiter + " " + column + ' NOT LIKE "' + excludedUser + '" '
delimiter = "AND"
return query

def whereExcludedUsers(self, users):
return self.andExcludedUsers(users, "WHERE")
def whereExcludedUsers(self, column):
return self.andExcludedUsers(column, "WHERE")

def andExcludeMemberlessOrganizations(self, orgs):
query = ""
Expand Down
2 changes: 1 addition & 1 deletion updater/reports/ReportContributorsByOrg.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def query(self, timeRange):
JOIN users ON users.id = repositories.owner_id
WHERE
pull_requests.created_at IS NOT NULL AND CAST(pull_requests.created_at AS date) BETWEEN "''' + str(timeRange[0]) + '''" AND "''' + str(timeRange[1]) + '''"
''' + self.andExcludedUsers("users") + '''
''' + self.andExcludedUsers("users.login") + '''
GROUP by
users.id
ORDER by
Expand Down
2 changes: 1 addition & 1 deletion updater/reports/ReportContributorsByRepo.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def query(self, timeRange):
JOIN users on users.id = repositories.owner_id
WHERE
pull_requests.created_at IS NOT NULL AND CAST(pull_requests.created_at AS date) BETWEEN "''' + str(timeRange[0]) + '''" AND "''' + str(timeRange[1]) + '''"
''' + self.andExcludedUsers("users") + '''
''' + self.andExcludedUsers("users.login") + '''
GROUP BY
repositories.id
ORDER BY
Expand Down
6 changes: 4 additions & 2 deletions updater/reports/ReportForksToOrgs.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,10 @@ def query(self):
parentOrgs.type = "organization" AND
parentRepos.owner_id = parentOrgs.id AND
parentRepos.id = repos.parent_id
''' + self.andExcludedEntities("orgs", "repos") \
+ self.andExcludedEntities("parentOrgs", "parentRepos") + '''
''' + self.andExcludedEntities("orgs.login") \
+ self.andExcludedEntities("repos.name") \
+ self.andExcludedEntities("parentOrgs.login") \
+ self.andExcludedEntities("parentRepos.name") + '''
ORDER BY
repos.created_at DESC
'''
Expand Down
11 changes: 7 additions & 4 deletions updater/reports/ReportOrgCollaboration.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ def pushCountQuery(self, timeRange):
AND orgs.id = repositories.owner_id
AND repositories.id = pushes.repository_id
AND cast(pushes.created_at AS DATE) BETWEEN "''' + str(timeRange[0]) + '''" and "''' + str(timeRange[1]) + '''"
''' + self.andExcludedEntities("orgs", "repositories") \
''' + self.andExcludedEntities("orgs.login") \
+ self.andExcludedEntities("repositories.name") \
+ self.andExcludeMemberlessOrganizations("orgs") + '''
GROUP BY org_id, pusher_id
'''
Expand All @@ -70,7 +71,7 @@ def homeOrgQuery(self, timeRange):
OR (a.push_count = b.push_count AND a.pusher_id != b.pusher_id)
)
WHERE b.push_count is NULL AND a.pusher_id = users.id ''' \
+ self.andExcludedUsers("users")
+ self.andExcludedUsers("users.login")
return query

# Calculates a table that contains all users that have contributed to a
Expand All @@ -90,7 +91,8 @@ def contributorsToOrgQuery(self, timeRange):
AND orgs.id = repositories.owner_id
AND repositories.id = pushes.repository_id
AND cast(pushes.created_at AS DATE) BETWEEN "''' + str(timeRange[0]) + '''" and "''' + str(timeRange[1]) + '''"
''' + self.andExcludedEntities("orgs", "repositories") + '''
''' + self.andExcludedEntities("orgs.login") \
+ self.andExcludedEntities("repositories.name") + '''

UNION

Expand All @@ -105,7 +107,8 @@ def contributorsToOrgQuery(self, timeRange):
AND repositories.id = pull_requests.repository_id
AND pull_requests.merged_at IS NOT NULL
AND cast(pull_requests.created_at AS DATE) BETWEEN "''' + str(timeRange[0]) + '''" and "''' + str(timeRange[1]) + '''"
''' + self.andExcludedEntities("orgs", "repositories") + '''
''' + self.andExcludedEntities("orgs.login") \
+ self.andExcludedEntities("repositories.name") + '''
) contributors
GROUP BY org_id, contributor_id
'''
Expand Down
27 changes: 27 additions & 0 deletions updater/reports/ReportOrgOwners.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
from .Report import *

# Lists all orgs and their owners without site admins or suspended users
class ReportOrgOwners(Report):
def name(self):
return "org-owners"

# The data is overwritten every day, so skip reading the old data
def readData(self):
pass

def updateData(self):
self.header, self.data = self.parseData(
self.executeGHEConsole('''
puts "organization\towner(s)\n"
User.where(:type => "Organization")
.where("''' + self.andExcludedEntities("login", "").replace('"', '\\\\"') + '''")
.order("login")
.each do |org|
owners = org.admins.where(:disabled => false, :gh_role => nil)
.where("''' + self.andExcludedUsers("login", "").replace('"', '\\\\"') + '''")
.order("login")
.join(",")
puts "#{org.login}\t#{owners}\n"
end
''')
)
2 changes: 1 addition & 1 deletion updater/reports/ReportPRByOrg.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def query(self, timeRange):
pull_requests
JOIN repositories ON repositories.id = pull_requests.repository_id
JOIN users ON users.id = repositories.owner_id
''' + self.whereExcludedUsers("users") + '''
''' + self.whereExcludedUsers("users.login") + '''
GROUP BY
users.id
ORDER BY
Expand Down
2 changes: 1 addition & 1 deletion updater/reports/ReportPRByRepo.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def query(self, timeRange):
pull_requests
join repositories ON repositories.id = pull_requests.repository_id
join users on users.id = repositories.owner_id
''' + self.whereExcludedUsers("users") + '''
''' + self.whereExcludedUsers("users.login") + '''
GROUP BY
repositories.id
ORDER BY
Expand Down
2 changes: 1 addition & 1 deletion updater/reports/ReportPRHistory.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def subquery(self, type, timeRange):
WHERE
CAST(pull_requests.''' + type + ''' AS date) BETWEEN "''' + str(timeRange[0]) + '''" AND "''' + str(timeRange[1]) + '''" AND
pull_requests.user_id = users.id
''' + self.andExcludedUsers("users") + '''
''' + self.andExcludedUsers("users.login") + '''
GROUP BY
date_format(pull_requests.''' + type + ''', "%Y-%m-%d")
ORDER BY
Expand Down
3 changes: 2 additions & 1 deletion updater/reports/ReportRepoActivity.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ def subquery(self, userType, timeRange):
WHERE
CAST(pushes.created_at AS DATE) BETWEEN "''' + str(timeRange[0]) + '''" AND "''' + str(timeRange[1]) + '''"'''

query += self.andExcludedEntities("users", "repositories")
query += self.andExcludedEntities("users.login") \
+ self.andExcludedEntities("repositories.name")

if userType != None:
query += ''' AND
Expand Down
3 changes: 2 additions & 1 deletion updater/reports/ReportRepositoryHistory.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ def subquery(self, userType):
repositories
JOIN users ON repositories.owner_id = users.id
WHERE
TRUE ''' + self.andExcludedEntities("users", "repositories")
TRUE ''' + self.andExcludedEntities("users.login") \
+ self.andExcludedEntities("repositories.name")

if userType != None:
query += ''' AND
Expand Down
2 changes: 1 addition & 1 deletion updater/reports/ReportUsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def usersPushingSubquery(self, timeRange):
JOIN users ON users.id = pushes.pusher_id
WHERE
CAST(pushes.created_at AS DATE) BETWEEN "''' + str(timeRange[0]) + '''" AND "''' + str(timeRange[1]) + '''"
''' + self.andExcludedUsers("users")
''' + self.andExcludedUsers("users.login")
return query

# Collects the number of users who currently use up a seat
Expand Down
2 changes: 2 additions & 0 deletions updater/update-stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from reports.ReportGitRequests import *
from reports.ReportGitVersions import *
from reports.ReportOrgCollaboration import *
from reports.ReportOrgOwners import *
from reports.ReportPRByOrg import *
from reports.ReportPRByRepo import *
from reports.ReportPRHistory import *
Expand Down Expand Up @@ -76,6 +77,7 @@ def main():
ReportGitRequests(configuration, dataDirectory, metaStats).update()
ReportGitVersions(configuration, dataDirectory, metaStats).update()
ReportOrgCollaboration(configuration, dataDirectory, metaStats).update()
ReportOrgOwners(configuration, dataDirectory, metaStats).update()
ReportPRByOrg(configuration, dataDirectory, metaStats).update()
ReportPRByRepo(configuration, dataDirectory, metaStats).update()
ReportPRHistory(configuration, dataDirectory, metaStats).update()
Expand Down