2017-02-22 19:33:59 +05:30
|
|
|
// Copyright 2017 The Gitea Authors. All rights reserved.
|
2022-11-27 23:50:29 +05:30
|
|
|
// SPDX-License-Identifier: MIT
|
2017-02-22 19:33:59 +05:30
|
|
|
|
2022-06-13 15:07:59 +05:30
|
|
|
package issues
|
2017-02-22 19:33:59 +05:30
|
|
|
|
2019-02-19 20:09:39 +05:30
|
|
|
import (
|
2022-05-20 19:38:52 +05:30
|
|
|
"context"
|
2019-02-19 20:09:39 +05:30
|
|
|
"fmt"
|
|
|
|
|
2021-09-19 17:19:59 +05:30
|
|
|
"code.gitea.io/gitea/models/db"
|
2022-07-26 19:12:23 +05:30
|
|
|
project_model "code.gitea.io/gitea/models/project"
|
2021-11-19 19:09:57 +05:30
|
|
|
repo_model "code.gitea.io/gitea/models/repo"
|
2021-11-24 15:19:20 +05:30
|
|
|
user_model "code.gitea.io/gitea/models/user"
|
2022-03-31 14:50:39 +05:30
|
|
|
"code.gitea.io/gitea/modules/container"
|
2021-11-17 18:04:35 +05:30
|
|
|
|
2019-06-23 20:52:43 +05:30
|
|
|
"xorm.io/builder"
|
2019-02-19 20:09:39 +05:30
|
|
|
)
|
2017-02-22 19:33:59 +05:30
|
|
|
|
|
|
|
// IssueList defines a list of issues
|
|
|
|
type IssueList []*Issue
|
|
|
|
|
2022-05-25 19:03:35 +05:30
|
|
|
// get the repo IDs to be loaded later, these IDs are for issue.Repo and issue.PullRequest.HeadRepo
|
2017-02-22 19:33:59 +05:30
|
|
|
func (issues IssueList) getRepoIDs() []int64 {
|
2022-10-12 10:48:26 +05:30
|
|
|
repoIDs := make(container.Set[int64], len(issues))
|
2017-02-22 19:33:59 +05:30
|
|
|
for _, issue := range issues {
|
2022-05-25 19:03:35 +05:30
|
|
|
if issue.Repo == nil {
|
2022-10-12 10:48:26 +05:30
|
|
|
repoIDs.Add(issue.RepoID)
|
2017-02-22 19:33:59 +05:30
|
|
|
}
|
2022-05-25 19:03:35 +05:30
|
|
|
if issue.PullRequest != nil && issue.PullRequest.HeadRepo == nil {
|
2022-10-12 10:48:26 +05:30
|
|
|
repoIDs.Add(issue.PullRequest.HeadRepoID)
|
2022-05-25 19:03:35 +05:30
|
|
|
}
|
2017-02-22 19:33:59 +05:30
|
|
|
}
|
2022-10-12 10:48:26 +05:30
|
|
|
return repoIDs.Values()
|
2017-02-22 19:33:59 +05:30
|
|
|
}
|
|
|
|
|
2022-11-19 13:42:33 +05:30
|
|
|
// LoadRepositories loads issues' all repositories
|
2023-06-05 12:55:47 +05:30
|
|
|
func (issues IssueList) LoadRepositories(ctx context.Context) (repo_model.RepositoryList, error) {
|
2017-02-22 19:33:59 +05:30
|
|
|
if len(issues) == 0 {
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
repoIDs := issues.getRepoIDs()
|
2021-12-10 06:57:50 +05:30
|
|
|
repoMaps := make(map[int64]*repo_model.Repository, len(repoIDs))
|
2021-03-15 00:22:12 +05:30
|
|
|
left := len(repoIDs)
|
2018-08-02 19:19:05 +05:30
|
|
|
for left > 0 {
|
2022-06-13 15:07:59 +05:30
|
|
|
limit := db.DefaultMaxInSize
|
2018-08-02 19:19:05 +05:30
|
|
|
if left < limit {
|
|
|
|
limit = left
|
|
|
|
}
|
2022-05-20 19:38:52 +05:30
|
|
|
err := db.GetEngine(ctx).
|
2018-08-02 19:19:05 +05:30
|
|
|
In("id", repoIDs[:limit]).
|
|
|
|
Find(&repoMaps)
|
|
|
|
if err != nil {
|
2022-10-25 00:59:17 +05:30
|
|
|
return nil, fmt.Errorf("find repository: %w", err)
|
2018-08-02 19:19:05 +05:30
|
|
|
}
|
2019-06-13 01:11:28 +05:30
|
|
|
left -= limit
|
2018-08-02 19:19:05 +05:30
|
|
|
repoIDs = repoIDs[limit:]
|
2017-02-22 19:33:59 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
for _, issue := range issues {
|
2021-12-29 18:32:12 +05:30
|
|
|
if issue.Repo == nil {
|
|
|
|
issue.Repo = repoMaps[issue.RepoID]
|
|
|
|
} else {
|
|
|
|
repoMaps[issue.RepoID] = issue.Repo
|
|
|
|
}
|
2022-05-25 19:03:35 +05:30
|
|
|
if issue.PullRequest != nil {
|
2021-04-15 23:04:43 +05:30
|
|
|
issue.PullRequest.BaseRepo = issue.Repo
|
2022-05-25 19:03:35 +05:30
|
|
|
if issue.PullRequest.HeadRepo == nil {
|
|
|
|
issue.PullRequest.HeadRepo = repoMaps[issue.PullRequest.HeadRepoID]
|
|
|
|
}
|
2021-04-15 23:04:43 +05:30
|
|
|
}
|
2017-02-22 19:33:59 +05:30
|
|
|
}
|
2022-06-06 13:31:49 +05:30
|
|
|
return repo_model.ValuesRepository(repoMaps), nil
|
2017-02-22 19:33:59 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
func (issues IssueList) getPosterIDs() []int64 {
|
2024-04-09 17:57:30 +05:30
|
|
|
return container.FilterSlice(issues, func(issue *Issue) (int64, bool) {
|
|
|
|
return issue.PosterID, true
|
|
|
|
})
|
2017-02-22 19:33:59 +05:30
|
|
|
}
|
|
|
|
|
2022-05-20 19:38:52 +05:30
|
|
|
func (issues IssueList) loadPosters(ctx context.Context) error {
|
2017-02-22 19:33:59 +05:30
|
|
|
if len(issues) == 0 {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
Implement actions (#21937)
Close #13539.
Co-authored by: @lunny @appleboy @fuxiaohei and others.
Related projects:
- https://gitea.com/gitea/actions-proto-def
- https://gitea.com/gitea/actions-proto-go
- https://gitea.com/gitea/act
- https://gitea.com/gitea/act_runner
### Summary
The target of this PR is to bring a basic implementation of "Actions",
an internal CI/CD system of Gitea. That means even though it has been
merged, the state of the feature is **EXPERIMENTAL**, and please note
that:
- It is disabled by default;
- It shouldn't be used in a production environment currently;
- It shouldn't be used in a public Gitea instance currently;
- Breaking changes may be made before it's stable.
**Please comment on #13539 if you have any different product design
ideas**, all decisions reached there will be adopted here. But in this
PR, we don't talk about **naming, feature-creep or alternatives**.
### ⚠️ Breaking
`gitea-actions` will become a reserved user name. If a user with the
name already exists in the database, it is recommended to rename it.
### Some important reviews
- What is `DEFAULT_ACTIONS_URL` in `app.ini` for?
- https://github.com/go-gitea/gitea/pull/21937#discussion_r1055954954
- Why the api for runners is not under the normal `/api/v1` prefix?
- https://github.com/go-gitea/gitea/pull/21937#discussion_r1061173592
- Why DBFS?
- https://github.com/go-gitea/gitea/pull/21937#discussion_r1061301178
- Why ignore events triggered by `gitea-actions` bot?
- https://github.com/go-gitea/gitea/pull/21937#discussion_r1063254103
- Why there's no permission control for actions?
- https://github.com/go-gitea/gitea/pull/21937#discussion_r1090229868
### What it looks like
<details>
#### Manage runners
<img width="1792" alt="image"
src="https://user-images.githubusercontent.com/9418365/205870657-c72f590e-2e08-4cd4-be7f-2e0abb299bbf.png">
#### List runs
<img width="1792" alt="image"
src="https://user-images.githubusercontent.com/9418365/205872794-50fde990-2b45-48c1-a178-908e4ec5b627.png">
#### View logs
<img width="1792" alt="image"
src="https://user-images.githubusercontent.com/9418365/205872501-9b7b9000-9542-4991-8f55-18ccdada77c3.png">
</details>
### How to try it
<details>
#### 1. Start Gitea
Clone this branch and [install from
source](https://docs.gitea.io/en-us/install-from-source).
Add additional configurations in `app.ini` to enable Actions:
```ini
[actions]
ENABLED = true
```
Start it.
If all is well, you'll see the management page of runners:
<img width="1792" alt="image"
src="https://user-images.githubusercontent.com/9418365/205877365-8e30a780-9b10-4154-b3e8-ee6c3cb35a59.png">
#### 2. Start runner
Clone the [act_runner](https://gitea.com/gitea/act_runner), and follow
the
[README](https://gitea.com/gitea/act_runner/src/branch/main/README.md)
to start it.
If all is well, you'll see a new runner has been added:
<img width="1792" alt="image"
src="https://user-images.githubusercontent.com/9418365/205878000-216f5937-e696-470d-b66c-8473987d91c3.png">
#### 3. Enable actions for a repo
Create a new repo or open an existing one, check the `Actions` checkbox
in settings and submit.
<img width="1792" alt="image"
src="https://user-images.githubusercontent.com/9418365/205879705-53e09208-73c0-4b3e-a123-2dcf9aba4b9c.png">
<img width="1792" alt="image"
src="https://user-images.githubusercontent.com/9418365/205879383-23f3d08f-1a85-41dd-a8b3-54e2ee6453e8.png">
If all is well, you'll see a new tab "Actions":
<img width="1792" alt="image"
src="https://user-images.githubusercontent.com/9418365/205881648-a8072d8c-5803-4d76-b8a8-9b2fb49516c1.png">
#### 4. Upload workflow files
Upload some workflow files to `.gitea/workflows/xxx.yaml`, you can
follow the [quickstart](https://docs.github.com/en/actions/quickstart)
of GitHub Actions. Yes, Gitea Actions is compatible with GitHub Actions
in most cases, you can use the same demo:
```yaml
name: GitHub Actions Demo
run-name: ${{ github.actor }} is testing out GitHub Actions 🚀
on: [push]
jobs:
Explore-GitHub-Actions:
runs-on: ubuntu-latest
steps:
- run: echo "🎉 The job was automatically triggered by a ${{ github.event_name }} event."
- run: echo "🐧 This job is now running on a ${{ runner.os }} server hosted by GitHub!"
- run: echo "🔎 The name of your branch is ${{ github.ref }} and your repository is ${{ github.repository }}."
- name: Check out repository code
uses: actions/checkout@v3
- run: echo "💡 The ${{ github.repository }} repository has been cloned to the runner."
- run: echo "🖥️ The workflow is now ready to test your code on the runner."
- name: List files in the repository
run: |
ls ${{ github.workspace }}
- run: echo "🍏 This job's status is ${{ job.status }}."
```
If all is well, you'll see a new run in `Actions` tab:
<img width="1792" alt="image"
src="https://user-images.githubusercontent.com/9418365/205884473-79a874bc-171b-4aaf-acd5-0241a45c3b53.png">
#### 5. Check the logs of jobs
Click a run and you'll see the logs:
<img width="1792" alt="image"
src="https://user-images.githubusercontent.com/9418365/205884800-994b0374-67f7-48ff-be9a-4c53f3141547.png">
#### 6. Go on
You can try more examples in [the
documents](https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions)
of GitHub Actions, then you might find a lot of bugs.
Come on, PRs are welcome.
</details>
See also: [Feature Preview: Gitea
Actions](https://blog.gitea.io/2022/12/feature-preview-gitea-actions/)
---------
Co-authored-by: a1012112796 <1012112796@qq.com>
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
Co-authored-by: delvh <dev.lh@web.de>
Co-authored-by: ChristopherHX <christopher.homberger@web.de>
Co-authored-by: John Olheiser <john.olheiser@gmail.com>
2023-01-31 07:15:19 +05:30
|
|
|
posterMaps, err := getPosters(ctx, issues.getPosterIDs())
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, issue := range issues {
|
|
|
|
issue.Poster = getPoster(issue.PosterID, posterMaps)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func getPosters(ctx context.Context, posterIDs []int64) (map[int64]*user_model.User, error) {
|
2021-11-24 15:19:20 +05:30
|
|
|
posterMaps := make(map[int64]*user_model.User, len(posterIDs))
|
2021-03-15 00:22:12 +05:30
|
|
|
left := len(posterIDs)
|
2018-08-02 19:19:05 +05:30
|
|
|
for left > 0 {
|
2022-06-13 15:07:59 +05:30
|
|
|
limit := db.DefaultMaxInSize
|
2018-08-02 19:19:05 +05:30
|
|
|
if left < limit {
|
|
|
|
limit = left
|
|
|
|
}
|
2022-05-20 19:38:52 +05:30
|
|
|
err := db.GetEngine(ctx).
|
2018-08-02 19:19:05 +05:30
|
|
|
In("id", posterIDs[:limit]).
|
|
|
|
Find(&posterMaps)
|
|
|
|
if err != nil {
|
Implement actions (#21937)
Close #13539.
Co-authored by: @lunny @appleboy @fuxiaohei and others.
Related projects:
- https://gitea.com/gitea/actions-proto-def
- https://gitea.com/gitea/actions-proto-go
- https://gitea.com/gitea/act
- https://gitea.com/gitea/act_runner
### Summary
The target of this PR is to bring a basic implementation of "Actions",
an internal CI/CD system of Gitea. That means even though it has been
merged, the state of the feature is **EXPERIMENTAL**, and please note
that:
- It is disabled by default;
- It shouldn't be used in a production environment currently;
- It shouldn't be used in a public Gitea instance currently;
- Breaking changes may be made before it's stable.
**Please comment on #13539 if you have any different product design
ideas**, all decisions reached there will be adopted here. But in this
PR, we don't talk about **naming, feature-creep or alternatives**.
### ⚠️ Breaking
`gitea-actions` will become a reserved user name. If a user with the
name already exists in the database, it is recommended to rename it.
### Some important reviews
- What is `DEFAULT_ACTIONS_URL` in `app.ini` for?
- https://github.com/go-gitea/gitea/pull/21937#discussion_r1055954954
- Why the api for runners is not under the normal `/api/v1` prefix?
- https://github.com/go-gitea/gitea/pull/21937#discussion_r1061173592
- Why DBFS?
- https://github.com/go-gitea/gitea/pull/21937#discussion_r1061301178
- Why ignore events triggered by `gitea-actions` bot?
- https://github.com/go-gitea/gitea/pull/21937#discussion_r1063254103
- Why there's no permission control for actions?
- https://github.com/go-gitea/gitea/pull/21937#discussion_r1090229868
### What it looks like
<details>
#### Manage runners
<img width="1792" alt="image"
src="https://user-images.githubusercontent.com/9418365/205870657-c72f590e-2e08-4cd4-be7f-2e0abb299bbf.png">
#### List runs
<img width="1792" alt="image"
src="https://user-images.githubusercontent.com/9418365/205872794-50fde990-2b45-48c1-a178-908e4ec5b627.png">
#### View logs
<img width="1792" alt="image"
src="https://user-images.githubusercontent.com/9418365/205872501-9b7b9000-9542-4991-8f55-18ccdada77c3.png">
</details>
### How to try it
<details>
#### 1. Start Gitea
Clone this branch and [install from
source](https://docs.gitea.io/en-us/install-from-source).
Add additional configurations in `app.ini` to enable Actions:
```ini
[actions]
ENABLED = true
```
Start it.
If all is well, you'll see the management page of runners:
<img width="1792" alt="image"
src="https://user-images.githubusercontent.com/9418365/205877365-8e30a780-9b10-4154-b3e8-ee6c3cb35a59.png">
#### 2. Start runner
Clone the [act_runner](https://gitea.com/gitea/act_runner), and follow
the
[README](https://gitea.com/gitea/act_runner/src/branch/main/README.md)
to start it.
If all is well, you'll see a new runner has been added:
<img width="1792" alt="image"
src="https://user-images.githubusercontent.com/9418365/205878000-216f5937-e696-470d-b66c-8473987d91c3.png">
#### 3. Enable actions for a repo
Create a new repo or open an existing one, check the `Actions` checkbox
in settings and submit.
<img width="1792" alt="image"
src="https://user-images.githubusercontent.com/9418365/205879705-53e09208-73c0-4b3e-a123-2dcf9aba4b9c.png">
<img width="1792" alt="image"
src="https://user-images.githubusercontent.com/9418365/205879383-23f3d08f-1a85-41dd-a8b3-54e2ee6453e8.png">
If all is well, you'll see a new tab "Actions":
<img width="1792" alt="image"
src="https://user-images.githubusercontent.com/9418365/205881648-a8072d8c-5803-4d76-b8a8-9b2fb49516c1.png">
#### 4. Upload workflow files
Upload some workflow files to `.gitea/workflows/xxx.yaml`, you can
follow the [quickstart](https://docs.github.com/en/actions/quickstart)
of GitHub Actions. Yes, Gitea Actions is compatible with GitHub Actions
in most cases, you can use the same demo:
```yaml
name: GitHub Actions Demo
run-name: ${{ github.actor }} is testing out GitHub Actions 🚀
on: [push]
jobs:
Explore-GitHub-Actions:
runs-on: ubuntu-latest
steps:
- run: echo "🎉 The job was automatically triggered by a ${{ github.event_name }} event."
- run: echo "🐧 This job is now running on a ${{ runner.os }} server hosted by GitHub!"
- run: echo "🔎 The name of your branch is ${{ github.ref }} and your repository is ${{ github.repository }}."
- name: Check out repository code
uses: actions/checkout@v3
- run: echo "💡 The ${{ github.repository }} repository has been cloned to the runner."
- run: echo "🖥️ The workflow is now ready to test your code on the runner."
- name: List files in the repository
run: |
ls ${{ github.workspace }}
- run: echo "🍏 This job's status is ${{ job.status }}."
```
If all is well, you'll see a new run in `Actions` tab:
<img width="1792" alt="image"
src="https://user-images.githubusercontent.com/9418365/205884473-79a874bc-171b-4aaf-acd5-0241a45c3b53.png">
#### 5. Check the logs of jobs
Click a run and you'll see the logs:
<img width="1792" alt="image"
src="https://user-images.githubusercontent.com/9418365/205884800-994b0374-67f7-48ff-be9a-4c53f3141547.png">
#### 6. Go on
You can try more examples in [the
documents](https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions)
of GitHub Actions, then you might find a lot of bugs.
Come on, PRs are welcome.
</details>
See also: [Feature Preview: Gitea
Actions](https://blog.gitea.io/2022/12/feature-preview-gitea-actions/)
---------
Co-authored-by: a1012112796 <1012112796@qq.com>
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
Co-authored-by: delvh <dev.lh@web.de>
Co-authored-by: ChristopherHX <christopher.homberger@web.de>
Co-authored-by: John Olheiser <john.olheiser@gmail.com>
2023-01-31 07:15:19 +05:30
|
|
|
return nil, err
|
2018-08-02 19:19:05 +05:30
|
|
|
}
|
2019-06-13 01:11:28 +05:30
|
|
|
left -= limit
|
2018-08-02 19:19:05 +05:30
|
|
|
posterIDs = posterIDs[limit:]
|
2017-02-22 19:33:59 +05:30
|
|
|
}
|
Implement actions (#21937)
Close #13539.
Co-authored by: @lunny @appleboy @fuxiaohei and others.
Related projects:
- https://gitea.com/gitea/actions-proto-def
- https://gitea.com/gitea/actions-proto-go
- https://gitea.com/gitea/act
- https://gitea.com/gitea/act_runner
### Summary
The target of this PR is to bring a basic implementation of "Actions",
an internal CI/CD system of Gitea. That means even though it has been
merged, the state of the feature is **EXPERIMENTAL**, and please note
that:
- It is disabled by default;
- It shouldn't be used in a production environment currently;
- It shouldn't be used in a public Gitea instance currently;
- Breaking changes may be made before it's stable.
**Please comment on #13539 if you have any different product design
ideas**, all decisions reached there will be adopted here. But in this
PR, we don't talk about **naming, feature-creep or alternatives**.
### ⚠️ Breaking
`gitea-actions` will become a reserved user name. If a user with the
name already exists in the database, it is recommended to rename it.
### Some important reviews
- What is `DEFAULT_ACTIONS_URL` in `app.ini` for?
- https://github.com/go-gitea/gitea/pull/21937#discussion_r1055954954
- Why the api for runners is not under the normal `/api/v1` prefix?
- https://github.com/go-gitea/gitea/pull/21937#discussion_r1061173592
- Why DBFS?
- https://github.com/go-gitea/gitea/pull/21937#discussion_r1061301178
- Why ignore events triggered by `gitea-actions` bot?
- https://github.com/go-gitea/gitea/pull/21937#discussion_r1063254103
- Why there's no permission control for actions?
- https://github.com/go-gitea/gitea/pull/21937#discussion_r1090229868
### What it looks like
<details>
#### Manage runners
<img width="1792" alt="image"
src="https://user-images.githubusercontent.com/9418365/205870657-c72f590e-2e08-4cd4-be7f-2e0abb299bbf.png">
#### List runs
<img width="1792" alt="image"
src="https://user-images.githubusercontent.com/9418365/205872794-50fde990-2b45-48c1-a178-908e4ec5b627.png">
#### View logs
<img width="1792" alt="image"
src="https://user-images.githubusercontent.com/9418365/205872501-9b7b9000-9542-4991-8f55-18ccdada77c3.png">
</details>
### How to try it
<details>
#### 1. Start Gitea
Clone this branch and [install from
source](https://docs.gitea.io/en-us/install-from-source).
Add additional configurations in `app.ini` to enable Actions:
```ini
[actions]
ENABLED = true
```
Start it.
If all is well, you'll see the management page of runners:
<img width="1792" alt="image"
src="https://user-images.githubusercontent.com/9418365/205877365-8e30a780-9b10-4154-b3e8-ee6c3cb35a59.png">
#### 2. Start runner
Clone the [act_runner](https://gitea.com/gitea/act_runner), and follow
the
[README](https://gitea.com/gitea/act_runner/src/branch/main/README.md)
to start it.
If all is well, you'll see a new runner has been added:
<img width="1792" alt="image"
src="https://user-images.githubusercontent.com/9418365/205878000-216f5937-e696-470d-b66c-8473987d91c3.png">
#### 3. Enable actions for a repo
Create a new repo or open an existing one, check the `Actions` checkbox
in settings and submit.
<img width="1792" alt="image"
src="https://user-images.githubusercontent.com/9418365/205879705-53e09208-73c0-4b3e-a123-2dcf9aba4b9c.png">
<img width="1792" alt="image"
src="https://user-images.githubusercontent.com/9418365/205879383-23f3d08f-1a85-41dd-a8b3-54e2ee6453e8.png">
If all is well, you'll see a new tab "Actions":
<img width="1792" alt="image"
src="https://user-images.githubusercontent.com/9418365/205881648-a8072d8c-5803-4d76-b8a8-9b2fb49516c1.png">
#### 4. Upload workflow files
Upload some workflow files to `.gitea/workflows/xxx.yaml`, you can
follow the [quickstart](https://docs.github.com/en/actions/quickstart)
of GitHub Actions. Yes, Gitea Actions is compatible with GitHub Actions
in most cases, you can use the same demo:
```yaml
name: GitHub Actions Demo
run-name: ${{ github.actor }} is testing out GitHub Actions 🚀
on: [push]
jobs:
Explore-GitHub-Actions:
runs-on: ubuntu-latest
steps:
- run: echo "🎉 The job was automatically triggered by a ${{ github.event_name }} event."
- run: echo "🐧 This job is now running on a ${{ runner.os }} server hosted by GitHub!"
- run: echo "🔎 The name of your branch is ${{ github.ref }} and your repository is ${{ github.repository }}."
- name: Check out repository code
uses: actions/checkout@v3
- run: echo "💡 The ${{ github.repository }} repository has been cloned to the runner."
- run: echo "🖥️ The workflow is now ready to test your code on the runner."
- name: List files in the repository
run: |
ls ${{ github.workspace }}
- run: echo "🍏 This job's status is ${{ job.status }}."
```
If all is well, you'll see a new run in `Actions` tab:
<img width="1792" alt="image"
src="https://user-images.githubusercontent.com/9418365/205884473-79a874bc-171b-4aaf-acd5-0241a45c3b53.png">
#### 5. Check the logs of jobs
Click a run and you'll see the logs:
<img width="1792" alt="image"
src="https://user-images.githubusercontent.com/9418365/205884800-994b0374-67f7-48ff-be9a-4c53f3141547.png">
#### 6. Go on
You can try more examples in [the
documents](https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions)
of GitHub Actions, then you might find a lot of bugs.
Come on, PRs are welcome.
</details>
See also: [Feature Preview: Gitea
Actions](https://blog.gitea.io/2022/12/feature-preview-gitea-actions/)
---------
Co-authored-by: a1012112796 <1012112796@qq.com>
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
Co-authored-by: delvh <dev.lh@web.de>
Co-authored-by: ChristopherHX <christopher.homberger@web.de>
Co-authored-by: John Olheiser <john.olheiser@gmail.com>
2023-01-31 07:15:19 +05:30
|
|
|
return posterMaps, nil
|
|
|
|
}
|
2017-02-22 19:33:59 +05:30
|
|
|
|
Implement actions (#21937)
Close #13539.
Co-authored by: @lunny @appleboy @fuxiaohei and others.
Related projects:
- https://gitea.com/gitea/actions-proto-def
- https://gitea.com/gitea/actions-proto-go
- https://gitea.com/gitea/act
- https://gitea.com/gitea/act_runner
### Summary
The target of this PR is to bring a basic implementation of "Actions",
an internal CI/CD system of Gitea. That means even though it has been
merged, the state of the feature is **EXPERIMENTAL**, and please note
that:
- It is disabled by default;
- It shouldn't be used in a production environment currently;
- It shouldn't be used in a public Gitea instance currently;
- Breaking changes may be made before it's stable.
**Please comment on #13539 if you have any different product design
ideas**, all decisions reached there will be adopted here. But in this
PR, we don't talk about **naming, feature-creep or alternatives**.
### ⚠️ Breaking
`gitea-actions` will become a reserved user name. If a user with the
name already exists in the database, it is recommended to rename it.
### Some important reviews
- What is `DEFAULT_ACTIONS_URL` in `app.ini` for?
- https://github.com/go-gitea/gitea/pull/21937#discussion_r1055954954
- Why the api for runners is not under the normal `/api/v1` prefix?
- https://github.com/go-gitea/gitea/pull/21937#discussion_r1061173592
- Why DBFS?
- https://github.com/go-gitea/gitea/pull/21937#discussion_r1061301178
- Why ignore events triggered by `gitea-actions` bot?
- https://github.com/go-gitea/gitea/pull/21937#discussion_r1063254103
- Why there's no permission control for actions?
- https://github.com/go-gitea/gitea/pull/21937#discussion_r1090229868
### What it looks like
<details>
#### Manage runners
<img width="1792" alt="image"
src="https://user-images.githubusercontent.com/9418365/205870657-c72f590e-2e08-4cd4-be7f-2e0abb299bbf.png">
#### List runs
<img width="1792" alt="image"
src="https://user-images.githubusercontent.com/9418365/205872794-50fde990-2b45-48c1-a178-908e4ec5b627.png">
#### View logs
<img width="1792" alt="image"
src="https://user-images.githubusercontent.com/9418365/205872501-9b7b9000-9542-4991-8f55-18ccdada77c3.png">
</details>
### How to try it
<details>
#### 1. Start Gitea
Clone this branch and [install from
source](https://docs.gitea.io/en-us/install-from-source).
Add additional configurations in `app.ini` to enable Actions:
```ini
[actions]
ENABLED = true
```
Start it.
If all is well, you'll see the management page of runners:
<img width="1792" alt="image"
src="https://user-images.githubusercontent.com/9418365/205877365-8e30a780-9b10-4154-b3e8-ee6c3cb35a59.png">
#### 2. Start runner
Clone the [act_runner](https://gitea.com/gitea/act_runner), and follow
the
[README](https://gitea.com/gitea/act_runner/src/branch/main/README.md)
to start it.
If all is well, you'll see a new runner has been added:
<img width="1792" alt="image"
src="https://user-images.githubusercontent.com/9418365/205878000-216f5937-e696-470d-b66c-8473987d91c3.png">
#### 3. Enable actions for a repo
Create a new repo or open an existing one, check the `Actions` checkbox
in settings and submit.
<img width="1792" alt="image"
src="https://user-images.githubusercontent.com/9418365/205879705-53e09208-73c0-4b3e-a123-2dcf9aba4b9c.png">
<img width="1792" alt="image"
src="https://user-images.githubusercontent.com/9418365/205879383-23f3d08f-1a85-41dd-a8b3-54e2ee6453e8.png">
If all is well, you'll see a new tab "Actions":
<img width="1792" alt="image"
src="https://user-images.githubusercontent.com/9418365/205881648-a8072d8c-5803-4d76-b8a8-9b2fb49516c1.png">
#### 4. Upload workflow files
Upload some workflow files to `.gitea/workflows/xxx.yaml`, you can
follow the [quickstart](https://docs.github.com/en/actions/quickstart)
of GitHub Actions. Yes, Gitea Actions is compatible with GitHub Actions
in most cases, you can use the same demo:
```yaml
name: GitHub Actions Demo
run-name: ${{ github.actor }} is testing out GitHub Actions 🚀
on: [push]
jobs:
Explore-GitHub-Actions:
runs-on: ubuntu-latest
steps:
- run: echo "🎉 The job was automatically triggered by a ${{ github.event_name }} event."
- run: echo "🐧 This job is now running on a ${{ runner.os }} server hosted by GitHub!"
- run: echo "🔎 The name of your branch is ${{ github.ref }} and your repository is ${{ github.repository }}."
- name: Check out repository code
uses: actions/checkout@v3
- run: echo "💡 The ${{ github.repository }} repository has been cloned to the runner."
- run: echo "🖥️ The workflow is now ready to test your code on the runner."
- name: List files in the repository
run: |
ls ${{ github.workspace }}
- run: echo "🍏 This job's status is ${{ job.status }}."
```
If all is well, you'll see a new run in `Actions` tab:
<img width="1792" alt="image"
src="https://user-images.githubusercontent.com/9418365/205884473-79a874bc-171b-4aaf-acd5-0241a45c3b53.png">
#### 5. Check the logs of jobs
Click a run and you'll see the logs:
<img width="1792" alt="image"
src="https://user-images.githubusercontent.com/9418365/205884800-994b0374-67f7-48ff-be9a-4c53f3141547.png">
#### 6. Go on
You can try more examples in [the
documents](https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions)
of GitHub Actions, then you might find a lot of bugs.
Come on, PRs are welcome.
</details>
See also: [Feature Preview: Gitea
Actions](https://blog.gitea.io/2022/12/feature-preview-gitea-actions/)
---------
Co-authored-by: a1012112796 <1012112796@qq.com>
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
Co-authored-by: delvh <dev.lh@web.de>
Co-authored-by: ChristopherHX <christopher.homberger@web.de>
Co-authored-by: John Olheiser <john.olheiser@gmail.com>
2023-01-31 07:15:19 +05:30
|
|
|
func getPoster(posterID int64, posterMaps map[int64]*user_model.User) *user_model.User {
|
|
|
|
if posterID == user_model.ActionsUserID {
|
|
|
|
return user_model.NewActionsUser()
|
2017-02-22 19:33:59 +05:30
|
|
|
}
|
Implement actions (#21937)
Close #13539.
Co-authored by: @lunny @appleboy @fuxiaohei and others.
Related projects:
- https://gitea.com/gitea/actions-proto-def
- https://gitea.com/gitea/actions-proto-go
- https://gitea.com/gitea/act
- https://gitea.com/gitea/act_runner
### Summary
The target of this PR is to bring a basic implementation of "Actions",
an internal CI/CD system of Gitea. That means even though it has been
merged, the state of the feature is **EXPERIMENTAL**, and please note
that:
- It is disabled by default;
- It shouldn't be used in a production environment currently;
- It shouldn't be used in a public Gitea instance currently;
- Breaking changes may be made before it's stable.
**Please comment on #13539 if you have any different product design
ideas**, all decisions reached there will be adopted here. But in this
PR, we don't talk about **naming, feature-creep or alternatives**.
### ⚠️ Breaking
`gitea-actions` will become a reserved user name. If a user with the
name already exists in the database, it is recommended to rename it.
### Some important reviews
- What is `DEFAULT_ACTIONS_URL` in `app.ini` for?
- https://github.com/go-gitea/gitea/pull/21937#discussion_r1055954954
- Why the api for runners is not under the normal `/api/v1` prefix?
- https://github.com/go-gitea/gitea/pull/21937#discussion_r1061173592
- Why DBFS?
- https://github.com/go-gitea/gitea/pull/21937#discussion_r1061301178
- Why ignore events triggered by `gitea-actions` bot?
- https://github.com/go-gitea/gitea/pull/21937#discussion_r1063254103
- Why there's no permission control for actions?
- https://github.com/go-gitea/gitea/pull/21937#discussion_r1090229868
### What it looks like
<details>
#### Manage runners
<img width="1792" alt="image"
src="https://user-images.githubusercontent.com/9418365/205870657-c72f590e-2e08-4cd4-be7f-2e0abb299bbf.png">
#### List runs
<img width="1792" alt="image"
src="https://user-images.githubusercontent.com/9418365/205872794-50fde990-2b45-48c1-a178-908e4ec5b627.png">
#### View logs
<img width="1792" alt="image"
src="https://user-images.githubusercontent.com/9418365/205872501-9b7b9000-9542-4991-8f55-18ccdada77c3.png">
</details>
### How to try it
<details>
#### 1. Start Gitea
Clone this branch and [install from
source](https://docs.gitea.io/en-us/install-from-source).
Add additional configurations in `app.ini` to enable Actions:
```ini
[actions]
ENABLED = true
```
Start it.
If all is well, you'll see the management page of runners:
<img width="1792" alt="image"
src="https://user-images.githubusercontent.com/9418365/205877365-8e30a780-9b10-4154-b3e8-ee6c3cb35a59.png">
#### 2. Start runner
Clone the [act_runner](https://gitea.com/gitea/act_runner), and follow
the
[README](https://gitea.com/gitea/act_runner/src/branch/main/README.md)
to start it.
If all is well, you'll see a new runner has been added:
<img width="1792" alt="image"
src="https://user-images.githubusercontent.com/9418365/205878000-216f5937-e696-470d-b66c-8473987d91c3.png">
#### 3. Enable actions for a repo
Create a new repo or open an existing one, check the `Actions` checkbox
in settings and submit.
<img width="1792" alt="image"
src="https://user-images.githubusercontent.com/9418365/205879705-53e09208-73c0-4b3e-a123-2dcf9aba4b9c.png">
<img width="1792" alt="image"
src="https://user-images.githubusercontent.com/9418365/205879383-23f3d08f-1a85-41dd-a8b3-54e2ee6453e8.png">
If all is well, you'll see a new tab "Actions":
<img width="1792" alt="image"
src="https://user-images.githubusercontent.com/9418365/205881648-a8072d8c-5803-4d76-b8a8-9b2fb49516c1.png">
#### 4. Upload workflow files
Upload some workflow files to `.gitea/workflows/xxx.yaml`, you can
follow the [quickstart](https://docs.github.com/en/actions/quickstart)
of GitHub Actions. Yes, Gitea Actions is compatible with GitHub Actions
in most cases, you can use the same demo:
```yaml
name: GitHub Actions Demo
run-name: ${{ github.actor }} is testing out GitHub Actions 🚀
on: [push]
jobs:
Explore-GitHub-Actions:
runs-on: ubuntu-latest
steps:
- run: echo "🎉 The job was automatically triggered by a ${{ github.event_name }} event."
- run: echo "🐧 This job is now running on a ${{ runner.os }} server hosted by GitHub!"
- run: echo "🔎 The name of your branch is ${{ github.ref }} and your repository is ${{ github.repository }}."
- name: Check out repository code
uses: actions/checkout@v3
- run: echo "💡 The ${{ github.repository }} repository has been cloned to the runner."
- run: echo "🖥️ The workflow is now ready to test your code on the runner."
- name: List files in the repository
run: |
ls ${{ github.workspace }}
- run: echo "🍏 This job's status is ${{ job.status }}."
```
If all is well, you'll see a new run in `Actions` tab:
<img width="1792" alt="image"
src="https://user-images.githubusercontent.com/9418365/205884473-79a874bc-171b-4aaf-acd5-0241a45c3b53.png">
#### 5. Check the logs of jobs
Click a run and you'll see the logs:
<img width="1792" alt="image"
src="https://user-images.githubusercontent.com/9418365/205884800-994b0374-67f7-48ff-be9a-4c53f3141547.png">
#### 6. Go on
You can try more examples in [the
documents](https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions)
of GitHub Actions, then you might find a lot of bugs.
Come on, PRs are welcome.
</details>
See also: [Feature Preview: Gitea
Actions](https://blog.gitea.io/2022/12/feature-preview-gitea-actions/)
---------
Co-authored-by: a1012112796 <1012112796@qq.com>
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
Co-authored-by: delvh <dev.lh@web.de>
Co-authored-by: ChristopherHX <christopher.homberger@web.de>
Co-authored-by: John Olheiser <john.olheiser@gmail.com>
2023-01-31 07:15:19 +05:30
|
|
|
if posterID <= 0 {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
poster, ok := posterMaps[posterID]
|
|
|
|
if !ok {
|
|
|
|
return user_model.NewGhostUser()
|
|
|
|
}
|
|
|
|
return poster
|
2017-02-22 19:33:59 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
func (issues IssueList) getIssueIDs() []int64 {
|
2021-03-15 00:22:12 +05:30
|
|
|
ids := make([]int64, 0, len(issues))
|
2017-02-22 19:33:59 +05:30
|
|
|
for _, issue := range issues {
|
|
|
|
ids = append(ids, issue.ID)
|
|
|
|
}
|
|
|
|
return ids
|
|
|
|
}
|
|
|
|
|
2022-05-20 19:38:52 +05:30
|
|
|
func (issues IssueList) loadLabels(ctx context.Context) error {
|
2017-02-22 19:33:59 +05:30
|
|
|
if len(issues) == 0 {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
type LabelIssue struct {
|
|
|
|
Label *Label `xorm:"extends"`
|
|
|
|
IssueLabel *IssueLabel `xorm:"extends"`
|
|
|
|
}
|
|
|
|
|
2021-03-15 00:22:12 +05:30
|
|
|
issueLabels := make(map[int64][]*Label, len(issues)*3)
|
|
|
|
issueIDs := issues.getIssueIDs()
|
|
|
|
left := len(issueIDs)
|
2018-08-02 19:19:05 +05:30
|
|
|
for left > 0 {
|
2022-06-13 15:07:59 +05:30
|
|
|
limit := db.DefaultMaxInSize
|
2018-08-02 19:19:05 +05:30
|
|
|
if left < limit {
|
|
|
|
limit = left
|
|
|
|
}
|
2022-05-20 19:38:52 +05:30
|
|
|
rows, err := db.GetEngine(ctx).Table("label").
|
2018-08-02 19:19:05 +05:30
|
|
|
Join("LEFT", "issue_label", "issue_label.label_id = label.id").
|
|
|
|
In("issue_label.issue_id", issueIDs[:limit]).
|
|
|
|
Asc("label.name").
|
|
|
|
Rows(new(LabelIssue))
|
2017-02-22 19:33:59 +05:30
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2018-08-02 19:19:05 +05:30
|
|
|
|
|
|
|
for rows.Next() {
|
|
|
|
var labelIssue LabelIssue
|
|
|
|
err = rows.Scan(&labelIssue)
|
|
|
|
if err != nil {
|
2019-06-23 20:52:43 +05:30
|
|
|
if err1 := rows.Close(); err1 != nil {
|
2022-10-25 00:59:17 +05:30
|
|
|
return fmt.Errorf("IssueList.loadLabels: Close: %w", err1)
|
2019-06-13 01:11:28 +05:30
|
|
|
}
|
2018-08-02 19:19:05 +05:30
|
|
|
return err
|
|
|
|
}
|
|
|
|
issueLabels[labelIssue.IssueLabel.IssueID] = append(issueLabels[labelIssue.IssueLabel.IssueID], labelIssue.Label)
|
|
|
|
}
|
2019-06-23 20:52:43 +05:30
|
|
|
// When there are no rows left and we try to close it.
|
2019-06-13 01:11:28 +05:30
|
|
|
// Since that is not relevant for us, we can safely ignore it.
|
2019-06-23 20:52:43 +05:30
|
|
|
if err1 := rows.Close(); err1 != nil {
|
2022-10-25 00:59:17 +05:30
|
|
|
return fmt.Errorf("IssueList.loadLabels: Close: %w", err1)
|
2019-06-13 01:11:28 +05:30
|
|
|
}
|
|
|
|
left -= limit
|
2018-08-02 19:19:05 +05:30
|
|
|
issueIDs = issueIDs[limit:]
|
2017-02-22 19:33:59 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
for _, issue := range issues {
|
|
|
|
issue.Labels = issueLabels[issue.ID]
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (issues IssueList) getMilestoneIDs() []int64 {
|
2024-04-09 17:57:30 +05:30
|
|
|
return container.FilterSlice(issues, func(issue *Issue) (int64, bool) {
|
|
|
|
return issue.MilestoneID, true
|
|
|
|
})
|
2017-02-22 19:33:59 +05:30
|
|
|
}
|
|
|
|
|
2022-05-20 19:38:52 +05:30
|
|
|
func (issues IssueList) loadMilestones(ctx context.Context) error {
|
2017-02-22 19:33:59 +05:30
|
|
|
milestoneIDs := issues.getMilestoneIDs()
|
|
|
|
if len(milestoneIDs) == 0 {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2022-06-13 15:07:59 +05:30
|
|
|
milestoneMaps := make(map[int64]*Milestone, len(milestoneIDs))
|
2021-03-15 00:22:12 +05:30
|
|
|
left := len(milestoneIDs)
|
2018-08-02 19:19:05 +05:30
|
|
|
for left > 0 {
|
2022-06-13 15:07:59 +05:30
|
|
|
limit := db.DefaultMaxInSize
|
2018-08-02 19:19:05 +05:30
|
|
|
if left < limit {
|
|
|
|
limit = left
|
|
|
|
}
|
2022-05-20 19:38:52 +05:30
|
|
|
err := db.GetEngine(ctx).
|
2018-08-02 19:19:05 +05:30
|
|
|
In("id", milestoneIDs[:limit]).
|
|
|
|
Find(&milestoneMaps)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2019-06-13 01:11:28 +05:30
|
|
|
left -= limit
|
2018-08-02 19:19:05 +05:30
|
|
|
milestoneIDs = milestoneIDs[limit:]
|
2017-02-22 19:33:59 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
for _, issue := range issues {
|
|
|
|
issue.Milestone = milestoneMaps[issue.MilestoneID]
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2023-06-24 21:01:28 +05:30
|
|
|
func (issues IssueList) LoadProjects(ctx context.Context) error {
|
|
|
|
issueIDs := issues.getIssueIDs()
|
|
|
|
projectMaps := make(map[int64]*project_model.Project, len(issues))
|
|
|
|
left := len(issueIDs)
|
2022-07-26 19:12:23 +05:30
|
|
|
|
2023-06-24 21:01:28 +05:30
|
|
|
type projectWithIssueID struct {
|
|
|
|
*project_model.Project `xorm:"extends"`
|
|
|
|
IssueID int64
|
2022-07-26 19:12:23 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
for left > 0 {
|
|
|
|
limit := db.DefaultMaxInSize
|
|
|
|
if left < limit {
|
|
|
|
limit = left
|
|
|
|
}
|
2023-06-24 21:01:28 +05:30
|
|
|
|
|
|
|
projects := make([]*projectWithIssueID, 0, limit)
|
2022-07-26 19:12:23 +05:30
|
|
|
err := db.GetEngine(ctx).
|
2023-06-24 21:01:28 +05:30
|
|
|
Table("project").
|
|
|
|
Select("project.*, project_issue.issue_id").
|
|
|
|
Join("INNER", "project_issue", "project.id = project_issue.project_id").
|
|
|
|
In("project_issue.issue_id", issueIDs[:limit]).
|
|
|
|
Find(&projects)
|
2022-07-26 19:12:23 +05:30
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2023-06-24 21:01:28 +05:30
|
|
|
for _, project := range projects {
|
|
|
|
projectMaps[project.IssueID] = project.Project
|
|
|
|
}
|
2022-07-26 19:12:23 +05:30
|
|
|
left -= limit
|
2023-06-24 21:01:28 +05:30
|
|
|
issueIDs = issueIDs[limit:]
|
2022-07-26 19:12:23 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
for _, issue := range issues {
|
2023-06-24 21:01:28 +05:30
|
|
|
issue.Project = projectMaps[issue.ID]
|
2022-07-26 19:12:23 +05:30
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2022-05-20 19:38:52 +05:30
|
|
|
func (issues IssueList) loadAssignees(ctx context.Context) error {
|
2018-05-09 21:59:04 +05:30
|
|
|
if len(issues) == 0 {
|
2017-02-22 19:33:59 +05:30
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2018-05-09 21:59:04 +05:30
|
|
|
type AssigneeIssue struct {
|
2021-11-24 15:19:20 +05:30
|
|
|
IssueAssignee *IssueAssignees `xorm:"extends"`
|
|
|
|
Assignee *user_model.User `xorm:"extends"`
|
2018-05-09 21:59:04 +05:30
|
|
|
}
|
|
|
|
|
2021-11-24 15:19:20 +05:30
|
|
|
assignees := make(map[int64][]*user_model.User, len(issues))
|
2021-03-15 00:22:12 +05:30
|
|
|
issueIDs := issues.getIssueIDs()
|
|
|
|
left := len(issueIDs)
|
2018-08-02 19:19:05 +05:30
|
|
|
for left > 0 {
|
2022-06-13 15:07:59 +05:30
|
|
|
limit := db.DefaultMaxInSize
|
2018-08-02 19:19:05 +05:30
|
|
|
if left < limit {
|
|
|
|
limit = left
|
|
|
|
}
|
2022-05-20 19:38:52 +05:30
|
|
|
rows, err := db.GetEngine(ctx).Table("issue_assignees").
|
2018-08-02 19:19:05 +05:30
|
|
|
Join("INNER", "`user`", "`user`.id = `issue_assignees`.assignee_id").
|
2022-07-14 21:30:10 +05:30
|
|
|
In("`issue_assignees`.issue_id", issueIDs[:limit]).OrderBy(user_model.GetOrderByName()).
|
2018-08-02 19:19:05 +05:30
|
|
|
Rows(new(AssigneeIssue))
|
2018-05-09 21:59:04 +05:30
|
|
|
if err != nil {
|
|
|
|
return err
|
2017-05-30 11:38:36 +05:30
|
|
|
}
|
2018-05-09 21:59:04 +05:30
|
|
|
|
2018-08-02 19:19:05 +05:30
|
|
|
for rows.Next() {
|
|
|
|
var assigneeIssue AssigneeIssue
|
|
|
|
err = rows.Scan(&assigneeIssue)
|
|
|
|
if err != nil {
|
2019-06-23 20:52:43 +05:30
|
|
|
if err1 := rows.Close(); err1 != nil {
|
2022-10-25 00:59:17 +05:30
|
|
|
return fmt.Errorf("IssueList.loadAssignees: Close: %w", err1)
|
2019-06-13 01:11:28 +05:30
|
|
|
}
|
2018-08-02 19:19:05 +05:30
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
assignees[assigneeIssue.IssueAssignee.IssueID] = append(assignees[assigneeIssue.IssueAssignee.IssueID], assigneeIssue.Assignee)
|
|
|
|
}
|
2019-06-23 20:52:43 +05:30
|
|
|
if err1 := rows.Close(); err1 != nil {
|
2022-10-25 00:59:17 +05:30
|
|
|
return fmt.Errorf("IssueList.loadAssignees: Close: %w", err1)
|
2019-06-13 01:11:28 +05:30
|
|
|
}
|
|
|
|
left -= limit
|
2018-08-02 19:19:05 +05:30
|
|
|
issueIDs = issueIDs[limit:]
|
2018-05-09 21:59:04 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
for _, issue := range issues {
|
|
|
|
issue.Assignees = assignees[issue.ID]
|
2017-02-22 19:33:59 +05:30
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (issues IssueList) getPullIssueIDs() []int64 {
|
2021-03-15 00:22:12 +05:30
|
|
|
ids := make([]int64, 0, len(issues))
|
2017-02-22 19:33:59 +05:30
|
|
|
for _, issue := range issues {
|
|
|
|
if issue.IsPull && issue.PullRequest == nil {
|
|
|
|
ids = append(ids, issue.ID)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ids
|
|
|
|
}
|
|
|
|
|
2022-11-19 13:42:33 +05:30
|
|
|
// LoadPullRequests loads pull requests
|
|
|
|
func (issues IssueList) LoadPullRequests(ctx context.Context) error {
|
2017-02-22 19:33:59 +05:30
|
|
|
issuesIDs := issues.getPullIssueIDs()
|
|
|
|
if len(issuesIDs) == 0 {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
pullRequestMaps := make(map[int64]*PullRequest, len(issuesIDs))
|
2021-03-15 00:22:12 +05:30
|
|
|
left := len(issuesIDs)
|
2018-08-02 19:19:05 +05:30
|
|
|
for left > 0 {
|
2022-06-13 15:07:59 +05:30
|
|
|
limit := db.DefaultMaxInSize
|
2018-08-02 19:19:05 +05:30
|
|
|
if left < limit {
|
|
|
|
limit = left
|
|
|
|
}
|
2022-05-20 19:38:52 +05:30
|
|
|
rows, err := db.GetEngine(ctx).
|
2018-08-02 19:19:05 +05:30
|
|
|
In("issue_id", issuesIDs[:limit]).
|
|
|
|
Rows(new(PullRequest))
|
2017-02-22 19:33:59 +05:30
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2018-08-02 19:19:05 +05:30
|
|
|
|
|
|
|
for rows.Next() {
|
|
|
|
var pr PullRequest
|
|
|
|
err = rows.Scan(&pr)
|
|
|
|
if err != nil {
|
2019-06-23 20:52:43 +05:30
|
|
|
if err1 := rows.Close(); err1 != nil {
|
2022-10-25 00:59:17 +05:30
|
|
|
return fmt.Errorf("IssueList.loadPullRequests: Close: %w", err1)
|
2019-06-13 01:11:28 +05:30
|
|
|
}
|
2018-08-02 19:19:05 +05:30
|
|
|
return err
|
|
|
|
}
|
|
|
|
pullRequestMaps[pr.IssueID] = &pr
|
|
|
|
}
|
2019-06-23 20:52:43 +05:30
|
|
|
if err1 := rows.Close(); err1 != nil {
|
2022-10-25 00:59:17 +05:30
|
|
|
return fmt.Errorf("IssueList.loadPullRequests: Close: %w", err1)
|
2019-06-13 01:11:28 +05:30
|
|
|
}
|
|
|
|
left -= limit
|
2018-08-02 19:19:05 +05:30
|
|
|
issuesIDs = issuesIDs[limit:]
|
2017-02-22 19:33:59 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
for _, issue := range issues {
|
|
|
|
issue.PullRequest = pullRequestMaps[issue.ID]
|
2024-03-21 18:43:08 +05:30
|
|
|
if issue.PullRequest != nil {
|
|
|
|
issue.PullRequest.Issue = issue
|
|
|
|
}
|
2017-02-22 19:33:59 +05:30
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2022-11-19 13:42:33 +05:30
|
|
|
// LoadAttachments loads attachments
|
|
|
|
func (issues IssueList) LoadAttachments(ctx context.Context) (err error) {
|
2017-02-22 19:33:59 +05:30
|
|
|
if len(issues) == 0 {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2021-11-19 19:09:57 +05:30
|
|
|
attachments := make(map[int64][]*repo_model.Attachment, len(issues))
|
2021-03-15 00:22:12 +05:30
|
|
|
issuesIDs := issues.getIssueIDs()
|
|
|
|
left := len(issuesIDs)
|
2018-08-02 19:19:05 +05:30
|
|
|
for left > 0 {
|
2022-06-13 15:07:59 +05:30
|
|
|
limit := db.DefaultMaxInSize
|
2018-08-02 19:19:05 +05:30
|
|
|
if left < limit {
|
|
|
|
limit = left
|
|
|
|
}
|
2024-03-12 12:53:44 +05:30
|
|
|
rows, err := db.GetEngine(ctx).
|
|
|
|
In("issue_id", issuesIDs[:limit]).
|
2021-11-19 19:09:57 +05:30
|
|
|
Rows(new(repo_model.Attachment))
|
2017-02-22 19:33:59 +05:30
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2018-08-02 19:19:05 +05:30
|
|
|
|
|
|
|
for rows.Next() {
|
2021-11-19 19:09:57 +05:30
|
|
|
var attachment repo_model.Attachment
|
2018-08-02 19:19:05 +05:30
|
|
|
err = rows.Scan(&attachment)
|
|
|
|
if err != nil {
|
2019-06-23 20:52:43 +05:30
|
|
|
if err1 := rows.Close(); err1 != nil {
|
2022-10-25 00:59:17 +05:30
|
|
|
return fmt.Errorf("IssueList.loadAttachments: Close: %w", err1)
|
2019-06-13 01:11:28 +05:30
|
|
|
}
|
2018-08-02 19:19:05 +05:30
|
|
|
return err
|
|
|
|
}
|
|
|
|
attachments[attachment.IssueID] = append(attachments[attachment.IssueID], &attachment)
|
|
|
|
}
|
2019-06-23 20:52:43 +05:30
|
|
|
if err1 := rows.Close(); err1 != nil {
|
2022-10-25 00:59:17 +05:30
|
|
|
return fmt.Errorf("IssueList.loadAttachments: Close: %w", err1)
|
2019-06-13 01:11:28 +05:30
|
|
|
}
|
|
|
|
left -= limit
|
2018-08-02 19:19:05 +05:30
|
|
|
issuesIDs = issuesIDs[limit:]
|
2017-02-22 19:33:59 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
for _, issue := range issues {
|
|
|
|
issue.Attachments = attachments[issue.ID]
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2022-05-20 19:38:52 +05:30
|
|
|
func (issues IssueList) loadComments(ctx context.Context, cond builder.Cond) (err error) {
|
2017-02-22 19:33:59 +05:30
|
|
|
if len(issues) == 0 {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2021-03-15 00:22:12 +05:30
|
|
|
comments := make(map[int64][]*Comment, len(issues))
|
|
|
|
issuesIDs := issues.getIssueIDs()
|
|
|
|
left := len(issuesIDs)
|
2018-08-02 19:19:05 +05:30
|
|
|
for left > 0 {
|
2022-06-13 15:07:59 +05:30
|
|
|
limit := db.DefaultMaxInSize
|
2018-08-02 19:19:05 +05:30
|
|
|
if left < limit {
|
|
|
|
limit = left
|
|
|
|
}
|
2022-05-20 19:38:52 +05:30
|
|
|
rows, err := db.GetEngine(ctx).Table("comment").
|
2018-08-02 19:19:05 +05:30
|
|
|
Join("INNER", "issue", "issue.id = comment.issue_id").
|
|
|
|
In("issue.id", issuesIDs[:limit]).
|
2019-02-19 20:09:39 +05:30
|
|
|
Where(cond).
|
2018-08-02 19:19:05 +05:30
|
|
|
Rows(new(Comment))
|
2017-02-22 19:33:59 +05:30
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2018-08-02 19:19:05 +05:30
|
|
|
|
|
|
|
for rows.Next() {
|
|
|
|
var comment Comment
|
|
|
|
err = rows.Scan(&comment)
|
|
|
|
if err != nil {
|
2019-06-23 20:52:43 +05:30
|
|
|
if err1 := rows.Close(); err1 != nil {
|
2022-10-25 00:59:17 +05:30
|
|
|
return fmt.Errorf("IssueList.loadComments: Close: %w", err1)
|
2019-06-13 01:11:28 +05:30
|
|
|
}
|
2018-08-02 19:19:05 +05:30
|
|
|
return err
|
|
|
|
}
|
|
|
|
comments[comment.IssueID] = append(comments[comment.IssueID], &comment)
|
|
|
|
}
|
2019-06-23 20:52:43 +05:30
|
|
|
if err1 := rows.Close(); err1 != nil {
|
2022-10-25 00:59:17 +05:30
|
|
|
return fmt.Errorf("IssueList.loadComments: Close: %w", err1)
|
2019-06-13 01:11:28 +05:30
|
|
|
}
|
|
|
|
left -= limit
|
2018-08-02 19:19:05 +05:30
|
|
|
issuesIDs = issuesIDs[limit:]
|
2017-02-22 19:33:59 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
for _, issue := range issues {
|
|
|
|
issue.Comments = comments[issue.ID]
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2022-05-20 19:38:52 +05:30
|
|
|
func (issues IssueList) loadTotalTrackedTimes(ctx context.Context) (err error) {
|
2018-04-29 11:28:47 +05:30
|
|
|
type totalTimesByIssue struct {
|
|
|
|
IssueID int64
|
|
|
|
Time int64
|
|
|
|
}
|
|
|
|
if len(issues) == 0 {
|
|
|
|
return nil
|
|
|
|
}
|
2021-03-15 00:22:12 +05:30
|
|
|
trackedTimes := make(map[int64]int64, len(issues))
|
2018-04-29 11:28:47 +05:30
|
|
|
|
2024-03-12 10:27:19 +05:30
|
|
|
reposMap := make(map[int64]*repo_model.Repository, len(issues))
|
|
|
|
for _, issue := range issues {
|
|
|
|
reposMap[issue.RepoID] = issue.Repo
|
|
|
|
}
|
|
|
|
repos := repo_model.RepositoryListOfMap(reposMap)
|
|
|
|
|
|
|
|
if err := repos.LoadUnits(ctx); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2021-03-15 00:22:12 +05:30
|
|
|
ids := make([]int64, 0, len(issues))
|
2018-04-29 11:28:47 +05:30
|
|
|
for _, issue := range issues {
|
2022-12-10 08:16:31 +05:30
|
|
|
if issue.Repo.IsTimetrackerEnabled(ctx) {
|
2018-04-29 11:28:47 +05:30
|
|
|
ids = append(ids, issue.ID)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-15 00:22:12 +05:30
|
|
|
left := len(ids)
|
2018-08-02 19:19:05 +05:30
|
|
|
for left > 0 {
|
2022-06-13 15:07:59 +05:30
|
|
|
limit := db.DefaultMaxInSize
|
2018-08-02 19:19:05 +05:30
|
|
|
if left < limit {
|
|
|
|
limit = left
|
|
|
|
}
|
2018-04-29 11:28:47 +05:30
|
|
|
|
2018-08-02 19:19:05 +05:30
|
|
|
// select issue_id, sum(time) from tracked_time where issue_id in (<issue ids in current page>) group by issue_id
|
2022-05-20 19:38:52 +05:30
|
|
|
rows, err := db.GetEngine(ctx).Table("tracked_time").
|
2019-12-28 02:00:58 +05:30
|
|
|
Where("deleted = ?", false).
|
2018-08-02 19:19:05 +05:30
|
|
|
Select("issue_id, sum(time) as time").
|
|
|
|
In("issue_id", ids[:limit]).
|
|
|
|
GroupBy("issue_id").
|
|
|
|
Rows(new(totalTimesByIssue))
|
2018-04-29 11:28:47 +05:30
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2018-08-02 19:19:05 +05:30
|
|
|
|
|
|
|
for rows.Next() {
|
|
|
|
var totalTime totalTimesByIssue
|
|
|
|
err = rows.Scan(&totalTime)
|
|
|
|
if err != nil {
|
2019-06-23 20:52:43 +05:30
|
|
|
if err1 := rows.Close(); err1 != nil {
|
2022-10-25 00:59:17 +05:30
|
|
|
return fmt.Errorf("IssueList.loadTotalTrackedTimes: Close: %w", err1)
|
2019-06-13 01:11:28 +05:30
|
|
|
}
|
2018-08-02 19:19:05 +05:30
|
|
|
return err
|
|
|
|
}
|
|
|
|
trackedTimes[totalTime.IssueID] = totalTime.Time
|
|
|
|
}
|
2019-06-23 20:52:43 +05:30
|
|
|
if err1 := rows.Close(); err1 != nil {
|
2022-10-25 00:59:17 +05:30
|
|
|
return fmt.Errorf("IssueList.loadTotalTrackedTimes: Close: %w", err1)
|
2019-06-13 01:11:28 +05:30
|
|
|
}
|
|
|
|
left -= limit
|
2018-08-02 19:19:05 +05:30
|
|
|
ids = ids[limit:]
|
2018-04-29 11:28:47 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
for _, issue := range issues {
|
|
|
|
issue.TotalTrackedTime = trackedTimes[issue.ID]
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2017-11-21 10:58:22 +05:30
|
|
|
// loadAttributes loads all attributes, expect for attachments and comments
|
2023-07-22 19:44:27 +05:30
|
|
|
func (issues IssueList) LoadAttributes(ctx context.Context) error {
|
2022-11-19 13:42:33 +05:30
|
|
|
if _, err := issues.LoadRepositories(ctx); err != nil {
|
|
|
|
return fmt.Errorf("issue.loadAttributes: LoadRepositories: %w", err)
|
2017-02-22 19:33:59 +05:30
|
|
|
}
|
|
|
|
|
2022-05-20 19:38:52 +05:30
|
|
|
if err := issues.loadPosters(ctx); err != nil {
|
2022-10-25 00:59:17 +05:30
|
|
|
return fmt.Errorf("issue.loadAttributes: loadPosters: %w", err)
|
2017-02-22 19:33:59 +05:30
|
|
|
}
|
|
|
|
|
2022-05-20 19:38:52 +05:30
|
|
|
if err := issues.loadLabels(ctx); err != nil {
|
2022-10-25 00:59:17 +05:30
|
|
|
return fmt.Errorf("issue.loadAttributes: loadLabels: %w", err)
|
2017-02-22 19:33:59 +05:30
|
|
|
}
|
|
|
|
|
2022-05-20 19:38:52 +05:30
|
|
|
if err := issues.loadMilestones(ctx); err != nil {
|
2022-10-25 00:59:17 +05:30
|
|
|
return fmt.Errorf("issue.loadAttributes: loadMilestones: %w", err)
|
2017-02-22 19:33:59 +05:30
|
|
|
}
|
|
|
|
|
2023-06-24 21:01:28 +05:30
|
|
|
if err := issues.LoadProjects(ctx); err != nil {
|
2022-10-25 00:59:17 +05:30
|
|
|
return fmt.Errorf("issue.loadAttributes: loadProjects: %w", err)
|
2022-07-26 19:12:23 +05:30
|
|
|
}
|
|
|
|
|
2022-05-20 19:38:52 +05:30
|
|
|
if err := issues.loadAssignees(ctx); err != nil {
|
2022-10-25 00:59:17 +05:30
|
|
|
return fmt.Errorf("issue.loadAttributes: loadAssignees: %w", err)
|
2017-02-22 19:33:59 +05:30
|
|
|
}
|
|
|
|
|
2022-11-19 13:42:33 +05:30
|
|
|
if err := issues.LoadPullRequests(ctx); err != nil {
|
2022-10-25 00:59:17 +05:30
|
|
|
return fmt.Errorf("issue.loadAttributes: loadPullRequests: %w", err)
|
2017-02-22 19:33:59 +05:30
|
|
|
}
|
|
|
|
|
2022-05-20 19:38:52 +05:30
|
|
|
if err := issues.loadTotalTrackedTimes(ctx); err != nil {
|
2022-10-25 00:59:17 +05:30
|
|
|
return fmt.Errorf("issue.loadAttributes: loadTotalTrackedTimes: %w", err)
|
2018-04-29 11:28:47 +05:30
|
|
|
}
|
|
|
|
|
2017-02-22 19:33:59 +05:30
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2017-11-21 10:58:22 +05:30
|
|
|
// LoadComments loads comments
|
2022-11-19 13:42:33 +05:30
|
|
|
func (issues IssueList) LoadComments(ctx context.Context) error {
|
|
|
|
return issues.loadComments(ctx, builder.NewCond())
|
2019-02-19 20:09:39 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
// LoadDiscussComments loads discuss comments
|
2022-11-19 13:42:33 +05:30
|
|
|
func (issues IssueList) LoadDiscussComments(ctx context.Context) error {
|
|
|
|
return issues.loadComments(ctx, builder.Eq{"comment.type": CommentTypeComment})
|
2021-04-15 23:04:43 +05:30
|
|
|
}
|
|
|
|
|
2020-03-06 09:14:06 +05:30
|
|
|
// GetApprovalCounts returns a map of issue ID to slice of approval counts
|
|
|
|
// FIXME: only returns official counts due to double counting of non-official approvals
|
2022-05-20 19:38:52 +05:30
|
|
|
func (issues IssueList) GetApprovalCounts(ctx context.Context) (map[int64][]*ReviewCount, error) {
|
2020-04-16 16:14:34 +05:30
|
|
|
rCounts := make([]*ReviewCount, 0, 2*len(issues))
|
2020-03-06 09:14:06 +05:30
|
|
|
ids := make([]int64, len(issues))
|
|
|
|
for i, issue := range issues {
|
|
|
|
ids[i] = issue.ID
|
|
|
|
}
|
2022-05-20 19:38:52 +05:30
|
|
|
sess := db.GetEngine(ctx).In("issue_id", ids)
|
2020-04-16 16:14:34 +05:30
|
|
|
err := sess.Select("issue_id, type, count(id) as `count`").
|
2021-02-11 23:02:25 +05:30
|
|
|
Where("official = ? AND dismissed = ?", true, false).
|
2020-04-16 16:14:34 +05:30
|
|
|
GroupBy("issue_id, type").
|
|
|
|
OrderBy("issue_id").
|
|
|
|
Table("review").
|
|
|
|
Find(&rCounts)
|
2020-03-06 09:14:06 +05:30
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
approvalCountMap := make(map[int64][]*ReviewCount, len(issues))
|
2020-04-16 16:14:34 +05:30
|
|
|
|
|
|
|
for _, c := range rCounts {
|
|
|
|
approvalCountMap[c.IssueID] = append(approvalCountMap[c.IssueID], c)
|
2020-03-06 09:14:06 +05:30
|
|
|
}
|
2020-04-16 16:14:34 +05:30
|
|
|
|
2020-03-06 09:14:06 +05:30
|
|
|
return approvalCountMap, nil
|
|
|
|
}
|
2024-03-12 12:53:44 +05:30
|
|
|
|
|
|
|
func (issues IssueList) LoadIsRead(ctx context.Context, userID int64) error {
|
|
|
|
issueIDs := issues.getIssueIDs()
|
|
|
|
issueUsers := make([]*IssueUser, 0, len(issueIDs))
|
|
|
|
if err := db.GetEngine(ctx).Where("uid =?", userID).
|
2024-04-08 18:46:40 +05:30
|
|
|
In("issue_id", issueIDs).
|
2024-03-12 12:53:44 +05:30
|
|
|
Find(&issueUsers); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, issueUser := range issueUsers {
|
|
|
|
for _, issue := range issues {
|
|
|
|
if issue.ID == issueUser.IssueID {
|
|
|
|
issue.IsRead = issueUser.IsRead
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|