<commit_before>'use strict';


class GitHubFile {
  constructor(repo, item) {
    this.repo = repo;
    this.path = item.path;
    this.sha = item.sha;
  }

  content() {
    if(! this.sha) { return Q(''); }
    return this.repo.api({url: '/git/blobs/' + this.sha})
      .then((resp) =>
        atob(resp.content));
  }

  save(newContent) {
    return this.repo.api({
      url: '/contents/' + this.path,
      method: 'PUT',
      data: JSON.stringify({
        branch: 'gh-pages',
        message: "Edit from JekyllCMS",
        path: this.path,
        sha: this.sha,
        content: btoa(newContent)
      })
    })
    .then((resp) => {
      this.sha = resp.content.sha;
    });
  }

  delete() {
    return this.repo.api({
      url: '/contents/' + this.path,
      method: 'DELETE',
      data: JSON.stringify({
        branch: 'gh-pages',
        message: "Edit from JekyllCMS",
        path: this.path,
        sha: this.sha,
      })
    });
  }
}


class GitHubRepo {
  constructor(repoName, token) {
    this.repoName = repoName;
    this.token = token;
  }

  api(options) {
    options.url = 'https://api.github.com/repos/' + this.repoName + options.url;
    options.headers = {Authorization: 'token ' + this.token}
    return Q($.ajax(options));
  }

  files() {
    return this.api({url: '/git/trees/gh-pages?recursive=1'})
      .then((resp) =>
        resp.tree
          .filter((i) => i.type == 'blob')
          .map((i) => new GitHubFile(this, i)));
  }

  newFile(path) {
    return new GitHubFile(this, {path: path});
  }
}


class GitHub {
  constructor(token) {
    this.token = token;
  }

  repo(repo) {
    return new GitHubRepo(repo, this.token);
  }
}
<commit_msg>move http function to github object<commit_after>'use strict';


class GitHubFile {
  constructor(repo, item) {
    this.repo = repo;
    this.path = item.path;
    this.sha = item.sha;
  }

  content() {
    if(! this.sha) { return Q(''); }
    return this.repo.api({url: '/git/blobs/' + this.sha})
      .then((resp) =>
        atob(resp.content));
  }

  save(newContent) {
    return this.repo.api({
      url: '/contents/' + this.path,
      method: 'PUT',
      data: JSON.stringify({
        branch: 'gh-pages',
        message: "Edit from JekyllCMS",
        path: this.path,
        sha: this.sha,
        content: btoa(newContent)
      })
    })
    .then((resp) => {
      this.sha = resp.content.sha;
    });
  }

  delete() {
    return this.repo.api({
      url: '/contents/' + this.path,
      method: 'DELETE',
      data: JSON.stringify({
        branch: 'gh-pages',
        message: "Edit from JekyllCMS",
        path: this.path,
        sha: this.sha,
      })
    });
  }
}


class GitHubRepo {
  constructor(gh, repoName) {
    this.gh = gh;
    this.repoName = repoName;
  }

  api(options) {
    options.url = '/repos/' + this.repoName + options.url;
    return this.gh.api(options);
  }

  files() {
    return this.api({url: '/git/trees/gh-pages?recursive=1'})
      .then((resp) =>
        resp.tree
          .filter((i) => i.type == 'blob')
          .map((i) => new GitHubFile(this, i)));
  }

  newFile(path) {
    return new GitHubFile(this, {path: path});
  }
}


class GitHub {
  constructor(token) {
    this.token = token;
  }

  api(options) {
    options.url = 'https://api.github.com' + options.url;
    options.headers = {Authorization: 'token ' + this.token}
    return Q($.ajax(options));
  }

  repo(repo) {
    return new GitHubRepo(this, repo);
  }
}

{'fraction_non_alphanumeric': 0.17362700228832953, 'fraction_numerical': 0.0005720823798627002, 'mean_word_length': 2.139138240574506, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, 'https://': 2, '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': '5721007', 'n_tokens_mistral': 1252, 'n_tokens_neox': 1212, 'n_words': 243}