// searchIssues can be used to query GitHub for issues matching the given filter.
// It handles pagination internally, it fetches all matching issues automatically.
189351
func (tracker *issueTracker) searchIssues(
	queryFormat string,
	v ...interface{},
) ([]*github.Issue, error) {

	logger := log.V(log.Debug)

	// Format the query.
	query := fmt.Sprintf(queryFormat, v...)

	// Since GH API does not allow OR queries, we need to send a concurrent request
	// for every item in tracker.config.StoryLabels label list.
	ch := make(chan *searchResult, len(tracker.config.StoryLabels))
	for _, label := range tracker.config.StoryLabels {
		go func(label string) {
			// We are only interested in issues for the given repository.
			innerQuery := fmt.Sprintf(`%v type:issue repo:%v/%v label:"%v"`,
				query, tracker.config.GitHubOwner, tracker.config.GitHubRepository, label)

			task := "Search GitHub: " + innerQuery

			if logger {
				logger.Go(task)
			}

			searchOpts := &github.SearchOptions{}
			searchOpts.Page = 1
			searchOpts.PerPage = 50

			var (
				acc      []*github.Issue
				searched int
			)

			client := tracker.newClient()

			for {
				// Fetch another page.
				var (
					result *github.IssuesSearchResult
					err    error
				)
				withRequestAllocated(func() {
					result, _, err = client.Search.Issues(innerQuery, searchOpts)
				})
				if err != nil {
					ch <- &searchResult{nil, errs.NewError(task, err)}
					return
				}

				// Check the issues for exact string match.
				for i := range result.Issues {
					acc = append(acc, &result.Issues[i])
				}

				// Check whether we have reached the end or not.
				searched += len(result.Issues)
				if searched == *result.Total {
					ch <- &searchResult{acc, nil}
					return
				}

				// Check the next page in the next iteration.
				searchOpts.Page += 1
			}
		}(label)
	}

	// Collect the results.
	var issues []*github.Issue
	for i := 0; i < cap(ch); i++ {
		res := <-ch
		if err := res.err; err != nil {
			return nil, err
		}
		issues = append(issues, res.issues...)
	}

	// Make sure there are no duplicates in the list.
	return dedupeIssues(issues), nil
}
121329
func (i *IssueComment) GetIssueURL() string {
	if i == nil || i.IssueURL == nil {
		return ""
	}
	return *i.IssueURL
}
371992
func Issues(opts *IssuesOptions) ([]*Issue, error) {
	sess := buildIssuesQuery(opts)
	if sess == nil {
		return make([]*Issue, 0), nil
	}

	sess.Limit(setting.UI.IssuePagingNum, (opts.Page-1)*setting.UI.IssuePagingNum)

	issues := make([]*Issue, 0, setting.UI.IssuePagingNum)
	if err := sess.Find(&issues); err != nil {
		return nil, fmt.Errorf("Find: %v", err)
	}

	// FIXME: use IssueList to improve performance.
	for i := range issues {
		if err := issues[i].LoadAttributes(); err != nil {
			return nil, fmt.Errorf("LoadAttributes [%d]: %v", issues[i].ID, err)
		}
	}

	return issues, nil
}
1285105
func (s *UserService) Search(query string, params *UserSearchParams) ([]User, *http.Response, error) {
	if params == nil {
		params = &UserSearchParams{}
	}
	params.Query = query
	users := new([]User)
	apiError := new(APIError)
	resp, err := s.sling.New().Get("search.json").QueryStruct(params).Receive(users, apiError)
	return *users, resp, relevantError(err, *apiError)
}
345246
func (c *Verification) Search(m *VerifySearchRequest) (*VerifySearchResponse, error) {
	var verifySearchResponse *VerifySearchResponse

	if !c.client.useOauth {
		m.apiKey = c.client.apiKey
		m.apiSecret = c.client.apiSecret
	}

	var r *http.Request
	buf, err := json.Marshal(m)
	if err != nil {
		return nil, errors.New("invalid message struct - unable to convert to JSON")
	}

	b := bytes.NewBuffer(buf)
	r, err = http.NewRequest("POST", apiRootv2+"/verify/search/json", b)
	if err != nil {
		return nil, err
	}

	r.Header.Add("Accept", "application/json")
	r.Header.Add("Content-Type", "application/json")

	resp, err := c.client.HTTPClient.Do(r)
	if err != nil {
		return nil, err
	}

	defer resp.Body.Close()
	body, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		return nil, err
	}

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

	return verifySearchResponse, nil
}
316757
func (c *Client) UidSearch(criteria *imap.SearchCriteria) (uids []uint32, err error) {
	return c.search(true, criteria)
}
226157
func (r MissingImageSearcher) Search(precise bool, terms ...string) (ComponentMatches, []error) {
	componentMatches := ComponentMatches{}
	for _, term := range terms {
		componentMatches = append(componentMatches, &ComponentMatch{
			Value:     term,
			Score:     0.0,
			LocalOnly: true,
		})
		klog.V(4).Infof("Added missing image match for %v", term)
	}
	return componentMatches, nil
}
917690
func (p *PUContext) searchRules(
	policies *policies,
	tags *policy.TagStore,
	skipRejectPolicies bool,
) (report *policy.FlowPolicy, packet *policy.FlowPolicy) {

	var reportingAction *policy.FlowPolicy
	var packetAction *policy.FlowPolicy

	if !skipRejectPolicies {
		// Look for rejection rules
		observeIndex, observeAction := policies.observeRejectRules.Search(tags)
		if observeIndex >= 0 {
			reportingAction = observeAction.(*policy.FlowPolicy)
		}

		index, action := policies.rejectRules.Search(tags)
		if index >= 0 {
			packetAction = action.(*policy.FlowPolicy)
			if reportingAction == nil {
				reportingAction = packetAction
			}
			return reportingAction, packetAction
		}
	}

	if reportingAction == nil {
		// Look for allow rules
		observeIndex, observeAction := policies.observeAcceptRules.Search(tags)
		if observeIndex >= 0 {
			reportingAction = observeAction.(*policy.FlowPolicy)
		}
	}

	index, action := policies.acceptRules.Search(tags)
	if index >= 0 {
		packetAction = action.(*policy.FlowPolicy)
		// Look for encrypt rules
		encryptIndex, _ := policies.encryptRules.Search(tags)
		if encryptIndex >= 0 {
			// Do not overwrite the action for accept rules.
			finalAction := action.(*policy.FlowPolicy)
			packetAction = &policy.FlowPolicy{
				Action:    policy.Accept | policy.Encrypt,
				PolicyID:  finalAction.PolicyID,
				ServiceID: finalAction.ServiceID,
			}
		}
		if reportingAction == nil {
			reportingAction = packetAction
		}
		return reportingAction, packetAction
	}

	// Look for observe apply rules
	observeIndex, observeAction := policies.observeApplyRules.Search(tags)
	if observeIndex >= 0 {
		packetAction = observeAction.(*policy.FlowPolicy)
		if reportingAction == nil {
			reportingAction = packetAction
		}
		return reportingAction, packetAction
	}

	// Handle default if nothing provides to drop with no policyID.
	packetAction = &policy.FlowPolicy{
		Action:   policy.Reject,
		PolicyID: "default",
	}

	if reportingAction == nil {
		reportingAction = packetAction
	}

	return reportingAction, packetAction
}
161859
func (s *UpgradeStepItem) SetIssues(v []*string) *UpgradeStepItem {
	s.Issues = v
	return s
}
245609
func (f *Filter) checkMatches(ctx context.Context, header *types.Header) (logs []*types.Log, err error) {
	// Get the logs of the block
	logsList, err := f.backend.GetLogs(ctx, header.Hash())
	if err != nil {
		return nil, err
	}
	var unfiltered []*types.Log
	for _, logs := range logsList {
		unfiltered = append(unfiltered, logs...)
	}
	logs = filterLogs(unfiltered, nil, nil, f.addresses, f.topics)
	if len(logs) > 0 {
		// We have matching logs, check if we need to resolve full logs via the light client
		if logs[0].TxHash == (common.Hash{}) {
			receipts, err := f.backend.GetReceipts(ctx, header.Hash())
			if err != nil {
				return nil, err
			}
			unfiltered = unfiltered[:0]
			for _, receipt := range receipts {
				unfiltered = append(unfiltered, receipt.Logs...)
			}
			logs = filterLogs(unfiltered, nil, nil, f.addresses, f.topics)
		}
		return logs, nil
	}
	return nil, nil
}
422498
func GetIssueByIndex(repoID, index int64) (*Issue, error) {
	issue, err := GetRawIssueByIndex(repoID, index)
	if err != nil {
		return nil, err
	}
	return issue, issue.LoadAttributes()
}
732672
func (i *InstallationPermissions) GetIssues() string {
	if i == nil || i.Issues == nil {
		return ""
	}
	return *i.Issues
}
383289
func (i *indexImpl) Search(req *SearchRequest) (sr *SearchResult, err error) {
	return i.SearchInContext(context.Background(), req)
}
96759
func NewSearchResult(Matches []*SearchMatch, More bool, Start uint64) *SearchResult {
	s := new(SearchResult)
	s.Matches = Matches
	s.More = More
	s.Start = Start
	return s
}
1001579
func (s *Session) Search(query string, opts *SearchOptions) (*Search, error) {
	return newSearch(s, query, opts)
}
138748
func (r *Report) GetAllIssues() []*issue.Issue {
	var issues []*issue.Issue
	switch r.Type {
	case TypeMulti:
		for _, subReport := range r.Multi {
			issues = append(issues, subReport.GetAllIssues()...)
		}
	case TypeIssues:
		issues = append(issues, r.Issues...)
	}
	return issues
}
158171
func (s *IssuesService) ListIssueEvents(ctx context.Context, owner, repo string, number int, opt *ListOptions) ([]*IssueEvent, *Response, error) {
	u := fmt.Sprintf("repos/%v/%v/issues/%v/events", owner, repo, number)
	u, err := addOptions(u, opt)
	if err != nil {
		return nil, nil, err
	}

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

	acceptHeaders := []string{mediaTypeLockReasonPreview, mediaTypeProjectCardDetailsPreview}
	req.Header.Set("Accept", strings.Join(acceptHeaders, ", "))

	var events []*IssueEvent
	resp, err := s.client.Do(ctx, req, &events)
	if err != nil {
		return nil, resp, err
	}

	return events, resp, nil
}