<commit_before>import React, { PropTypes } from 'react';

import APINotLoaded from 'es6!display/not_loaded';
import { InfoList, InfoItem } from 'es6!display/info_list';

import * as api from 'es6!server/api';

import * as utils from 'es6!utils/utils';

var DetailsTab = React.createClass({

  propTypes: {
    // the API response from the fetch below
    details: PropTypes.object,
    // the project api response
    project: PropTypes.object,
  },

  componentDidMount: function() {
    var slug = this.props.project.getReturnedData().slug;
    api.fetch(this.props.pageElem, {
      details: `/api/0/projects/${slug}/plans/`
    });
  },

  render: function() {
    if (!api.isLoaded(this.props.details)) {
      return <APINotLoaded calls={this.props.details} />;
    }

    var plans = this.props.details.getReturnedData();
    var project = this.props.project.getReturnedData();

    var markup = _.map(plans, p =>
      <div className="marginBottomL">
        <b className="block">Build Plan:{" "}{p.name}</b>
        <InfoList>
          <InfoItem label="Infrastructure">
            {!_.isEmpty(p.steps) && p.steps[0].name}
          </InfoItem>
          <InfoItem label="Timeout">
            {!_.isEmpty(p.steps) && p.steps[0].options['build.timeout']}
          </InfoItem>
          <InfoItem label="Config:">
            <span />
          </InfoItem>
        </InfoList>
        <pre className="defaultPre">
          {!_.isEmpty(p.steps) && p.steps[0].data}
        </pre>
      </div>
    );

    return <div>
      {this.renderHeader(project, plans)}
      {markup}
    </div>;
  },

  renderHeader: function(project, plans) {
    var builds_on_diffs = project.options["phabricator.diff-trigger"];
    var builds_on_commits = project.options["build.commit-trigger"];

    var triggers = 'Does not automatically run';
    if (builds_on_commits && builds_on_diffs) {
      triggers = 'Diffs and Commits';
    } else if (builds_on_diffs) {
      triggers = 'Only diffs';
    } else if (builds_on_commits) {
      triggers = 'Only commits';
    }

    var branches_option = project.options["build.branch-names"] || '*';
    var branches = branches_option === "*" ?
      'any' :
      branches_option.replace(/ /g, ", ");

    var whitelist_option = project.options["build.file-whitelist"].trim();
    var whitelist_paths = 'No path filter';
    if (whitelist_option) {
      whitelist_paths = _.map(utils.split_lines(whitelist_option), line => {
        <div>{line}</div>
      });
    }

    return <div className="marginBottomL">
      <b>{project.name}</b>
      <InfoList>
        <InfoItem label="Repository">
          {project.repository.url}
        </InfoItem>
        <InfoItem label="Builds for">
          {triggers}
        </InfoItem>
        <InfoItem label="On branches">
          {branches}
        </InfoItem>
        <InfoItem label="Touching paths">
          {whitelist_paths}
        </InfoItem>
        <InfoItem label="Build plans">
          {plans.length}
        </InfoItem>
      </InfoList>
    </div>;

    // TODO: how many tests? how many commits in the last week?
  }
});

export default DetailsTab;<commit_msg>Add more useful info to the project details tab<commit_after>import React, { PropTypes } from 'react';

import APINotLoaded from 'es6!display/not_loaded';
import ChangesLinks from 'es6!display/changes/links';
import { InfoList, InfoItem } from 'es6!display/info_list';

import * as api from 'es6!server/api';

import * as utils from 'es6!utils/utils';

var DetailsTab = React.createClass({

  propTypes: {
    // the API response from the fetch below
    details: PropTypes.object,
    // the project api response
    project: PropTypes.object,
  },

  componentDidMount: function() {
    var slug = this.props.project.getReturnedData().slug;
    api.fetch(this.props.pageElem, {
      details: `/api/0/projects/${slug}/plans/`
    });
  },

  render: function() {
    if (!api.isLoaded(this.props.details)) {
      return <APINotLoaded calls={this.props.details} />;
    }

    var plans = this.props.details.getReturnedData();
    var project = this.props.project.getReturnedData();

    var markup = _.map(plans, p =>
      <div className="marginBottomL">
        <b className="block">Build Plan:{" "}{p.name}</b>
        <InfoList>
          <InfoItem label="Infrastructure">
            {!_.isEmpty(p.steps) && p.steps[0].name}
          </InfoItem>
          <InfoItem label="Timeout">
            {!_.isEmpty(p.steps) && p.steps[0].options['build.timeout']}
          </InfoItem>
          <InfoItem label="Config:">
            <span />
          </InfoItem>
        </InfoList>
        <pre className="defaultPre">
          {!_.isEmpty(p.steps) && p.steps[0].data}
        </pre>
      </div>
    );

    return <div>
      {this.renderHeader(project, plans)}
      {markup}
    </div>;
  },

  renderHeader: function(project, plans) {
    var builds_on_diffs = project.options["phabricator.diff-trigger"];
    var builds_on_commits = project.options["build.commit-trigger"];

    var triggers = 'Does not automatically run';
    if (builds_on_commits && builds_on_diffs) {
      triggers = 'Diffs and Commits';
    } else if (builds_on_diffs) {
      triggers = 'Only diffs';
    } else if (builds_on_commits) {
      triggers = 'Only commits';
    }

    var branches_option = project.options["build.branch-names"] || '*';
    var branches = branches_option === "*" ?
      'any' :
      branches_option.replace(/ /g, ", ");

    var whitelist_option = project.options["build.file-whitelist"].trim();
    var whitelist_paths = 'No path filter';
    if (whitelist_option) {
      whitelist_paths = _.map(utils.split_lines(whitelist_option), line => {
        <div>{line}</div>
      });
    }

    // Most projects should have a current snapshot, so it's worth the potential noise
    // to say one isn't set even when the build plan doesn't make it possible.
    var snapshot_info = "None configured";
    var current_snapshot = project.options["snapshot.current"];
    if (current_snapshot) {
        snapshot_info = <a href={URI(`/snapshot/${current_snapshot}/`)}>{current_snapshot.substring(0, 8)}</a>;
    }

    return <div className="marginBottomL">
      <b>{project.name}</b>
      <InfoList>
        <InfoItem label="Repository">
          {project.repository.url}
        </InfoItem>
        <InfoItem label="Owners">
          {project.options["project.owners"] || "unknown"}
        </InfoItem>
        <InfoItem label="Builds for">
          {triggers}
        </InfoItem>
        <InfoItem label="On branches">
          {branches}
        </InfoItem>
        <InfoItem label="Touching paths">
          {whitelist_paths}
        </InfoItem>
        <InfoItem label="Current snapshot">
          {snapshot_info}
        </InfoItem>
        <InfoItem label="Build plans">
          {plans.length}
        </InfoItem>
      </InfoList>
    </div>;

    // TODO: how many tests? how many commits in the last week?
  }
});

export default DetailsTab;
{'fraction_non_alphanumeric': 0.14602587800369685, 'fraction_numerical': 0.0027015498364851413, 'mean_word_length': 2.5669371196754565, 'pattern_counts': {'":': 0, '<': 81, '<?xml version=': 0, '>': 85, 'https://': 0, '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': '1677058', 'n_tokens_mistral': 2196, 'n_tokens_neox': 2174, 'n_words': 469}