// extendReviewRequest is a general function that can be used to extend
// the given review issue with the given list of commits.
323705
func extendReviewRequest(
	config *moduleConfig,
	owner string,
	repo string,
	issue *github.Issue,
	commits []*git.Commit,
	opts map[string]interface{},
) (*github.Issue, []*git.Commit, error) {

	issueNum := *issue.Number

	// Parse the issue.
	task := fmt.Sprintf("Parse review issue #%v", issueNum)
	reviewIssue, err := ghissues.ParseReviewIssue(issue)
	if err != nil {
		return nil, nil, errs.NewError(task, err)
	}

	// Add the commits.
	newCommits := make([]*git.Commit, 0, len(commits))
	for _, commit := range commits {
		if reviewIssue.AddCommit(false, commit.SHA, commit.MessageTitle) {
			newCommits = append(newCommits, commit)
		}
	}
	if len(newCommits) == 0 {
		log.Log(fmt.Sprintf("All commits already listed in issue #%v", issueNum))
		return issue, nil, nil
	}

	// Add the implemented label if necessary.
	var (
		implemented      bool
		implementedLabel = config.StoryImplementedLabel
		labelsPtr        *[]string
	)
	implementedOpt, ok := opts["implemented"]
	if ok {
		implemented = implementedOpt.(bool)
	}
	if implemented {
		labels := make([]string, 0, len(issue.Labels)+1)
		labelsPtr = &labels

		for _, label := range issue.Labels {
			if *label.Name == implementedLabel {
				// The label is already there, for some reason.
				// Set the pointer to nil so that we don't update labels.
				labelsPtr = nil
				break
			}
			labels = append(labels, *label.Name)
		}
		if labelsPtr != nil {
			labels = append(labels, implementedLabel)
		}
	}

	// Edit the issue.
	task = fmt.Sprintf("Update GitHub issue #%v", issueNum)
	log.Run(task)

	client := ghutil.NewClient(config.Token)
	updatedIssue, _, err := client.Issues.Edit(owner, repo, issueNum, &github.IssueRequest{
		Body:   github.String(reviewIssue.FormatBody()),
		State:  github.String("open"),
		Labels: labelsPtr,
	})
	if err != nil {
		return nil, nil, errs.NewError(task, err)
	}

	// Add the review comment.
	if err := addReviewComment(config, owner, repo, issueNum, newCommits); err != nil {
		return nil, nil, err
	}

	return updatedIssue, newCommits, nil
}
132757
func (m *MockGerritServer) SetReview(arg0 context.Context, arg1 *SetReviewRequest) (*ReviewResult, error) {
	m.ctrl.T.Helper()
	ret := m.ctrl.Call(m, "SetReview", arg0, arg1)
	ret0, _ := ret[0].(*ReviewResult)
	ret1, _ := ret[1].(error)
	return ret0, ret1
}
474336
func (db *BytesConnectionEtcd) GetRevision() (revision int64, err error) {
	return getRevisionInternal(db.Logger, db.etcdClient, db.opTimeout)
}
412869
func (c *Files) ListRevisions(in *ListRevisionsInput) (out *ListRevisionsOutput, err error) {
	body, err := c.call("/files/list_revisions", in)
	if err != nil {
		return
	}
	defer body.Close()

	err = json.NewDecoder(body).Decode(&out)
	return
}
677322
func (th *TlfHistory) FlushRevision(rev kbfsmd.Revision) {
	th.lock.Lock()
	defer th.lock.Unlock()
	if th.unflushed == nil {
		return
	}
	lastToKeep := len(th.unflushed.notifications) - 1
	for ; lastToKeep >= 0; lastToKeep-- {
		if th.unflushed.notifications[lastToKeep].Revision > rev {
			break
		}
	}
	if lastToKeep < len(th.unflushed.notifications)-1 {
		th.unflushed.notifications = th.unflushed.notifications[:lastToKeep+1]
		// Invalidate the cached results.
		th.computed = false
		th.cachedLoggedInUser = ""
	}
}
634731
func (s *ReviewReport) SetReviewActions(v []*ReviewActionDetail) *ReviewReport {
	s.ReviewActions = v
	return s
}
1286582
func (s *RepositoriesService) GetPullRequestReviewEnforcement(ctx context.Context, owner, repo, branch string) (*PullRequestReviewsEnforcement, *Response, error) {
	u := fmt.Sprintf("repos/%v/%v/branches/%v/protection/required_pull_request_reviews", owner, repo, branch)
	req, err := s.client.NewRequest("GET", u, nil)
	if err != nil {
		return nil, nil, err
	}

	// TODO: remove custom Accept header when this API fully launches
	req.Header.Set("Accept", mediaTypeRequiredApprovingReviewsPreview)

	r := new(PullRequestReviewsEnforcement)
	resp, err := s.client.Do(ctx, req, r)
	if err != nil {
		return nil, resp, err
	}

	return r, resp, nil
}
816538
func (s *ChangesService) PublishDraftRevision(changeID, revisionID string) (*Response, error) {
	u := fmt.Sprintf("changes/%s/revisions/%s/publish", changeID, revisionID)

	req, err := s.client.NewRequest("POST", u, nil)
	if err != nil {
		return nil, err
	}

	return s.client.Do(req, nil)
}
1330253
func FindReviewIssueByCommitItem(
	client *github.Client,
	owner string,
	repo string,
	commitSHA string,
) (*github.Issue, error) {

	// Use the first 7 chars from the commit hexsha.
	shortSHA := commitSHA[:7]

	// Commit item regexp.
	re := regexp.MustCompile(fmt.Sprintf(`[-*] \[[xX ]\] %v[:]`, shortSHA))

	// Perform the search.
	return findReviewIssue(client, owner, repo, shortSHA, "in:body", matchesBodyRe(re))
}
1039451
func (o *FilterProcessScanner) readRequest() (*Request, error) {
	requestList, err := o.pl.readPacketList()
	if err != nil {
		return nil, err
	}

	req := &Request{
		Header:  make(map[string]string),
		Payload: &pktlineReader{pl: o.pl},
	}

	for _, pair := range requestList {
		v := strings.SplitN(pair, "=", 2)
		req.Header[v[0]] = v[1]
	}

	return req, nil
}
898918
func NewApprovalRequest(response *http.Response) (*ApprovalRequest, error) {
	body, err := ioutil.ReadAll(response.Body)
	if err != nil {
		return nil, err
	}

	jsonResponse := struct {
		Success         bool             `json:"success"`
		ApprovalRequest *ApprovalRequest `json:"approval_request"`
		Message         string           `json:"message"`
	}{}

	err = json.Unmarshal(body, &jsonResponse)
	if err != nil {
		return nil, err
	}

	if !jsonResponse.Success {
		return nil, fmt.Errorf("invalid approval request response: %s", jsonResponse.Message)
	}
	approvalRequest := jsonResponse.ApprovalRequest
	approvalRequest.HTTPResponse = response

	return approvalRequest, nil
}
932927
func (limit ResourceLimit) ListRequest() (ListCommand, error) {
	req := &ListResourceLimits{
		ResourceType:     limit.ResourceType,
		ResourceTypeName: limit.ResourceTypeName,
	}

	return req, nil
}
939603
func (rt *upgradeRequestRoundTripper) WrapRequest(req *http.Request) (*http.Request, error) {
	resp, err := rt.upgrader.RoundTrip(req)
	if err != nil {
		return nil, err
	}
	return resp.Request, nil
}
758561
func (veq *visibilityExtenderQueue) extendBatch(msgs []*sqs.Message) ([]*sqs.Message, error) {
	if len(msgs) == 0 {
		return nil, nil
	}

	var entries []*sqs.ChangeMessageVisibilityBatchRequestEntry
	for _, m := range msgs {
		veq.svc.Logger("Extending visibility timeout for message %s", aws.StringValue(m.MessageId))
		entries = append(entries, &sqs.ChangeMessageVisibilityBatchRequestEntry{
			Id:                m.MessageId,
			ReceiptHandle:     m.ReceiptHandle,
			VisibilityTimeout: aws.Int64(veq.extensionSecs),
		})
	}

	p := &sqs.ChangeMessageVisibilityBatchInput{
		QueueUrl: veq.svc.URL,
		Entries:  entries,
	}
	resp, err := veq.svc.Svc.ChangeMessageVisibilityBatch(p)
	if err != nil {
		return msgs, err
	}

	var failed []*sqs.Message
	for _, f := range resp.Failed {
		for _, m := range msgs {
			if *m.MessageId == *f.Id {
				failed = append(failed, m)
				break
			}
		}
	}
	return failed, nil
}
162288
func (m *MockGerritClient) SetReview(ctx context.Context, in *SetReviewRequest, opts ...grpc.CallOption) (*ReviewResult, error) {
	m.ctrl.T.Helper()
	varargs := []interface{}{ctx, in}
	for _, a := range opts {
		varargs = append(varargs, a)
	}
	ret := m.ctrl.Call(m, "SetReview", varargs...)
	ret0, _ := ret[0].(*ReviewResult)
	ret1, _ := ret[1].(error)
	return ret0, ret1
}
1230761
func (a *auditLogFile) AddRequest(m Request) error {
	return errors.Trace(a.addRecord(Record{Request: &m}))

}
945663
func (p *PullRequest) GetReviewComments() int {
	if p == nil || p.ReviewComments == nil {
		return 0
	}
	return *p.ReviewComments
}