wtf icon indicating copy to clipboard operation
wtf copied to clipboard

Extra Buildkite options please

Open snoblenet opened this issue 2 years ago • 4 comments

Great tool thanks.

What should it do?

I would love the Buildkite module to have options to:

  • optionally just show status for my builds
  • optionally match any pipeline in org
  • optionally provide a pretty name for matched pipeline
  • optionally match any branch in pipeline
  • open the focused build on buildkite

snoblenet avatar Jul 12 '22 07:07 snoblenet

I'll call this from the command runner for now:

const axios = require('axios');
const colors = require('colors');
const https = require('https');

const client = axios.create({
  headers: {
    Authorization: `Bearer ${process.env.BUILDKITE_TOKEN}`,
    'Content-Type': 'application/json',
  },
  httpsAgent: new https.Agent({ keepAlive: true }),
});

client
  .get(`https://api.buildkite.com/v2/builds?creator=${process.env.BUILDKITE_CREATOR_ID}&per_page=8`)
  .then(result => {
    result.data.forEach(build => {
      const colourCode =
        {
          running: 'yellow',
          scheduled: 'yellow',
          passed: 'green',
          failed: 'red',
          blocked: 'grey',
          canceled: 'grey',
          canceling: 'grey',
          skipped: 'grey',
          not_run: 'grey',
          finished: 'green',
        }[build.state] || 'red';

      console.log(colors.blue(build.pipeline.name), colors.white(build.branch), colors[colourCode](build.state));
    });
  })
  .catch(error => {
    console.error(error);
  });

snoblenet avatar Jul 12 '22 10:07 snoblenet

Newer version below. It works well, but I'm not sure how to go about adding the equivalent of openStory as seen in the HackerNews module etc.

#!/usr/bin/env node

const axios = require('axios');
const colors = require('colors');
const https = require('https');

const client = axios.create({
  headers: {
    Authorization: `Bearer ${process.env.BUILDKITE_TOKEN}`,
    'Content-Type': 'application/json',
  },
  httpsAgent: new https.Agent({ keepAlive: true }),
});

client
  .get(`https://api.buildkite.com/v2/builds?creator=${process.env.BUILDKITE_CREATOR_ID}&per_page=8`)
  .then(result => {
    const builds = result.data.map(build => {
      const colourCode =
        {
          running: 'yellow',
          scheduled: 'yellow',
          passed: 'green',
          failed: 'red',
          blocked: 'blue',
          canceled: 'blue',
          canceling: 'blue',
          skipped: 'blue',
          not_run: 'blue',
          finished: 'green',
        }[build.state] || 'red';

      const date = new Date(Date.parse(build.created_at));

      return {
        pipeline: build.pipeline.name,
        branch: build.branch,
        colourCode,
        state: build.state,
        time: [date.getHours(), ':', String(date.getMinutes()).padStart(2, '0')].join(''),
      };
    });

    const pipelineLength = Math.max(...builds.map(build => build.pipeline.length + 2));
    const branchLength = Math.max(...builds.map(build => build.branch.length + 2));
    const stateLength = Math.max(...builds.map(build => build.state.length + 2));

    builds.forEach(build => {
      console.log(
        colors.magenta(build.pipeline.padEnd(pipelineLength, ' ')),
        colors.white(build.branch.padEnd(branchLength, ' ')),
        colors[build.colourCode](build.state.padEnd(stateLength, ' ')),
        colors.cyan(build.time),
      );
    });
  })
  .catch(error => {
    console.error(error);
  });

snoblenet avatar Jul 12 '22 12:07 snoblenet

Either that, or CmdRunner could provide a way to bind <enter> to open https://buildkite.com/builds when the module is focused?

snoblenet avatar Jul 12 '22 12:07 snoblenet

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Jan 14 '23 16:01 stale[bot]