Pswadi/buddy approval for release

The tag / SHA specified in the deploy will be used for checking if the same deploy to another production stage was already approved in last 4 hours. If so, the buddy will be "carried forward" for the new stage.   BUDDY_CHECK_GRACE_PERIOD decides how long we want to search for.

This does not start the queued up deploys, yet.

/cc @zendesk/samson @grosser @steved555 

### References
 - Jira link: 

### Risks
 - Buddy approval anomalies?
I agree, it makes sense, just looked weird when calling it ... either way
is fine :)

On Thu, Oct 30, 2014 at 4:15 PM, Praveen Swadi <notifications@github.com>
wrote:

> In app/models/deploy_service.rb:
>
> > @@ -31,6 +31,25 @@ def auto_confirm?(stage)
> >      !BuddyCheck.enabled? || !stage.production?
> >    end
> >
> > +  def latest_approved_deploy(deploy)
> > +    Deploy.where('reference = ? AND buddy_id is NOT NULL AND started_at > ?', deploy.reference, (Time.now - (BuddyCheck.grace_period*60*60)))
> > +      .order(started_at: :asc)
> > +      .includes(:stage)
> > +      .where(stages: {project_id: deploy.stage.project, production: true})
> > +      .first
> > +  end
> > +
> > +  def release_approved?(deploy)
> > +    last_d = latest_approved_deploy(deploy)
>
> well, we want a "similar" deploy to the one we are looking at. So thought
> it was appropriate to send it in. :-) But i can change it.
>
> —
> Reply to this email directly or view it on GitHub
> <https://github.com/zendesk/samson/pull/182/files#r19643159>.
>