// Copyright 2017 The Gitea Authors. All rights reserved. // Use of this source code is governed by a MIT-style // license that can be found in the LICENSE file. package models import ( "fmt" "sort" "time" "code.gitea.io/gitea/models/db" "code.gitea.io/gitea/modules/git" "xorm.io/xorm" ) // ActivityAuthorData represents statistical git commit count data type ActivityAuthorData struct { Name string `json:"name"` Login string `json:"login"` AvatarLink string `json:"avatar_link"` HomeLink string `json:"home_link"` Commits int64 `json:"commits"` } // ActivityStats represets issue and pull request information. type ActivityStats struct { OpenedPRs PullRequestList OpenedPRAuthorCount int64 MergedPRs PullRequestList MergedPRAuthorCount int64 OpenedIssues IssueList OpenedIssueAuthorCount int64 ClosedIssues IssueList ClosedIssueAuthorCount int64 UnresolvedIssues IssueList PublishedReleases []*Release PublishedReleaseAuthorCount int64 Code *git.CodeActivityStats } // GetActivityStats return stats for repository at given time range func GetActivityStats(repo *Repository, timeFrom time.Time, releases, issues, prs, code bool) (*ActivityStats, error) { stats := &ActivityStats{Code: &git.CodeActivityStats{}} if releases { if err := stats.FillReleases(repo.ID, timeFrom); err != nil { return nil, fmt.Errorf("FillReleases: %v", err) } } if prs { if err := stats.FillPullRequests(repo.ID, timeFrom); err != nil { return nil, fmt.Errorf("FillPullRequests: %v", err) } } if issues { if err := stats.FillIssues(repo.ID, timeFrom); err != nil { return nil, fmt.Errorf("FillIssues: %v", err) } } if err := stats.FillUnresolvedIssues(repo.ID, timeFrom, issues, prs); err != nil { return nil, fmt.Errorf("FillUnresolvedIssues: %v", err) } if code { gitRepo, err := git.OpenRepository(repo.RepoPath()) if err != nil { return nil, fmt.Errorf("OpenRepository: %v", err) } defer gitRepo.Close() code, err := gitRepo.GetCodeActivityStats(timeFrom, repo.DefaultBranch) if err != nil { return nil, fmt.Errorf("FillFromGit: %v", err) } stats.Code = code } return stats, nil } // GetActivityStatsTopAuthors returns top author stats for git commits for all branches func GetActivityStatsTopAuthors(repo *Repository, timeFrom time.Time, count int) ([]*ActivityAuthorData, error) { gitRepo, err := git.OpenRepository(repo.RepoPath()) if err != nil { return nil, fmt.Errorf("OpenRepository: %v", err) } defer gitRepo.Close() code, err := gitRepo.GetCodeActivityStats(timeFrom, "") if err != nil { return nil, fmt.Errorf("FillFromGit: %v", err) } if code.Authors == nil { return nil, nil } users := make(map[int64]*ActivityAuthorData) var unknownUserID int64 unknownUserAvatarLink := NewGhostUser().AvatarLink() for _, v := range code.Authors { if len(v.Email) == 0 { continue } u, err := GetUserByEmail(v.Email) if u == nil || IsErrUserNotExist(err) { unknownUserID-- users[unknownUserID] = &ActivityAuthorData{ Name: v.Name, AvatarLink: unknownUserAvatarLink, Commits: v.Commits, } continue } if err != nil { return nil, err } if user, ok := users[u.ID]; !ok { users[u.ID] = &ActivityAuthorData{ Name: u.DisplayName(), Login: u.LowerName, AvatarLink: u.AvatarLink(), HomeLink: u.HomeLink(), Commits: v.Commits, } } else { user.Commits += v.Commits } } v := make([]*ActivityAuthorData, 0) for _, u := range users { v = append(v, u) } sort.Slice(v, func(i, j int) bool { return v[i].Commits > v[j].Commits }) cnt := count if cnt > len(v) { cnt = len(v) } return v[:cnt], nil } // ActivePRCount returns total active pull request count func (stats *ActivityStats) ActivePRCount() int { return stats.OpenedPRCount() + stats.MergedPRCount() } // OpenedPRCount returns opened pull request count func (stats *ActivityStats) OpenedPRCount() int { return len(stats.OpenedPRs) } // OpenedPRPerc returns opened pull request percents from total active func (stats *ActivityStats) OpenedPRPerc() int { return int(float32(stats.OpenedPRCount()) / float32(stats.ActivePRCount()) * 100.0) } // MergedPRCount returns merged pull request count func (stats *ActivityStats) MergedPRCount() int { return len(stats.MergedPRs) } // MergedPRPerc returns merged pull request percent from total active func (stats *ActivityStats) MergedPRPerc() int { return int(float32(stats.MergedPRCount()) / float32(stats.ActivePRCount()) * 100.0) } // ActiveIssueCount returns total active issue count func (stats *ActivityStats) ActiveIssueCount() int { return stats.OpenedIssueCount() + stats.ClosedIssueCount() } // OpenedIssueCount returns open issue count func (stats *ActivityStats) OpenedIssueCount() int { return len(stats.OpenedIssues) } // OpenedIssuePerc returns open issue count percent from total active func (stats *ActivityStats) OpenedIssuePerc() int { return int(float32(stats.OpenedIssueCount()) / float32(stats.ActiveIssueCount()) * 100.0) } // ClosedIssueCount returns closed issue count func (stats *ActivityStats) ClosedIssueCount() int { return len(stats.ClosedIssues) } // ClosedIssuePerc returns closed issue count percent from total active func (stats *ActivityStats) ClosedIssuePerc() int { return int(float32(stats.ClosedIssueCount()) / float32(stats.ActiveIssueCount()) * 100.0) } // UnresolvedIssueCount returns unresolved issue and pull request count func (stats *ActivityStats) UnresolvedIssueCount() int { return len(stats.UnresolvedIssues) } // PublishedReleaseCount returns published release count func (stats *ActivityStats) PublishedReleaseCount() int { return len(stats.PublishedReleases) } // FillPullRequests returns pull request information for activity page func (stats *ActivityStats) FillPullRequests(repoID int64, fromTime time.Time) error { var err error var count int64 // Merged pull requests sess := pullRequestsForActivityStatement(repoID, fromTime, true) sess.OrderBy("pull_request.merged_unix DESC") stats.MergedPRs = make(PullRequestList, 0) if err = sess.Find(&stats.MergedPRs); err != nil { return err } if err = stats.MergedPRs.LoadAttributes(); err != nil { return err } // Merged pull request authors sess = pullRequestsForActivityStatement(repoID, fromTime, true) if _, err = sess.Select("count(distinct issue.poster_id) as `count`").Table("pull_request").Get(&count); err != nil { return err } stats.MergedPRAuthorCount = count // Opened pull requests sess = pullRequestsForActivityStatement(repoID, fromTime, false) sess.OrderBy("issue.created_unix ASC") stats.OpenedPRs = make(PullRequestList, 0) if err = sess.Find(&stats.OpenedPRs); err != nil { return err } if err = stats.OpenedPRs.LoadAttributes(); err != nil { return err } // Opened pull request authors sess = pullRequestsForActivityStatement(repoID, fromTime, false) if _, err = sess.Select("count(distinct issue.poster_id) as `count`").Table("pull_request").Get(&count); err != nil { return err } stats.OpenedPRAuthorCount = count return nil } func pullRequestsForActivityStatement(repoID int64, fromTime time.Time, merged bool) *xorm.Session { sess := db.GetEngine(db.DefaultContext).Where("pull_request.base_repo_id=?", repoID). Join("INNER", "issue", "pull_request.issue_id = issue.id") if merged { sess.And("pull_request.has_merged = ?", true) sess.And("pull_request.merged_unix >= ?", fromTime.Unix()) } else { sess.And("issue.is_closed = ?", false) sess.And("issue.created_unix >= ?", fromTime.Unix()) } return sess } // FillIssues returns issue information for activity page func (stats *ActivityStats) FillIssues(repoID int64, fromTime time.Time) error { var err error var count int64 // Closed issues sess := issuesForActivityStatement(repoID, fromTime, true, false) sess.OrderBy("issue.closed_unix DESC") stats.ClosedIssues = make(IssueList, 0) if err = sess.Find(&stats.ClosedIssues); err != nil { return err } // Closed issue authors sess = issuesForActivityStatement(repoID, fromTime, true, false) if _, err = sess.Select("count(distinct issue.poster_id) as `count`").Table("issue").Get(&count); err != nil { return err } stats.ClosedIssueAuthorCount = count // New issues sess = issuesForActivityStatement(repoID, fromTime, false, false) sess.OrderBy("issue.created_unix ASC") stats.OpenedIssues = make(IssueList, 0) if err = sess.Find(&stats.OpenedIssues); err != nil { return err } // Opened issue authors sess = issuesForActivityStatement(repoID, fromTime, false, false) if _, err = sess.Select("count(distinct issue.poster_id) as `count`").Table("issue").Get(&count); err != nil { return err } stats.OpenedIssueAuthorCount = count return nil } // FillUnresolvedIssues returns unresolved issue and pull request information for activity page func (stats *ActivityStats) FillUnresolvedIssues(repoID int64, fromTime time.Time, issues, prs bool) error { // Check if we need to select anything if !issues && !prs { return nil } sess := issuesForActivityStatement(repoID, fromTime, false, true) if !issues || !prs { sess.And("issue.is_pull = ?", prs) } sess.OrderBy("issue.updated_unix DESC") stats.UnresolvedIssues = make(IssueList, 0) return sess.Find(&stats.UnresolvedIssues) } func issuesForActivityStatement(repoID int64, fromTime time.Time, closed, unresolved bool) *xorm.Session { sess := db.GetEngine(db.DefaultContext).Where("issue.repo_id = ?", repoID). And("issue.is_closed = ?", closed) if !unresolved { sess.And("issue.is_pull = ?", false) if closed { sess.And("issue.closed_unix >= ?", fromTime.Unix()) } else { sess.And("issue.created_unix >= ?", fromTime.Unix()) } } else { sess.And("issue.created_unix < ?", fromTime.Unix()) sess.And("issue.updated_unix >= ?", fromTime.Unix()) } return sess } // FillReleases returns release information for activity page func (stats *ActivityStats) FillReleases(repoID int64, fromTime time.Time) error { var err error var count int64 // Published releases list sess := releasesForActivityStatement(repoID, fromTime) sess.OrderBy("release.created_unix DESC") stats.PublishedReleases = make([]*Release, 0) if err = sess.Find(&stats.PublishedReleases); err != nil { return err } // Published releases authors sess = releasesForActivityStatement(repoID, fromTime) if _, err = sess.Select("count(distinct release.publisher_id) as `count`").Table("release").Get(&count); err != nil { return err } stats.PublishedReleaseAuthorCount = count return nil } func releasesForActivityStatement(repoID int64, fromTime time.Time) *xorm.Session { return db.GetEngine(db.DefaultContext).Where("release.repo_id = ?", repoID). And("release.is_draft = ?", false). And("release.created_unix >= ?", fromTime.Unix()) } 44' href='#n144'>144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<?pde?>
<!-- generated with https://github.com/eclipse-cbi/targetplatform-dsl -->
<target name="jgit-4.23" sequenceNumber="1714661050">
  <locations>
    <location includeMode="slicer" includeAllPlatforms="false" includeSource="true" includeConfigurePhase="true" type="InstallableUnit">
      <unit id="com.jcraft.jsch" version="0.1.55.v20230916-1400"/>
      <unit id="com.jcraft.jsch.source" version="0.1.55.v20230916-1400"/>
      <unit id="com.jcraft.jzlib" version="1.1.3.v20230916-1400"/>
      <unit id="com.jcraft.jzlib.source" version="1.1.3.v20230916-1400"/>
      <unit id="net.i2p.crypto.eddsa" version="0.3.0"/>
      <unit id="net.i2p.crypto.eddsa.source" version="0.3.0"/>
      <unit id="org.apache.ant" version="1.10.14.v20230922-1200"/>
      <unit id="org.apache.ant.source" version="1.10.14.v20230922-1200"/>
      <unit id="org.apache.httpcomponents.httpclient" version="4.5.14"/>
      <unit id="org.apache.httpcomponents.httpclient.source" version="4.5.14"/>
      <unit id="org.apache.httpcomponents.httpcore" version="4.4.16"/>
      <unit id="org.apache.httpcomponents.httpcore.source" version="4.4.16"/>
      <unit id="org.hamcrest.core" version="1.3.0.v20230809-1000"/>
      <unit id="org.hamcrest.core.source" version="1.3.0.v20230809-1000"/>
      <unit id="org.hamcrest.library" version="1.3.0.v20230809-1000"/>
      <unit id="org.hamcrest.library.source" version="1.3.0.v20230809-1000"/>
      <unit id="org.junit" version="4.13.2.v20230809-1000"/>
      <unit id="org.junit.source" version="4.13.2.v20230809-1000"/>
      <unit id="org.objenesis" version="3.3.0"/>
      <unit id="org.objenesis.source" version="3.3.0"/>
      <unit id="org.osgi.service.cm" version="1.6.1.202109301733"/>
      <unit id="org.osgi.service.cm.source" version="1.6.1.202109301733"/>
      <repository location="https://download.eclipse.org/tools/orbit/simrel/orbit-aggregation/2023-12"/>
    </location>
    <location includeMode="slicer" includeAllPlatforms="false" includeSource="true" includeConfigurePhase="true" type="InstallableUnit">
      <unit id="org.eclipse.osgi" version="0.0.0"/>
      <repository location="https://download.eclipse.org/releases/2022-03/"/>
    </location>
    <location includeDependencyDepth="none" includeDependencyScopes="compile" includeSource="true" missingManifest="error" type="Maven" label="xz">
    <dependencies>
    	<dependency>
    		<groupId>org.tukaani</groupId>
    		<artifactId>xz</artifactId>
    		<version>1.9</version>
    		<type>jar</type>
    	</dependency>
    </dependencies>
    </location>
    <location includeDependencyDepth="none" includeDependencyScopes="compile" includeSource="true" missingManifest="error" type="Maven" label="slf4j">
    <dependencies>
    	<dependency>
    		<groupId>org.slf4j</groupId>
    		<artifactId>slf4j-api</artifactId>
    		<version>1.7.36</version>
    		<type>jar</type>
    	</dependency>
    	<dependency>
    		<groupId>org.slf4j</groupId>
    		<artifactId>slf4j-simple</artifactId>
    		<version>1.7.36</version>
    		<type>jar</type>
    	</dependency>
    </dependencies>
    </location>
    <location includeDependencyDepth="none" includeDependencyScopes="compile" includeSource="true" missingManifest="error" type="Maven" label="sshd">
    <dependencies>
    	<dependency>
    		<groupId>org.apache.sshd</groupId>
    		<artifactId>sshd-osgi</artifactId>
    		<version>2.12.0</version>
    		<type>jar</type>
    	</dependency>
    	<dependency>
    		<groupId>org.apache.sshd</groupId>
    		<artifactId>sshd-sftp</artifactId>
    		<version>2.12.0</version>
    		<type>jar</type>
    	</dependency>
    </dependencies>
    </location>
    <location includeDependencyDepth="none" includeDependencyScopes="compile" includeSource="true" missingManifest="error" type="Maven" label="mockito">
    <dependencies>
    	<dependency>
    		<groupId>org.mockito</groupId>
    		<artifactId>mockito-core</artifactId>
    		<version>5.10.0</version>
    		<type>jar</type>
    	</dependency>
    </dependencies>
    </location>
    <location includeDependencyDepth="none" includeDependencyScopes="compile" includeSource="true" missingManifest="error" type="Maven" label="jna">
    <dependencies>
    	<dependency>
    		<groupId>net.java.dev.jna</groupId>
    		<artifactId>jna</artifactId>
    		<version>5.14.0</version>
    		<type>jar</type>
    	</dependency>
    	<dependency>
    		<groupId>net.java.dev.jna</groupId>
    		<artifactId>jna-platform</artifactId>
    		<version>5.14.0</version>
    		<type>jar</type>
    	</dependency>
    </dependencies>
    </location>
    <location includeDependencyDepth="none" includeDependencyScopes="compile" includeSource="true" missingManifest="error" type="Maven" label="jetty">
    <dependencies>
    	<dependency>
    		<groupId>org.eclipse.jetty</groupId>
    		<artifactId>jetty-http</artifactId>
    		<version>11.0.20</version>
    		<type>jar</type>
    	</dependency>
    	<dependency>
    		<groupId>org.eclipse.jetty</groupId>
    		<artifactId>jetty-io</artifactId>
    		<version>11.0.20</version>
    		<type>jar</type>
    	</dependency>
    	<dependency>
    		<groupId>org.eclipse.jetty</groupId>
    		<artifactId>jetty-security</artifactId>
    		<version>11.0.20</version>
    		<type>jar</type>
    	</dependency>
    	<dependency>
    		<groupId>org.eclipse.jetty</groupId>
    		<artifactId>jetty-server</artifactId>
    		<version>11.0.20</version>
    		<type>jar</type>
    	</dependency>
    	<dependency>
    		<groupId>org.eclipse.jetty</groupId>
    		<artifactId>jetty-servlet</artifactId>
    		<version>11.0.20</version>
    		<type>jar</type>
    	</dependency>
    	<dependency>
    		<groupId>org.eclipse.jetty</groupId>
    		<artifactId>jetty-util</artifactId>
    		<version>11.0.20</version>
    		<type>jar</type>
    	</dependency>
    	<dependency>
    		<groupId>org.eclipse.jetty</groupId>
    		<artifactId>jetty-util-ajax</artifactId>
    		<version>11.0.20</version>
    		<type>jar</type>
    	</dependency>
    	<dependency>
    		<groupId>jakarta.servlet</groupId>
    		<artifactId>jakarta.servlet-api</artifactId>
    		<version>5.0.0</version>
    		<type>jar</type>
    	</dependency>
    </dependencies>
    </location>
    <location includeDependencyDepth="none" includeDependencyScopes="compile" includeSource="true" missingManifest="error" type="Maven" label="javaewah">
    <dependencies>
    	<dependency>
    		<groupId>com.googlecode.javaewah</groupId>
    		<artifactId>JavaEWAH</artifactId>
    		<version>1.2.3</version>
    		<type>jar</type>
    	</dependency>
    </dependencies>
    </location>
    <location includeDependencyDepth="none" includeDependencyScopes="compile" includeSource="true" missingManifest="error" type="Maven" label="hamcrest">
    <dependencies>
    	<dependency>
    		<groupId>org.hamcrest</groupId>
    		<artifactId>hamcrest</artifactId>
    		<version>2.2</version>
    		<type>jar</type>
    	</dependency>
    </dependencies>
    </location>
    <location includeDependencyDepth="none" includeDependencyScopes="compile" includeSource="true" missingManifest="error" type="Maven" label="gson">
    <dependencies>
    	<dependency>
    		<groupId>com.google.code.gson</groupId>
    		<artifactId>gson</artifactId>
    		<version>2.10.1</version>
    		<type>jar</type>
    	</dependency>
    </dependencies>
    </location>
    <location includeDependencyDepth="none" includeDependencyScopes="compile" includeSource="true" missingManifest="error" type="Maven" label="bytebuddy">
    <dependencies>
    	<dependency>
    		<groupId>net.bytebuddy</groupId>
    		<artifactId>byte-buddy</artifactId>
    		<version>1.14.12</version>
    		<type>jar</type>
    	</dependency>
    	<dependency>
    		<groupId>net.bytebuddy</groupId>
    		<artifactId>byte-buddy-agent</artifactId>
    		<version>1.14.12</version>
    		<type>jar</type>
    	</dependency>
    </dependencies>
    </location>
    <location includeDependencyDepth="none" includeDependencyScopes="compile" includeSource="true" missingManifest="error" type="Maven" label="bouncycastle">
    <dependencies>
    	<dependency>
    		<groupId>org.bouncycastle</groupId>
    		<artifactId>bcpg-jdk18on</artifactId>
    		<version>1.77</version>
    		<type>jar</type>
    	</dependency>
    	<dependency>
    		<groupId>org.bouncycastle</groupId>
    		<artifactId>bcprov-jdk18on</artifactId>
    		<version>1.77</version>
    		<type>jar</type>
    	</dependency>
    	<dependency>
    		<groupId>org.bouncycastle</groupId>
    		<artifactId>bcpkix-jdk18on</artifactId>
    		<version>1.77</version>
    		<type>jar</type>
    	</dependency>
    	<dependency>
    		<groupId>org.bouncycastle</groupId>
    		<artifactId>bcutil-jdk18on</artifactId>
    		<version>1.77</version>
    		<type>jar</type>
    	</dependency>
    </dependencies>
    </location>
    <location includeDependencyDepth="none" includeDependencyScopes="compile" includeSource="true" missingManifest="error" type="Maven" label="assertj">
    <dependencies>
    	<dependency>
    		<groupId>org.assertj</groupId>
    		<artifactId>assertj-core</artifactId>
    		<version>3.25.3</version>
    		<type>jar</type>
    	</dependency>
    </dependencies>
    </location>
    <location includeDependencyDepth="none" includeDependencyScopes="compile" includeSource="true" missingManifest="error" type="Maven" label="args4j">
    <dependencies>
    	<dependency>
    		<groupId>args4j</groupId>
    		<artifactId>args4j</artifactId>
    		<version>2.33</version>
    		<type>jar</type>
    	</dependency>
    </dependencies>
    </location>
    <location includeDependencyDepth="none" includeDependencyScopes="compile" includeSource="true" missingManifest="error" type="Maven" label="apache">
    <dependencies>
    	<dependency>
    		<groupId>commons-codec</groupId>
    		<artifactId>commons-codec</artifactId>
    		<version>1.16.0</version>
    		<type>jar</type>
    	</dependency>
    	<dependency>
    		<groupId>org.apache.commons</groupId>
    		<artifactId>commons-compress</artifactId>
    		<version>1.26.0</version>
    		<type>jar</type>
    	</dependency>
    	<dependency>
    		<groupId>commons-io</groupId>
    		<artifactId>commons-io</artifactId>
    		<version>2.15.1</version>
    		<type>jar</type>
    	</dependency>
    	<dependency>
    		<groupId>commons-logging</groupId>
    		<artifactId>commons-logging</artifactId>
    		<version>1.2</version>
    		<type>jar</type>
    	</dependency>
    </dependencies>
    </location>
  </locations>
</target>