mirror of
https://github.com/documize/community.git
synced 2025-08-10 07:55:25 +02:00
remove secrets from JS, make branch name clickable
This commit is contained in:
parent
8a6af3d0a1
commit
9cebfbe219
2 changed files with 83 additions and 50 deletions
|
@ -24,44 +24,52 @@ export default Ember.Component.extend(SectionMixin, NotifierMixin, TooltipMixin,
|
||||||
noRepos: false,
|
noRepos: false,
|
||||||
|
|
||||||
didReceiveAttrs() {
|
didReceiveAttrs() {
|
||||||
let config = {};
|
|
||||||
|
|
||||||
try {
|
let self = this;
|
||||||
config = JSON.parse(this.get('meta.config'));
|
let page = this.get('page');
|
||||||
} catch (e) {}
|
console.log(this.get('config.clientId'));
|
||||||
|
|
||||||
if (is.empty(config)) {
|
if (is.undefined(this.get('config.clientId')) || is.undefined(this.get('config.callbackUrl'))) {
|
||||||
config = {
|
self.get('sectionService').fetch(page, "config", {})
|
||||||
clientId: "8574d0c34142dcdc53f6",
|
.then(function(cfg) {
|
||||||
callbackUrl: "https://localhost:5001/api/public/validate?section=github",
|
let config = {};
|
||||||
token: "",
|
|
||||||
repo: null,
|
try {
|
||||||
lists: [],
|
config = JSON.parse(self.get('meta.config'));
|
||||||
owner: "",
|
} catch (e) {}
|
||||||
repo_name: "",
|
|
||||||
branch: ""
|
config = {
|
||||||
};
|
clientId: cfg.clientID,
|
||||||
|
callbackUrl: cfg.authorizationCallbackURL,
|
||||||
|
token: "",
|
||||||
|
repo: null,
|
||||||
|
lists: [],
|
||||||
|
owner: "",
|
||||||
|
repo_name: "",
|
||||||
|
branch: "",
|
||||||
|
branchURL: "",
|
||||||
|
branchSince: ""
|
||||||
|
};
|
||||||
|
self.set('config', config);
|
||||||
|
|
||||||
|
// On auth callback capture code
|
||||||
|
let code = window.location.search;
|
||||||
|
|
||||||
|
if (is.not.undefined(code) && is.not.null(code)) {
|
||||||
|
let tok = code.replace("?code=", "");
|
||||||
|
if (is.not.empty(code)) {
|
||||||
|
self.set('config.token', tok);
|
||||||
|
self.send('authStage2');
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (self.get('config.token') === "") {
|
||||||
|
self.send('auth');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, function(error) { //jshint ignore: line
|
||||||
|
console.log(error);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
this.set('config', config);
|
|
||||||
|
|
||||||
|
|
||||||
// On auth callback capture code
|
|
||||||
let code = window.location.search;
|
|
||||||
if (is.not.undefined(code) && is.not.null(code)) {
|
|
||||||
let tok = code.replace("?code=", "");
|
|
||||||
if (is.not.empty(code)) {
|
|
||||||
this.set('config.token', tok);
|
|
||||||
this.send('authStage2');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((this.get('config.clientId') === "" || this.get('config.token') === "")) {
|
|
||||||
|
|
||||||
this.send('auth');
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
willDestroyElement() {
|
willDestroyElement() {
|
||||||
|
@ -160,8 +168,6 @@ export default Ember.Component.extend(SectionMixin, NotifierMixin, TooltipMixin,
|
||||||
auth() {
|
auth() {
|
||||||
|
|
||||||
let self = this;
|
let self = this;
|
||||||
|
|
||||||
|
|
||||||
self.set('busy', true);
|
self.set('busy', true);
|
||||||
self.set('authenticated', false);
|
self.set('authenticated', false);
|
||||||
let target = "https://github.com/login/oauth/authorize?client_id=" + self.get('config.clientId') +
|
let target = "https://github.com/login/oauth/authorize?client_id=" + self.get('config.clientId') +
|
||||||
|
@ -169,7 +175,6 @@ export default Ember.Component.extend(SectionMixin, NotifierMixin, TooltipMixin,
|
||||||
"&state=" + encodeURIComponent(window.location.href);
|
"&state=" + encodeURIComponent(window.location.href);
|
||||||
window.location.href = target;
|
window.location.href = target;
|
||||||
|
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
onRepoChange(thisRepo) {
|
onRepoChange(thisRepo) {
|
||||||
|
|
|
@ -21,6 +21,7 @@ import (
|
||||||
"net/url"
|
"net/url"
|
||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/documize/community/documize/api/request"
|
"github.com/documize/community/documize/api/request"
|
||||||
"github.com/documize/community/wordsmith/log"
|
"github.com/documize/community/wordsmith/log"
|
||||||
|
@ -85,6 +86,17 @@ func (t *GithubT) Command(w http.ResponseWriter, r *http.Request) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if method == "config" {
|
||||||
|
var ret struct {
|
||||||
|
CID string `json:"clientID"`
|
||||||
|
URL string `json:"authorizationCallbackURL"`
|
||||||
|
}
|
||||||
|
ret.CID = clientID()
|
||||||
|
ret.URL = authorizationCallbackURL()
|
||||||
|
writeJSON(w, ret)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
defer r.Body.Close()
|
defer r.Body.Close()
|
||||||
body, err := ioutil.ReadAll(r.Body)
|
body, err := ioutil.ReadAll(r.Body)
|
||||||
|
|
||||||
|
@ -205,6 +217,7 @@ func (t *GithubT) Command(w http.ResponseWriter, r *http.Request) {
|
||||||
Name: *vb.Name,
|
Name: *vb.Name,
|
||||||
ID: fmt.Sprintf("%s:%s:%s:%d", config.Owner, config.Repo, *vb.Name, kc),
|
ID: fmt.Sprintf("%s:%s:%s:%d", config.Owner, config.Repo, *vb.Name, kc),
|
||||||
Included: false,
|
Included: false,
|
||||||
|
URL: "https://github.com/" + config.Owner + "/" + config.Repo + "/tree/" + *vb.Name,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -227,8 +240,19 @@ func (*GithubT) githubClient(config githubConfig) *gogithub.Client {
|
||||||
|
|
||||||
func (*GithubT) getCommits(client *gogithub.Client, config githubConfig) ([]githubBranchCommits, error) {
|
func (*GithubT) getCommits(client *gogithub.Client, config githubConfig) ([]githubBranchCommits, error) {
|
||||||
|
|
||||||
guff, _, err := client.Repositories.ListCommits(config.Owner, config.Repo,
|
opts := &gogithub.CommitsListOptions{
|
||||||
&gogithub.CommitsListOptions{SHA: config.Branch, ListOptions: gogithub.ListOptions{PerPage: 100}})
|
SHA: config.Branch,
|
||||||
|
ListOptions: gogithub.ListOptions{PerPage: 100}}
|
||||||
|
|
||||||
|
var since time.Time
|
||||||
|
|
||||||
|
err := since.UnmarshalText([]byte(config.BranchSince))
|
||||||
|
if err == nil {
|
||||||
|
opts.Since = since
|
||||||
|
}
|
||||||
|
|
||||||
|
guff, _, err := client.Repositories.ListCommits(config.Owner, config.Repo, opts)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -347,7 +371,7 @@ func (*GithubT) Render(config, data string) string {
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
t, err = t.Parse(`
|
t, err = t.Parse(`
|
||||||
<p>There are {{ .CommitCount }} commits for branch <span class="bold">{{.Config.Branch}}</span> of repository <a href="{{ .Repo.URL }}">{{.Repo.Name}}.</a></p>
|
<p>There are {{ .CommitCount }} commits for branch <a href="{{.Config.BranchURL}}">{{.Config.Branch}}</a> of repository <a href="{{ .Repo.URL }}">{{.Repo.Name}}.</a></p>
|
||||||
<div class="github-board">
|
<div class="github-board">
|
||||||
{{range $data := .Data}}
|
{{range $data := .Data}}
|
||||||
<div class="github-group-title">
|
<div class="github-group-title">
|
||||||
|
@ -417,6 +441,7 @@ type githubBranch struct {
|
||||||
ID string `json:"id"`
|
ID string `json:"id"`
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
Included bool `json:"included"`
|
Included bool `json:"included"`
|
||||||
|
URL string `json:"url"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type githubBranchCommits struct {
|
type githubBranchCommits struct {
|
||||||
|
@ -434,15 +459,17 @@ type githubCommit struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type githubConfig struct {
|
type githubConfig struct {
|
||||||
AppKey string `json:"appKey"` // TODO keep?
|
AppKey string `json:"appKey"` // TODO keep?
|
||||||
Token string `json:"token"`
|
Token string `json:"token"`
|
||||||
Owner string `json:"owner"`
|
Owner string `json:"owner"`
|
||||||
Repo string `json:"repo_name"`
|
Repo string `json:"repo_name"`
|
||||||
Branch string `json:"branch"`
|
Branch string `json:"branch"`
|
||||||
RepoInfo githubRepo `json:"repo"`
|
BranchURL string `json:"branchURL"`
|
||||||
ClientID string `json:"clientId"`
|
BranchSince string `json:"branchSince"`
|
||||||
CallbackURL string `json:"callbackUrl"`
|
RepoInfo githubRepo `json:"repo"`
|
||||||
Lists []githubRepo `json:"lists"`
|
ClientID string `json:"clientId"`
|
||||||
|
CallbackURL string `json:"callbackUrl"`
|
||||||
|
Lists []githubBranch `json:"lists"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *githubConfig) Clean() {
|
func (c *githubConfig) Clean() {
|
||||||
|
@ -453,6 +480,7 @@ func (c *githubConfig) Clean() {
|
||||||
for _, l := range c.Lists {
|
for _, l := range c.Lists {
|
||||||
if l.Included {
|
if l.Included {
|
||||||
c.Branch = l.Name
|
c.Branch = l.Name
|
||||||
|
c.BranchURL = l.URL
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue