Skip to content
This repository was archived by the owner on Nov 20, 2023. It is now read-only.

Conversation

@dmitryrn
Copy link
Contributor

@dmitryrn dmitryrn commented Sep 25, 2019

I added setCommits command to be able set associated commits through this plugin as requested here #71. Without this options you forced to use sentry-cli to set associated commits directly. Please check this out.

ToDo:

  • add tests for setCommits
  • update setCommits options descriptions in README.md

@dmitryrn
Copy link
Contributor Author

Also I realised that I also might need to use deploys. This is for the thread #71.

BTW I wrote simple webpack-3 plugin:

const SentryCli = require('@sentry/cli')

class SentryCommitsPlugin {
  constructor(options) {
    this.options = options
  }

  apply(compiler) {
    compiler.hooks.emit.tapAsync(
      'MyExampleWebpackPlugin',
      async (compilation, callback) => {
        const cli = new SentryCli()

        const {
          release,
          commit,
          previousCommit,
          repo,
          auto,
        } = this.options

        console.info('\n\n> Associating sentry release commits...')

        await cli.releases.setCommits(release, {
          commit,
          previousCommit,
          repo,
          auto,
        })

        console.info('> Sentry release commits associated successfully\n')

        callback()
      }
    )
  }
}

module.exports = SentryCommitsPlugin

I run this SentryCommitsPlugin after SentryCLIPlugin

Also I'll write and use similar SentryDeploysPlugin

So what do you think: do we really need such functionality in this plugin?

@dmitryrn
Copy link
Contributor Author

dmitryrn commented Sep 26, 2019

Oh, no way! We need to add deploys here first

@dmitryrn
Copy link
Contributor Author

@kamilogorek can you review this?

@dmitryrn
Copy link
Contributor Author

dmitryrn commented Oct 1, 2019

Also I wrote and use following plugin for Sentry Deploys:

I use Sentry API here instead of sentry-cli because bridge-like thing from Rust to JS does not implemented like for setCommits (https://github.com/getsentry/sentry-cli/blob/master/js/releases/index.js#L61)

const assert = require('assert')
const axios = require('axios').default

class SentryDeploysPlugin {
  constructor(options) {
    this.options = options
  }

  apply(compiler) {
    compiler.hooks.emit.tapAsync(
      'SentryDeploysPlugin',
      async (compilation, callback) => {
        const {
          version,
          authToken,
          orgSlug,
          serverUrl,
        } = this.options

        assert(typeof version === 'string', 'option version is incorrect')
        assert(typeof authToken === 'string', 'option authToken is incorrect')
        assert(typeof orgSlug === 'string', 'option orgSlug is incorrect')
        assert(typeof serverUrl === 'string', 'option serverUrl is incorrect')

        try {
          console.info('\n\n> Creating sentry deploy...')

          await axios.post(`${serverUrl}api/0/organizations/${orgSlug}/releases/${version}/deploys/`, {
            environment: 'production',
          }, {
            headers: {
              Authorization: `Bearer ${authToken}`,
            },
          })

          console.info('> Sentry deploy created successfully\n')

          callback()
        } catch (error) {
          console.info('> Sentry deploy failed!\n')
          console.error('Sentry server response: ', error.response.data)
          callback(error)
        }
      }
    )
  }
}

module.exports = SentryDeploysPlugin

Copy link
Contributor

@kamilogorek kamilogorek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

edit: missed one thing. Updated.

Copy link
Contributor

@kamilogorek kamilogorek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Few minor changes

@kamilogorek kamilogorek merged commit a98392b into getsentry:master Oct 8, 2019
@kamilogorek
Copy link
Contributor

Thanks!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants