<commit_before>import Ember from 'ember';
import {task} from 'ember-concurrency';

export default Ember.Component.extend({

  classNames: Ember.String.w('ui grid full-height'),

  build: Ember.inject.service(),
  notify: Ember.inject.service(),

  buildNumber: "",
  sortByNumberDesc: ['number:desc'],
  all: Ember.computed.sort('pipeline.builds', 'sortByNumberDesc'),
  buildQuery: Ember.computed('buildNumber', function() {
    return {
      owner: this.get('pipeline.owner'),
      repo: this.get('pipeline.repo'),
      build_number: this.get('buildNumber'),
    };
  }),

  willInsertElement() {
    this.addObserver('buildNumber', this, this.getBuildDetails);
    this.setLatestBuild();
  },

  willDestroyElement() {
    this.removeObserver('buildNumber', this, this.getBuildDetails);
  },

  didInsertElement() {
    this.$(".in-header.icon.button").popup({
      variation: "small inverted",
      position: "top right",
      inline: true,
      exclusive: true,
    });
  },

  getBuildDetails() {
    this.get('buildFetcher').perform();
  },

  setLatestBuild() {
    let buildnum = this.get('pipeline.latest_build.number');
    if (buildnum) {
      this.set('buildNumber', buildnum.toString());
    }
  },

  buildFetcher: task(function * () {
    if (this.get('buildNumber')) {
      yield this.get('build').find(this.get('buildQuery'))
        .then((build) => {
          this.set('model', build);
        });
    }
  }).drop(),

  buildCreator: task(function * () {
    let note = this.get('notify').info('Sending request to create build for pipeline.', {closeAfter: null});

    let p = this.get('pipeline');
    let b = this.get('build').new(p);

    yield b.save()
      .then(() => {
        note.set('visible', false);
        this.get('notify').success('Successfully created build for pipeline.');
      }, (res) => {
        note.set('visible', false);
        this.get('notify').error(res.errors.Message || 'Failed to create build for pipeline.');
      })
      .finally(() => {
        this.get('pipeline').reload();
        this.setLatestBuild();
      });
  }).drop(),

  actions: {
    selectBuild() {
      this.send('unselectStage');
    },
    confirmCreateBuild() {
      this.$('.ui.modal.create-build-confirmation').modal('show');
    },
    createBuild() {
      this.get('buildCreator').perform();
    },
    selectStage(stage) {
      this.send('closePipelineDetails');
      this.set('selectedStage', stage);
    },
    unselectStage() {
      this.set('selectedStage', null);
    },
    viewPipelineDetails() {
      this.send('unselectStage');
      this.set('isViewingPipelineDetails', true);<commit_msg>Update pipeline page with latest_build on pipeline trigger<commit_after>import Ember from 'ember';
import {task} from 'ember-concurrency';

export default Ember.Component.extend({

  classNames: Ember.String.w('ui grid full-height'),

  build: Ember.inject.service(),
  notify: Ember.inject.service(),

  buildNumber: "",
  sortByNumberDesc: ['number:desc'],
  all: Ember.computed.sort('pipeline.builds', 'sortByNumberDesc'),
  buildQuery: Ember.computed('buildNumber', function() {
    return {
      owner: this.get('pipeline.owner'),
      repo: this.get('pipeline.repo'),
      build_number: this.get('buildNumber'),
    };
  }),

  willInsertElement() {
    this.addObserver('buildNumber', this, this.getBuildDetails);
    this.setLatestBuild();
  },

  willDestroyElement() {
    this.removeObserver('buildNumber', this, this.getBuildDetails);
  },

  didInsertElement() {
    this.$(".in-header.icon.button").popup({
      variation: "small inverted",
      position: "top right",
      inline: true,
      exclusive: true,
    });
  },

  getBuildDetails() {
    this.get('buildFetcher').perform();
  },

  setLatestBuild() {
    let buildnum = this.get('pipeline.latest_build.number');
    if (buildnum) {
      this.set('buildNumber', buildnum.toString());
    }
  },

  buildFetcher: task(function * () {
    if (this.get('buildNumber')) {
      yield this.get('build').find(this.get('buildQuery'))
        .then((build) => {
          this.set('model', build);
        });
    }
  }).drop(),

  buildCreator: task(function * () {
    let notify = this.get('notify');
    let note = notify.info('Sending request to create build for pipeline.', {closeAfter: null});

    let p = this.get('pipeline');
    let b = this.get('build').new(p);

    yield b.save()
      .then(() => {
        note.set('visible', false);
        notify.success('Successfully created build for pipeline.');
      }, (res) => {
        note.set('visible', false);
        notify.error(res.errors.Message || 'Failed to create build for pipeline.');
      })
      .finally(() => {
        this.get('build').unload(b);
        this.get('pipeline').reload()
          .then((p) => {
            p.get('builds').reload();
            this.set('pipeline', p);
            this.setLatestBuild();
          });
      });
  }).drop(),

  actions: {
    selectBuild() {
      this.send('unselectStage');
    },
    confirmCreateBuild() {
      this.$('.ui.modal.create-build-confirmation').modal('show');
    },
    createBuild() {
      this.get('buildCreator').perform();
    },
    selectStage(stage) {
      this.send('closePipelineDetails');
      this.set('selectedStage', stage);
    },
    unselectStage() {
      this.set('selectedStage', null);
    },
    viewPipelineDetails() {
      this.send('unselectStage');
      this.set('isViewingPipelineDetails', true);
{'fraction_non_alphanumeric': 0.17970170971262278, 'fraction_numerical': 0.0, 'mean_word_length': 2.9675324675324677, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 12, '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': '3495313', 'n_tokens_mistral': 1679, 'n_tokens_neox': 1675, 'n_words': 288}