Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extra Buildkite options please #1273

Open
snoblenet opened this issue Jul 12, 2022 · 4 comments
Open

Extra Buildkite options please #1273

snoblenet opened this issue Jul 12, 2022 · 4 comments
Labels
💥 feature "Good luck, you're gonna need it." wontfix

Comments

@snoblenet
Copy link

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
Copy link
Author

snoblenet commented Jul 12, 2022

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
Copy link
Author

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
Copy link
Author

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

@senorprogrammer senorprogrammer added the 💥 feature "Good luck, you're gonna need it." label Jul 18, 2022
@stale
Copy link

stale bot commented Jan 14, 2023

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 stale bot added the wontfix label Jan 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
💥 feature "Good luck, you're gonna need it." wontfix
2 participants