// GetIssueByIndex returns issue by index in a repository.
422498
func GetIssueByIndex(repoID, index int64) (*Issue, error) {
	issue, err := GetRawIssueByIndex(repoID, index)
	if err != nil {
		return nil, err
	}
	return issue, issue.LoadAttributes()
}
1137054
func (e *Entry) GetIndex(key string) int {
	for i := range e.Values {
		if e.Values[i].Key == key {
			return i
		}
	}
	return -1
}
564659
func GetIssueUserPairsByRepoIds(rids []int64, isClosed bool, page int) ([]*IssueUser, error) {
	if len(rids) == 0 {
		return []*IssueUser{}, nil
	}

	ius := make([]*IssueUser, 0, 10)
	sess := x.Limit(20, (page-1)*20).Where("is_closed=?", isClosed).In("repo_id", rids)
	err := sess.Find(&ius)
	return ius, err
}
83208
func GetRepoIssueStats(repoID, userID int64, filterMode FilterMode, isPull bool) (numOpen int64, numClosed int64) {
	countSession := func(isClosed, isPull bool, repoID int64) *xorm.Session {
		sess := x.Where("issue.repo_id = ?", isClosed).
			And("is_pull = ?", isPull).
			And("repo_id = ?", repoID)

		return sess
	}

	openCountSession := countSession(false, isPull, repoID)
	closedCountSession := countSession(true, isPull, repoID)

	switch filterMode {
	case FILTER_MODE_ASSIGN:
		openCountSession.And("assignee_id = ?", userID)
		closedCountSession.And("assignee_id = ?", userID)
	case FILTER_MODE_CREATE:
		openCountSession.And("poster_id = ?", userID)
		closedCountSession.And("poster_id = ?", userID)
	}

	openResult, _ := openCountSession.Count(new(Issue))
	closedResult, _ := closedCountSession.Count(new(Issue))

	return openResult, closedResult
}
426025
func (p *PullRequest) GetIssueURL() string {
	if p == nil || p.IssueURL == nil {
		return ""
	}
	return *p.IssueURL
}
607117
func (r *Repository) GetHasIssues() bool {
	if r == nil || r.HasIssues == nil {
		return false
	}
	return *r.HasIssues
}
908627
func getIndex(pk crypto.PubKey, keys []crypto.PubKey) int {
	for i := 0; i < len(keys); i++ {
		if pk.Equals(keys[i]) {
			return i
		}
	}
	return -1
}
630401
func (c *VPCRouterDHCPServerConfig) InterfaceIndex() int {
	strIndex := strings.Replace(c.Interface, "eth", "", -1)
	index, err := strconv.Atoi(strIndex)
	if err != nil {
		return -1
	}
	return index
}
961080
func (r *raftLog) getIndex(first bool) (uint64, error) {
	tx, err := r.conn.Begin(false)
	if err != nil {
		return 0, err
	}
	var (
		key []byte
		idx uint64
	)
	curs := tx.Bucket(logsBucket).Cursor()
	if first {
		key, _ = curs.First()
	} else {
		key, _ = curs.Last()
	}
	if key != nil {
		idx = binary.BigEndian.Uint64(key)
	}
	tx.Rollback()
	return idx, nil
}
1102185
func (s *IndicesExistsService) Index(index []string) *IndicesExistsService {
	s.index = index
	return s
}
365848
func (t Term) GetAllByIndex(index interface{}, keys ...interface{}) Term {
	return constructMethodTerm(t, "GetAll", p.Term_GET_ALL, keys, map[string]interface{}{"index": index})
}
741968
func (bridge *Bridge) GetLightByIndex(index int) (Light, error) {
	// Send an http GET and inspect the response
	uri := fmt.Sprintf("/api/%s/lights/%d", bridge.Username, index)
	body, _, err := bridge.Get(uri)
	if err != nil {
		return Light{}, err
	}
	if strings.Contains(string(body), "not available") {
		return Light{}, errors.New("Error: Light selection index out of bounds. ")
	}

	// Parse and load the response into the light array
	light := Light{}
	err = json.Unmarshal(body, &light)
	if err != nil {
		return Light{}, errors.New("Error: Unable to unmarshal light data. ")
	}
	light.Index = index
	light.Bridge = bridge
	return light, nil
}
272419
func GetIndexName(dockerURL string) string {
	index, _ := docker.SplitReposName(dockerURL)
	return index
}
48288
func (lrs LinearRegressionSeries) GetEndIndex() int {
	windowEnd := lrs.GetOffset() + lrs.GetLimit()
	innerSeriesLastIndex := lrs.InnerSeries.Len() - 1
	return util.Math.MinInt(windowEnd, innerSeriesLastIndex)
}
371750
func GetAssigneeByID(repo *Repository, userID int64) (*User, error) {
	has, err := HasAccess(userID, repo, ACCESS_MODE_READ)
	if err != nil {
		return nil, err
	} else if !has {
		return nil, errors.UserNotExist{userID, ""}
	}
	return GetUserByID(userID)
}
244497
func GetIssueStats(opts *IssueStatsOptions) *IssueStats {
	stats := &IssueStats{}

	countSession := func(opts *IssueStatsOptions) *xorm.Session {
		sess := x.Where("issue.repo_id = ?", opts.RepoID).And("is_pull = ?", opts.IsPull)

		if len(opts.Labels) > 0 && opts.Labels != "0" {
			labelIDs := tool.StringsToInt64s(strings.Split(opts.Labels, ","))
			if len(labelIDs) > 0 {
				sess.Join("INNER", "issue_label", "issue.id = issue_id").In("label_id", labelIDs)
			}
		}

		if opts.MilestoneID > 0 {
			sess.And("issue.milestone_id = ?", opts.MilestoneID)
		}

		if opts.AssigneeID > 0 {
			sess.And("assignee_id = ?", opts.AssigneeID)
		}

		return sess
	}

	switch opts.FilterMode {
	case FILTER_MODE_YOUR_REPOS, FILTER_MODE_ASSIGN:
		stats.OpenCount, _ = countSession(opts).
			And("is_closed = ?", false).
			Count(new(Issue))

		stats.ClosedCount, _ = countSession(opts).
			And("is_closed = ?", true).
			Count(new(Issue))
	case FILTER_MODE_CREATE:
		stats.OpenCount, _ = countSession(opts).
			And("poster_id = ?", opts.UserID).
			And("is_closed = ?", false).
			Count(new(Issue))

		stats.ClosedCount, _ = countSession(opts).
			And("poster_id = ?", opts.UserID).
			And("is_closed = ?", true).
			Count(new(Issue))
	case FILTER_MODE_MENTION:
		stats.OpenCount, _ = countSession(opts).
			Join("INNER", "issue_user", "issue.id = issue_user.issue_id").
			And("issue_user.uid = ?", opts.UserID).
			And("issue_user.is_mentioned = ?", true).
			And("issue.is_closed = ?", false).
			Count(new(Issue))

		stats.ClosedCount, _ = countSession(opts).
			Join("INNER", "issue_user", "issue.id = issue_user.issue_id").
			And("issue_user.uid = ?", opts.UserID).
			And("issue_user.is_mentioned = ?", true).
			And("issue.is_closed = ?", true).
			Count(new(Issue))
	}
	return stats
}
830987
func (v *Repository) CheckoutIndex(index *Index, opts *CheckoutOpts) error {
	var iptr *C.git_index = nil
	if index != nil {
		iptr = index.ptr
	}

	runtime.LockOSThread()
	defer runtime.UnlockOSThread()

	cOpts := opts.toC()
	defer freeCheckoutOpts(cOpts)

	ret := C.git_checkout_index(v.ptr, iptr, cOpts)
	runtime.KeepAlive(v)
	if ret < 0 {
		return MakeGitError(ret)
	}

	return nil
}