danger-js icon indicating copy to clipboard operation
danger-js copied to clipboard

Semaphore - Might need disclaimer

Open GantMan opened this issue 7 years ago • 5 comments

Not sure where the docs for this page are located, otherwise I would have just done a PR: http://danger.systems/js/guides/getting_started.html

The semaphore integration works, but there's a catch. Semaphore won't do a PR build unless it's a fork. So anyone who owns the repo, and simply does branch PRs, will see this message: image

I wrote to Semaphore and they responded with the following:

After a project has been added, Semaphore builds branches that are created within the repository.
 Because of this, at the moment Semaphore doesn't support building pull requests that are opened 
within the same repository. Opening a PR will trigger a build only if it was opened from a fork. For 
more details please refer to this page. 

Good news is that adding the option for building pull requests within repository is on our roadmap. 
So, we'd really appreciate if you have few moments to describe your use-case. We don't have an 
ETA yet, but we expect to deliver this feature during the first half of 2018. 

I believe a caveat should be added to the docs (I personally moved danger-js to Travis for this reason). But then again, maybe danger JS should detect semaphore and be willing to skip the detection process?

I hope this helps ^

GantMan avatar Dec 26 '17 00:12 GantMan

The code comes from here:

https://github.com/danger/danger-js/blob/9772aacbb62155a55ee5e6a1e4346ebb9aea0129/source/ci_source/providers/Semaphore.ts#L4-L16

Danger doesn't strictly check if it's a PR, but cares about these build vars - could there be alternatives?

https://github.com/danger/danger-js/blob/9772aacbb62155a55ee5e6a1e4346ebb9aea0129/source/ci_source/providers/Semaphore.ts#L27-L31

orta avatar Dec 26 '17 00:12 orta

Yeah, there's not going to be a PULL_REQUEST_NUMBER if semaphore is simply treating it as a branch. I assume that's the crux of the problem.

Also Merry Xmas! 🎄 🎁 🎅 🤶

GantMan avatar Dec 26 '17 00:12 GantMan

same 🥇

orta avatar Dec 26 '17 00:12 orta

Have any updated ? I also have this problem. Do you have workaround for this one ?

Elecweb avatar Mar 05 '19 04:03 Elecweb

Here's your workaround https://semaphoreci.com/docs/how-to-fetch-pull-request-number-from-github.html

Edit: These docs are outdated, but it does work with changes

#!/bin/env ruby

# Necessary for Danger to work in Semaphore -_-' see:
# https://semaphoreci.com/docs/how-to-fetch-pull-request-number-from-github.html
require 'octokit'

c = Octokit::Client.new(access_token: ENV['DANGER_GITHUB_API_TOKEN'], auto_paginate: true)
prs = c.pull_requests(ENV['SEMAPHORE_GIT_REPO_SLUG'], state: 'open')
current_pr = prs.select { |pr| pr[:head][:ref] == ENV['SEMAPHORE_GIT_BRANCH'] }

pr_value = current_pr.first[:number].to_s unless current_pr.nil?

puts pr_value
            - export SEMAPHORE_REPO_SLUG=$SEMAPHORE_GIT_REPO_SLUG
            - export PULL_REQUEST_NUMBER=$(ruby bin/pull_request_number.rb)
            - bundle exec danger

bessey avatar Oct 30 '19 16:10 bessey