<commit_before>/// <reference path="../typings/rx/rx.d.ts" />
/// <reference path="../typings/rx/rx-lite.d.ts" />
/// <reference path="../typings/github/github.d.ts" />
import {Observable, Subject} from 'rx';

declare var Firebase;

export class Github {
  private _issues: Subject<AngularIssue[]>;
  private _ref = new Firebase("https://ng2-projects.firebaseio.com");

  constructor(public owner: string, public repository: string) {}

  get isAuthenticated(): boolean { return !!(this._ref.getAuth()); }

  get issues(): Observable<AngularIssue[]> {
    if (!this._issues) {
      this.refresh();
    }
    return this._issues;
  }

  get username(): string { return this._ref.getAuth().github.username; }

  authenticate(): void {
    this._ref.authWithOAuthPopup("github", (error: any, authData: any) => {
      if (error) {
        console.error(error);
      } else {
        console.log("Authenticated successfully!", authData);
      }
    });
  }

  refresh(): void {
    if (!this._issues) {
      this._issues = new Subject<AngularIssue[]>();
    }
    this._fetchPage(0).toArray().subscribe(
        (issues: AngularIssue[]) => this._issues.onNext(issues),
        (error: any) => this._issues.onError(error));
  }

  private _buildUrl(path: string, params: {[param: string] : any}): string {
    params['access_token'] = this._ref.getAuth().github.accessToken;
    var arr: Array<string> =
        Object.keys(params).map((p: string) => `${p}=${params[p]}`);
    return `https://api.github.com${path}?${arr.join('&')}`;
  }
<commit_msg>Fixes bug where the user would need to restart the app if they hadn't already authenticated with Github.<commit_after>/// <reference path="../typings/rx/rx.d.ts" />
/// <reference path="../typings/rx/rx-lite.d.ts" />
/// <reference path="../typings/github/github.d.ts" />
import {Observable, Subject} from 'rx';

declare var Firebase;

export class Github {
  private _issues: Subject<AngularIssue[]>;
  private _ref = new Firebase("https://ng2-projects.firebaseio.com");

  constructor(public owner: string, public repository: string) {}

  get isAuthenticated(): boolean { return !!(this._ref.getAuth()); }

  get issues(): Observable<AngularIssue[]> {
    if (!this._issues) {
      this.refresh();
    }
    return this._issues;
  }

  get username(): string {
    return (this.isAuthenticated) ? this._ref.getAuth().github.username : '';
  }

  authenticate(): void {
    this._ref.authWithOAuthPopup("github", (error: any, authData: any) => {
      if (error) {
        console.error(error);
      } else {
        console.log("Authenticated successfully!", authData);
        this.refresh();
      }
    });
  }

  refresh(): void {
    if (!this._issues) {
      this._issues = new Subject<AngularIssue[]>();
    }
    this._fetchPage(0).toArray().subscribe(
        (issues: AngularIssue[]) => this._issues.onNext(issues),
        (error: any) => this._issues.onError(error));
  }

  private _buildUrl(path: string, params: {[param: string] : any}): string {
    params['access_token'] = this._ref.getAuth().github.accessToken;
    var arr: Array<string> =
        Object.keys(params).map((p: string) => `${p}=${params[p]}`);
    return `https://api.github.com${path}?${arr.join('&')}`;
  }

{'fraction_non_alphanumeric': 0.18682671591258848, 'fraction_numerical': 0.0012311480455524776, 'mean_word_length': 3.3449197860962565, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 25, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6365031', 'n_tokens_mistral': 1056, 'n_tokens_neox': 1029, 'n_words': 209}