mirror of
https://github.com/documize/community.git
synced 2025-08-05 05:25:27 +02:00
commit
772aeff93d
21 changed files with 14951 additions and 1268 deletions
|
@ -21,11 +21,6 @@ export default Ember.Component.extend(SectionMixin, NotifierMixin, TooltipMixin,
|
|||
authenticated: false,
|
||||
config: {},
|
||||
owners: null,
|
||||
repos: null,
|
||||
noRepos: false,
|
||||
showCommits: false,
|
||||
showIssueNum: false,
|
||||
showLabels: false,
|
||||
|
||||
didReceiveAttrs() {
|
||||
let self = this;
|
||||
|
@ -41,16 +36,9 @@ export default Ember.Component.extend(SectionMixin, NotifierMixin, TooltipMixin,
|
|||
callbackUrl: cfg.authorizationCallbackURL,
|
||||
owner: null,
|
||||
owner_name: "",
|
||||
repo: null,
|
||||
repo_name: "",
|
||||
report: null,
|
||||
lists: [],
|
||||
branch: "",
|
||||
branchURL: "",
|
||||
branchSince: "",
|
||||
branchLines: "30",
|
||||
state: null,
|
||||
issues: "",
|
||||
branchLines: "100",
|
||||
userId: "",
|
||||
pageId: page.get('id'),
|
||||
};
|
||||
|
@ -58,13 +46,8 @@ export default Ember.Component.extend(SectionMixin, NotifierMixin, TooltipMixin,
|
|||
try {
|
||||
let metaConfig = JSON.parse(self.get('meta.config'));
|
||||
config.owner = metaConfig.owner;
|
||||
config.repo = metaConfig.repo;
|
||||
config.report = metaConfig.report;
|
||||
config.lists = metaConfig.lists;
|
||||
config.branchSince = metaConfig.branchSince;
|
||||
config.branchLines = metaConfig.branchLines;
|
||||
config.state = metaConfig.state;
|
||||
config.issues = metaConfig.issues;
|
||||
config.userId = metaConfig.userId;
|
||||
config.pageId = metaConfig.pageId;
|
||||
} catch (e) {}
|
||||
|
@ -112,10 +95,8 @@ export default Ember.Component.extend(SectionMixin, NotifierMixin, TooltipMixin,
|
|||
getOwnerLists() {
|
||||
this.set('busy', true);
|
||||
|
||||
let self = this;
|
||||
let owners = this.get('owners');
|
||||
let thisOwner = this.get('config.owner');
|
||||
let page = this.get('page');
|
||||
|
||||
if (is.null(thisOwner) || is.undefined(thisOwner)) {
|
||||
if (owners.length) {
|
||||
|
@ -128,75 +109,7 @@ export default Ember.Component.extend(SectionMixin, NotifierMixin, TooltipMixin,
|
|||
|
||||
this.set('owner', thisOwner);
|
||||
|
||||
this.get('sectionService').fetch(page, "repos", self.get('config'))
|
||||
.then(function (lists) {
|
||||
self.set('busy', false);
|
||||
self.set('repos', lists);
|
||||
self.getRepoLists();
|
||||
}, function (error) { //jshint ignore: line
|
||||
self.set('busy', false);
|
||||
self.set('authenticated', false);
|
||||
self.showNotification("Unable to fetch repositories");
|
||||
console.log(error);
|
||||
});
|
||||
},
|
||||
|
||||
getRepoLists() {
|
||||
this.set('busy', true);
|
||||
|
||||
let repos = this.get('repos');
|
||||
let thisRepo = this.get('config.repo');
|
||||
|
||||
if (is.null(repos) || is.undefined(repos) || repos.length === 0) {
|
||||
this.set('noRepos', true);
|
||||
return;
|
||||
}
|
||||
|
||||
this.set('noRepos', false);
|
||||
|
||||
if (is.null(thisRepo) || is.undefined(thisRepo) || thisRepo.owner !== this.get('config.owner').name) {
|
||||
if (repos.length) {
|
||||
thisRepo = repos[0];
|
||||
this.set('config.repo', thisRepo);
|
||||
}
|
||||
} else {
|
||||
this.set('config.repo', repos.findBy('id', thisRepo.id));
|
||||
}
|
||||
|
||||
this.set('repo', thisRepo);
|
||||
|
||||
this.getReportLists();
|
||||
},
|
||||
|
||||
getReportLists() {
|
||||
let reports = [];
|
||||
reports[0] = {
|
||||
id: "commitsData", // used as method for fetching Go data
|
||||
name: "Commits on a branch"
|
||||
};
|
||||
reports[1] = {
|
||||
id: "issuesData", // used as method for fetching Go data
|
||||
name: "Issues"
|
||||
};
|
||||
|
||||
this.set("reports", reports);
|
||||
|
||||
let thisReport = this.get('config.report');
|
||||
|
||||
if (is.null(thisReport) || is.undefined(thisReport)) {
|
||||
thisReport = reports[0];
|
||||
this.set('config.report', thisReport);
|
||||
} else {
|
||||
this.set('config.report', reports.findBy('id', thisReport.id));
|
||||
}
|
||||
|
||||
this.set('report', thisReport);
|
||||
|
||||
this.renderSwitch(thisReport);
|
||||
|
||||
},
|
||||
|
||||
renderSwitch(thisReport) {
|
||||
this.getOrgReposLists();
|
||||
|
||||
if (is.undefined(this.get('initDateTimePicker'))) {
|
||||
$.datetimepicker.setLocale('en');
|
||||
|
@ -204,32 +117,15 @@ export default Ember.Component.extend(SectionMixin, NotifierMixin, TooltipMixin,
|
|||
this.set('initDateTimePicker', "Done");
|
||||
}
|
||||
|
||||
let bl = this.get('config.branchLines');
|
||||
if (is.undefined(bl) || bl === "" || bl <= 0) {
|
||||
this.set('config.branchLines', "30");
|
||||
}
|
||||
|
||||
this.set('showCommits', false);
|
||||
this.set('showLabels', false);
|
||||
switch (thisReport.id) {
|
||||
case 'commitsData':
|
||||
this.set('showCommits', true);
|
||||
this.getBranchLists();
|
||||
break;
|
||||
case 'issuesData':
|
||||
this.set('showLabels', true);
|
||||
this.getLabelLists();
|
||||
break;
|
||||
}
|
||||
},
|
||||
|
||||
getBranchLists() {
|
||||
getOrgReposLists() {
|
||||
this.set('busy', true);
|
||||
|
||||
let self = this;
|
||||
let page = this.get('page');
|
||||
|
||||
this.get('sectionService').fetch(page, "branches", self.get('config'))
|
||||
this.get('sectionService').fetch(page, "orgrepos", self.get('config'))
|
||||
.then(function (lists) {
|
||||
let savedLists = self.get('config.lists');
|
||||
if (savedLists === null) {
|
||||
|
@ -262,71 +158,7 @@ export default Ember.Component.extend(SectionMixin, NotifierMixin, TooltipMixin,
|
|||
}, function (error) { //jshint ignore: line
|
||||
self.set('busy', false);
|
||||
self.set('authenticated', false);
|
||||
self.showNotification("Unable to fetch repository branches");
|
||||
console.log(error);
|
||||
});
|
||||
},
|
||||
|
||||
getLabelLists() {
|
||||
this.set('busy', true);
|
||||
|
||||
let self = this;
|
||||
let page = this.get('page');
|
||||
|
||||
let states = [];
|
||||
states[0] = {
|
||||
id: "open",
|
||||
name: "Open Issues"
|
||||
};
|
||||
states[1] = {
|
||||
id: "closed",
|
||||
name: "Closed Issues"
|
||||
};
|
||||
states[2] = {
|
||||
id: "all",
|
||||
name: "All Issues"
|
||||
};
|
||||
|
||||
this.set("states", states);
|
||||
|
||||
let thisState = this.get('config.state');
|
||||
|
||||
if (is.null(thisState) || is.undefined(thisState)) {
|
||||
thisState = states[0];
|
||||
this.set('config.state', thisState);
|
||||
} else {
|
||||
this.set('config.state', states.findBy('id', thisState.id));
|
||||
}
|
||||
|
||||
this.set('state', thisState);
|
||||
|
||||
this.get('sectionService').fetch(page, "labels", self.get('config'))
|
||||
.then(function (lists) {
|
||||
let savedLists = self.get('config.lists');
|
||||
if (savedLists === null) {
|
||||
savedLists = [];
|
||||
}
|
||||
|
||||
if (lists.length > 0) {
|
||||
lists.forEach(function (list) {
|
||||
var saved;
|
||||
if (is.not.undefined(savedLists)) {
|
||||
saved = savedLists.findBy("id", list.id);
|
||||
}
|
||||
let included = false;
|
||||
if (is.not.undefined(saved)) {
|
||||
included = saved.included;
|
||||
}
|
||||
list.included = included;
|
||||
});
|
||||
}
|
||||
|
||||
self.set('config.lists', lists);
|
||||
self.set('busy', false);
|
||||
}, function (error) { //jshint ignore: line
|
||||
self.set('busy', false);
|
||||
self.set('authenticated', false);
|
||||
self.showNotification("Unable to fetch repository labels");
|
||||
self.showNotification("Unable to fetch repositories");
|
||||
console.log(error);
|
||||
});
|
||||
},
|
||||
|
@ -340,20 +172,6 @@ export default Ember.Component.extend(SectionMixin, NotifierMixin, TooltipMixin,
|
|||
let lists = this.get('config.lists');
|
||||
let list = lists.findBy('id', id);
|
||||
|
||||
// restore the list of branches to the default state
|
||||
lists.forEach(function (lst) {
|
||||
Ember.set(lst, 'included', false);
|
||||
});
|
||||
|
||||
if (list !== null) {
|
||||
Ember.set(list, 'included', !list.included);
|
||||
}
|
||||
},
|
||||
|
||||
onLabelCheckbox(id) {
|
||||
let lists = this.get('config.lists');
|
||||
let list = lists.findBy('id', id);
|
||||
|
||||
if (list !== null) {
|
||||
Ember.set(list, 'included', !list.included);
|
||||
}
|
||||
|
@ -394,24 +212,10 @@ export default Ember.Component.extend(SectionMixin, NotifierMixin, TooltipMixin,
|
|||
onOwnerChange(thisOwner) {
|
||||
this.set('isDirty', true);
|
||||
this.set('config.owner', thisOwner);
|
||||
this.set('config.repos', []);
|
||||
this.set('config.lists', []);
|
||||
this.getOwnerLists();
|
||||
},
|
||||
|
||||
onRepoChange(thisRepo) {
|
||||
this.set('isDirty', true);
|
||||
this.set('config.repo', thisRepo);
|
||||
this.set('config.lists', []);
|
||||
this.getRepoLists();
|
||||
},
|
||||
|
||||
onReportChange(thisReport) {
|
||||
this.set('isDirty', true);
|
||||
this.set('config.report', thisReport);
|
||||
this.getReportLists();
|
||||
},
|
||||
|
||||
onStateChange(thisState) {
|
||||
this.set('config.state', thisState);
|
||||
},
|
||||
|
@ -423,15 +227,6 @@ export default Ember.Component.extend(SectionMixin, NotifierMixin, TooltipMixin,
|
|||
onAction(title) {
|
||||
this.set('busy', true);
|
||||
|
||||
let thisLines = this.get('config.branchLines');
|
||||
if (is.undefined(thisLines) || thisLines === "") {
|
||||
this.set('config.branchLines', 30);
|
||||
} else if (thisLines < 1) {
|
||||
this.set('config.branchLines', 1);
|
||||
} else if (thisLines > 100) {
|
||||
this.set('config.branchLines', 100);
|
||||
}
|
||||
|
||||
let self = this;
|
||||
let page = this.get('page');
|
||||
let meta = this.get('meta');
|
||||
|
@ -440,8 +235,7 @@ export default Ember.Component.extend(SectionMixin, NotifierMixin, TooltipMixin,
|
|||
meta.set('config', JSON.stringify(this.get('config')));
|
||||
meta.set('externalSource', true);
|
||||
|
||||
let thisReport = this.get('config.report');
|
||||
this.get('sectionService').fetch(page, thisReport.id, this.get('config'))
|
||||
this.get('sectionService').fetch(page, 'content', this.get('config'))
|
||||
.then(function (response) {
|
||||
meta.set('rawBody', JSON.stringify(response));
|
||||
self.set('busy', false);
|
||||
|
|
|
@ -40,6 +40,73 @@
|
|||
}
|
||||
|
||||
.section-github-render {
|
||||
|
||||
h3 {
|
||||
margin-bottom: 0px;
|
||||
}
|
||||
|
||||
h6 {
|
||||
font-size: 18px;
|
||||
margin: 0;
|
||||
display: inline;
|
||||
}
|
||||
|
||||
h6 a {
|
||||
color: inherit;
|
||||
}
|
||||
|
||||
p {
|
||||
margin-top: 5px;
|
||||
}
|
||||
|
||||
.github-board {
|
||||
margin-top: 30px;
|
||||
}
|
||||
|
||||
table {
|
||||
margin-left: 0px!important;
|
||||
border: none!important;
|
||||
}
|
||||
|
||||
thead.github th {
|
||||
background-color: #f8f8f8;
|
||||
text-align: left;
|
||||
padding: 4px 30px;
|
||||
font-family: "open_sanssemibold";
|
||||
border-bottom: 1px solid #e1e1e1 !important;
|
||||
}
|
||||
|
||||
tbody.github td {
|
||||
border: none !important;
|
||||
padding: 8px 30px !important;
|
||||
vertical-align: top;
|
||||
}
|
||||
|
||||
span.label-private {
|
||||
font-weight: normal;
|
||||
color: #4c4a42;
|
||||
background-color: #ffefc6;
|
||||
padding: 3px 4px;
|
||||
font-size: 12px;
|
||||
border-radius: 2px;
|
||||
box-shadow: inset 0 -1px 0 rgba(0,0,0,0.12);
|
||||
line-height: 1;
|
||||
margin-left: 10px;
|
||||
}
|
||||
|
||||
table.label-table {
|
||||
margin-top:30px !important;
|
||||
}
|
||||
|
||||
table.milestone-table {
|
||||
progress[value] {
|
||||
background-color: #eeeeee;
|
||||
border-radius: 3px;
|
||||
height: 15px;
|
||||
width: 50%;
|
||||
}
|
||||
}
|
||||
|
||||
.github-issue-label {
|
||||
font-size: 11px;
|
||||
color: white;
|
||||
|
@ -49,100 +116,31 @@
|
|||
box-shadow: inset 0 -1px 0 rgba(0,0,0,0.12);
|
||||
display: inline-block;
|
||||
line-height: 22px;
|
||||
}
|
||||
|
||||
.date-meta {
|
||||
color: #767676;
|
||||
font-size: 13px;
|
||||
}
|
||||
.dataid {
|
||||
color: #767676;
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
.github-board {
|
||||
width: 100%;
|
||||
white-space: nowrap;
|
||||
color: #767676;
|
||||
.repo {
|
||||
font-size: 16px;
|
||||
}
|
||||
|
||||
> .github-group-title {
|
||||
margin: 10px 0;
|
||||
font-size: 14px;
|
||||
color: #767676;
|
||||
}
|
||||
.branch {
|
||||
font-family: "open_sanssemibold";
|
||||
}
|
||||
|
||||
> .github-list {
|
||||
margin: 10px 20px 0 20px !important;
|
||||
padding: 0;
|
||||
color: #767676;
|
||||
.milestone {
|
||||
font-size: 15px;
|
||||
}
|
||||
|
||||
> .github-commit-item {
|
||||
display: block;
|
||||
width: 95%;
|
||||
font-size: 12px;
|
||||
color: #999;
|
||||
padding: 10px;
|
||||
border-left: 1px solid #eee;
|
||||
border-right: 1px solid #eee;
|
||||
border-top: 1px solid #eee;
|
||||
.github-avatar {
|
||||
border-radius: 4px;
|
||||
}
|
||||
|
||||
&:first-of-type {
|
||||
border-top-left-radius: 2px;
|
||||
border-top-right-radius: 2px;
|
||||
}
|
||||
|
||||
&:last-of-type {
|
||||
border-bottom-left-radius: 2px;
|
||||
border-bottom-right-radius: 2px;
|
||||
border-bottom: 1px solid #eee;
|
||||
}
|
||||
|
||||
&:hover {
|
||||
background-color: #f7fbfc;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
> .link {
|
||||
color: #999;
|
||||
|
||||
> .github-avatar {
|
||||
float: left;
|
||||
margin-right: 15px;
|
||||
margin-top: 2px;
|
||||
}
|
||||
|
||||
> .issue-avatar {
|
||||
float: left;
|
||||
margin-right: 15px;
|
||||
margin-top: 10px;
|
||||
}
|
||||
|
||||
> .github-commit-body {
|
||||
margin: 0px;
|
||||
padding: 0px;
|
||||
|
||||
> .github-commit-title {
|
||||
color: #4e575b;
|
||||
text-decoration: none;
|
||||
font-size: 13px;
|
||||
font-weight: 600;
|
||||
line-height: 22px;
|
||||
margin: 0;
|
||||
padding: 0px;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
width: 90%;
|
||||
|
||||
.label-name {
|
||||
font-size: 16px;
|
||||
font-family: "open_sanssemibold";
|
||||
margin: 0 10px 0 0;
|
||||
}
|
||||
}
|
||||
|
||||
> .github-commit-meta {
|
||||
font-weight: normal;
|
||||
color: #767676;
|
||||
font-size: 12px;
|
||||
line-height: 22px;
|
||||
margin: 0px;
|
||||
padding: 0px;
|
||||
width: 90%;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -45,7 +45,7 @@
|
|||
|
||||
h1
|
||||
{
|
||||
font-size: 2.3em;
|
||||
font-size: 2em;
|
||||
font-weight: bold;
|
||||
color:$color-off-black;
|
||||
margin: 30px 0 20px 0;
|
||||
|
|
|
@ -7,38 +7,18 @@
|
|||
<div class="pull-left width-45">
|
||||
<div class="input-form">
|
||||
<div class="heading">
|
||||
<div class="title">Select Repository</div>
|
||||
<div class="title">Select Repositories</div>
|
||||
<div class="tip">Choose source of code information to be displayed</div>
|
||||
</div>
|
||||
<div class="input-control">
|
||||
<label>Organizations and User</label>
|
||||
<div class="tip">Select organization or username</div>
|
||||
<label>Organization or User</label>
|
||||
<div class="tip">Select organization or username whose repositories you want to show</div>
|
||||
{{ui-select id="owners-dropdown" content=owners action=(action 'onOwnerChange') optionValuePath="id" optionLabelPath="name" selection=config.owner}}
|
||||
</div>
|
||||
{{#if noRepos}}
|
||||
<div class="input-control">
|
||||
<div class="color-error">You have no repositories.</div>
|
||||
</div>
|
||||
{{else}}
|
||||
<div class="input-control">
|
||||
<label>Repositories</label>
|
||||
<div class="tip">Select repository</div>
|
||||
{{ui-select id="repos-dropdown" content=repos action=(action 'onRepoChange') optionValuePath="id" optionLabelPath="name" selection=config.repo}}
|
||||
</div>
|
||||
<div class="input-control">
|
||||
<label>Report</label>
|
||||
<div class="tip">Select report type</div>
|
||||
{{ui-select id="report-dropdown" content=reports action=(action 'onReportChange') optionValuePath="id" optionLabelPath="name" selection=config.report}}
|
||||
</div>
|
||||
<div class="input-control">
|
||||
<label>Show items since</label>
|
||||
{{input id="branch-since" value=config.branchSince type="text" }}
|
||||
</div>
|
||||
<div class="input-control">
|
||||
<label>Number of items to show</label>
|
||||
{{input id="branch-lines" value=config.branchLines type="number" min="1" step="1" max="100" }}
|
||||
</div>
|
||||
{{/if}}
|
||||
<div class="input-control">
|
||||
<label>Show items since (default 7 days ago)</label>
|
||||
{{input id="branch-since" value=config.branchSince type="text" }}<br>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
@ -46,10 +26,9 @@
|
|||
|
||||
<div class="pull-left width-45">
|
||||
<div class="input-form">
|
||||
{{#if showCommits}}
|
||||
<div class="input-control">
|
||||
<label>Branches</label>
|
||||
<div class="tip">Select branch</div>
|
||||
<label>Repositories</label>
|
||||
<div class="tip">Select the repositories to show</div>
|
||||
<div class="github-board">
|
||||
{{#each config.lists as |list|}}
|
||||
<div class="github-list" {{action 'onListCheckbox' list.id}}>
|
||||
|
@ -58,42 +37,12 @@
|
|||
{{else}}
|
||||
<i class="material-icons widget-checkbox checkbox-gray github-list-checkbox">check_box_outline_blank</i>
|
||||
{{/if}}
|
||||
<span class="github-list-title">{{list.name}}</span>
|
||||
<span class="github-list-title">{{list.repo}} {{#if list.private}}(private){{/if}}</span>
|
||||
</div>
|
||||
{{/each}}
|
||||
<div class="clearfix" />
|
||||
</div>
|
||||
</div>
|
||||
{{/if}}
|
||||
{{#if showLabels}}
|
||||
<div class="input-control">
|
||||
<label>State</label>
|
||||
<div class="tip">Open, Closed or All issues</div>
|
||||
{{ui-select id="issue-state-dropdown" content=states action=(action 'onStateChange') optionValuePath="id" optionLabelPath="name" selection=config.state}}
|
||||
</div>
|
||||
<div class="input-control">
|
||||
<label>Issue numbers</label>
|
||||
<div class="tip">A comma separated list of issue numbers e.g. 42, 1066, 1966 (other selection criteria are ignored)</div>
|
||||
{{input id="github-issues" value=config.issues type="text" }}
|
||||
</div>
|
||||
<div class="input-control">
|
||||
<label>Labels</label>
|
||||
<div class="tip">Select labels - an issue must have all labels to be shown, if no label is selected all issues are shown.</div>
|
||||
<div class="github-board">
|
||||
{{#each config.lists as |list|}}
|
||||
<div class="github-list" {{action 'onLabelCheckbox' list.id}} >
|
||||
{{#if list.included}}
|
||||
<i class="material-icons widget-checkbox checkbox-gray github-list-checkbox">check_box</i>
|
||||
{{else}}
|
||||
<i class="material-icons widget-checkbox checkbox-gray github-list-checkbox">check_box_outline_blank</i>
|
||||
{{/if}}
|
||||
<span class="github-list-title"><span class="github-issue-label" style="background-color:#{{list.color}}">{{list.name}}</span></span>
|
||||
</div>
|
||||
{{/each}}
|
||||
<div class="clearfix" />
|
||||
</div>
|
||||
</div>
|
||||
{{/if}}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
|
BIN
app/public/assets/img/github/icon-last-updated.png
Normal file
BIN
app/public/assets/img/github/icon-last-updated.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.3 KiB |
|
@ -26,8 +26,8 @@ type ProdInfo struct {
|
|||
// Product returns product edition details
|
||||
func Product() (p ProdInfo) {
|
||||
p.Major = "0"
|
||||
p.Minor = "16"
|
||||
p.Patch = "1"
|
||||
p.Minor = "17"
|
||||
p.Patch = "0"
|
||||
p.Version = fmt.Sprintf("%s.%s.%s", p.Major, p.Minor, p.Patch)
|
||||
p.Edition = "Community"
|
||||
p.Title = fmt.Sprintf("%s Edition", p.Edition)
|
||||
|
|
110
core/section/github/auth.go
Normal file
110
core/section/github/auth.go
Normal file
|
@ -0,0 +1,110 @@
|
|||
// Copyright 2016 Documize Inc. <legal@documize.com>. All rights reserved.
|
||||
//
|
||||
// This software (Documize Community Edition) is licensed under
|
||||
// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html
|
||||
//
|
||||
// You can operate outside the AGPL restrictions by purchasing
|
||||
// Documize Enterprise Edition and obtaining a commercial license
|
||||
// by contacting <sales@documize.com>.
|
||||
//
|
||||
// https://documize.com
|
||||
|
||||
package github
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strings"
|
||||
|
||||
"github.com/documize/community/core/api/request"
|
||||
|
||||
gogithub "github.com/google/go-github/github"
|
||||
"golang.org/x/oauth2"
|
||||
)
|
||||
|
||||
func clientID() string {
|
||||
return request.ConfigString(meta.ConfigHandle(), "clientID")
|
||||
}
|
||||
|
||||
func clientSecret() string {
|
||||
return request.ConfigString(meta.ConfigHandle(), "clientSecret")
|
||||
}
|
||||
|
||||
func authorizationCallbackURL() string {
|
||||
// NOTE: URL value must have the path and query "/api/public/validate?section=github"
|
||||
return request.ConfigString(meta.ConfigHandle(), "authorizationCallbackURL")
|
||||
}
|
||||
|
||||
func validateToken(ptoken string) error {
|
||||
// Github authorization check
|
||||
authClient := gogithub.NewClient((&gogithub.BasicAuthTransport{
|
||||
Username: clientID(),
|
||||
Password: clientSecret(),
|
||||
}).Client())
|
||||
_, _, err := authClient.Authorizations.Check(clientID(), ptoken)
|
||||
return err
|
||||
}
|
||||
|
||||
func (*Provider) githubClient(config *githubConfig) *gogithub.Client {
|
||||
ts := oauth2.StaticTokenSource(
|
||||
&oauth2.Token{AccessToken: config.Token},
|
||||
)
|
||||
tc := oauth2.NewClient(oauth2.NoContext, ts)
|
||||
|
||||
return gogithub.NewClient(tc)
|
||||
}
|
||||
|
||||
// Callback is called by a browser redirect from Github, via the validation endpoint
|
||||
func Callback(res http.ResponseWriter, req *http.Request) error {
|
||||
|
||||
code := req.URL.Query().Get("code")
|
||||
state := req.URL.Query().Get("state")
|
||||
|
||||
ghurl := "https://github.com/login/oauth/access_token"
|
||||
vals := "client_id=" + clientID()
|
||||
vals += "&client_secret=" + clientSecret()
|
||||
vals += "&code=" + code
|
||||
vals += "&state=" + state
|
||||
|
||||
req2, err := http.NewRequest("POST", ghurl+"?"+vals, strings.NewReader(vals))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
|
||||
req2.Header.Set("Accept", "application/json")
|
||||
|
||||
res2, err := http.DefaultClient.Do(req2)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var gt githubCallbackT
|
||||
|
||||
err = json.NewDecoder(res2.Body).Decode(>)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = res2.Body.Close()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
returl, err := url.QueryUnescape(state)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
up, err := url.Parse(returl)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
target := up.Scheme + "://" + up.Host + up.Path + "?code=" + gt.AccessToken
|
||||
|
||||
http.Redirect(res, req, target, http.StatusTemporaryRedirect)
|
||||
|
||||
return nil
|
||||
}
|
306
core/section/github/commits.go
Normal file
306
core/section/github/commits.go
Normal file
|
@ -0,0 +1,306 @@
|
|||
// Copyright 2016 Documize Inc. <legal@documize.com>. All rights reserved.
|
||||
//
|
||||
// This software (Documize Community Edition) is licensed under
|
||||
// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html
|
||||
//
|
||||
// You can operate outside the AGPL restrictions by purchasing
|
||||
// Documize Enterprise Edition and obtaining a commercial license
|
||||
// by contacting <sales@documize.com>.
|
||||
//
|
||||
// https://documize.com
|
||||
|
||||
package github
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"html/template"
|
||||
"sort"
|
||||
"time"
|
||||
|
||||
"github.com/documize/community/core/log"
|
||||
|
||||
gogithub "github.com/google/go-github/github"
|
||||
)
|
||||
|
||||
const commitTimeFormat = "January 2 2006, 15:04"
|
||||
|
||||
type githubCommit struct {
|
||||
Owner string `json:"owner"`
|
||||
Repo string `json:"repo"`
|
||||
ShowRepo bool `json:"showRepo"`
|
||||
Branch string `json:"branch"`
|
||||
ShowBranch bool `json:"ShowBranch"`
|
||||
Date string `json:"date"`
|
||||
BinDate time.Time `json:"-"` // only used for sorting
|
||||
ShowDate bool `json:"ShowDate"`
|
||||
Login string `json:"login"`
|
||||
Name string `json:"name"`
|
||||
Avatar string `json:"avatar"`
|
||||
ShowUser bool `json:"ShowUser"`
|
||||
Message string `json:"message"`
|
||||
URL template.URL `json:"url"`
|
||||
}
|
||||
|
||||
type githubAuthorStats struct {
|
||||
Author string `json:"author"`
|
||||
Login string `json:"login"`
|
||||
Avatar string `json:"avatar"`
|
||||
CommitCount int `json:"commitCount"`
|
||||
Repos []string `json:"repos"`
|
||||
OpenIssues int `json:"openIssues"`
|
||||
ClosedIssues int `json:"closedIssues"`
|
||||
}
|
||||
|
||||
// order commits in a way that makes sense of the table
|
||||
type orderCommits []githubCommit
|
||||
|
||||
func (s orderCommits) Len() int { return len(s) }
|
||||
func (s orderCommits) Swap(i, j int) { s[i], s[j] = s[j], s[i] }
|
||||
func (s orderCommits) Less(i, j int) bool {
|
||||
if s[i].Repo == s[j].Repo {
|
||||
if s[i].Branch == s[j].Branch {
|
||||
if s[i].BinDate == s[j].BinDate {
|
||||
return s[i].Name < s[j].Name
|
||||
}
|
||||
return s[i].BinDate.Before(s[j].BinDate)
|
||||
}
|
||||
return s[i].Branch < s[j].Branch
|
||||
}
|
||||
return s[i].Repo < s[j].Repo
|
||||
}
|
||||
|
||||
// sort stats in order that that should be presented.
|
||||
type asToSort []githubAuthorStats
|
||||
|
||||
func (s asToSort) Len() int { return len(s) }
|
||||
func (s asToSort) Swap(i, j int) { s[i], s[j] = s[j], s[i] }
|
||||
func (s asToSort) Less(i, j int) bool {
|
||||
return s[i].CommitCount > s[j].CommitCount
|
||||
}
|
||||
|
||||
// sort branches in order that that should be presented.
|
||||
type branchByID []githubBranch
|
||||
|
||||
func (s branchByID) Len() int { return len(s) }
|
||||
func (s branchByID) Swap(i, j int) { s[i], s[j] = s[j], s[i] }
|
||||
func (s branchByID) Less(i, j int) bool {
|
||||
return s[i].ID < s[j].ID
|
||||
}
|
||||
|
||||
const tagCommitsData = "commitsData"
|
||||
|
||||
func getCommits(client *gogithub.Client, config *githubConfig) ([]githubCommit, []githubAuthorStats, error) {
|
||||
|
||||
// first make sure we've got all the branches
|
||||
for _, orb := range config.Lists {
|
||||
if orb.Included {
|
||||
|
||||
branches, _, err := client.Repositories.ListBranches(orb.Owner, orb.Repo,
|
||||
&gogithub.ListOptions{PerPage: 100})
|
||||
if err == nil {
|
||||
render := make([]githubBranch, len(branches))
|
||||
for kc, vb := range branches {
|
||||
for _, existing := range config.Lists {
|
||||
if orb.Owner == existing.Owner && orb.Repo == existing.Repo && orb.Name == *vb.Name {
|
||||
goto found
|
||||
}
|
||||
}
|
||||
render[kc] = githubBranch{
|
||||
Owner: orb.Owner,
|
||||
Repo: orb.Repo,
|
||||
Name: *vb.Name,
|
||||
ID: fmt.Sprintf("%s:%s:%s", orb.Owner, orb.Repo, *vb.Name),
|
||||
Included: true,
|
||||
URL: "https://github.com/" + orb.Owner + "/" + orb.Repo + "/tree/" + *vb.Name,
|
||||
}
|
||||
found:
|
||||
}
|
||||
config.Lists = append(config.Lists, render...)
|
||||
}
|
||||
}
|
||||
}
|
||||
sort.Sort(branchByID(config.Lists))
|
||||
|
||||
config.UserNames = make(map[string]string)
|
||||
|
||||
authorStats := make(map[string]githubAuthorStats)
|
||||
|
||||
contribBranch := make(map[string]map[string]struct{})
|
||||
|
||||
overall := []githubCommit{}
|
||||
|
||||
for _, orb := range config.Lists {
|
||||
if orb.Included {
|
||||
|
||||
opts := &gogithub.CommitsListOptions{
|
||||
SHA: orb.Name,
|
||||
ListOptions: gogithub.ListOptions{PerPage: config.BranchLines}}
|
||||
|
||||
if config.SincePtr != nil {
|
||||
opts.Since = *config.SincePtr
|
||||
}
|
||||
|
||||
guff, _, err := client.Repositories.ListCommits(orb.Owner, orb.Repo, opts)
|
||||
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
thisBranch := fmt.Sprintf("%s:%s", orb.Repo, orb.Name)
|
||||
|
||||
for _, v := range guff {
|
||||
|
||||
var d, m, u string
|
||||
var bd time.Time
|
||||
if v.Commit != nil {
|
||||
if v.Commit.Committer.Date != nil {
|
||||
d = v.Commit.Committer.Date.Format(commitTimeFormat)
|
||||
bd = *v.Commit.Committer.Date
|
||||
}
|
||||
if v.Commit.Message != nil {
|
||||
m = *v.Commit.Message
|
||||
}
|
||||
}
|
||||
|
||||
if v.HTMLURL != nil {
|
||||
u = *v.HTMLURL
|
||||
}
|
||||
|
||||
// author commits
|
||||
al, an, aa := "", "", githubGravatar
|
||||
if v.Author != nil {
|
||||
if v.Author.Login != nil {
|
||||
al = *v.Author.Login
|
||||
an = getUserName(client, config, al)
|
||||
}
|
||||
|
||||
if v.Author.AvatarURL != nil {
|
||||
aa = *v.Author.AvatarURL
|
||||
}
|
||||
}
|
||||
l := al // use author login
|
||||
|
||||
overall = append(overall, githubCommit{
|
||||
Owner: orb.Owner,
|
||||
Repo: orb.Repo,
|
||||
Branch: orb.Name,
|
||||
Name: an,
|
||||
Login: l,
|
||||
Message: m,
|
||||
Date: d,
|
||||
BinDate: bd,
|
||||
Avatar: aa,
|
||||
URL: template.URL(u),
|
||||
})
|
||||
|
||||
if _, ok := contribBranch[l]; !ok {
|
||||
contribBranch[l] = make(map[string]struct{})
|
||||
}
|
||||
contribBranch[l][thisBranch] = struct{}{}
|
||||
|
||||
cum := authorStats[l]
|
||||
cum.Login = l
|
||||
cum.Author = an
|
||||
cum.Avatar = aa
|
||||
cum.CommitCount++
|
||||
// TODO review, this code removed as too slow
|
||||
//cmt, _, err := client.Repositories.GetCommit(orb.Owner, orb.Repo, *v.SHA)
|
||||
//if err == nil {
|
||||
// if cmt.Stats != nil {
|
||||
// if cmt.Stats.Total != nil {
|
||||
// cum.TotalChanges += (*cmt.Stats.Total)
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
//
|
||||
authorStats[l] = cum
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sort.Sort(orderCommits(overall))
|
||||
|
||||
for k := range overall {
|
||||
overall[k].ShowRepo = true
|
||||
overall[k].ShowBranch = true
|
||||
overall[k].ShowDate = true
|
||||
overall[k].ShowUser = true
|
||||
if k > 0 {
|
||||
if overall[k].Repo == overall[k-1].Repo {
|
||||
overall[k].ShowRepo = false
|
||||
if overall[k].Branch == overall[k-1].Branch {
|
||||
overall[k].ShowBranch = false
|
||||
if overall[k].Date == overall[k-1].Date {
|
||||
overall[k].ShowDate = false
|
||||
overall[k].ShowUser = overall[k].Name != overall[k-1].Name
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
retStats := make([]githubAuthorStats, 0, len(authorStats))
|
||||
for _, v := range authorStats {
|
||||
repos := contribBranch[v.Login]
|
||||
v.Repos = make([]string, 0, len(repos))
|
||||
for r := range repos {
|
||||
v.Repos = append(v.Repos, r)
|
||||
}
|
||||
sort.Strings(v.Repos)
|
||||
retStats = append(retStats, v)
|
||||
}
|
||||
sort.Sort(asToSort(retStats))
|
||||
|
||||
return overall, retStats, nil
|
||||
|
||||
}
|
||||
|
||||
func refreshCommits(gr *githubRender, config *githubConfig, client *gogithub.Client) (err error) {
|
||||
gr.BranchCommits, gr.AuthorStats, err = getCommits(client, config)
|
||||
if err != nil {
|
||||
log.Error("github refreshCommits:", err)
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func renderCommits(payload *githubRender, c *githubConfig) error {
|
||||
payload.CommitCount = 0
|
||||
for range payload.BranchCommits {
|
||||
payload.CommitCount++
|
||||
}
|
||||
payload.HasCommits = payload.CommitCount > 0
|
||||
|
||||
for i := range payload.Issues {
|
||||
var author int
|
||||
for a := range payload.AuthorStats {
|
||||
if payload.AuthorStats[a].Login == payload.Issues[i].Name ||
|
||||
(payload.AuthorStats[a].Login == "" && payload.Issues[i].Name == unassignedIssue) {
|
||||
author = a
|
||||
goto found
|
||||
}
|
||||
}
|
||||
// no Author found for issue, so create one
|
||||
payload.AuthorStats = append(payload.AuthorStats, githubAuthorStats{
|
||||
Author: payload.Issues[i].Name,
|
||||
Avatar: payload.Issues[i].Avatar,
|
||||
})
|
||||
author = len(payload.AuthorStats) - 1
|
||||
found:
|
||||
if payload.Issues[i].IsOpen {
|
||||
payload.AuthorStats[author].OpenIssues++
|
||||
} else {
|
||||
payload.AuthorStats[author].ClosedIssues++
|
||||
}
|
||||
}
|
||||
payload.HasAuthorStats = len(payload.AuthorStats) > 0
|
||||
sort.Sort(asToSort(payload.AuthorStats))
|
||||
|
||||
payload.NumContributors = len(payload.AuthorStats) - 1
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func init() {
|
||||
reports[tagCommitsData] = report{refreshCommits, renderCommits, commitsTemplate}
|
||||
}
|
93
core/section/github/commits_template.go
Normal file
93
core/section/github/commits_template.go
Normal file
|
@ -0,0 +1,93 @@
|
|||
// Copyright 2016 Documize Inc. <legal@documize.com>. All rights reserved.
|
||||
//
|
||||
// This software (Documize Community Edition) is licensed under
|
||||
// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html
|
||||
//
|
||||
// You can operate outside the AGPL restrictions by purchasing
|
||||
// Documize Enterprise Edition and obtaining a commercial license
|
||||
// by contacting <sales@documize.com>.
|
||||
//
|
||||
// https://documize.com
|
||||
|
||||
package github
|
||||
|
||||
const commitsTemplate = `
|
||||
<div class="section-github-render">
|
||||
{{if .HasAuthorStats}}
|
||||
<h3>Contributors</h3>
|
||||
|
||||
<p>
|
||||
There
|
||||
{{if eq 1 .NumContributors}}is{{else}}are{{end}}
|
||||
{{.NumContributors}}
|
||||
{{if eq 1 .NumContributors}}contributor{{else}}contributors{{end}}
|
||||
across {{.RepoCount}}
|
||||
{{if eq 1 .RepoCount}} repository. {{else}} repositories. {{end}}
|
||||
</p>
|
||||
|
||||
<table class="contributor-table" style="width:100%;">
|
||||
<tbody class="github">
|
||||
{{range $stats := .AuthorStats}}
|
||||
<tr>
|
||||
<td class="width-5">
|
||||
<img class="github-avatar" alt="@{{$stats.Author}}" src="{{$stats.Avatar}}" height="36" width="36">
|
||||
</td>
|
||||
|
||||
<td class="width-95">
|
||||
<h6>{{$stats.Author}}</h6>
|
||||
{{if gt $stats.OpenIssues 0}}
|
||||
has been assigned {{$stats.OpenIssues}}
|
||||
{{if eq 1 $stats.OpenIssues}} issue,
|
||||
{{else}} issues, {{end}}
|
||||
{{end}}
|
||||
{{if gt $stats.ClosedIssues 0}}
|
||||
{{$stats.ClosedIssues}} have been closed,
|
||||
{{end}}
|
||||
|
||||
{{if gt $stats.CommitCount 0}}
|
||||
has made {{$stats.CommitCount}}
|
||||
{{if eq 1 $stats.CommitCount}} commit {{else}} commits {{end}}
|
||||
on {{len $stats.Repos}} {{if eq 1 (len $stats.Repos)}} branch. {{else}} branches. {{end}}
|
||||
<br>
|
||||
{{range $repo := $stats.Repos}} {{$repo}}, {{end}}
|
||||
{{end}}
|
||||
</td>
|
||||
|
||||
</tr>
|
||||
{{end}}
|
||||
</tbody>
|
||||
</table>
|
||||
{{end}}
|
||||
|
||||
{{if .HasCommits}}
|
||||
<h3>Commits</h3>
|
||||
<p> There are {{len .BranchCommits}} commits by {{.NumContributors}} contributors
|
||||
across {{.RepoCount}}
|
||||
{{if eq 1 .RepoCount}} repository. {{else}} repositories. {{end}}
|
||||
</p>
|
||||
<table class="contributor-table" style="width:100%;">
|
||||
<tbody class="github">
|
||||
{{range $commit := .BranchCommits}}
|
||||
<tr>
|
||||
<td style="width:5%;">
|
||||
<img class="github-avatar" alt="@{{$commit.Name}}" src="{{$commit.Avatar}}" height="36" width="36">
|
||||
</td>
|
||||
<td style="width:45%;">
|
||||
{{if $commit.ShowUser}}
|
||||
<h6>{{$commit.Name}}</h6>
|
||||
{{end}}
|
||||
<a class="link" href="{{$commit.URL}}">{{$commit.Message}}</a><br>
|
||||
<span class="date-meta">{{if $commit.ShowDate}}{{$commit.Date}}{{end}}</span>
|
||||
</td>
|
||||
<td style="width:55%;">
|
||||
{{if $commit.ShowBranch}}{{$commit.Repo}}:<span class="branch">{{$commit.Branch}}</span>{{end}}
|
||||
<br>
|
||||
</td>
|
||||
</tr>
|
||||
{{end}}
|
||||
</tbody>
|
||||
</table>
|
||||
{{end}}
|
||||
|
||||
</div>
|
||||
`
|
|
@ -15,20 +15,15 @@ import (
|
|||
"bytes"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"html/template"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/documize/community/core/api/request"
|
||||
"github.com/documize/community/core/section/provider"
|
||||
"github.com/documize/community/core/log"
|
||||
"github.com/documize/community/core/section/provider"
|
||||
|
||||
gogithub "github.com/google/go-github/github"
|
||||
"golang.org/x/oauth2"
|
||||
)
|
||||
|
||||
// TODO find a smaller image than the one below
|
||||
|
@ -55,26 +50,6 @@ func (*Provider) Meta() provider.TypeMeta {
|
|||
return meta
|
||||
}
|
||||
|
||||
func clientID() string {
|
||||
return request.ConfigString(meta.ConfigHandle(), "clientID")
|
||||
}
|
||||
func clientSecret() string {
|
||||
return request.ConfigString(meta.ConfigHandle(), "clientSecret")
|
||||
}
|
||||
func authorizationCallbackURL() string {
|
||||
// NOTE: URL value must have the path and query "/api/public/validate?section=github"
|
||||
return request.ConfigString(meta.ConfigHandle(), "authorizationCallbackURL")
|
||||
}
|
||||
func validateToken(ptoken string) error {
|
||||
// Github authorization check
|
||||
authClient := gogithub.NewClient((&gogithub.BasicAuthTransport{
|
||||
Username: clientID(),
|
||||
Password: clientSecret(),
|
||||
}).Client())
|
||||
_, _, err := authClient.Authorizations.Check(clientID(), ptoken)
|
||||
return err
|
||||
}
|
||||
|
||||
// Command to run the various functions required...
|
||||
func (p *Provider) Command(ctx *provider.Context, w http.ResponseWriter, r *http.Request) {
|
||||
query := r.URL.Query()
|
||||
|
@ -105,16 +80,11 @@ func (p *Provider) Command(ctx *provider.Context, w http.ResponseWriter, r *http
|
|||
if err != nil {
|
||||
msg := "Bad body"
|
||||
log.ErrorString("github: " + msg)
|
||||
provider.WriteMessage(w, "gitub", msg)
|
||||
provider.WriteMessage(w, "github", msg)
|
||||
return
|
||||
}
|
||||
|
||||
// get the secret token in the database
|
||||
ptoken := ctx.GetSecrets("token")
|
||||
|
||||
switch method {
|
||||
|
||||
case "saveSecret": // secret Token update code
|
||||
if method == "saveSecret" { // secret Token update code
|
||||
|
||||
// write the new one, direct from JS
|
||||
if err = ctx.SaveSecrets(string(body)); err != nil {
|
||||
|
@ -139,18 +109,18 @@ func (p *Provider) Command(ctx *provider.Context, w http.ResponseWriter, r *http
|
|||
|
||||
config.Clean()
|
||||
// always use DB version of the token
|
||||
config.Token = ptoken
|
||||
config.Token = ctx.GetSecrets("token") // get the secret token in the database
|
||||
|
||||
client := p.githubClient(config)
|
||||
client := p.githubClient(&config)
|
||||
|
||||
switch method { // the main data handling switch
|
||||
switch method {
|
||||
|
||||
case "checkAuth":
|
||||
|
||||
if len(ptoken) == 0 {
|
||||
if len(config.Token) == 0 {
|
||||
err = errors.New("empty github token")
|
||||
} else {
|
||||
err = validateToken(ptoken)
|
||||
err = validateToken(config.Token)
|
||||
}
|
||||
if err != nil {
|
||||
// token now invalid, so wipe it
|
||||
|
@ -160,462 +130,22 @@ func (p *Provider) Command(ctx *provider.Context, w http.ResponseWriter, r *http
|
|||
return
|
||||
}
|
||||
provider.WriteEmpty(w)
|
||||
return
|
||||
|
||||
case tagCommitsData:
|
||||
|
||||
render, err := p.getCommits(client, config)
|
||||
if err != nil {
|
||||
log.Error("github getCommits:", err)
|
||||
provider.WriteError(w, "github", err)
|
||||
return
|
||||
}
|
||||
|
||||
provider.WriteJSON(w, render)
|
||||
|
||||
case tagIssuesData:
|
||||
|
||||
render, err := p.getIssues(client, config)
|
||||
if err != nil {
|
||||
log.Error("github getIssues:", err)
|
||||
provider.WriteError(w, "github", err)
|
||||
return
|
||||
}
|
||||
|
||||
provider.WriteJSON(w, render)
|
||||
|
||||
/*case "issuenum_data":
|
||||
|
||||
render, err := t.getIssueNum(client, config)
|
||||
if err != nil {
|
||||
log.Error("github getIssueNum:", err)
|
||||
provider.WriteError(w, "github", err)
|
||||
return
|
||||
}
|
||||
|
||||
provider.WriteJSON(w, render)*/
|
||||
|
||||
case "owners":
|
||||
|
||||
me, _, err := client.Users.Get("")
|
||||
if err != nil {
|
||||
log.Error("github get user details:", err)
|
||||
provider.WriteError(w, "github", err)
|
||||
return
|
||||
}
|
||||
|
||||
orgs, _, err := client.Organizations.List("", nil)
|
||||
if err != nil {
|
||||
log.Error("github get user's organisations:", err)
|
||||
provider.WriteError(w, "github", err)
|
||||
return
|
||||
}
|
||||
|
||||
owners := make([]githubOwner, 1+len(orgs))
|
||||
owners[0] = githubOwner{ID: *me.Login, Name: *me.Login}
|
||||
for ko, vo := range orgs {
|
||||
id := 1 + ko
|
||||
owners[id].ID = *vo.Login
|
||||
owners[id].Name = *vo.Login
|
||||
}
|
||||
|
||||
owners = sortOwners(owners)
|
||||
|
||||
provider.WriteJSON(w, owners)
|
||||
|
||||
case "repos":
|
||||
|
||||
var render []githubRepo
|
||||
if config.Owner != "" {
|
||||
|
||||
me, _, err := client.Users.Get("")
|
||||
if err != nil {
|
||||
log.Error("github get user details:", err)
|
||||
provider.WriteError(w, "github", err)
|
||||
return
|
||||
}
|
||||
|
||||
var repos []*gogithub.Repository
|
||||
if config.Owner == *me.Login {
|
||||
repos, _, err = client.Repositories.List(config.Owner, nil)
|
||||
} else {
|
||||
opt := &gogithub.RepositoryListByOrgOptions{
|
||||
ListOptions: gogithub.ListOptions{PerPage: 100},
|
||||
}
|
||||
repos, _, err = client.Repositories.ListByOrg(config.Owner, opt)
|
||||
}
|
||||
if err != nil {
|
||||
log.Error("github get user/org repositories:", err)
|
||||
provider.WriteError(w, "github", err)
|
||||
return
|
||||
}
|
||||
for _, vr := range repos {
|
||||
private := ""
|
||||
if *vr.Private {
|
||||
private = " (private)"
|
||||
}
|
||||
render = append(render,
|
||||
githubRepo{
|
||||
Name: config.Owner + "/" + *vr.Name + private,
|
||||
ID: fmt.Sprintf("%s:%s", config.Owner, *vr.Name),
|
||||
Owner: config.Owner,
|
||||
Repo: *vr.Name,
|
||||
Private: *vr.Private,
|
||||
URL: *vr.HTMLURL,
|
||||
})
|
||||
}
|
||||
}
|
||||
render = sortRepos(render)
|
||||
|
||||
provider.WriteJSON(w, render)
|
||||
|
||||
case "branches":
|
||||
|
||||
if config.Owner == "" || config.Repo == "" {
|
||||
provider.WriteJSON(w, []githubBranch{}) // we have nothing to return
|
||||
return
|
||||
}
|
||||
branches, _, err := client.Repositories.ListBranches(config.Owner, config.Repo,
|
||||
&gogithub.ListOptions{PerPage: 100})
|
||||
if err != nil {
|
||||
log.Error("github get branch details:", err)
|
||||
provider.WriteError(w, "github", err)
|
||||
return
|
||||
}
|
||||
render := make([]githubBranch, len(branches))
|
||||
for kc, vb := range branches {
|
||||
render[kc] = githubBranch{
|
||||
Name: *vb.Name,
|
||||
ID: fmt.Sprintf("%s:%s:%s", config.Owner, config.Repo, *vb.Name),
|
||||
Included: false,
|
||||
URL: "https://github.com/" + config.Owner + "/" + config.Repo + "/tree/" + *vb.Name,
|
||||
}
|
||||
}
|
||||
|
||||
provider.WriteJSON(w, render)
|
||||
|
||||
case "labels":
|
||||
|
||||
if config.Owner == "" || config.Repo == "" {
|
||||
provider.WriteJSON(w, []githubBranch{}) // we have nothing to return
|
||||
return
|
||||
}
|
||||
labels, _, err := client.Issues.ListLabels(config.Owner, config.Repo,
|
||||
&gogithub.ListOptions{PerPage: 100})
|
||||
if err != nil {
|
||||
log.Error("github get labels:", err)
|
||||
provider.WriteError(w, "github", err)
|
||||
return
|
||||
}
|
||||
render := make([]githubBranch, len(labels))
|
||||
for kc, vb := range labels {
|
||||
render[kc] = githubBranch{
|
||||
Name: *vb.Name,
|
||||
ID: fmt.Sprintf("%s:%s:%s", config.Owner, config.Repo, *vb.Name),
|
||||
Included: false,
|
||||
Color: *vb.Color,
|
||||
}
|
||||
}
|
||||
|
||||
provider.WriteJSON(w, render)
|
||||
|
||||
default:
|
||||
|
||||
log.ErrorString("Github connector unknown method: " + method)
|
||||
provider.WriteEmpty(w)
|
||||
if listFailed(method, config, client, w) {
|
||||
|
||||
gr := githubRender{}
|
||||
for _, rep := range reports {
|
||||
log.IfErr(rep.refresh(&gr, &config, client))
|
||||
}
|
||||
provider.WriteJSON(w, &gr)
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
func (*Provider) githubClient(config githubConfig) *gogithub.Client {
|
||||
ts := oauth2.StaticTokenSource(
|
||||
&oauth2.Token{AccessToken: config.Token},
|
||||
)
|
||||
tc := oauth2.NewClient(oauth2.NoContext, ts)
|
||||
|
||||
return gogithub.NewClient(tc)
|
||||
}
|
||||
|
||||
/*
|
||||
func (*Provider) getIssueNum(client *gogithub.Client, config githubConfig) ([]githubIssueActivity, error) {
|
||||
|
||||
ret := []githubIssueActivity{}
|
||||
|
||||
issue, _, err := client.Issues.Get(config.Owner, config.Repo, config.IssueNum)
|
||||
|
||||
if err == nil {
|
||||
n := ""
|
||||
a := ""
|
||||
p := issue.User
|
||||
if p != nil {
|
||||
if p.Login != nil {
|
||||
n = *p.Login
|
||||
}
|
||||
if p.AvatarURL != nil {
|
||||
a = *p.AvatarURL
|
||||
}
|
||||
}
|
||||
ret = append(ret, githubIssueActivity{
|
||||
Name: n,
|
||||
Event: "created",
|
||||
Message: template.HTML(*issue.Title),
|
||||
Date: "on " + issue.UpdatedAt.Format("January 2 2006, 15:04"),
|
||||
Avatar: a,
|
||||
URL: template.URL(*issue.HTMLURL),
|
||||
})
|
||||
ret = append(ret, githubIssueActivity{
|
||||
Name: n,
|
||||
Event: "described",
|
||||
Message: template.HTML(*issue.Body),
|
||||
Date: "on " + issue.UpdatedAt.Format("January 2 2006, 15:04"),
|
||||
Avatar: a,
|
||||
URL: template.URL(*issue.HTMLURL),
|
||||
})
|
||||
ret = append(ret, githubIssueActivity{
|
||||
Name: "",
|
||||
Event: "Note",
|
||||
Message: template.HTML("the issue timeline below is in reverse order"),
|
||||
Date: "",
|
||||
Avatar: githubGravatar,
|
||||
URL: template.URL(*issue.HTMLURL),
|
||||
})
|
||||
} else {
|
||||
return ret, err
|
||||
}
|
||||
|
||||
opts := &gogithub.ListOptions{PerPage: config.BranchLines}
|
||||
|
||||
guff, _, err := client.Issues.ListIssueTimeline(config.Owner, config.Repo, config.IssueNum, opts)
|
||||
|
||||
if err != nil {
|
||||
return ret, err
|
||||
}
|
||||
|
||||
for _, v := range guff {
|
||||
if config.SincePtr == nil || v.CreatedAt.After(*config.SincePtr) {
|
||||
var n, a, m, u string
|
||||
|
||||
p := v.Actor
|
||||
if p != nil {
|
||||
if p.Name != nil {
|
||||
n = *p.Name
|
||||
}
|
||||
if p.AvatarURL != nil {
|
||||
a = *p.AvatarURL
|
||||
}
|
||||
}
|
||||
|
||||
u = fmt.Sprintf("https://github.com/%s/%s/issues/%d#event-%d",
|
||||
config.Owner, config.Repo, config.IssueNum, *v.ID)
|
||||
|
||||
switch *v.Event {
|
||||
case "commented":
|
||||
ic, _, err := client.Issues.GetComment(config.Owner, config.Repo, *v.ID)
|
||||
if err != nil {
|
||||
log.ErrorString("github error fetching issue event comment: " + err.Error())
|
||||
} else {
|
||||
m = *ic.Body
|
||||
u = *ic.HTMLURL
|
||||
p := ic.User
|
||||
if p != nil {
|
||||
if p.Login != nil {
|
||||
n = *p.Login
|
||||
}
|
||||
if p.AvatarURL != nil {
|
||||
a = *p.AvatarURL
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ret = append(ret, githubIssueActivity{
|
||||
Name: n,
|
||||
Event: *v.Event,
|
||||
Message: template.HTML(m),
|
||||
Date: "on " + v.CreatedAt.Format("January 2 2006, 15:04"),
|
||||
Avatar: a,
|
||||
URL: template.URL(u),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
return ret, nil
|
||||
|
||||
}
|
||||
*/
|
||||
|
||||
func wrapLabels(labels []gogithub.Label) string {
|
||||
l := ""
|
||||
for _, ll := range labels {
|
||||
l += `<span class="github-issue-label" style="background-color:#` + *ll.Color + `">` + *ll.Name + `</span> `
|
||||
}
|
||||
return l
|
||||
}
|
||||
|
||||
func (*Provider) getIssues(client *gogithub.Client, config githubConfig) ([]githubIssue, error) {
|
||||
|
||||
ret := []githubIssue{}
|
||||
|
||||
isRequired := make([]int, 0, 10)
|
||||
for _, s := range strings.Split(strings.Replace(config.IssuesText, "#", "", -1), ",") {
|
||||
i, err := strconv.Atoi(strings.TrimSpace(s))
|
||||
if err == nil {
|
||||
isRequired = append(isRequired, i)
|
||||
}
|
||||
}
|
||||
if len(isRequired) > 0 {
|
||||
|
||||
for _, i := range isRequired {
|
||||
|
||||
issue, _, err := client.Issues.Get(config.Owner, config.Repo, i)
|
||||
|
||||
if err == nil {
|
||||
n := ""
|
||||
p := issue.User
|
||||
if p != nil {
|
||||
if p.Login != nil {
|
||||
n = *p.Login
|
||||
}
|
||||
}
|
||||
l := wrapLabels(issue.Labels)
|
||||
ret = append(ret, githubIssue{
|
||||
Name: n,
|
||||
Message: *issue.Title,
|
||||
Date: issue.CreatedAt.Format("January 2 2006, 15:04"),
|
||||
Updated: issue.UpdatedAt.Format("January 2 2006, 15:04"),
|
||||
URL: template.URL(*issue.HTMLURL),
|
||||
Labels: template.HTML(l),
|
||||
ID: *issue.Number,
|
||||
IsOpen: *issue.State == "open",
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
opts := &gogithub.IssueListByRepoOptions{
|
||||
Sort: "updated",
|
||||
State: config.IssueState.ID,
|
||||
ListOptions: gogithub.ListOptions{PerPage: config.BranchLines}}
|
||||
|
||||
if config.SincePtr != nil {
|
||||
opts.Since = *config.SincePtr
|
||||
}
|
||||
|
||||
for _, lab := range config.Lists {
|
||||
if lab.Included {
|
||||
opts.Labels = append(opts.Labels, lab.Name)
|
||||
}
|
||||
}
|
||||
|
||||
guff, _, err := client.Issues.ListByRepo(config.Owner, config.Repo, opts)
|
||||
|
||||
if err != nil {
|
||||
return ret, err
|
||||
}
|
||||
|
||||
for _, v := range guff {
|
||||
n := ""
|
||||
ptr := v.User
|
||||
if ptr != nil {
|
||||
if ptr.Login != nil {
|
||||
n = *ptr.Login
|
||||
}
|
||||
}
|
||||
l := wrapLabels(v.Labels)
|
||||
ret = append(ret, githubIssue{
|
||||
Name: n,
|
||||
Message: *v.Title,
|
||||
Date: v.CreatedAt.Format("January 2 2006, 15:04"),
|
||||
Updated: v.UpdatedAt.Format("January 2 2006, 15:04"),
|
||||
URL: template.URL(*v.HTMLURL),
|
||||
Labels: template.HTML(l),
|
||||
ID: *v.Number,
|
||||
IsOpen: *v.State == "open",
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
return ret, nil
|
||||
|
||||
}
|
||||
|
||||
func (*Provider) getCommits(client *gogithub.Client, config githubConfig) ([]githubBranchCommits, error) {
|
||||
|
||||
opts := &gogithub.CommitsListOptions{
|
||||
SHA: config.Branch,
|
||||
ListOptions: gogithub.ListOptions{PerPage: config.BranchLines}}
|
||||
|
||||
if config.SincePtr != nil {
|
||||
opts.Since = *config.SincePtr
|
||||
}
|
||||
|
||||
guff, _, err := client.Repositories.ListCommits(config.Owner, config.Repo, opts)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if len(guff) == 0 {
|
||||
return []githubBranchCommits{}, nil
|
||||
}
|
||||
|
||||
day := ""
|
||||
newDay := ""
|
||||
ret := []githubBranchCommits{}
|
||||
|
||||
for k, v := range guff {
|
||||
|
||||
if guff[k].Commit != nil {
|
||||
if guff[k].Commit.Committer.Date != nil {
|
||||
y, m, d := (*guff[k].Commit.Committer.Date).Date()
|
||||
newDay = fmt.Sprintf("%s %d, %d", m.String(), d, y)
|
||||
}
|
||||
}
|
||||
if day != newDay {
|
||||
day = newDay
|
||||
ret = append(ret, githubBranchCommits{
|
||||
Name: fmt.Sprintf("%s/%s:%s", config.Owner, config.Repo, config.Branch),
|
||||
Day: day,
|
||||
})
|
||||
}
|
||||
|
||||
var a, d, l, m, u string
|
||||
if v.Commit != nil {
|
||||
if v.Commit.Committer.Date != nil {
|
||||
// d = fmt.Sprintf("%v", *v.Commit.Committer.Date)
|
||||
d = v.Commit.Committer.Date.Format("January 2 2006, 15:04")
|
||||
}
|
||||
if v.Commit.Message != nil {
|
||||
m = *v.Commit.Message
|
||||
}
|
||||
}
|
||||
if v.Committer != nil {
|
||||
if v.Committer.Login != nil {
|
||||
l = *v.Committer.Login
|
||||
}
|
||||
if v.Committer.AvatarURL != nil {
|
||||
a = *v.Committer.AvatarURL
|
||||
}
|
||||
}
|
||||
if a == "" {
|
||||
a = githubGravatar
|
||||
}
|
||||
if v.HTMLURL != nil {
|
||||
u = *v.HTMLURL
|
||||
}
|
||||
ret[len(ret)-1].Commits = append(ret[len(ret)-1].Commits, githubCommit{
|
||||
Name: l,
|
||||
Message: m,
|
||||
Date: d,
|
||||
Avatar: a,
|
||||
URL: template.URL(u),
|
||||
})
|
||||
}
|
||||
|
||||
return ret, nil
|
||||
|
||||
}
|
||||
|
||||
// Refresh ... gets the latest version
|
||||
func (p *Provider) Refresh(ctx *provider.Context, configJSON, data string) string {
|
||||
var c = githubConfig{}
|
||||
|
@ -630,52 +160,24 @@ func (p *Provider) Refresh(ctx *provider.Context, configJSON, data string) strin
|
|||
c.Clean()
|
||||
c.Token = ctx.GetSecrets("token")
|
||||
|
||||
switch c.ReportInfo.ID {
|
||||
/*case "issuenum_data":
|
||||
refreshed, err := t.getIssueNum(t.githubClient(c), c)
|
||||
client := p.githubClient(&c)
|
||||
|
||||
byts, err := json.Marshal(refreshReportData(&c, client))
|
||||
if err != nil {
|
||||
log.Error("unable to get github issue number activity", err)
|
||||
return data
|
||||
}
|
||||
j, err := json.Marshal(refreshed)
|
||||
if err != nil {
|
||||
log.Error("unable to marshall github issue number activity", err)
|
||||
return data
|
||||
}
|
||||
return string(j)*/
|
||||
|
||||
case tagIssuesData:
|
||||
refreshed, err := p.getIssues(p.githubClient(c), c)
|
||||
if err != nil {
|
||||
log.Error("unable to get github issues", err)
|
||||
return data
|
||||
}
|
||||
j, err := json.Marshal(refreshed)
|
||||
if err != nil {
|
||||
log.Error("unable to marshall github issues", err)
|
||||
return data
|
||||
}
|
||||
return string(j)
|
||||
|
||||
case tagCommitsData:
|
||||
refreshed, err := p.getCommits(p.githubClient(c), c)
|
||||
if err != nil {
|
||||
log.Error("unable to get github commits", err)
|
||||
return data
|
||||
}
|
||||
j, err := json.Marshal(refreshed)
|
||||
if err != nil {
|
||||
log.Error("unable to marshall github commits", err)
|
||||
return data
|
||||
}
|
||||
return string(j)
|
||||
|
||||
default:
|
||||
msg := "unknown data format: " + c.ReportInfo.ID
|
||||
log.ErrorString(msg)
|
||||
return "internal configuration error, " + msg
|
||||
log.Error("unable to marshall github data", err)
|
||||
return "internal configuration error '" + err.Error() + "'"
|
||||
}
|
||||
|
||||
return string(byts)
|
||||
|
||||
}
|
||||
|
||||
func refreshReportData(c *githubConfig, client *gogithub.Client) *githubRender {
|
||||
var gr = githubRender{}
|
||||
for _, rep := range reports {
|
||||
log.IfErr(rep.refresh(&gr, c, client))
|
||||
}
|
||||
return &gr
|
||||
}
|
||||
|
||||
// Render ... just returns the data given, suitably formatted
|
||||
|
@ -695,163 +197,56 @@ func (p *Provider) Render(ctx *provider.Context, config, data string) string {
|
|||
c.Clean()
|
||||
c.Token = ctx.GetSecrets("token")
|
||||
|
||||
data = strings.TrimSpace(data)
|
||||
if len(data) == 0 {
|
||||
// TODO review why this error occurs & if it should be reported - seems to occur for new sections
|
||||
// log.ErrorString(fmt.Sprintf("Rendered empty github JSON payload as '' for owner %s repos %#v", c.Owner, c.Lists))
|
||||
return ""
|
||||
}
|
||||
|
||||
err = json.Unmarshal([]byte(data), &payload)
|
||||
if err != nil {
|
||||
log.Error("unable to unmarshall github data", err)
|
||||
return "Please delete and recreate this Github section."
|
||||
}
|
||||
|
||||
payload.Config = c
|
||||
payload.Repo = c.RepoInfo
|
||||
payload.Limit = c.BranchLines
|
||||
if len(c.BranchSince) > 0 {
|
||||
payload.DateMessage = "created after " + c.BranchSince
|
||||
}
|
||||
payload.List = c.Lists
|
||||
|
||||
switch c.ReportInfo.ID {
|
||||
/* case "issuenum_data":
|
||||
payload.IssueNum = c.IssueNum
|
||||
raw := []githubIssueActivity{}
|
||||
ret := ""
|
||||
for _, repID := range c.ReportOrder {
|
||||
|
||||
if len(data) > 0 {
|
||||
err = json.Unmarshal([]byte(data), &raw)
|
||||
if err != nil {
|
||||
log.Error("unable to unmarshall github issue activity data", err)
|
||||
return "Documize internal github json umarshall issue activity data error: " + err.Error()
|
||||
}
|
||||
}
|
||||
|
||||
opt := &gogithub.MarkdownOptions{Mode: "gfm", Context: c.Owner + "/" + c.Repo}
|
||||
client := p.githubClient(c)
|
||||
for k, v := range raw {
|
||||
if v.Event == "commented" {
|
||||
output, _, err := client.Markdown(string(v.Message), opt)
|
||||
if err != nil {
|
||||
log.Error("convert commented text to markdown", err)
|
||||
} else {
|
||||
raw[k].Message = template.HTML(output)
|
||||
}
|
||||
}
|
||||
}
|
||||
payload.IssueNumActivity = raw */
|
||||
|
||||
case tagIssuesData:
|
||||
raw := []githubIssue{}
|
||||
|
||||
if len(data) > 0 {
|
||||
err = json.Unmarshal([]byte(data), &raw)
|
||||
if err != nil {
|
||||
log.Error("unable to unmarshall github issue data", err)
|
||||
return "Documize internal github json umarshall open data error: " + err.Error() + "<BR>" + data
|
||||
}
|
||||
}
|
||||
payload.Issues = raw
|
||||
if strings.TrimSpace(c.IssuesText) != "" {
|
||||
payload.ShowIssueNumbers = true
|
||||
payload.DateMessage = c.IssuesText
|
||||
} else {
|
||||
if len(c.Lists) > 0 {
|
||||
for _, v := range c.Lists {
|
||||
if v.Included {
|
||||
payload.ShowList = true
|
||||
break
|
||||
}
|
||||
}
|
||||
payload.List = c.Lists
|
||||
}
|
||||
rep, ok := reports[repID]
|
||||
if !ok {
|
||||
msg := "github report not found for: " + repID
|
||||
log.ErrorString(msg)
|
||||
return "Documize internal error: " + msg
|
||||
}
|
||||
|
||||
case tagCommitsData:
|
||||
raw := []githubBranchCommits{}
|
||||
err = json.Unmarshal([]byte(data), &raw)
|
||||
if err = rep.render(&payload, &c); err != nil {
|
||||
log.Error("unable to render "+repID, err)
|
||||
return "Documize internal github render " + repID + " error: " + err.Error() + "<BR>" + data
|
||||
}
|
||||
|
||||
t := template.New("github")
|
||||
|
||||
t, err = t.Parse(rep.template)
|
||||
|
||||
if err != nil {
|
||||
log.Error("unable to unmarshall github commit data", err)
|
||||
return "Documize internal github json umarshall data error: " + err.Error() + "<BR>" + data
|
||||
}
|
||||
c.ReportInfo.ID = tagCommitsData
|
||||
payload.BranchCommits = raw
|
||||
for _, list := range raw {
|
||||
payload.CommitCount += len(list.Commits)
|
||||
log.Error("github render template.Parse error:", err)
|
||||
return "Documize internal github template.Parse error: " + err.Error()
|
||||
}
|
||||
|
||||
default:
|
||||
msg := "unknown data format: " + c.ReportInfo.ID
|
||||
log.ErrorString(msg)
|
||||
return "internal configuration error, " + msg
|
||||
buffer := new(bytes.Buffer)
|
||||
err = t.Execute(buffer, payload)
|
||||
if err != nil {
|
||||
log.Error("github render template.Execute error:", err)
|
||||
return "Documize internal github template.Execute error: " + err.Error()
|
||||
}
|
||||
|
||||
ret += buffer.String()
|
||||
|
||||
}
|
||||
|
||||
t := template.New("github")
|
||||
|
||||
tmpl, ok := renderTemplates[c.ReportInfo.ID]
|
||||
if !ok {
|
||||
msg := "github render template not found for: " + c.ReportInfo.ID
|
||||
log.ErrorString(msg)
|
||||
return "Documize internal error: " + msg
|
||||
}
|
||||
|
||||
t, err = t.Parse(tmpl)
|
||||
|
||||
if err != nil {
|
||||
log.Error("github render template.Parse error:", err)
|
||||
return "Documize internal github template.Parse error: " + err.Error()
|
||||
}
|
||||
|
||||
buffer := new(bytes.Buffer)
|
||||
err = t.Execute(buffer, payload)
|
||||
if err != nil {
|
||||
log.Error("github render template.Execute error:", err)
|
||||
return "Documize internal github template.Execute error: " + err.Error()
|
||||
}
|
||||
|
||||
return buffer.String()
|
||||
}
|
||||
|
||||
// Callback is called by a browser redirect from Github, via the validation endpoint
|
||||
func Callback(res http.ResponseWriter, req *http.Request) error {
|
||||
|
||||
code := req.URL.Query().Get("code")
|
||||
state := req.URL.Query().Get("state")
|
||||
|
||||
ghurl := "https://github.com/login/oauth/access_token"
|
||||
vals := "client_id=" + clientID()
|
||||
vals += "&client_secret=" + clientSecret()
|
||||
vals += "&code=" + code
|
||||
vals += "&state=" + state
|
||||
|
||||
req2, err := http.NewRequest("POST", ghurl+"?"+vals, strings.NewReader(vals))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
|
||||
req2.Header.Set("Accept", "application/json")
|
||||
|
||||
res2, err := http.DefaultClient.Do(req2)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var gt githubCallbackT
|
||||
|
||||
err = json.NewDecoder(res2.Body).Decode(>)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = res2.Body.Close()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
returl, err := url.QueryUnescape(state)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
up, err := url.Parse(returl)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
target := up.Scheme + "://" + up.Host + up.Path + "?code=" + gt.AccessToken
|
||||
|
||||
http.Redirect(res, req, target, http.StatusTemporaryRedirect)
|
||||
|
||||
return nil
|
||||
return ret
|
||||
}
|
||||
|
|
235
core/section/github/issues.go
Normal file
235
core/section/github/issues.go
Normal file
|
@ -0,0 +1,235 @@
|
|||
// Copyright 2016 Documize Inc. <legal@documize.com>. All rights reserved.
|
||||
//
|
||||
// This software (Documize Community Edition) is licensed under
|
||||
// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html
|
||||
//
|
||||
// You can operate outside the AGPL restrictions by purchasing
|
||||
// Documize Enterprise Edition and obtaining a commercial license
|
||||
// by contacting <sales@documize.com>.
|
||||
//
|
||||
// https://documize.com
|
||||
|
||||
package github
|
||||
|
||||
import (
|
||||
"html/template"
|
||||
"sort"
|
||||
"time"
|
||||
|
||||
"github.com/documize/community/core/log"
|
||||
|
||||
gogithub "github.com/google/go-github/github"
|
||||
)
|
||||
|
||||
type githubIssue struct {
|
||||
ID int `json:"id"`
|
||||
Date string `json:"date"`
|
||||
Updated string `json:"dated"`
|
||||
Message string `json:"message"`
|
||||
URL template.URL `json:"url"`
|
||||
Name string `json:"name"`
|
||||
Creator string `json:"creator"`
|
||||
Avatar string `json:"avatar"`
|
||||
Labels template.HTML `json:"labels"`
|
||||
LabelNames []string `json:"labelNames"`
|
||||
LabelColors []string `json:"labelColors"`
|
||||
IsOpen bool `json:"isopen"`
|
||||
Repo string `json:"repo"`
|
||||
Private bool `json:"private"`
|
||||
Milestone string `json:"milestone"`
|
||||
}
|
||||
|
||||
type githubSharedLabel struct {
|
||||
Name string `json:"name"`
|
||||
Count int `json:"count"`
|
||||
Color string `json:"color"`
|
||||
Repos template.HTML `json:"Repos"`
|
||||
}
|
||||
|
||||
// sort issues in order that that should be presented - by date updated.
|
||||
type issuesToSort []githubIssue
|
||||
|
||||
func (s issuesToSort) Len() int { return len(s) }
|
||||
func (s issuesToSort) Swap(i, j int) { s[i], s[j] = s[j], s[i] }
|
||||
func (s issuesToSort) Less(i, j int) bool {
|
||||
if s[i].Milestone != noMilestone && s[j].Milestone == noMilestone {
|
||||
return true
|
||||
}
|
||||
if s[i].Milestone == noMilestone && s[j].Milestone != noMilestone {
|
||||
return false
|
||||
}
|
||||
if s[i].Milestone != s[j].Milestone {
|
||||
// TODO should this order be by milestone completion?
|
||||
return s[i].Milestone < s[j].Milestone
|
||||
}
|
||||
if !s[i].IsOpen && s[j].IsOpen {
|
||||
return true
|
||||
}
|
||||
if s[i].IsOpen && !s[j].IsOpen {
|
||||
return false
|
||||
}
|
||||
// TODO this seems a very slow approach
|
||||
iDate, iErr := time.Parse(issuesTimeFormat, s[i].Updated)
|
||||
log.IfErr(iErr)
|
||||
jDate, jErr := time.Parse(issuesTimeFormat, s[j].Updated)
|
||||
log.IfErr(jErr)
|
||||
return iDate.Before(jDate)
|
||||
}
|
||||
|
||||
// sort shared labels alphabetically
|
||||
type sharedLabelsSort []githubSharedLabel
|
||||
|
||||
func (s sharedLabelsSort) Len() int { return len(s) }
|
||||
func (s sharedLabelsSort) Swap(i, j int) { s[i], s[j] = s[j], s[i] }
|
||||
func (s sharedLabelsSort) Less(i, j int) bool { return s[i].Name < s[j].Name }
|
||||
|
||||
const (
|
||||
tagIssuesData = "issuesData"
|
||||
issuesTimeFormat = "January 2 2006, 15:04"
|
||||
unassignedIssue = "(unassigned)"
|
||||
)
|
||||
|
||||
func init() {
|
||||
reports[tagIssuesData] = report{refreshIssues, renderIssues, issuesTemplate}
|
||||
}
|
||||
|
||||
func wrapLabels(labels []gogithub.Label) (l string, labelNames []string, labelColors []string) {
|
||||
labelNames = make([]string, 0, len(labels))
|
||||
labelColors = make([]string, 0, len(labels))
|
||||
for _, ll := range labels {
|
||||
labelNames = append(labelNames, *ll.Name)
|
||||
labelColors = append(labelColors, *ll.Color)
|
||||
l += `<span class="github-issue-label" style="background-color:#` + *ll.Color + `">` + *ll.Name + `</span> `
|
||||
}
|
||||
return l, labelNames, labelColors
|
||||
}
|
||||
|
||||
func getIssues(client *gogithub.Client, config *githubConfig) ([]githubIssue, error) {
|
||||
|
||||
ret := []githubIssue{}
|
||||
|
||||
hadRepo := make(map[string]bool)
|
||||
|
||||
for _, orb := range config.Lists {
|
||||
if orb.Included {
|
||||
|
||||
rName := orb.Owner + "/" + orb.Repo
|
||||
|
||||
if !hadRepo[rName] {
|
||||
|
||||
for _, state := range []string{"open", "closed"} {
|
||||
|
||||
opts := &gogithub.IssueListByRepoOptions{
|
||||
Sort: "updated",
|
||||
State: state,
|
||||
ListOptions: gogithub.ListOptions{PerPage: config.BranchLines}}
|
||||
|
||||
if config.SincePtr != nil && state == "closed" /* we want all the open ones */ {
|
||||
opts.Since = *config.SincePtr
|
||||
}
|
||||
|
||||
guff, _, err := client.Issues.ListByRepo(orb.Owner, orb.Repo, opts)
|
||||
|
||||
if err != nil {
|
||||
return ret, err
|
||||
}
|
||||
|
||||
for _, v := range guff {
|
||||
n := unassignedIssue
|
||||
av := githubGravatar
|
||||
ptr := v.Assignee
|
||||
if ptr != nil {
|
||||
if ptr.Login != nil {
|
||||
n = *ptr.Login
|
||||
av = *ptr.AvatarURL
|
||||
}
|
||||
}
|
||||
ms := noMilestone
|
||||
if v.Milestone != nil {
|
||||
if v.Milestone.Title != nil {
|
||||
ms = *v.Milestone.Title
|
||||
}
|
||||
}
|
||||
l, ln, lc := wrapLabels(v.Labels)
|
||||
ret = append(ret, githubIssue{
|
||||
Name: n,
|
||||
Creator: getUserName(client, config, *v.User.Login),
|
||||
Avatar: av,
|
||||
Message: *v.Title,
|
||||
Date: v.CreatedAt.Format(issuesTimeFormat),
|
||||
Updated: v.UpdatedAt.Format(issuesTimeFormat),
|
||||
URL: template.URL(*v.HTMLURL),
|
||||
Labels: template.HTML(l),
|
||||
LabelNames: ln,
|
||||
LabelColors: lc,
|
||||
ID: *v.Number,
|
||||
IsOpen: *v.State == "open",
|
||||
Repo: repoName(rName),
|
||||
Private: orb.Private,
|
||||
Milestone: ms,
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
hadRepo[rName] = true
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
sort.Sort(issuesToSort(ret))
|
||||
|
||||
return ret, nil
|
||||
|
||||
}
|
||||
|
||||
func refreshIssues(gr *githubRender, config *githubConfig, client *gogithub.Client) (err error) {
|
||||
gr.Issues, err = getIssues(client, config)
|
||||
if err != nil {
|
||||
log.Error("unable to get github issues (cmd)", err)
|
||||
return err
|
||||
}
|
||||
|
||||
gr.OpenIssues = 0
|
||||
gr.ClosedIssues = 0
|
||||
sharedLabels := make(map[string][]string)
|
||||
sharedLabelColors := make(map[string]string)
|
||||
for _, v := range gr.Issues {
|
||||
if v.IsOpen {
|
||||
gr.OpenIssues++
|
||||
} else {
|
||||
gr.ClosedIssues++
|
||||
}
|
||||
for i, lab := range v.LabelNames {
|
||||
sharedLabels[lab] = append(sharedLabels[lab], v.Repo)
|
||||
if _, exists := sharedLabelColors[lab]; !exists { // use the first one we see
|
||||
sharedLabelColors[lab] = v.LabelColors[i]
|
||||
}
|
||||
}
|
||||
}
|
||||
gr.HasIssues = (gr.OpenIssues + gr.ClosedIssues) > 0
|
||||
|
||||
gr.SharedLabels = make([]githubSharedLabel, 0, len(sharedLabels)) // will usually be too big
|
||||
for name, repos := range sharedLabels {
|
||||
if len(repos) > 1 {
|
||||
thisLab := githubSharedLabel{Name: name, Count: len(repos), Color: sharedLabelColors[name]}
|
||||
show := ""
|
||||
for i, r := range repos {
|
||||
if i > 0 {
|
||||
show += ", "
|
||||
}
|
||||
show += "<a href='https://github.com/" + config.Owner + "/" + r +
|
||||
"/issues?q=is%3Aissue+label%3A" + name + "'>" + r + "</a>"
|
||||
}
|
||||
thisLab.Repos = template.HTML(show)
|
||||
gr.SharedLabels = append(gr.SharedLabels, thisLab)
|
||||
}
|
||||
}
|
||||
sort.Sort(sharedLabelsSort(gr.SharedLabels))
|
||||
gr.HasSharedLabels = len(gr.SharedLabels) > 0
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func renderIssues(payload *githubRender, c *githubConfig) error {
|
||||
return nil
|
||||
}
|
85
core/section/github/issues_template.go
Normal file
85
core/section/github/issues_template.go
Normal file
|
@ -0,0 +1,85 @@
|
|||
// Copyright 2016 Documize Inc. <legal@documize.com>. All rights reserved.
|
||||
//
|
||||
// This software (Documize Community Edition) is licensed under
|
||||
// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html
|
||||
//
|
||||
// You can operate outside the AGPL restrictions by purchasing
|
||||
// Documize Enterprise Edition and obtaining a commercial license
|
||||
// by contacting <sales@documize.com>.
|
||||
//
|
||||
// https://documize.com
|
||||
|
||||
package github
|
||||
|
||||
const (
|
||||
openIsvg = `
|
||||
<span title="Open issue">
|
||||
<svg height="16" version="1.1" viewBox="0 0 14 16" width="14" class="color:#6cc644;">
|
||||
<path d="M7 2.3c3.14 0 5.7 2.56 5.7 5.7s-2.56 5.7-5.7 5.7A5.71 5.71 0 0 1 1.3 8c0-3.14 2.56-5.7 5.7-5.7zM7 1C3.14 1 0 4.14 0 8s3.14 7 7 7 7-3.14 7-7-3.14-7-7-7zm1 3H6v5h2V4zm0 6H6v2h2v-2z"></path>
|
||||
</svg>
|
||||
</span>
|
||||
`
|
||||
closedIsvg = `
|
||||
<span title="Closed issue">
|
||||
<svg height="16" version="1.1" viewBox="0 0 16 16" width="16" class="color:#bd2c00;">
|
||||
<path d="M7 10h2v2H7v-2zm2-6H7v5h2V4zm1.5 1.5l-1 1L12 9l4-4.5-1-1L12 7l-1.5-1.5zM8 13.7A5.71 5.71 0 0 1 2.3 8c0-3.14 2.56-5.7 5.7-5.7 1.83 0 3.45.88 4.5 2.2l.92-.92A6.947 6.947 0 0 0 8 1C4.14 1 1 4.14 1 8s3.14 7 7 7 7-3.14 7-7l-1.52 1.52c-.66 2.41-2.86 4.19-5.48 4.19v-.01z"></path>
|
||||
</svg>
|
||||
</span>
|
||||
`
|
||||
issuesTemplate = `
|
||||
<div class="section-github-render">
|
||||
{{if .HasIssues}}
|
||||
<h3>Issues</h3>
|
||||
<p>
|
||||
There are {{.ClosedIssues}} closed
|
||||
{{if eq 1 .ClosedIssues}}issue{{else}}issues{{end}}
|
||||
and {{.OpenIssues}} open
|
||||
{{if eq 1 .OpenIssues}}issue{{else}}issues{{end}}
|
||||
across {{.RepoCount}}
|
||||
{{if eq 1 .RepoCount}} repository. {{else}} repositories. {{end}}
|
||||
</p>
|
||||
<p>
|
||||
{{if .ShowList}}
|
||||
Including issues labelled
|
||||
{{range $label := .List}}
|
||||
{{if $label.Included}}
|
||||
<span class="github-issue-label" style="background-color:#{{$label.Color}}">{{$label.Name}}</span>
|
||||
{{end}}
|
||||
{{end}}
|
||||
{{end}}
|
||||
</p>
|
||||
<div class="github-board">
|
||||
|
||||
<table class="issue-table width-100">
|
||||
<tbody class="github">
|
||||
{{range $data := .Issues}}
|
||||
<tr>
|
||||
<td class="width-5">
|
||||
<div class="issue-avatar">
|
||||
{{if $data.IsOpen}}
|
||||
` + openIsvg + `
|
||||
{{else}}
|
||||
` + closedIsvg + `
|
||||
{{end}}
|
||||
</div>
|
||||
</td>
|
||||
|
||||
<td class="width-55">
|
||||
<h6><a class="link" href="{{$data.URL}}">{{$data.Message}} <span class="dataid">#{{$data.ID}}</span></a></h6> </br>
|
||||
<span class="milestone">{{$data.Milestone}}</span> <span class="issue-label">{{$data.Labels}}</span>
|
||||
</td>
|
||||
|
||||
<td class="width-40">
|
||||
<h6>{{$data.Repo}}</h6> <br>
|
||||
<span class="date-meta">{{$data.Creator}} opened on {{$data.Date}}</span>
|
||||
</td>
|
||||
</tr>
|
||||
{{end}}
|
||||
</tbody>
|
||||
|
||||
</table>
|
||||
</div>
|
||||
{{end}}
|
||||
</div>
|
||||
`
|
||||
)
|
106
core/section/github/lists.go
Normal file
106
core/section/github/lists.go
Normal file
|
@ -0,0 +1,106 @@
|
|||
// Copyright 2016 Documize Inc. <legal@documize.com>. All rights reserved.
|
||||
//
|
||||
// This software (Documize Community Edition) is licensed under
|
||||
// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html
|
||||
//
|
||||
// You can operate outside the AGPL restrictions by purchasing
|
||||
// Documize Enterprise Edition and obtaining a commercial license
|
||||
// by contacting <sales@documize.com>.
|
||||
//
|
||||
// https://documize.com
|
||||
|
||||
package github
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
"github.com/documize/community/core/log"
|
||||
"github.com/documize/community/core/section/provider"
|
||||
|
||||
gogithub "github.com/google/go-github/github"
|
||||
)
|
||||
|
||||
func listFailed(method string, config githubConfig, client *gogithub.Client, w http.ResponseWriter) (failed bool) {
|
||||
switch method { // which list to choose?
|
||||
|
||||
case "owners":
|
||||
|
||||
me, _, err := client.Users.Get("")
|
||||
if err != nil {
|
||||
log.Error("github get user details:", err)
|
||||
provider.WriteError(w, "github", err)
|
||||
return
|
||||
}
|
||||
|
||||
orgs, _, err := client.Organizations.List("", nil)
|
||||
if err != nil {
|
||||
log.Error("github get user's organisations:", err)
|
||||
provider.WriteError(w, "github", err)
|
||||
return
|
||||
}
|
||||
|
||||
owners := make([]githubOwner, 1+len(orgs))
|
||||
owners[0] = githubOwner{ID: *me.Login, Name: *me.Login}
|
||||
for ko, vo := range orgs {
|
||||
id := 1 + ko
|
||||
owners[id].ID = *vo.Login
|
||||
owners[id].Name = *vo.Login
|
||||
}
|
||||
|
||||
owners = sortOwners(owners)
|
||||
|
||||
provider.WriteJSON(w, owners)
|
||||
|
||||
case "orgrepos":
|
||||
|
||||
var render []githubBranch
|
||||
if config.Owner != "" {
|
||||
|
||||
me, _, err := client.Users.Get("")
|
||||
if err != nil {
|
||||
log.Error("github get user details:", err)
|
||||
provider.WriteError(w, "github", err)
|
||||
return
|
||||
}
|
||||
|
||||
var repos []*gogithub.Repository
|
||||
if config.Owner == *me.Login {
|
||||
repos, _, err = client.Repositories.List(config.Owner, nil)
|
||||
} else {
|
||||
opt := &gogithub.RepositoryListByOrgOptions{
|
||||
ListOptions: gogithub.ListOptions{PerPage: 100},
|
||||
}
|
||||
repos, _, err = client.Repositories.ListByOrg(config.Owner, opt)
|
||||
}
|
||||
if err != nil {
|
||||
log.Error("github get user/org repositories:", err)
|
||||
provider.WriteError(w, "github", err)
|
||||
return
|
||||
}
|
||||
for _, vr := range repos {
|
||||
render = append(render,
|
||||
githubBranch{
|
||||
Name: "master",
|
||||
ID: fmt.Sprintf("%s:%s", config.Owner, *vr.Name),
|
||||
Owner: config.Owner,
|
||||
Repo: *vr.Name,
|
||||
Private: *vr.Private,
|
||||
Included: false,
|
||||
URL: *vr.HTMLURL,
|
||||
})
|
||||
}
|
||||
}
|
||||
render = sortBranches(render)
|
||||
|
||||
provider.WriteJSON(w, render)
|
||||
|
||||
case "content":
|
||||
|
||||
provider.WriteJSON(w, refreshReportData(&config, client))
|
||||
|
||||
default:
|
||||
return true // failed to get a list
|
||||
}
|
||||
return
|
||||
}
|
211
core/section/github/milestones.go
Normal file
211
core/section/github/milestones.go
Normal file
|
@ -0,0 +1,211 @@
|
|||
// Copyright 2016 Documize Inc. <legal@documize.com>. All rights reserved.
|
||||
//
|
||||
// This software (Documize Community Edition) is licensed under
|
||||
// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html
|
||||
//
|
||||
// You can operate outside the AGPL restrictions by purchasing
|
||||
// Documize Enterprise Edition and obtaining a commercial license
|
||||
// by contacting <sales@documize.com>.
|
||||
//
|
||||
// https://documize.com
|
||||
|
||||
package github
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"sort"
|
||||
|
||||
"github.com/documize/community/core/log"
|
||||
|
||||
gogithub "github.com/google/go-github/github"
|
||||
)
|
||||
|
||||
type githubMilestone struct {
|
||||
Repo string `json:"repo"`
|
||||
Private bool `json:"private"`
|
||||
Name string `json:"name"`
|
||||
URL string `json:"url"`
|
||||
IsOpen bool `json:"isopen"`
|
||||
OpenIssues int `json:"openIssues"`
|
||||
ClosedIssues int `json:"closedIssues"`
|
||||
CompleteMsg string `json:"completeMsg"`
|
||||
DueDate string `json:"dueDate"`
|
||||
UpdatedAt string `json:"updatedAt"`
|
||||
Progress uint `json:"progress"`
|
||||
IsMilestone bool `json:"isMilestone"`
|
||||
}
|
||||
|
||||
// sort milestones in order that that should be presented.
|
||||
|
||||
type milestonesToSort []githubMilestone
|
||||
|
||||
func (s milestonesToSort) Len() int { return len(s) }
|
||||
func (s milestonesToSort) Swap(i, j int) { s[i], s[j] = s[j], s[i] }
|
||||
func (s milestonesToSort) Less(i, j int) bool {
|
||||
if s[i].Repo < s[j].Repo {
|
||||
return true
|
||||
}
|
||||
if s[i].Repo > s[j].Repo {
|
||||
return false
|
||||
}
|
||||
if !s[i].IsOpen && s[j].IsOpen {
|
||||
return true
|
||||
}
|
||||
if s[i].IsOpen && !s[j].IsOpen {
|
||||
return false
|
||||
}
|
||||
if s[i].Name != noMilestone && s[j].Name == noMilestone {
|
||||
return true
|
||||
}
|
||||
if s[i].Name == noMilestone && s[j].Name != noMilestone {
|
||||
return false
|
||||
}
|
||||
if s[i].Progress == s[j].Progress { // order equal progress milestones
|
||||
return s[i].Name < s[j].Name
|
||||
}
|
||||
return s[i].Progress >= s[j].Progress // put more complete milestones first
|
||||
}
|
||||
|
||||
const (
|
||||
tagMilestonesData = "milestonesData"
|
||||
milestonesTimeFormat = "January 2 2006"
|
||||
noMilestone = "no milestone"
|
||||
)
|
||||
|
||||
func init() {
|
||||
reports[tagMilestonesData] = report{refreshMilestones, renderMilestones, milestonesTemplate}
|
||||
}
|
||||
|
||||
func getMilestones(client *gogithub.Client, config *githubConfig) ([]githubMilestone, error) {
|
||||
|
||||
ret := []githubMilestone{}
|
||||
|
||||
hadRepo := make(map[string]bool)
|
||||
|
||||
for _, orb := range config.Lists {
|
||||
if orb.Included {
|
||||
rName := orb.Owner + "/" + orb.Repo
|
||||
|
||||
if !hadRepo[rName] {
|
||||
|
||||
for _, state := range []string{"open", "closed"} {
|
||||
|
||||
opts := &gogithub.MilestoneListOptions{
|
||||
Sort: "updated",
|
||||
State: state,
|
||||
ListOptions: gogithub.ListOptions{PerPage: config.BranchLines}}
|
||||
|
||||
guff, _, err := client.Issues.ListMilestones(orb.Owner, orb.Repo, opts)
|
||||
|
||||
if err != nil {
|
||||
return ret, err
|
||||
}
|
||||
|
||||
for _, v := range guff {
|
||||
include := true
|
||||
if state == "closed" {
|
||||
if config.SincePtr != nil {
|
||||
if (*config.SincePtr).After(*v.ClosedAt) {
|
||||
include = false
|
||||
}
|
||||
}
|
||||
}
|
||||
if include {
|
||||
dd := "No due date."
|
||||
if v.DueOn != nil {
|
||||
// TODO refactor to add message in red if the milestone is overdue
|
||||
dd = "due on " + (*v.DueOn).Format(milestonesTimeFormat) + ""
|
||||
}
|
||||
up := ""
|
||||
if v.UpdatedAt != nil {
|
||||
up = (*v.UpdatedAt).Format(milestonesTimeFormat)
|
||||
}
|
||||
|
||||
progress := float64(*v.ClosedIssues*100) / float64(*v.OpenIssues+*v.ClosedIssues)
|
||||
|
||||
ret = append(ret, githubMilestone{
|
||||
Repo: repoName(rName),
|
||||
Private: orb.Private,
|
||||
Name: *v.Title,
|
||||
URL: *v.HTMLURL,
|
||||
IsOpen: *v.State == "open",
|
||||
OpenIssues: *v.OpenIssues,
|
||||
ClosedIssues: *v.ClosedIssues,
|
||||
CompleteMsg: fmt.Sprintf("%2.0f%%", progress),
|
||||
DueDate: dd,
|
||||
UpdatedAt: up,
|
||||
Progress: uint(progress),
|
||||
IsMilestone: true,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
hadRepo[rName] = true
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return ret, nil
|
||||
|
||||
}
|
||||
|
||||
func refreshMilestones(gr *githubRender, config *githubConfig, client *gogithub.Client) (err error) {
|
||||
|
||||
gr.Milestones, err = getMilestones(client, config)
|
||||
if err != nil {
|
||||
log.Error("unable to get github milestones", err)
|
||||
return err
|
||||
}
|
||||
gr.OpenMS = 0
|
||||
gr.ClosedMS = 0
|
||||
for _, v := range gr.Milestones {
|
||||
if v.IsOpen {
|
||||
gr.OpenMS++
|
||||
} else {
|
||||
gr.ClosedMS++
|
||||
}
|
||||
}
|
||||
gr.HasMilestones = (gr.OpenMS + gr.ClosedMS) > 0
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func renderMilestones(payload *githubRender, c *githubConfig) error {
|
||||
hadRepo := make(map[string]bool)
|
||||
payload.RepoCount = 0
|
||||
for _, orb := range payload.List {
|
||||
rName := orb.Owner + "/" + orb.Repo
|
||||
if !hadRepo[rName] {
|
||||
if orb.Included {
|
||||
|
||||
payload.RepoCount++
|
||||
issuesOpen, issuesClosed := 0, 0
|
||||
for _, iss := range payload.Issues {
|
||||
if iss.Repo == repoName(rName) {
|
||||
if iss.Milestone == noMilestone {
|
||||
if iss.IsOpen {
|
||||
issuesOpen++
|
||||
} else {
|
||||
issuesClosed++
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if issuesClosed+issuesOpen > 0 {
|
||||
payload.Milestones = append(payload.Milestones, githubMilestone{
|
||||
Repo: orb.Repo, Private: orb.Private, Name: noMilestone, IsOpen: true,
|
||||
OpenIssues: issuesOpen, ClosedIssues: issuesClosed, URL: orb.URL,
|
||||
})
|
||||
}
|
||||
|
||||
hadRepo[rName] = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sort.Sort(milestonesToSort(payload.Milestones))
|
||||
|
||||
return nil
|
||||
}
|
81
core/section/github/milestones_template.go
Normal file
81
core/section/github/milestones_template.go
Normal file
|
@ -0,0 +1,81 @@
|
|||
// Copyright 2016 Documize Inc. <legal@documize.com>. All rights reserved.
|
||||
//
|
||||
// This software (Documize Community Edition) is licensed under
|
||||
// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html
|
||||
//
|
||||
// You can operate outside the AGPL restrictions by purchasing
|
||||
// Documize Enterprise Edition and obtaining a commercial license
|
||||
// by contacting <sales@documize.com>.
|
||||
//
|
||||
// https://documize.com
|
||||
|
||||
package github
|
||||
|
||||
const (
|
||||
rawMSsvg = `<path d="M8 2H6V0h2v2zm4 5H2c-.55 0-1-.45-1-1V4c0-.55.45-1 1-1h10l2 2-2 2zM8 4H6v2h2V4zM6 16h2V8H6v8z"></path>`
|
||||
openMSsvg = `
|
||||
<span title="Open milestone">
|
||||
<svg height="16" width="14" version="1.1" viewBox="0 0 14 16">
|
||||
` + rawMSsvg + `
|
||||
</svg>
|
||||
</span>
|
||||
`
|
||||
closedMSsvg = `
|
||||
<span title="Closed milestone">
|
||||
<svg aria-hidden="true" class="octicon octicon-check" height="16" version="1.1" viewBox="0 0 12 16" width="12">
|
||||
<path d="M12 5l-8 8-4-4 1.5-1.5L4 10l6.5-6.5z"></path>
|
||||
</svg>
|
||||
</span>
|
||||
`
|
||||
milestonesTemplate = `
|
||||
|
||||
<div class="section-github-render">
|
||||
{{if .HasMilestones}}
|
||||
<h3>Milestones</h3>
|
||||
<p>
|
||||
There are
|
||||
{{.ClosedMS}}
|
||||
{{if eq 1 .ClosedMS}} milestone {{else}} milestones {{end}}
|
||||
closed and {{.OpenMS}}
|
||||
{{if eq 1 .OpenMS}} milestone {{else}} milestones {{end}}
|
||||
open across {{.RepoCount}}
|
||||
{{if eq 1 .RepoCount}} repository. {{else}} repositories. {{end}}
|
||||
</p>
|
||||
<div class="github-board">
|
||||
<table class="milestone-table width-100">
|
||||
<tbody class="github">
|
||||
{{range $data := .Milestones}}
|
||||
<tr>
|
||||
<td style="width:5%;">
|
||||
{{if $data.IsMilestone}}
|
||||
{{if $data.IsOpen}}
|
||||
` + openMSsvg + `
|
||||
{{else}}
|
||||
` + closedMSsvg + `
|
||||
{{end}}
|
||||
{{end}}
|
||||
</td>
|
||||
<td class="width-55">
|
||||
<h6>{{$data.Name}}</h6>
|
||||
{{if $data.IsMilestone}}
|
||||
<span class="date-meta">{{$data.DueDate}}</span>
|
||||
{{end}}<br>
|
||||
<span class="repo"><a class="link" href="{{$data.URL}}">{{$data.Repo}}</a></span>
|
||||
</td>
|
||||
<td class="width-40">
|
||||
{{if $data.IsMilestone}}
|
||||
<progress value="{{$data.Progress}}" max="100"></progress> <br>
|
||||
{{$data.CompleteMsg}} complete {{$data.OpenIssues}} open {{$data.ClosedIssues}} closed
|
||||
{{else}}
|
||||
{{$data.OpenIssues}} open {{$data.ClosedIssues}} closed
|
||||
{{end}}
|
||||
</td>
|
||||
</tr>
|
||||
{{end}}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
{{end}}
|
||||
</div>
|
||||
`
|
||||
)
|
|
@ -12,242 +12,97 @@
|
|||
package github
|
||||
|
||||
import (
|
||||
"html/template"
|
||||
"sort"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/documize/community/core/log"
|
||||
|
||||
gogithub "github.com/google/go-github/github"
|
||||
)
|
||||
|
||||
const tagIssuesData = "issuesData"
|
||||
const tagCommitsData = "commitsData"
|
||||
|
||||
type githubRender struct {
|
||||
Config githubConfig
|
||||
Repo githubRepo
|
||||
List []githubBranch
|
||||
ShowList bool
|
||||
ShowIssueNumbers bool
|
||||
BranchCommits []githubBranchCommits
|
||||
CommitCount int
|
||||
Issues []githubIssue
|
||||
//IssueNum int
|
||||
//IssueNumActivity []githubIssueActivity
|
||||
Limit int
|
||||
DateMessage string
|
||||
Config githubConfig `json:"config"`
|
||||
List []githubBranch `json:"list"`
|
||||
RepoCount int `json:"repoCount"`
|
||||
ShowList bool `json:"showList"`
|
||||
ShowIssueNumbers bool `json:"showIssueNumbers"`
|
||||
BranchCommits []githubCommit `json:"branchCommits"`
|
||||
HasCommits bool `json:"hasCommits"`
|
||||
CommitCount int `json:"commitCount"`
|
||||
Issues []githubIssue `json:"issues"`
|
||||
HasIssues bool `json:"hasIssues"`
|
||||
SharedLabels []githubSharedLabel `json:"sharedLabels"`
|
||||
HasSharedLabels bool `json:"hasSharedLabels"`
|
||||
OpenIssues int `json:"openIssues"`
|
||||
ClosedIssues int `json:"closedIssues"`
|
||||
Limit int `json:"limit"`
|
||||
Milestones []githubMilestone `json:"milestones"`
|
||||
HasMilestones bool `json:"hasMilestones"`
|
||||
OpenMS int `json:"openMS"`
|
||||
ClosedMS int `json:"closedMS"`
|
||||
OpenPRs int `json:"openPRs"`
|
||||
ClosedPRs int `json:"closedPRs"`
|
||||
AuthorStats []githubAuthorStats `json:"authorStats"`
|
||||
HasAuthorStats bool `json:"hasAuthorStats"`
|
||||
NumContributors int `json:"numContributors"`
|
||||
}
|
||||
|
||||
var renderTemplates = map[string]string{
|
||||
tagCommitsData: `
|
||||
<div class="section-github-render">
|
||||
<p>
|
||||
There are {{ .CommitCount }} commits for branch <a href="{{.Config.BranchURL}}">{{.Config.Branch}}</a> of repository <a href="{{ .Repo.URL }}">{{.Repo.Name}}.</a>
|
||||
Showing {{ .Limit }} items {{ .DateMessage }}.
|
||||
</p>
|
||||
<div class="github-board">
|
||||
{{range $data := .BranchCommits}}
|
||||
<div class="github-group-title">
|
||||
Commits on {{ $data.Day }}
|
||||
</div>
|
||||
<ul class="github-list">
|
||||
{{range $commit := $data.Commits}}
|
||||
<li class="github-commit-item">
|
||||
<a class="link" href="{{$commit.URL}}">
|
||||
<div class="github-avatar">
|
||||
<img alt="@{{$commit.Name}}" src="{{$commit.Avatar}}" height="36" width="36">
|
||||
</div>
|
||||
<div class="github-commit-body">
|
||||
<div class="github-commit-title">{{$commit.Message}}</div>
|
||||
<div class="github-commit-meta">{{$commit.Name}} committed on {{$commit.Date}}</div>
|
||||
</div>
|
||||
</a>
|
||||
<div class="clearfix" />
|
||||
</li>
|
||||
{{end}}
|
||||
</ul>
|
||||
{{end}}
|
||||
</div>
|
||||
</div>
|
||||
`,
|
||||
tagIssuesData: `
|
||||
<div class="section-github-render">
|
||||
<p>
|
||||
{{if .ShowIssueNumbers}}
|
||||
Showing Selected Issues
|
||||
{{else}}
|
||||
{{ .Config.IssueState.Name }}
|
||||
{{end}}
|
||||
for repository <a href="{{ .Repo.URL }}/issues">{{.Repo.Name}}</a>
|
||||
{{if .ShowList}}
|
||||
labelled
|
||||
{{range $label := .List}}
|
||||
{{if $label.Included}}
|
||||
<span class="github-issue-label" style="background-color:#{{$label.Color}}">{{$label.Name}}</span>
|
||||
{{end}}
|
||||
{{end}}
|
||||
{{end}}
|
||||
{{if .ShowIssueNumbers}}
|
||||
issue(s) {{ .DateMessage }}.
|
||||
{{else}}
|
||||
up to {{ .Limit }} items are shown{{ .DateMessage }}.
|
||||
{{end}}
|
||||
</p>
|
||||
<div class="github-board">
|
||||
<ul class="github-list">
|
||||
{{range $data := .Issues}}
|
||||
<li class="github-commit-item">
|
||||
<a class="link" href="{{$data.URL}}">
|
||||
<div class="issue-avatar">
|
||||
{{if $data.IsOpen}}
|
||||
<span title="Open issue">
|
||||
<svg height="16" version="1.1" viewBox="0 0 14 16" width="14"><path d="M7 2.3c3.14 0 5.7 2.56 5.7 5.7s-2.56 5.7-5.7 5.7A5.71 5.71 0 0 1 1.3 8c0-3.14 2.56-5.7 5.7-5.7zM7 1C3.14 1 0 4.14 0 8s3.14 7 7 7 7-3.14 7-7-3.14-7-7-7zm1 3H6v5h2V4zm0 6H6v2h2v-2z"></path></svg>
|
||||
</span>
|
||||
{{else}}
|
||||
<span title="Closed issue">
|
||||
<svg height="16" version="1.1" viewBox="0 0 16 16" width="16"><path d="M7 10h2v2H7v-2zm2-6H7v5h2V4zm1.5 1.5l-1 1L12 9l4-4.5-1-1L12 7l-1.5-1.5zM8 13.7A5.71 5.71 0 0 1 2.3 8c0-3.14 2.56-5.7 5.7-5.7 1.83 0 3.45.88 4.5 2.2l.92-.92A6.947 6.947 0 0 0 8 1C4.14 1 1 4.14 1 8s3.14 7 7 7 7-3.14 7-7l-1.52 1.52c-.66 2.41-2.86 4.19-5.48 4.19v-.01z"></path></svg>
|
||||
</span>
|
||||
{{end}}
|
||||
</div>
|
||||
<div class="github-commit-body">
|
||||
<div class="github-commit-title"><span class="label-name">{{$data.Message}}</span> {{$data.Labels}}</div>
|
||||
<div class="github-commit-meta">
|
||||
#{{$data.ID}} opened on {{$data.Date}} by {{$data.Name}}, last updated {{$data.Updated}}
|
||||
</div>
|
||||
</div>
|
||||
</a>
|
||||
<div class="clearfix" />
|
||||
</li>
|
||||
{{end}}
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
`,
|
||||
/* "issuenum_data": `
|
||||
<div class="section-github-render">
|
||||
<p>
|
||||
Activity for issue #{{.IssueNum}} in repository <a href="{{ .Repo.URL }}/issues">{{.Repo.Name}}.</a>
|
||||
Up to {{ .Limit }} items are shown{{ .DateMessage }}.
|
||||
</p>
|
||||
<div class="github-board">
|
||||
<ul class="github-list">
|
||||
{{range $data := .IssueNumActivity}}
|
||||
<li class="github-commit-item">
|
||||
<div class="github-avatar">
|
||||
<img alt="@{{$data.Name}}" src="{{$data.Avatar}}" height="36" width="36">
|
||||
</div>
|
||||
<div class="github-commit-meta">
|
||||
{{$data.Name}} <a class="link" href="{{$data.URL}}">{{$data.Event}}</a> {{$data.Date}}
|
||||
</div>
|
||||
<div class="github-commit-body">
|
||||
<div class="github-commit-title">
|
||||
{{$data.Message}}
|
||||
</div>
|
||||
</div>
|
||||
<div class="clearfix" />
|
||||
</li>
|
||||
{{end}}
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
`,*/
|
||||
type report struct {
|
||||
refresh func(*githubRender, *githubConfig, *gogithub.Client) error
|
||||
render func(*githubRender, *githubConfig) error
|
||||
template string
|
||||
}
|
||||
|
||||
type githubReport struct {
|
||||
ID string `json:"id"`
|
||||
Name string `json:"name"`
|
||||
}
|
||||
var reports = make(map[string]report)
|
||||
|
||||
type githubOwner struct {
|
||||
ID string `json:"id"`
|
||||
Name string `json:"name"`
|
||||
}
|
||||
|
||||
type githubRepo struct {
|
||||
ID string `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Included bool `json:"included"`
|
||||
Owner string `json:"owner"`
|
||||
Repo string `json:"repo"`
|
||||
Private bool `json:"private"` // TODO review field use
|
||||
URL string `json:"url"`
|
||||
}
|
||||
|
||||
type githubBranch struct {
|
||||
ID string `json:"id"`
|
||||
Owner string `json:"owner"`
|
||||
Repo string `json:"repo"`
|
||||
Name string `json:"name"`
|
||||
Included bool `json:"included"`
|
||||
URL string `json:"url"`
|
||||
Color string `json:"color,omitempty"`
|
||||
Comma bool `json:"comma"`
|
||||
Private bool `json:"private"`
|
||||
}
|
||||
|
||||
type githubLabel struct {
|
||||
ID string `json:"id"`
|
||||
Owner string `json:"owner"`
|
||||
Repo string `json:"repo"`
|
||||
Name string `json:"name"`
|
||||
Included bool `json:"included"`
|
||||
URL string `json:"url"`
|
||||
Color string `json:"color,omitempty"`
|
||||
}
|
||||
|
||||
type githubBranchCommits struct {
|
||||
Name string `json:"name"`
|
||||
Day string `json:"day"`
|
||||
Commits []githubCommit
|
||||
}
|
||||
|
||||
type githubCommit struct {
|
||||
Date string `json:"date"`
|
||||
Message string `json:"message"`
|
||||
URL template.URL `json:"url"`
|
||||
Name string `json:"name"`
|
||||
Avatar string `json:"avatar"`
|
||||
}
|
||||
|
||||
type githubIssue struct {
|
||||
ID int `json:"id"`
|
||||
Date string `json:"date"`
|
||||
Updated string `json:"dated"`
|
||||
Message string `json:"message"`
|
||||
URL template.URL `json:"url"`
|
||||
Name string `json:"name"`
|
||||
Avatar string `json:"avatar"`
|
||||
Labels template.HTML `json:"labels"`
|
||||
IsOpen bool `json:"isopen"`
|
||||
}
|
||||
|
||||
/*
|
||||
type githubIssueActivity struct {
|
||||
Date string `json:"date"`
|
||||
Event string `json:"event"`
|
||||
Message template.HTML `json:"message"`
|
||||
URL template.URL `json:"url"`
|
||||
Name string `json:"name"`
|
||||
Avatar string `json:"avatar"`
|
||||
}
|
||||
*/
|
||||
|
||||
type githubConfig struct {
|
||||
Token string `json:"-"` // NOTE very important that the secret Token is not leaked to the client side, so "-"
|
||||
UserID string `json:"userId"`
|
||||
PageID string `json:"pageId"`
|
||||
Owner string `json:"owner_name"`
|
||||
Repo string `json:"repo_name"`
|
||||
Branch string `json:"branch"`
|
||||
BranchURL string `json:"branchURL"`
|
||||
BranchSince string `json:"branchSince,omitempty"`
|
||||
SincePtr *time.Time `json:"-"`
|
||||
BranchLines int `json:"branchLines,omitempty,string"`
|
||||
OwnerInfo githubOwner `json:"owner"`
|
||||
RepoInfo githubRepo `json:"repo"`
|
||||
ReportInfo githubReport `json:"report"`
|
||||
ClientID string `json:"clientId"`
|
||||
CallbackURL string `json:"callbackUrl"`
|
||||
Lists []githubBranch `json:"lists,omitempty"`
|
||||
IssueState githubReport `json:"state,omitempty"`
|
||||
IssuesText string `json:"issues,omitempty"`
|
||||
//IssueNum int `json:"issueNum,omitempty,string"`
|
||||
Token string `json:"-"` // NOTE very important that the secret Token is not leaked to the client side, so "-"
|
||||
UserID string `json:"userId"`
|
||||
PageID string `json:"pageId"`
|
||||
Owner string `json:"owner_name"`
|
||||
BranchSince string `json:"branchSince,omitempty"`
|
||||
SincePtr *time.Time `json:"-"`
|
||||
Since string `json:"-"`
|
||||
BranchLines int `json:"branchLines,omitempty,string"`
|
||||
OwnerInfo githubOwner `json:"owner"`
|
||||
ClientID string `json:"clientId"`
|
||||
CallbackURL string `json:"callbackUrl"`
|
||||
Lists []githubBranch `json:"lists,omitempty"`
|
||||
ReportOrder []string `json:"-"`
|
||||
DateMessage string `json:"-"`
|
||||
UserNames map[string]string `json:"UserNames"`
|
||||
}
|
||||
|
||||
func (c *githubConfig) Clean() {
|
||||
c.Owner = c.OwnerInfo.Name
|
||||
c.Repo = c.RepoInfo.Repo
|
||||
for _, l := range c.Lists {
|
||||
if l.Included {
|
||||
c.Branch = l.Name
|
||||
c.BranchURL = l.URL
|
||||
break
|
||||
}
|
||||
}
|
||||
if len(c.BranchSince) >= len("yyyy/mm/dd hh:ss") {
|
||||
var since time.Time
|
||||
tt := []byte("yyyy-mm-ddThh:mm:00Z")
|
||||
|
@ -261,8 +116,71 @@ func (c *githubConfig) Clean() {
|
|||
c.SincePtr = &since
|
||||
}
|
||||
}
|
||||
if c.SincePtr == nil {
|
||||
c.DateMessage = " (the last 7 days)"
|
||||
since := time.Now().AddDate(0, 0, -7)
|
||||
c.SincePtr = &since
|
||||
} else {
|
||||
c.DateMessage = ""
|
||||
}
|
||||
c.Since = (*c.SincePtr).Format(issuesTimeFormat)
|
||||
|
||||
c.ReportOrder = []string{tagSummaryData, tagMilestonesData, tagIssuesData, tagCommitsData}
|
||||
c.BranchLines = 100 // overide any existing value with maximum allowable in one call
|
||||
|
||||
sort.Sort(branchesToSort(c.Lists)) // get the configured branches in a sensible order for display
|
||||
|
||||
lastItem := 0
|
||||
for i := range c.Lists {
|
||||
c.Lists[i].Comma = true
|
||||
if c.Lists[i].Included {
|
||||
lastItem = i
|
||||
}
|
||||
}
|
||||
if lastItem < len(c.Lists) {
|
||||
c.Lists[lastItem].Comma = false
|
||||
}
|
||||
|
||||
if c.UserNames == nil {
|
||||
c.UserNames = make(map[string]string)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
type githubCallbackT struct {
|
||||
AccessToken string `json:"access_token"`
|
||||
}
|
||||
|
||||
func repoName(branchName string) string {
|
||||
bits := strings.Split(branchName, "/")
|
||||
if len(bits) != 2 {
|
||||
return branchName + "?repo"
|
||||
}
|
||||
pieces := strings.Split(bits[1], ":")
|
||||
if len(pieces) == 0 {
|
||||
return branchName + "?repo:?branch"
|
||||
}
|
||||
return pieces[0]
|
||||
}
|
||||
|
||||
func getUserName(client *gogithub.Client, config *githubConfig, login string) (fullName string) {
|
||||
an := login
|
||||
if content, found := config.UserNames[login]; found {
|
||||
if len(content) > 0 {
|
||||
an = content
|
||||
}
|
||||
} else {
|
||||
usr, _, err := client.Users.Get(login)
|
||||
if err == nil {
|
||||
if usr.Name != nil {
|
||||
if len(*usr.Name) > 0 {
|
||||
config.UserNames[login] = *usr.Name
|
||||
an = *usr.Name
|
||||
}
|
||||
}
|
||||
} else {
|
||||
config.UserNames[login] = login // don't look again for a missing name
|
||||
}
|
||||
}
|
||||
return an
|
||||
}
|
||||
|
|
|
@ -13,21 +13,6 @@ package github
|
|||
|
||||
import "sort"
|
||||
|
||||
// sort repos in order that that should be presented.
|
||||
type reposToSort []githubRepo
|
||||
|
||||
func (s reposToSort) Len() int { return len(s) }
|
||||
func (s reposToSort) Swap(i, j int) { s[i], s[j] = s[j], s[i] }
|
||||
func (s reposToSort) Less(i, j int) bool {
|
||||
return s[i].Name < s[j].Name
|
||||
}
|
||||
|
||||
func sortRepos(in []githubRepo) []githubRepo {
|
||||
sts := reposToSort(in)
|
||||
sort.Sort(sts)
|
||||
return []githubRepo(sts)
|
||||
}
|
||||
|
||||
// sort owners in order that that should be presented.
|
||||
type ownersToSort []githubOwner
|
||||
|
||||
|
@ -42,3 +27,10 @@ func sortOwners(in []githubOwner) []githubOwner {
|
|||
sort.Sort(sts)
|
||||
return []githubOwner(sts)
|
||||
}
|
||||
|
||||
// sort branches in order that that should be presented.
|
||||
func sortBranches(in []githubBranch) []githubBranch {
|
||||
sts := branchesToSort(in)
|
||||
sort.Sort(sts)
|
||||
return []githubBranch(sts)
|
||||
}
|
||||
|
|
42
core/section/github/summary.go
Normal file
42
core/section/github/summary.go
Normal file
|
@ -0,0 +1,42 @@
|
|||
// Copyright 2016 Documize Inc. <legal@documize.com>. All rights reserved.
|
||||
//
|
||||
// This software (Documize Community Edition) is licensed under
|
||||
// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html
|
||||
//
|
||||
// You can operate outside the AGPL restrictions by purchasing
|
||||
// Documize Enterprise Edition and obtaining a commercial license
|
||||
// by contacting <sales@documize.com>.
|
||||
//
|
||||
// https://documize.com
|
||||
|
||||
package github
|
||||
|
||||
import (
|
||||
gogithub "github.com/google/go-github/github"
|
||||
)
|
||||
|
||||
const (
|
||||
tagSummaryData = "summaryData"
|
||||
)
|
||||
|
||||
// sort branches in order that that should be presented.
|
||||
|
||||
type branchesToSort []githubBranch
|
||||
|
||||
func (s branchesToSort) Len() int { return len(s) }
|
||||
func (s branchesToSort) Swap(i, j int) { s[i], s[j] = s[j], s[i] }
|
||||
func (s branchesToSort) Less(i, j int) bool {
|
||||
return s[i].URL < s[j].URL
|
||||
}
|
||||
|
||||
func init() {
|
||||
reports[tagSummaryData] = report{refreshSummary, renderSummary, summaryTemplate}
|
||||
}
|
||||
|
||||
func refreshSummary(gr *githubRender, config *githubConfig, client *gogithub.Client) (err error) {
|
||||
return nil
|
||||
}
|
||||
|
||||
func renderSummary(payload *githubRender, c *githubConfig) error {
|
||||
return nil
|
||||
}
|
49
core/section/github/summary_template.go
Normal file
49
core/section/github/summary_template.go
Normal file
|
@ -0,0 +1,49 @@
|
|||
// Copyright 2016 Documize Inc. <legal@documize.com>. All rights reserved.
|
||||
//
|
||||
// This software (Documize Community Edition) is licensed under
|
||||
// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html
|
||||
//
|
||||
// You can operate outside the AGPL restrictions by purchasing
|
||||
// Documize Enterprise Edition and obtaining a commercial license
|
||||
// by contacting <sales@documize.com>.
|
||||
//
|
||||
// https://documize.com
|
||||
|
||||
package github
|
||||
|
||||
const summaryTemplate = `
|
||||
<div class="section-github-render">
|
||||
|
||||
<p>
|
||||
Activity since {{.Config.Since}}{{.Config.DateMessage}} for {{.Config.Owner}} repositories:
|
||||
{{range $data := .Config.Lists}}
|
||||
{{if $data.Included}}
|
||||
<a class="link" href="{{$data.URL}}">
|
||||
{{$data.Repo}}{{if $data.Comma}},{{end}}
|
||||
</a>
|
||||
{{end}}
|
||||
{{end}}
|
||||
</p>
|
||||
|
||||
{{if .HasSharedLabels}}
|
||||
<h3>Common Labels</h3>
|
||||
<p>There
|
||||
{{if eq 1 (len .SharedLabels)}} is {{else}} are {{end}}
|
||||
{{len .SharedLabels}}
|
||||
shared
|
||||
{{if eq 1 (len .SharedLabels)}} label {{else}} labels {{end}}
|
||||
across the repositories.</p>
|
||||
<table class="width-100">
|
||||
<tbody class="github">
|
||||
{{range $slabel := .SharedLabels}}
|
||||
<tr>
|
||||
<td class="width-100">
|
||||
<span class="github-issue-label" style="background-color:#{{$slabel.Color}}">{{$slabel.Name}} ({{$slabel.Count}})</span> in {{$slabel.Repos}}
|
||||
</td>
|
||||
</tr>
|
||||
{{end}}
|
||||
</tbody>
|
||||
</table>
|
||||
{{end}}
|
||||
</div>
|
||||
`
|
13319
embed/bindata_assetfs.go
Normal file
13319
embed/bindata_assetfs.go
Normal file
File diff suppressed because one or more lines are too long
|
@ -3,7 +3,7 @@
|
|||
# run github.com/alecthomas/gometalinter to check correctness, style and error handling
|
||||
# also check spelling with github.com/client9/misspell
|
||||
# Only set up to look at non-vendored code, should be run from top level
|
||||
for dir in $(find documize wordsmith sdk plugin-* -type d -print | grep -v -e "web" | grep -v -e "templates" | sort | tr '\n' ' ')
|
||||
for dir in $(find core sdk plugin-* -type d -print | grep -v -e "web" | grep -v -e "templates" | sort | tr '\n' ' ')
|
||||
do
|
||||
echo "*** " $dir
|
||||
gometalinter --vendor --disable='gotype' --deadline=30s $dir | sort
|
||||
|
@ -12,7 +12,7 @@ done
|
|||
|
||||
# run github.com/FiloSottile/vendorcheck (including tests)
|
||||
echo "*** vendorcheck"
|
||||
for dir in documize sdk
|
||||
for dir in core sdk
|
||||
do
|
||||
cd $dir
|
||||
vendorcheck -t . | grep -v 'github.com/documize/community'
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue