// Trigger triggers a webhook event. The sha1 digest of v is calculated and
// including in the X-Hub-Signature header.
324875
func (c *Client) Trigger(event string, v interface{}) (*http.Response, error) {
	b := new(bytes.Buffer)

	switch v := v.(type) {
	case io.Reader:
		if _, err := io.Copy(b, v); err != nil {
			return nil, err
		}
	default:
		if err := json.NewEncoder(b).Encode(v); err != nil {
			return nil, err
		}
	}

	req, err := http.NewRequest("POST", c.URL, b)
	if err != nil {
		return nil, err
	}

	req.Header.Set("X-GitHub-Event", event)
	req.Header.Set("X-Hub-Signature", fmt.Sprintf("sha1=%s", hookshot.Signature(b.Bytes(), c.Secret)))

	return c.Do(req)
}
317402
func (a *MandrillAPI) WebhookAdd(url string, events []string) (Webhook, error) {
	if url == "" {
		return Webhook{}, errors.New("url cannot be blank")
	}
	var params map[string]interface{} = make(map[string]interface{})
	params["url"] = url
	params["events"] = events
	return getWebhook(a, params, webhooks_add_endpoint)
}
772268
func (c *ContextAction) Trigger() {
	packet := MumbleProto.ContextAction{
		Action: &c.Name,
	}
	c.client.Conn.WriteProto(&packet)
}
697366
func Convert_build_WebHookTrigger_To_v1_WebHookTrigger(in *build.WebHookTrigger, out *v1.WebHookTrigger, s conversion.Scope) error {
	return autoConvert_build_WebHookTrigger_To_v1_WebHookTrigger(in, out, s)
}
960667
func (db *DB) triggerPushSubscriptions() {
	db.pushTriggersMu.RLock()
	triggers := db.pushTriggers
	db.pushTriggersMu.RUnlock()

	for _, t := range triggers {
		select {
		case t <- struct{}{}:
		default:
		}
	}
}
184661
func (tm *Timer) TriggerAfter(duration time.Duration) {
	go func() {
		time.Sleep(duration)
		tm.Trigger()
	}()
}
681389
func (self *Service) CreateTrigger(createRequest TriggerCreateRequest) (Trigger, error) {

	url := "service/" + self.Uuid + "/trigger/"
	request := "POST"
	var response Trigger

	newTrigger, err := json.Marshal(createRequest)
	if err != nil {
		return response, err
	}

	data, err := TutumCall(url, request, newTrigger)
	if err != nil {
		return response, err
	}

	err = json.Unmarshal(data, &response)
	if err != nil {
		return response, err
	}

	return response, nil
}
529630
func (b *Backend) TriggerChord(groupUUID string) (bool, error) {
	// Get the group meta data
	groupMeta, err := b.getGroupMeta(groupUUID)

	if err != nil {
		return false, err
	}

	// Chord has already been triggered, return false (should not trigger again)
	if groupMeta.ChordTriggered {
		return false, nil
	}

	// If group meta is locked, wait until it's unlocked
	for groupMeta.Lock {
		groupMeta, _ = b.getGroupMeta(groupUUID)
		log.WARNING.Print("Group meta locked, waiting")
		time.Sleep(time.Millisecond * 5)
	}

	// Acquire lock
	if err = b.lockGroupMeta(groupUUID); err != nil {
		return false, err
	}
	defer b.unlockGroupMeta(groupUUID)

	// update group meta data
	err = b.chordTriggered(groupUUID)
	if err != nil {
		return false, err
	}
	return true, err
}
677436
func (c oauthClient) Webhook(webhookID uint) (wl.Webhook, error) {
	allWebhooks, err := c.Webhooks()
	for _, w := range allWebhooks {
		if w.ID == webhookID {
			return w, err
		}
	}

	return wl.Webhook{}, fmt.Errorf("webhook not found")
}
1003516
func (d *Daemon) TriggerPolicyUpdates(force bool, reason string) {
	if force {
		log.Debugf("Artifically increasing policy revision to enforce policy recalculation")
		d.policy.BumpRevision()
	}

	d.policyTrigger.TriggerWithReason(reason)
}
984996
func trigger(phase string, stack []plugin.Plugin, ctx *c.Context) *c.Context {
	var wg sync.WaitGroup
	wg.Add(1)

	// Finisher function
	done := func(_ctx *c.Context) {
		ctx = _ctx
		wg.Done()
	}

	i := len(stack)
	if i == 0 {
		wg.Done()
		return ctx
	}

	next := done
	for i > 0 {
		i--
		next = nextHandler(phase, stack[i], next, done)
	}

	// Exposes current middleware phase via context
	ctx.Set("$phase", phase)

	// Triggers the middleware call chain
	next(ctx)

	wg.Wait()
	return ctx
}
700232
func (w *eventWorker) emit(token string) {
	// set the token on the HTTPSink
	w.sink.AuthToken = token
	w.stats.EVBatchSizes.Add(float64(len(w.buffer)))
	// emit datapoints and handle any errors
	err := w.sink.AddEvents(context.Background(), w.buffer)
	w.handleError(err, token, w.buffer, w.sink.AddEvents)
	// account for the emitted datapoints
	atomic.AddInt64(&w.stats.TotalEventsBuffered, int64(len(w.buffer)*-1))
	w.buffer = w.buffer[:0]
}
124215
func (gs GlobalScope) Trigger(key int, data interface{}) error {
	if err := gs.EventScope.Trigger(key, data); err != nil {
		return err
	}
	for _, scope := range gs.scopes {
		if err := scope.Trigger(key, data); err != nil {
			return err
		}
	}
	return nil
}
829515
func (d *Datapath) triggerNegotiation(udpPacket *packet.Packet, context *pucontext.PUContext, conn *connection.UDPConnection) (err error) {

	udpOptions := packet.CreateUDPAuthMarker(packet.UDPSynMask)

	udpData, err := d.tokenAccessor.CreateSynPacketToken(context, &conn.Auth)
	if err != nil {
		return err
	}

	newPacket, err := d.clonePacketHeaders(udpPacket)
	if err != nil {
		return fmt.Errorf("Unable to clone packet: %s", err)
	}
	// Attach the UDP data and token
	newPacket.UDPTokenAttach(udpOptions, udpData)

	// send packet
	err = d.writeWithRetransmit(newPacket.GetBuffer(0), conn, conn.SynChannel())
	if err != nil {
		zap.L().Error("Unable to send syn token on raw socket", zap.Error(err))
		return fmt.Errorf("unable to transmit syn packet")
	}

	// Populate the caches to track the connection
	hash := udpPacket.L4FlowHash()
	d.udpAppOrigConnectionTracker.AddOrUpdate(hash, conn)
	d.udpSourcePortConnectionCache.AddOrUpdate(newPacket.SourcePortHash(packet.PacketTypeApplication), conn)
	d.udpNatConnectionTracker.AddOrUpdate(newPacket.SourcePortHash(packet.PacketTypeApplication), newPacket.SourcePortHash(packet.PacketTypeNetwork))

	return nil

}
671023
func (c *ApiController) TriggerGithubPushHook() {
	log.Info("Trigger github push hook")

	/*
		{
		  "zen": "Mind your words, they are important.",
		  "hook_id": 5371014,
		  "hook": {
			"url": "https://api.github.com/repos/ArchCI/success-test/hooks/5371014",
			"test_url": "https://api.github.com/repos/ArchCI/success-test/hooks/5371014/test",
			"ping_url": "https://api.github.com/repos/ArchCI/success-test/hooks/5371014/pings",
			"id": 5371014,
			"name": "web",
			"active": true,
			"events": [
			  "push"
			],
			"config": {
			  "url": "http://192.168.1.113:10010/v1/hook/github/push",
			  "content_type": "json",
			  "insecure_ssl": "0",
			  "secret": "********"
			},
			"last_response": {
			  "code": null,
			  "status": "unused",
			  "message": null
			},
			"updated_at": "2015-07-22T14:48:22Z",
			"created_at": "2015-07-22T14:48:22Z"
		  },
		  "repository": {
			"id": 39022734,
			"name": "success-test",
			"full_name": "ArchCI/success-test",
			"owner": {
			  "login": "ArchCI",
			  "id": 12673804,
			  "avatar_url": "https://avatars.githubusercontent.com/u/12673804?v=3",
			  "gravatar_id": "",
			  "url": "https://api.github.com/users/ArchCI",
			  "html_url": "https://github.com/ArchCI",
			  "followers_url": "https://api.github.com/users/ArchCI/followers",
			  "following_url": "https://api.github.com/users/ArchCI/following{/other_user}",
			  "gists_url": "https://api.github.com/users/ArchCI/gists{/gist_id}",
			  "starred_url": "https://api.github.com/users/ArchCI/starred{/owner}{/repo}",
			  "subscriptions_url": "https://api.github.com/users/ArchCI/subscriptions",
			  "organizations_url": "https://api.github.com/users/ArchCI/orgs",
			  "repos_url": "https://api.github.com/users/ArchCI/repos",
			  "events_url": "https://api.github.com/users/ArchCI/events{/privacy}",
			  "received_events_url": "https://api.github.com/users/ArchCI/received_events",
			  "type": "Organization",
			  "site_admin": false
			},
			"private": false,
			"html_url": "https://github.com/ArchCI/success-test",
			"description": "Success test project for ArchCI",
			"fork": false,
			"url": "https://api.github.com/repos/ArchCI/success-test",
			"forks_url": "https://api.github.com/repos/ArchCI/success-test/forks",
			"keys_url": "https://api.github.com/repos/ArchCI/success-test/keys{/key_id}",
			"collaborators_url": "https://api.github.com/repos/ArchCI/success-test/collaborators{/collaborator}",
			"teams_url": "https://api.github.com/repos/ArchCI/success-test/teams",
			"hooks_url": "https://api.github.com/repos/ArchCI/success-test/hooks",
			"issue_events_url": "https://api.github.com/repos/ArchCI/success-test/issues/events{/number}",
			"events_url": "https://api.github.com/repos/ArchCI/success-test/events",
			"assignees_url": "https://api.github.com/repos/ArchCI/success-test/assignees{/user}",
			"branches_url": "https://api.github.com/repos/ArchCI/success-test/branches{/branch}",
			"tags_url": "https://api.github.com/repos/ArchCI/success-test/tags",
			"blobs_url": "https://api.github.com/repos/ArchCI/success-test/git/blobs{/sha}",
			"git_tags_url": "https://api.github.com/repos/ArchCI/success-test/git/tags{/sha}",
			"git_refs_url": "https://api.github.com/repos/ArchCI/success-test/git/refs{/sha}",
			"trees_url": "https://api.github.com/repos/ArchCI/success-test/git/trees{/sha}",
			"statuses_url": "https://api.github.com/repos/ArchCI/success-test/statuses/{sha}",
			"languages_url": "https://api.github.com/repos/ArchCI/success-test/languages",
			"stargazers_url": "https://api.github.com/repos/ArchCI/success-test/stargazers",
			"contributors_url": "https://api.github.com/repos/ArchCI/success-test/contributors",
			"subscribers_url": "https://api.github.com/repos/ArchCI/success-test/subscribers",
			"subscription_url": "https://api.github.com/repos/ArchCI/success-test/subscription",
			"commits_url": "https://api.github.com/repos/ArchCI/success-test/commits{/sha}",
			"git_commits_url": "https://api.github.com/repos/ArchCI/success-test/git/commits{/sha}",
			"comments_url": "https://api.github.com/repos/ArchCI/success-test/comments{/number}",
			"issue_comment_url": "https://api.github.com/repos/ArchCI/success-test/issues/comments{/number}",
			"contents_url": "https://api.github.com/repos/ArchCI/success-test/contents/{+path}",
			"compare_url": "https://api.github.com/repos/ArchCI/success-test/compare/{base}...{head}",
			"merges_url": "https://api.github.com/repos/ArchCI/success-test/merges",
			"archive_url": "https://api.github.com/repos/ArchCI/success-test/{archive_format}{/ref}",
			"downloads_url": "https://api.github.com/repos/ArchCI/success-test/downloads",
			"issues_url": "https://api.github.com/repos/ArchCI/success-test/issues{/number}",
			"pulls_url": "https://api.github.com/repos/ArchCI/success-test/pulls{/number}",
			"milestones_url": "https://api.github.com/repos/ArchCI/success-test/milestones{/number}",
			"notifications_url": "https://api.github.com/repos/ArchCI/success-test/notifications{?since,all,participating}",
			"labels_url": "https://api.github.com/repos/ArchCI/success-test/labels{/name}",
			"releases_url": "https://api.github.com/repos/ArchCI/success-test/releases{/id}",
			"created_at": "2015-07-13T16:06:28Z",
			"updated_at": "2015-07-22T02:12:02Z",
			"pushed_at": "2015-07-22T02:12:02Z",
			"git_url": "git://github.com/ArchCI/success-test.git",
			"ssh_url": "git@github.com:ArchCI/success-test.git",
			"clone_url": "https://github.com/ArchCI/success-test.git",
			"svn_url": "https://github.com/ArchCI/success-test",
			"homepage": null,
			"size": 120,
			"stargazers_count": 0,
			"watchers_count": 0,
			"language": "Go",
			"has_issues": true,
			"has_downloads": true,
			"has_wiki": true,
			"has_pages": false,
			"forks_count": 0,
			"mirror_url": null,
			"open_issues_count": 0,
			"forks": 0,
			"open_issues": 0,
			"watchers": 0,
			"default_branch": "master"
		  },
		  "sender": {
			"login": "tobegit3hub",
			"id": 2715000,
			"avatar_url": "https://avatars.githubusercontent.com/u/2715000?v=3",
			"gravatar_id": "",
			"url": "https://api.github.com/users/tobegit3hub",
			"html_url": "https://github.com/tobegit3hub",
			"followers_url": "https://api.github.com/users/tobegit3hub/followers",
			"following_url": "https://api.github.com/users/tobegit3hub/following{/other_user}",
			"gists_url": "https://api.github.com/users/tobegit3hub/gists{/gist_id}",
			"starred_url": "https://api.github.com/users/tobegit3hub/starred{/owner}{/repo}",
			"subscriptions_url": "https://api.github.com/users/tobegit3hub/subscriptions",
			"organizations_url": "https://api.github.com/users/tobegit3hub/orgs",
			"repos_url": "https://api.github.com/users/tobegit3hub/repos",
			"events_url": "https://api.github.com/users/tobegit3hub/events{/privacy}",
			"received_events_url": "https://api.github.com/users/tobegit3hub/received_events",
			"type": "User",
			"site_admin": false
		  }
		}
	*/

	hook := githubutil.GithubPushHook{}

	if err := json.Unmarshal(c.Ctx.Input.RequestBody, &hook); err != nil {
		c.Ctx.Output.SetStatus(400)
		c.Ctx.Output.Body([]byte("empty title"))
		fmt.Println(err)
	}

	projectId, _ := models.ReadOrCreateProject(hook.Repository.Owner.Login, hook.Repository.Name, hook.Repository.URL)

	models.AddGithubBuild(projectId, hook)

	return

}
1196216
func (o *TriggersOptions) updateTriggers(triggers *TriggerDefinition) {
	// clear everything
	if o.RemoveAll {
		*triggers = TriggerDefinition{}
		return
	}

	// clear a specific field
	if o.Remove {
		if o.FromConfig {
			triggers.ConfigChange = false
		}
		if len(o.FromImage) > 0 {
			var newTriggers []ImageChangeTrigger
			for _, trigger := range triggers.ImageChange {
				if trigger.From != o.FromImage {
					newTriggers = append(newTriggers, trigger)
				}
			}
			triggers.ImageChange = newTriggers
		}
		if o.FromWebHook != nil && *o.FromWebHook {
			triggers.GenericWebHooks = nil
		}
		if o.FromWebHookAllowEnv != nil && *o.FromWebHookAllowEnv {
			triggers.GenericWebHooks = nil
		}
		if o.FromGitHub != nil && *o.FromGitHub {
			triggers.GitHubWebHooks = nil
		}
		if o.FromGitLab != nil && *o.FromGitLab {
			triggers.GitLabWebHooks = nil
		}
		if o.FromBitbucket != nil && *o.FromBitbucket {
			triggers.BitbucketWebHooks = nil
		}
		return
	}

	// change the automated status
	if o.Reset {
		triggers.ConfigChange = o.Auto
		for i := range triggers.ImageChange {
			triggers.ImageChange[i].Auto = o.Auto
		}
		return
	}

	// change individual elements
	if o.FromConfig {
		triggers.ConfigChange = true
	}
	if len(o.FromImage) > 0 {
		names := strings.Split(o.ContainerNames, ",")
		if len(o.ContainerNames) == 0 {
			names = nil
		}
		found := false
		for i, trigger := range triggers.ImageChange {
			if trigger.From == o.FromImage && trigger.Namespace == o.FromImageNamespace {
				found = true
				triggers.ImageChange[i].Auto = !o.Manual
				triggers.ImageChange[i].Names = names
				break
			}
		}
		if !found {
			triggers.ImageChange = append(triggers.ImageChange, ImageChangeTrigger{
				From:      o.FromImage,
				Namespace: o.FromImageNamespace,
				Auto:      !o.Manual,
				Names:     names,
			})
		}
	}
	if o.FromWebHook != nil && *o.FromWebHook {
		secret := app.GenerateSecret(20)
		triggers.GenericWebHooks = append(triggers.GenericWebHooks,
			buildv1.WebHookTrigger{
				Secret:   secret,
				AllowEnv: false,
			},
		)
	}
	if o.FromWebHookAllowEnv != nil && *o.FromWebHookAllowEnv {
		secret := app.GenerateSecret(20)
		triggers.GenericWebHooks = append(triggers.GenericWebHooks,
			buildv1.WebHookTrigger{
				Secret:   secret,
				AllowEnv: true,
			},
		)
	}
	if o.FromGitHub != nil && *o.FromGitHub {
		secret := app.GenerateSecret(20)
		triggers.GitHubWebHooks = append(triggers.GitHubWebHooks,
			buildv1.WebHookTrigger{
				Secret: secret,
			},
		)
	}
	if o.FromGitLab != nil && *o.FromGitLab {
		secret := app.GenerateSecret(20)
		triggers.GitLabWebHooks = append(triggers.GitLabWebHooks,
			buildv1.WebHookTrigger{
				Secret: secret,
			},
		)
	}
	if o.FromBitbucket != nil && *o.FromBitbucket {
		secret := app.GenerateSecret(20)
		triggers.BitbucketWebHooks = append(triggers.BitbucketWebHooks,
			buildv1.WebHookTrigger{
				Secret: secret,
			},
		)
	}
}
173123
func NewHookForLevels(token string, env string, levels []logrus.Level) *Hook {
	return &Hook{
		Client:          roll.New(token, env),
		triggers:        levels,
		ignoredErrors:   make([]error, 0),
		ignoreErrorFunc: func(error) bool { return false },
		ignoreFunc:      func(error, map[string]string) bool { return false },
	}
}