You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

issue.go 51 kB

11 years ago
Allow cross-repository dependencies on issues (#7901) * in progress changes for #7405, added ability to add cross-repo dependencies * removed unused repolink var * fixed query that was breaking ci tests; fixed check in issue dependency add so that the id of the issue and dependency is checked rather than the indexes * reverted removal of string in local files becasue these are done via crowdin, not updated manually * removed 'Select("issue.*")' from getBlockedByDependencies and getBlockingDependencies based on comments in PR review * changed getBlockedByDependencies and getBlockingDependencies to use a more xorm-like query, also updated the sidebar as a result * simplified the getBlockingDependencies and getBlockedByDependencies methods; changed the sidebar to show the dependencies in a different format where you can see the name of the repository * made some changes to the issue view in the dependencies (issue name on top, repo full name on separate line). Change view of issue in the dependency search results (also showing the full repo name on separate line) * replace call to FindUserAccessibleRepoIDs with SearchRepositoryByName. The former was hardcoded to use isPrivate = false on the repo search, but this code needed it to be true. The SearchRepositoryByName method is used more in the code including on the user's dashboard * some more tweaks to the layout of the issues when showing dependencies and in the search box when you add new dependencies * added Name to the RepositoryMeta struct * updated swagger doc * fixed total count for link header on SearchIssues * fixed indentation * fixed aligment of remove icon on dependencies in issue sidebar * removed unnecessary nil check (unnecessary because issue.loadRepo is called prior to this block) * reverting .css change, somehow missed or forgot that less is used * updated less file and generated css; updated sidebar template with styles to line up delete and issue index * added ordering to the blocked by/depends on queries * fixed sorting in issue dependency search and the depends on/blocks views to show issues from the current repo first, then by created date descending; added a "all cross repository dependencies" setting to allow this feature to be turned off, if turned off, the issue dependency search will work the way it did before (restricted to the current repository) * re-applied my swagger changes after merge * fixed split string condition in issue search * changed ALLOW_CROSS_REPOSITORY_DEPENDENCIES description to sound more global than just the issue dependency search; returning 400 in the cross repo issue search api method if not enabled; fixed bug where the issue count did not respect the state parameter * when adding a dependency to an issue, added a check to make sure the issue and dependency are in the same repo if cross repo dependencies is not enabled * updated sortIssuesSession call in PullRequests, another commit moved this method from pull.go to pull_list.go so I had to re-apply my change here * fixed incorrect setting of user id parameter in search repos call
5 years ago
11 years ago
11 years ago
Issue due date (#3794) * Started adding deadline to ui * Implemented basic issue due date managing * Improved UI for due date managing * Added at least write access to the repo in order to modify issue due dates * Ui improvements * Added issue comments creation when adding/modifying/removing a due date * Show due date in issue list * Added api support for issue due dates * Fixed lint suggestions * Added deadline to sdk * Updated css * Added support for adding/modifiying deadlines for pull requests via api * Fixed comments not created when updating or removing a deadline * update sdk (will do properly once go-gitea/go-sdk#103 is merged) * enhanced updateIssueDeadline * Removed unnessecary Issue.DeadlineString * UI improvements * Small improvments to comment creation + ui & validation improvements * Check if an issue is overdue is now a seperate function * Updated go-sdk with govendor as it was merged * Simplified isOverdue method * removed unessecary deadline to 0 set * Update swagger definitions * Added missing return * Added an explanary comment * Improved updateIssueDeadline method so it'll only update `deadline_unix` * Small changes and improvements * no need to explicitly load the issue when updating a deadline, just use whats already there * small optimisations * Added check if a deadline was modified before updating it * Moved comment creating logic into its own function * Code cleanup for creating deadline comment * locale improvement * When modifying a deadline, the old deadline is saved with the comment * small improvments to xorm session handling when updating an issue deadline + style nitpicks * style nitpicks * Moved checking for if the user has write acces to middleware
7 years ago
Shows total tracked time in issue and milestone list (#3341) * Show total tracked time in issue and milestone list Show total tracked time at issue page Signed-off-by: Jonas Franz <info@jonasfranz.software> * Optimizing TotalTimes by using SumInt Signed-off-by: Jonas Franz <info@jonasfranz.software> * Fixing wrong total times for milestones caused by a missing JOIN Adding unit tests for total times Signed-off-by: Jonas Franz <info@jonasfranz.software> * Logging error instead of ignoring it Signed-off-by: Jonas Franz <info@jonasfranz.software> * Correcting spelling mistakes Signed-off-by: Jonas Franz <info@jonasfranz.software> * Change error message to a short version Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add error handling to TotalTimes Add variable for totalTimes Signed-off-by: Jonas Franz <info@jonasfranz.de> * Introduce TotalTrackedTimes as variable of issue Load TotalTrackedTimes by loading attributes of IssueList Load TotalTrackedTimes by loading attributes of single issue Add Sec2Time as helper to use it in templates Signed-off-by: Jonas Franz <info@jonasfranz.software> * Fixed test + gofmt Signed-off-by: Jonas Franz <info@jonasfranz.software> * Load TotalTrackedTimes via MilestoneList instead of single requests Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add documentation for MilestoneList Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add documentation for MilestoneList Signed-off-by: Jonas Franz <info@jonasfranz.software> * Fix test Signed-off-by: Jonas Franz <info@jonasfranz.software> * Change comment from SQL query to description Signed-off-by: Jonas Franz <info@jonasfranz.software> * Fix unit test by using int64 instead of int Signed-off-by: Jonas Franz <info@jonasfranz.software> * Fix unit test by using int64 instead of int Signed-off-by: Jonas Franz <info@jonasfranz.software> * Check if timetracker is enabled Signed-off-by: Jonas Franz <info@jonasfranz.software> * Fix test by enabling timetracking Signed-off-by: Jonas Franz <info@jonasfranz.de>
7 years ago
Shows total tracked time in issue and milestone list (#3341) * Show total tracked time in issue and milestone list Show total tracked time at issue page Signed-off-by: Jonas Franz <info@jonasfranz.software> * Optimizing TotalTimes by using SumInt Signed-off-by: Jonas Franz <info@jonasfranz.software> * Fixing wrong total times for milestones caused by a missing JOIN Adding unit tests for total times Signed-off-by: Jonas Franz <info@jonasfranz.software> * Logging error instead of ignoring it Signed-off-by: Jonas Franz <info@jonasfranz.software> * Correcting spelling mistakes Signed-off-by: Jonas Franz <info@jonasfranz.software> * Change error message to a short version Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add error handling to TotalTimes Add variable for totalTimes Signed-off-by: Jonas Franz <info@jonasfranz.de> * Introduce TotalTrackedTimes as variable of issue Load TotalTrackedTimes by loading attributes of IssueList Load TotalTrackedTimes by loading attributes of single issue Add Sec2Time as helper to use it in templates Signed-off-by: Jonas Franz <info@jonasfranz.software> * Fixed test + gofmt Signed-off-by: Jonas Franz <info@jonasfranz.software> * Load TotalTrackedTimes via MilestoneList instead of single requests Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add documentation for MilestoneList Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add documentation for MilestoneList Signed-off-by: Jonas Franz <info@jonasfranz.software> * Fix test Signed-off-by: Jonas Franz <info@jonasfranz.software> * Change comment from SQL query to description Signed-off-by: Jonas Franz <info@jonasfranz.software> * Fix unit test by using int64 instead of int Signed-off-by: Jonas Franz <info@jonasfranz.software> * Fix unit test by using int64 instead of int Signed-off-by: Jonas Franz <info@jonasfranz.software> * Check if timetracker is enabled Signed-off-by: Jonas Franz <info@jonasfranz.software> * Fix test by enabling timetracking Signed-off-by: Jonas Franz <info@jonasfranz.de>
7 years ago
Issue due date (#3794) * Started adding deadline to ui * Implemented basic issue due date managing * Improved UI for due date managing * Added at least write access to the repo in order to modify issue due dates * Ui improvements * Added issue comments creation when adding/modifying/removing a due date * Show due date in issue list * Added api support for issue due dates * Fixed lint suggestions * Added deadline to sdk * Updated css * Added support for adding/modifiying deadlines for pull requests via api * Fixed comments not created when updating or removing a deadline * update sdk (will do properly once go-gitea/go-sdk#103 is merged) * enhanced updateIssueDeadline * Removed unnessecary Issue.DeadlineString * UI improvements * Small improvments to comment creation + ui & validation improvements * Check if an issue is overdue is now a seperate function * Updated go-sdk with govendor as it was merged * Simplified isOverdue method * removed unessecary deadline to 0 set * Update swagger definitions * Added missing return * Added an explanary comment * Improved updateIssueDeadline method so it'll only update `deadline_unix` * Small changes and improvements * no need to explicitly load the issue when updating a deadline, just use whats already there * small optimisations * Added check if a deadline was modified before updating it * Moved comment creating logic into its own function * Code cleanup for creating deadline comment * locale improvement * When modifying a deadline, the old deadline is saved with the comment * small improvments to xorm session handling when updating an issue deadline + style nitpicks * style nitpicks * Moved checking for if the user has write acces to middleware
7 years ago
Issue due date (#3794) * Started adding deadline to ui * Implemented basic issue due date managing * Improved UI for due date managing * Added at least write access to the repo in order to modify issue due dates * Ui improvements * Added issue comments creation when adding/modifying/removing a due date * Show due date in issue list * Added api support for issue due dates * Fixed lint suggestions * Added deadline to sdk * Updated css * Added support for adding/modifiying deadlines for pull requests via api * Fixed comments not created when updating or removing a deadline * update sdk (will do properly once go-gitea/go-sdk#103 is merged) * enhanced updateIssueDeadline * Removed unnessecary Issue.DeadlineString * UI improvements * Small improvments to comment creation + ui & validation improvements * Check if an issue is overdue is now a seperate function * Updated go-sdk with govendor as it was merged * Simplified isOverdue method * removed unessecary deadline to 0 set * Update swagger definitions * Added missing return * Added an explanary comment * Improved updateIssueDeadline method so it'll only update `deadline_unix` * Small changes and improvements * no need to explicitly load the issue when updating a deadline, just use whats already there * small optimisations * Added check if a deadline was modified before updating it * Moved comment creating logic into its own function * Code cleanup for creating deadline comment * locale improvement * When modifying a deadline, the old deadline is saved with the comment * small improvments to xorm session handling when updating an issue deadline + style nitpicks * style nitpicks * Moved checking for if the user has write acces to middleware
7 years ago
Shows total tracked time in issue and milestone list (#3341) * Show total tracked time in issue and milestone list Show total tracked time at issue page Signed-off-by: Jonas Franz <info@jonasfranz.software> * Optimizing TotalTimes by using SumInt Signed-off-by: Jonas Franz <info@jonasfranz.software> * Fixing wrong total times for milestones caused by a missing JOIN Adding unit tests for total times Signed-off-by: Jonas Franz <info@jonasfranz.software> * Logging error instead of ignoring it Signed-off-by: Jonas Franz <info@jonasfranz.software> * Correcting spelling mistakes Signed-off-by: Jonas Franz <info@jonasfranz.software> * Change error message to a short version Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add error handling to TotalTimes Add variable for totalTimes Signed-off-by: Jonas Franz <info@jonasfranz.de> * Introduce TotalTrackedTimes as variable of issue Load TotalTrackedTimes by loading attributes of IssueList Load TotalTrackedTimes by loading attributes of single issue Add Sec2Time as helper to use it in templates Signed-off-by: Jonas Franz <info@jonasfranz.software> * Fixed test + gofmt Signed-off-by: Jonas Franz <info@jonasfranz.software> * Load TotalTrackedTimes via MilestoneList instead of single requests Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add documentation for MilestoneList Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add documentation for MilestoneList Signed-off-by: Jonas Franz <info@jonasfranz.software> * Fix test Signed-off-by: Jonas Franz <info@jonasfranz.software> * Change comment from SQL query to description Signed-off-by: Jonas Franz <info@jonasfranz.software> * Fix unit test by using int64 instead of int Signed-off-by: Jonas Franz <info@jonasfranz.software> * Fix unit test by using int64 instead of int Signed-off-by: Jonas Franz <info@jonasfranz.software> * Check if timetracker is enabled Signed-off-by: Jonas Franz <info@jonasfranz.software> * Fix test by enabling timetracking Signed-off-by: Jonas Franz <info@jonasfranz.de>
7 years ago
Better logging (#6038) (#6095) * Panic don't fatal on create new logger Fixes #5854 Signed-off-by: Andrew Thornton <art27@cantab.net> * partial broken * Update the logging infrastrcture Signed-off-by: Andrew Thornton <art27@cantab.net> * Reset the skip levels for Fatal and Error Signed-off-by: Andrew Thornton <art27@cantab.net> * broken ncsa * More log.Error fixes Signed-off-by: Andrew Thornton <art27@cantab.net> * Remove nal * set log-levels to lowercase * Make console_test test all levels * switch to lowercased levels * OK now working * Fix vetting issues * Fix lint * Fix tests * change default logging to match current gitea * Improve log testing Signed-off-by: Andrew Thornton <art27@cantab.net> * reset error skip levels to 0 * Update documentation and access logger configuration * Redirect the router log back to gitea if redirect macaron log but also allow setting the log level - i.e. TRACE * Fix broken level caching * Refactor the router log * Add Router logger * Add colorizing options * Adjust router colors * Only create logger if they will be used * update app.ini.sample * rename Attribute ColorAttribute * Change from white to green for function * Set fatal/error levels * Restore initial trace logger * Fix Trace arguments in modules/auth/auth.go * Properly handle XORMLogger * Improve admin/config page * fix fmt * Add auto-compression of old logs * Update error log levels * Remove the unnecessary skip argument from Error, Fatal and Critical * Add stacktrace support * Fix tests * Remove x/sync from vendors? * Add stderr option to console logger * Use filepath.ToSlash to protect against Windows in tests * Remove prefixed underscores from names in colors.go * Remove not implemented database logger This was removed from Gogs on 4 Mar 2016 but left in the configuration since then. * Ensure that log paths are relative to ROOT_PATH * use path.Join * rename jsonConfig to logConfig * Rename "config" to "jsonConfig" to make it clearer * Requested changes * Requested changes: XormLogger * Try to color the windows terminal If successful default to colorizing the console logs * fixup * Colorize initially too * update vendor * Colorize logs on default and remove if this is not a colorizing logger * Fix documentation * fix test * Use go-isatty to detect if on windows we are on msys or cygwin * Fix spelling mistake * Add missing vendors * More changes * Rationalise the ANSI writer protection * Adjust colors on advice from @0x5c * Make Flags a comma separated list * Move to use the windows constant for ENABLE_VIRTUAL_TERMINAL_PROCESSING * Ensure matching is done on the non-colored message - to simpify EXPRESSION
6 years ago
Shows total tracked time in issue and milestone list (#3341) * Show total tracked time in issue and milestone list Show total tracked time at issue page Signed-off-by: Jonas Franz <info@jonasfranz.software> * Optimizing TotalTimes by using SumInt Signed-off-by: Jonas Franz <info@jonasfranz.software> * Fixing wrong total times for milestones caused by a missing JOIN Adding unit tests for total times Signed-off-by: Jonas Franz <info@jonasfranz.software> * Logging error instead of ignoring it Signed-off-by: Jonas Franz <info@jonasfranz.software> * Correcting spelling mistakes Signed-off-by: Jonas Franz <info@jonasfranz.software> * Change error message to a short version Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add error handling to TotalTimes Add variable for totalTimes Signed-off-by: Jonas Franz <info@jonasfranz.de> * Introduce TotalTrackedTimes as variable of issue Load TotalTrackedTimes by loading attributes of IssueList Load TotalTrackedTimes by loading attributes of single issue Add Sec2Time as helper to use it in templates Signed-off-by: Jonas Franz <info@jonasfranz.software> * Fixed test + gofmt Signed-off-by: Jonas Franz <info@jonasfranz.software> * Load TotalTrackedTimes via MilestoneList instead of single requests Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add documentation for MilestoneList Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add documentation for MilestoneList Signed-off-by: Jonas Franz <info@jonasfranz.software> * Fix test Signed-off-by: Jonas Franz <info@jonasfranz.software> * Change comment from SQL query to description Signed-off-by: Jonas Franz <info@jonasfranz.software> * Fix unit test by using int64 instead of int Signed-off-by: Jonas Franz <info@jonasfranz.software> * Fix unit test by using int64 instead of int Signed-off-by: Jonas Franz <info@jonasfranz.software> * Check if timetracker is enabled Signed-off-by: Jonas Franz <info@jonasfranz.software> * Fix test by enabling timetracking Signed-off-by: Jonas Franz <info@jonasfranz.de>
7 years ago
Shows total tracked time in issue and milestone list (#3341) * Show total tracked time in issue and milestone list Show total tracked time at issue page Signed-off-by: Jonas Franz <info@jonasfranz.software> * Optimizing TotalTimes by using SumInt Signed-off-by: Jonas Franz <info@jonasfranz.software> * Fixing wrong total times for milestones caused by a missing JOIN Adding unit tests for total times Signed-off-by: Jonas Franz <info@jonasfranz.software> * Logging error instead of ignoring it Signed-off-by: Jonas Franz <info@jonasfranz.software> * Correcting spelling mistakes Signed-off-by: Jonas Franz <info@jonasfranz.software> * Change error message to a short version Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add error handling to TotalTimes Add variable for totalTimes Signed-off-by: Jonas Franz <info@jonasfranz.de> * Introduce TotalTrackedTimes as variable of issue Load TotalTrackedTimes by loading attributes of IssueList Load TotalTrackedTimes by loading attributes of single issue Add Sec2Time as helper to use it in templates Signed-off-by: Jonas Franz <info@jonasfranz.software> * Fixed test + gofmt Signed-off-by: Jonas Franz <info@jonasfranz.software> * Load TotalTrackedTimes via MilestoneList instead of single requests Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add documentation for MilestoneList Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add documentation for MilestoneList Signed-off-by: Jonas Franz <info@jonasfranz.software> * Fix test Signed-off-by: Jonas Franz <info@jonasfranz.software> * Change comment from SQL query to description Signed-off-by: Jonas Franz <info@jonasfranz.software> * Fix unit test by using int64 instead of int Signed-off-by: Jonas Franz <info@jonasfranz.software> * Fix unit test by using int64 instead of int Signed-off-by: Jonas Franz <info@jonasfranz.software> * Check if timetracker is enabled Signed-off-by: Jonas Franz <info@jonasfranz.software> * Fix test by enabling timetracking Signed-off-by: Jonas Franz <info@jonasfranz.de>
7 years ago
9 years ago
8 years ago
8 years ago
Allow cross-repository dependencies on issues (#7901) * in progress changes for #7405, added ability to add cross-repo dependencies * removed unused repolink var * fixed query that was breaking ci tests; fixed check in issue dependency add so that the id of the issue and dependency is checked rather than the indexes * reverted removal of string in local files becasue these are done via crowdin, not updated manually * removed 'Select("issue.*")' from getBlockedByDependencies and getBlockingDependencies based on comments in PR review * changed getBlockedByDependencies and getBlockingDependencies to use a more xorm-like query, also updated the sidebar as a result * simplified the getBlockingDependencies and getBlockedByDependencies methods; changed the sidebar to show the dependencies in a different format where you can see the name of the repository * made some changes to the issue view in the dependencies (issue name on top, repo full name on separate line). Change view of issue in the dependency search results (also showing the full repo name on separate line) * replace call to FindUserAccessibleRepoIDs with SearchRepositoryByName. The former was hardcoded to use isPrivate = false on the repo search, but this code needed it to be true. The SearchRepositoryByName method is used more in the code including on the user's dashboard * some more tweaks to the layout of the issues when showing dependencies and in the search box when you add new dependencies * added Name to the RepositoryMeta struct * updated swagger doc * fixed total count for link header on SearchIssues * fixed indentation * fixed aligment of remove icon on dependencies in issue sidebar * removed unnecessary nil check (unnecessary because issue.loadRepo is called prior to this block) * reverting .css change, somehow missed or forgot that less is used * updated less file and generated css; updated sidebar template with styles to line up delete and issue index * added ordering to the blocked by/depends on queries * fixed sorting in issue dependency search and the depends on/blocks views to show issues from the current repo first, then by created date descending; added a "all cross repository dependencies" setting to allow this feature to be turned off, if turned off, the issue dependency search will work the way it did before (restricted to the current repository) * re-applied my swagger changes after merge * fixed split string condition in issue search * changed ALLOW_CROSS_REPOSITORY_DEPENDENCIES description to sound more global than just the issue dependency search; returning 400 in the cross repo issue search api method if not enabled; fixed bug where the issue count did not respect the state parameter * when adding a dependency to an issue, added a check to make sure the issue and dependency are in the same repo if cross repo dependencies is not enabled * updated sortIssuesSession call in PullRequests, another commit moved this method from pull.go to pull_list.go so I had to re-apply my change here * fixed incorrect setting of user id parameter in search repos call
5 years ago
Issue due date (#3794) * Started adding deadline to ui * Implemented basic issue due date managing * Improved UI for due date managing * Added at least write access to the repo in order to modify issue due dates * Ui improvements * Added issue comments creation when adding/modifying/removing a due date * Show due date in issue list * Added api support for issue due dates * Fixed lint suggestions * Added deadline to sdk * Updated css * Added support for adding/modifiying deadlines for pull requests via api * Fixed comments not created when updating or removing a deadline * update sdk (will do properly once go-gitea/go-sdk#103 is merged) * enhanced updateIssueDeadline * Removed unnessecary Issue.DeadlineString * UI improvements * Small improvments to comment creation + ui & validation improvements * Check if an issue is overdue is now a seperate function * Updated go-sdk with govendor as it was merged * Simplified isOverdue method * removed unessecary deadline to 0 set * Update swagger definitions * Added missing return * Added an explanary comment * Improved updateIssueDeadline method so it'll only update `deadline_unix` * Small changes and improvements * no need to explicitly load the issue when updating a deadline, just use whats already there * small optimisations * Added check if a deadline was modified before updating it * Moved comment creating logic into its own function * Code cleanup for creating deadline comment * locale improvement * When modifying a deadline, the old deadline is saved with the comment * small improvments to xorm session handling when updating an issue deadline + style nitpicks * style nitpicks * Moved checking for if the user has write acces to middleware
7 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
11 years ago
Allow cross-repository dependencies on issues (#7901) * in progress changes for #7405, added ability to add cross-repo dependencies * removed unused repolink var * fixed query that was breaking ci tests; fixed check in issue dependency add so that the id of the issue and dependency is checked rather than the indexes * reverted removal of string in local files becasue these are done via crowdin, not updated manually * removed 'Select("issue.*")' from getBlockedByDependencies and getBlockingDependencies based on comments in PR review * changed getBlockedByDependencies and getBlockingDependencies to use a more xorm-like query, also updated the sidebar as a result * simplified the getBlockingDependencies and getBlockedByDependencies methods; changed the sidebar to show the dependencies in a different format where you can see the name of the repository * made some changes to the issue view in the dependencies (issue name on top, repo full name on separate line). Change view of issue in the dependency search results (also showing the full repo name on separate line) * replace call to FindUserAccessibleRepoIDs with SearchRepositoryByName. The former was hardcoded to use isPrivate = false on the repo search, but this code needed it to be true. The SearchRepositoryByName method is used more in the code including on the user's dashboard * some more tweaks to the layout of the issues when showing dependencies and in the search box when you add new dependencies * added Name to the RepositoryMeta struct * updated swagger doc * fixed total count for link header on SearchIssues * fixed indentation * fixed aligment of remove icon on dependencies in issue sidebar * removed unnecessary nil check (unnecessary because issue.loadRepo is called prior to this block) * reverting .css change, somehow missed or forgot that less is used * updated less file and generated css; updated sidebar template with styles to line up delete and issue index * added ordering to the blocked by/depends on queries * fixed sorting in issue dependency search and the depends on/blocks views to show issues from the current repo first, then by created date descending; added a "all cross repository dependencies" setting to allow this feature to be turned off, if turned off, the issue dependency search will work the way it did before (restricted to the current repository) * re-applied my swagger changes after merge * fixed split string condition in issue search * changed ALLOW_CROSS_REPOSITORY_DEPENDENCIES description to sound more global than just the issue dependency search; returning 400 in the cross repo issue search api method if not enabled; fixed bug where the issue count did not respect the state parameter * when adding a dependency to an issue, added a check to make sure the issue and dependency are in the same repo if cross repo dependencies is not enabled * updated sortIssuesSession call in PullRequests, another commit moved this method from pull.go to pull_list.go so I had to re-apply my change here * fixed incorrect setting of user id parameter in search repos call
5 years ago
Allow cross-repository dependencies on issues (#7901) * in progress changes for #7405, added ability to add cross-repo dependencies * removed unused repolink var * fixed query that was breaking ci tests; fixed check in issue dependency add so that the id of the issue and dependency is checked rather than the indexes * reverted removal of string in local files becasue these are done via crowdin, not updated manually * removed 'Select("issue.*")' from getBlockedByDependencies and getBlockingDependencies based on comments in PR review * changed getBlockedByDependencies and getBlockingDependencies to use a more xorm-like query, also updated the sidebar as a result * simplified the getBlockingDependencies and getBlockedByDependencies methods; changed the sidebar to show the dependencies in a different format where you can see the name of the repository * made some changes to the issue view in the dependencies (issue name on top, repo full name on separate line). Change view of issue in the dependency search results (also showing the full repo name on separate line) * replace call to FindUserAccessibleRepoIDs with SearchRepositoryByName. The former was hardcoded to use isPrivate = false on the repo search, but this code needed it to be true. The SearchRepositoryByName method is used more in the code including on the user's dashboard * some more tweaks to the layout of the issues when showing dependencies and in the search box when you add new dependencies * added Name to the RepositoryMeta struct * updated swagger doc * fixed total count for link header on SearchIssues * fixed indentation * fixed aligment of remove icon on dependencies in issue sidebar * removed unnecessary nil check (unnecessary because issue.loadRepo is called prior to this block) * reverting .css change, somehow missed or forgot that less is used * updated less file and generated css; updated sidebar template with styles to line up delete and issue index * added ordering to the blocked by/depends on queries * fixed sorting in issue dependency search and the depends on/blocks views to show issues from the current repo first, then by created date descending; added a "all cross repository dependencies" setting to allow this feature to be turned off, if turned off, the issue dependency search will work the way it did before (restricted to the current repository) * re-applied my swagger changes after merge * fixed split string condition in issue search * changed ALLOW_CROSS_REPOSITORY_DEPENDENCIES description to sound more global than just the issue dependency search; returning 400 in the cross repo issue search api method if not enabled; fixed bug where the issue count did not respect the state parameter * when adding a dependency to an issue, added a check to make sure the issue and dependency are in the same repo if cross repo dependencies is not enabled * updated sortIssuesSession call in PullRequests, another commit moved this method from pull.go to pull_list.go so I had to re-apply my change here * fixed incorrect setting of user id parameter in search repos call
5 years ago
Allow cross-repository dependencies on issues (#7901) * in progress changes for #7405, added ability to add cross-repo dependencies * removed unused repolink var * fixed query that was breaking ci tests; fixed check in issue dependency add so that the id of the issue and dependency is checked rather than the indexes * reverted removal of string in local files becasue these are done via crowdin, not updated manually * removed 'Select("issue.*")' from getBlockedByDependencies and getBlockingDependencies based on comments in PR review * changed getBlockedByDependencies and getBlockingDependencies to use a more xorm-like query, also updated the sidebar as a result * simplified the getBlockingDependencies and getBlockedByDependencies methods; changed the sidebar to show the dependencies in a different format where you can see the name of the repository * made some changes to the issue view in the dependencies (issue name on top, repo full name on separate line). Change view of issue in the dependency search results (also showing the full repo name on separate line) * replace call to FindUserAccessibleRepoIDs with SearchRepositoryByName. The former was hardcoded to use isPrivate = false on the repo search, but this code needed it to be true. The SearchRepositoryByName method is used more in the code including on the user's dashboard * some more tweaks to the layout of the issues when showing dependencies and in the search box when you add new dependencies * added Name to the RepositoryMeta struct * updated swagger doc * fixed total count for link header on SearchIssues * fixed indentation * fixed aligment of remove icon on dependencies in issue sidebar * removed unnecessary nil check (unnecessary because issue.loadRepo is called prior to this block) * reverting .css change, somehow missed or forgot that less is used * updated less file and generated css; updated sidebar template with styles to line up delete and issue index * added ordering to the blocked by/depends on queries * fixed sorting in issue dependency search and the depends on/blocks views to show issues from the current repo first, then by created date descending; added a "all cross repository dependencies" setting to allow this feature to be turned off, if turned off, the issue dependency search will work the way it did before (restricted to the current repository) * re-applied my swagger changes after merge * fixed split string condition in issue search * changed ALLOW_CROSS_REPOSITORY_DEPENDENCIES description to sound more global than just the issue dependency search; returning 400 in the cross repo issue search api method if not enabled; fixed bug where the issue count did not respect the state parameter * when adding a dependency to an issue, added a check to make sure the issue and dependency are in the same repo if cross repo dependencies is not enabled * updated sortIssuesSession call in PullRequests, another commit moved this method from pull.go to pull_list.go so I had to re-apply my change here * fixed incorrect setting of user id parameter in search repos call
5 years ago
11 years ago
11 years ago
Allow cross-repository dependencies on issues (#7901) * in progress changes for #7405, added ability to add cross-repo dependencies * removed unused repolink var * fixed query that was breaking ci tests; fixed check in issue dependency add so that the id of the issue and dependency is checked rather than the indexes * reverted removal of string in local files becasue these are done via crowdin, not updated manually * removed 'Select("issue.*")' from getBlockedByDependencies and getBlockingDependencies based on comments in PR review * changed getBlockedByDependencies and getBlockingDependencies to use a more xorm-like query, also updated the sidebar as a result * simplified the getBlockingDependencies and getBlockedByDependencies methods; changed the sidebar to show the dependencies in a different format where you can see the name of the repository * made some changes to the issue view in the dependencies (issue name on top, repo full name on separate line). Change view of issue in the dependency search results (also showing the full repo name on separate line) * replace call to FindUserAccessibleRepoIDs with SearchRepositoryByName. The former was hardcoded to use isPrivate = false on the repo search, but this code needed it to be true. The SearchRepositoryByName method is used more in the code including on the user's dashboard * some more tweaks to the layout of the issues when showing dependencies and in the search box when you add new dependencies * added Name to the RepositoryMeta struct * updated swagger doc * fixed total count for link header on SearchIssues * fixed indentation * fixed aligment of remove icon on dependencies in issue sidebar * removed unnecessary nil check (unnecessary because issue.loadRepo is called prior to this block) * reverting .css change, somehow missed or forgot that less is used * updated less file and generated css; updated sidebar template with styles to line up delete and issue index * added ordering to the blocked by/depends on queries * fixed sorting in issue dependency search and the depends on/blocks views to show issues from the current repo first, then by created date descending; added a "all cross repository dependencies" setting to allow this feature to be turned off, if turned off, the issue dependency search will work the way it did before (restricted to the current repository) * re-applied my swagger changes after merge * fixed split string condition in issue search * changed ALLOW_CROSS_REPOSITORY_DEPENDENCIES description to sound more global than just the issue dependency search; returning 400 in the cross repo issue search api method if not enabled; fixed bug where the issue count did not respect the state parameter * when adding a dependency to an issue, added a check to make sure the issue and dependency are in the same repo if cross repo dependencies is not enabled * updated sortIssuesSession call in PullRequests, another commit moved this method from pull.go to pull_list.go so I had to re-apply my change here * fixed incorrect setting of user id parameter in search repos call
5 years ago
11 years ago
[UI] IssuePage multi repo select (#8741) * Make repository list @ issues/PR page persist Will partially fix #6355 * Enable multiple selections in repo list @ issues/PR page Part of issue #6355 * Add RepoIDs to UserIssueStatsOptions to make "type" count correct when selecting one/multiple repos. * Replace variable "repo" with list "repos[]" and enable multiple selections of repositories from list by including/excluding RepoIDs in list. * * Remove redundant code * Add 'All' button Improves functionality of the page, so that backtracking is not necessary to reset the page * Remove redundant variable Completely replace 'RepoID' with 'RepoIDs' and remove redundant code * Add RepoIDs to label link * Revert part of code to previous version to troubleshoot build failure * Implement old and new pieces of code whilst adhering to multi select * Attempt to join the two versions Last commit passed tests but doesn't work in practice, this works in practice and hopefully passes the tests. * Update tests to desired state * Fix pagination implementation and tests * Pass repoIDs as `repos=[1,2,3...]` instead of several `repos[]=..` * Update tests file to reflect new functionality * Update template with new `repos` format * Implement new solution to show constant "total issues" count for "All" button * Correct behavior when passing zero to array * Comment out test url returning 404 This keeps returning 404 in the test despite working in practice, for the sake of running more tests I am commenting it out * Comment out another test url returning 404 Last attempt, if more tests crash I will uncomment the urls and request assistance. * Reenable tests and test fix * Re-enable tests * Make selecting "In your repositories" reset selection as passing IDs of repos belonging to other profiles causes breakage * Remove unnecessary (with multi-selection enable) code * Drop repo from repo map and total count if permission denied * Remove extra parenthesis * make template work again * find bug! * forgot the '#' at bugfixing * delete unused RepoID * compile regex only one time * make fmt * local variable = capital letter lower * check if repos query pattern is correct * pagination remove last , - make regex work again * use Replace instead of ReplaceAll; del delete * fix test * how did this test binary got in?!? dont forgot the "-p" at git add * ! * dont replace -> cut fisrt & last string Co-Authored-By: zeripath <art27@cantab.net> * jet another regex dont mind as long as it has the same result and is performatn ... Co-Authored-By: zeripath <art27@cantab.net> * dont use nonexisting repo for test * exclude /issues?type=created_by from test * add table to querys use same syntax in each query (table.colum) * add new issue for test * dont make a workaround or something else this need a refactor itself and is out of scope for this PR * fix misspell * CI.redo() * englisch txt update Co-Authored-By: zeripath <art27@cantab.net> * add sugestions * Tweak & Fix * CI.restart()
5 years ago
[UI] IssuePage multi repo select (#8741) * Make repository list @ issues/PR page persist Will partially fix #6355 * Enable multiple selections in repo list @ issues/PR page Part of issue #6355 * Add RepoIDs to UserIssueStatsOptions to make "type" count correct when selecting one/multiple repos. * Replace variable "repo" with list "repos[]" and enable multiple selections of repositories from list by including/excluding RepoIDs in list. * * Remove redundant code * Add 'All' button Improves functionality of the page, so that backtracking is not necessary to reset the page * Remove redundant variable Completely replace 'RepoID' with 'RepoIDs' and remove redundant code * Add RepoIDs to label link * Revert part of code to previous version to troubleshoot build failure * Implement old and new pieces of code whilst adhering to multi select * Attempt to join the two versions Last commit passed tests but doesn't work in practice, this works in practice and hopefully passes the tests. * Update tests to desired state * Fix pagination implementation and tests * Pass repoIDs as `repos=[1,2,3...]` instead of several `repos[]=..` * Update tests file to reflect new functionality * Update template with new `repos` format * Implement new solution to show constant "total issues" count for "All" button * Correct behavior when passing zero to array * Comment out test url returning 404 This keeps returning 404 in the test despite working in practice, for the sake of running more tests I am commenting it out * Comment out another test url returning 404 Last attempt, if more tests crash I will uncomment the urls and request assistance. * Reenable tests and test fix * Re-enable tests * Make selecting "In your repositories" reset selection as passing IDs of repos belonging to other profiles causes breakage * Remove unnecessary (with multi-selection enable) code * Drop repo from repo map and total count if permission denied * Remove extra parenthesis * make template work again * find bug! * forgot the '#' at bugfixing * delete unused RepoID * compile regex only one time * make fmt * local variable = capital letter lower * check if repos query pattern is correct * pagination remove last , - make regex work again * use Replace instead of ReplaceAll; del delete * fix test * how did this test binary got in?!? dont forgot the "-p" at git add * ! * dont replace -> cut fisrt & last string Co-Authored-By: zeripath <art27@cantab.net> * jet another regex dont mind as long as it has the same result and is performatn ... Co-Authored-By: zeripath <art27@cantab.net> * dont use nonexisting repo for test * exclude /issues?type=created_by from test * add table to querys use same syntax in each query (table.colum) * add new issue for test * dont make a workaround or something else this need a refactor itself and is out of scope for this PR * fix misspell * CI.redo() * englisch txt update Co-Authored-By: zeripath <art27@cantab.net> * add sugestions * Tweak & Fix * CI.restart()
5 years ago
[UI] IssuePage multi repo select (#8741) * Make repository list @ issues/PR page persist Will partially fix #6355 * Enable multiple selections in repo list @ issues/PR page Part of issue #6355 * Add RepoIDs to UserIssueStatsOptions to make "type" count correct when selecting one/multiple repos. * Replace variable "repo" with list "repos[]" and enable multiple selections of repositories from list by including/excluding RepoIDs in list. * * Remove redundant code * Add 'All' button Improves functionality of the page, so that backtracking is not necessary to reset the page * Remove redundant variable Completely replace 'RepoID' with 'RepoIDs' and remove redundant code * Add RepoIDs to label link * Revert part of code to previous version to troubleshoot build failure * Implement old and new pieces of code whilst adhering to multi select * Attempt to join the two versions Last commit passed tests but doesn't work in practice, this works in practice and hopefully passes the tests. * Update tests to desired state * Fix pagination implementation and tests * Pass repoIDs as `repos=[1,2,3...]` instead of several `repos[]=..` * Update tests file to reflect new functionality * Update template with new `repos` format * Implement new solution to show constant "total issues" count for "All" button * Correct behavior when passing zero to array * Comment out test url returning 404 This keeps returning 404 in the test despite working in practice, for the sake of running more tests I am commenting it out * Comment out another test url returning 404 Last attempt, if more tests crash I will uncomment the urls and request assistance. * Reenable tests and test fix * Re-enable tests * Make selecting "In your repositories" reset selection as passing IDs of repos belonging to other profiles causes breakage * Remove unnecessary (with multi-selection enable) code * Drop repo from repo map and total count if permission denied * Remove extra parenthesis * make template work again * find bug! * forgot the '#' at bugfixing * delete unused RepoID * compile regex only one time * make fmt * local variable = capital letter lower * check if repos query pattern is correct * pagination remove last , - make regex work again * use Replace instead of ReplaceAll; del delete * fix test * how did this test binary got in?!? dont forgot the "-p" at git add * ! * dont replace -> cut fisrt & last string Co-Authored-By: zeripath <art27@cantab.net> * jet another regex dont mind as long as it has the same result and is performatn ... Co-Authored-By: zeripath <art27@cantab.net> * dont use nonexisting repo for test * exclude /issues?type=created_by from test * add table to querys use same syntax in each query (table.colum) * add new issue for test * dont make a workaround or something else this need a refactor itself and is out of scope for this PR * fix misspell * CI.redo() * englisch txt update Co-Authored-By: zeripath <art27@cantab.net> * add sugestions * Tweak & Fix * CI.restart()
5 years ago
[UI] IssuePage multi repo select (#8741) * Make repository list @ issues/PR page persist Will partially fix #6355 * Enable multiple selections in repo list @ issues/PR page Part of issue #6355 * Add RepoIDs to UserIssueStatsOptions to make "type" count correct when selecting one/multiple repos. * Replace variable "repo" with list "repos[]" and enable multiple selections of repositories from list by including/excluding RepoIDs in list. * * Remove redundant code * Add 'All' button Improves functionality of the page, so that backtracking is not necessary to reset the page * Remove redundant variable Completely replace 'RepoID' with 'RepoIDs' and remove redundant code * Add RepoIDs to label link * Revert part of code to previous version to troubleshoot build failure * Implement old and new pieces of code whilst adhering to multi select * Attempt to join the two versions Last commit passed tests but doesn't work in practice, this works in practice and hopefully passes the tests. * Update tests to desired state * Fix pagination implementation and tests * Pass repoIDs as `repos=[1,2,3...]` instead of several `repos[]=..` * Update tests file to reflect new functionality * Update template with new `repos` format * Implement new solution to show constant "total issues" count for "All" button * Correct behavior when passing zero to array * Comment out test url returning 404 This keeps returning 404 in the test despite working in practice, for the sake of running more tests I am commenting it out * Comment out another test url returning 404 Last attempt, if more tests crash I will uncomment the urls and request assistance. * Reenable tests and test fix * Re-enable tests * Make selecting "In your repositories" reset selection as passing IDs of repos belonging to other profiles causes breakage * Remove unnecessary (with multi-selection enable) code * Drop repo from repo map and total count if permission denied * Remove extra parenthesis * make template work again * find bug! * forgot the '#' at bugfixing * delete unused RepoID * compile regex only one time * make fmt * local variable = capital letter lower * check if repos query pattern is correct * pagination remove last , - make regex work again * use Replace instead of ReplaceAll; del delete * fix test * how did this test binary got in?!? dont forgot the "-p" at git add * ! * dont replace -> cut fisrt & last string Co-Authored-By: zeripath <art27@cantab.net> * jet another regex dont mind as long as it has the same result and is performatn ... Co-Authored-By: zeripath <art27@cantab.net> * dont use nonexisting repo for test * exclude /issues?type=created_by from test * add table to querys use same syntax in each query (table.colum) * add new issue for test * dont make a workaround or something else this need a refactor itself and is out of scope for this PR * fix misspell * CI.redo() * englisch txt update Co-Authored-By: zeripath <art27@cantab.net> * add sugestions * Tweak & Fix * CI.restart()
5 years ago
[UI] IssuePage multi repo select (#8741) * Make repository list @ issues/PR page persist Will partially fix #6355 * Enable multiple selections in repo list @ issues/PR page Part of issue #6355 * Add RepoIDs to UserIssueStatsOptions to make "type" count correct when selecting one/multiple repos. * Replace variable "repo" with list "repos[]" and enable multiple selections of repositories from list by including/excluding RepoIDs in list. * * Remove redundant code * Add 'All' button Improves functionality of the page, so that backtracking is not necessary to reset the page * Remove redundant variable Completely replace 'RepoID' with 'RepoIDs' and remove redundant code * Add RepoIDs to label link * Revert part of code to previous version to troubleshoot build failure * Implement old and new pieces of code whilst adhering to multi select * Attempt to join the two versions Last commit passed tests but doesn't work in practice, this works in practice and hopefully passes the tests. * Update tests to desired state * Fix pagination implementation and tests * Pass repoIDs as `repos=[1,2,3...]` instead of several `repos[]=..` * Update tests file to reflect new functionality * Update template with new `repos` format * Implement new solution to show constant "total issues" count for "All" button * Correct behavior when passing zero to array * Comment out test url returning 404 This keeps returning 404 in the test despite working in practice, for the sake of running more tests I am commenting it out * Comment out another test url returning 404 Last attempt, if more tests crash I will uncomment the urls and request assistance. * Reenable tests and test fix * Re-enable tests * Make selecting "In your repositories" reset selection as passing IDs of repos belonging to other profiles causes breakage * Remove unnecessary (with multi-selection enable) code * Drop repo from repo map and total count if permission denied * Remove extra parenthesis * make template work again * find bug! * forgot the '#' at bugfixing * delete unused RepoID * compile regex only one time * make fmt * local variable = capital letter lower * check if repos query pattern is correct * pagination remove last , - make regex work again * use Replace instead of ReplaceAll; del delete * fix test * how did this test binary got in?!? dont forgot the "-p" at git add * ! * dont replace -> cut fisrt & last string Co-Authored-By: zeripath <art27@cantab.net> * jet another regex dont mind as long as it has the same result and is performatn ... Co-Authored-By: zeripath <art27@cantab.net> * dont use nonexisting repo for test * exclude /issues?type=created_by from test * add table to querys use same syntax in each query (table.colum) * add new issue for test * dont make a workaround or something else this need a refactor itself and is out of scope for this PR * fix misspell * CI.redo() * englisch txt update Co-Authored-By: zeripath <art27@cantab.net> * add sugestions * Tweak & Fix * CI.restart()
5 years ago
[UI] IssuePage multi repo select (#8741) * Make repository list @ issues/PR page persist Will partially fix #6355 * Enable multiple selections in repo list @ issues/PR page Part of issue #6355 * Add RepoIDs to UserIssueStatsOptions to make "type" count correct when selecting one/multiple repos. * Replace variable "repo" with list "repos[]" and enable multiple selections of repositories from list by including/excluding RepoIDs in list. * * Remove redundant code * Add 'All' button Improves functionality of the page, so that backtracking is not necessary to reset the page * Remove redundant variable Completely replace 'RepoID' with 'RepoIDs' and remove redundant code * Add RepoIDs to label link * Revert part of code to previous version to troubleshoot build failure * Implement old and new pieces of code whilst adhering to multi select * Attempt to join the two versions Last commit passed tests but doesn't work in practice, this works in practice and hopefully passes the tests. * Update tests to desired state * Fix pagination implementation and tests * Pass repoIDs as `repos=[1,2,3...]` instead of several `repos[]=..` * Update tests file to reflect new functionality * Update template with new `repos` format * Implement new solution to show constant "total issues" count for "All" button * Correct behavior when passing zero to array * Comment out test url returning 404 This keeps returning 404 in the test despite working in practice, for the sake of running more tests I am commenting it out * Comment out another test url returning 404 Last attempt, if more tests crash I will uncomment the urls and request assistance. * Reenable tests and test fix * Re-enable tests * Make selecting "In your repositories" reset selection as passing IDs of repos belonging to other profiles causes breakage * Remove unnecessary (with multi-selection enable) code * Drop repo from repo map and total count if permission denied * Remove extra parenthesis * make template work again * find bug! * forgot the '#' at bugfixing * delete unused RepoID * compile regex only one time * make fmt * local variable = capital letter lower * check if repos query pattern is correct * pagination remove last , - make regex work again * use Replace instead of ReplaceAll; del delete * fix test * how did this test binary got in?!? dont forgot the "-p" at git add * ! * dont replace -> cut fisrt & last string Co-Authored-By: zeripath <art27@cantab.net> * jet another regex dont mind as long as it has the same result and is performatn ... Co-Authored-By: zeripath <art27@cantab.net> * dont use nonexisting repo for test * exclude /issues?type=created_by from test * add table to querys use same syntax in each query (table.colum) * add new issue for test * dont make a workaround or something else this need a refactor itself and is out of scope for this PR * fix misspell * CI.redo() * englisch txt update Co-Authored-By: zeripath <art27@cantab.net> * add sugestions * Tweak & Fix * CI.restart()
5 years ago
Allow cross-repository dependencies on issues (#7901) * in progress changes for #7405, added ability to add cross-repo dependencies * removed unused repolink var * fixed query that was breaking ci tests; fixed check in issue dependency add so that the id of the issue and dependency is checked rather than the indexes * reverted removal of string in local files becasue these are done via crowdin, not updated manually * removed 'Select("issue.*")' from getBlockedByDependencies and getBlockingDependencies based on comments in PR review * changed getBlockedByDependencies and getBlockingDependencies to use a more xorm-like query, also updated the sidebar as a result * simplified the getBlockingDependencies and getBlockedByDependencies methods; changed the sidebar to show the dependencies in a different format where you can see the name of the repository * made some changes to the issue view in the dependencies (issue name on top, repo full name on separate line). Change view of issue in the dependency search results (also showing the full repo name on separate line) * replace call to FindUserAccessibleRepoIDs with SearchRepositoryByName. The former was hardcoded to use isPrivate = false on the repo search, but this code needed it to be true. The SearchRepositoryByName method is used more in the code including on the user's dashboard * some more tweaks to the layout of the issues when showing dependencies and in the search box when you add new dependencies * added Name to the RepositoryMeta struct * updated swagger doc * fixed total count for link header on SearchIssues * fixed indentation * fixed aligment of remove icon on dependencies in issue sidebar * removed unnecessary nil check (unnecessary because issue.loadRepo is called prior to this block) * reverting .css change, somehow missed or forgot that less is used * updated less file and generated css; updated sidebar template with styles to line up delete and issue index * added ordering to the blocked by/depends on queries * fixed sorting in issue dependency search and the depends on/blocks views to show issues from the current repo first, then by created date descending; added a "all cross repository dependencies" setting to allow this feature to be turned off, if turned off, the issue dependency search will work the way it did before (restricted to the current repository) * re-applied my swagger changes after merge * fixed split string condition in issue search * changed ALLOW_CROSS_REPOSITORY_DEPENDENCIES description to sound more global than just the issue dependency search; returning 400 in the cross repo issue search api method if not enabled; fixed bug where the issue count did not respect the state parameter * when adding a dependency to an issue, added a check to make sure the issue and dependency are in the same repo if cross repo dependencies is not enabled * updated sortIssuesSession call in PullRequests, another commit moved this method from pull.go to pull_list.go so I had to re-apply my change here * fixed incorrect setting of user id parameter in search repos call
5 years ago
Issue due date (#3794) * Started adding deadline to ui * Implemented basic issue due date managing * Improved UI for due date managing * Added at least write access to the repo in order to modify issue due dates * Ui improvements * Added issue comments creation when adding/modifying/removing a due date * Show due date in issue list * Added api support for issue due dates * Fixed lint suggestions * Added deadline to sdk * Updated css * Added support for adding/modifiying deadlines for pull requests via api * Fixed comments not created when updating or removing a deadline * update sdk (will do properly once go-gitea/go-sdk#103 is merged) * enhanced updateIssueDeadline * Removed unnessecary Issue.DeadlineString * UI improvements * Small improvments to comment creation + ui & validation improvements * Check if an issue is overdue is now a seperate function * Updated go-sdk with govendor as it was merged * Simplified isOverdue method * removed unessecary deadline to 0 set * Update swagger definitions * Added missing return * Added an explanary comment * Improved updateIssueDeadline method so it'll only update `deadline_unix` * Small changes and improvements * no need to explicitly load the issue when updating a deadline, just use whats already there * small optimisations * Added check if a deadline was modified before updating it * Moved comment creating logic into its own function * Code cleanup for creating deadline comment * locale improvement * When modifying a deadline, the old deadline is saved with the comment * small improvments to xorm session handling when updating an issue deadline + style nitpicks * style nitpicks * Moved checking for if the user has write acces to middleware
7 years ago
Issue due date (#3794) * Started adding deadline to ui * Implemented basic issue due date managing * Improved UI for due date managing * Added at least write access to the repo in order to modify issue due dates * Ui improvements * Added issue comments creation when adding/modifying/removing a due date * Show due date in issue list * Added api support for issue due dates * Fixed lint suggestions * Added deadline to sdk * Updated css * Added support for adding/modifiying deadlines for pull requests via api * Fixed comments not created when updating or removing a deadline * update sdk (will do properly once go-gitea/go-sdk#103 is merged) * enhanced updateIssueDeadline * Removed unnessecary Issue.DeadlineString * UI improvements * Small improvments to comment creation + ui & validation improvements * Check if an issue is overdue is now a seperate function * Updated go-sdk with govendor as it was merged * Simplified isOverdue method * removed unessecary deadline to 0 set * Update swagger definitions * Added missing return * Added an explanary comment * Improved updateIssueDeadline method so it'll only update `deadline_unix` * Small changes and improvements * no need to explicitly load the issue when updating a deadline, just use whats already there * small optimisations * Added check if a deadline was modified before updating it * Moved comment creating logic into its own function * Code cleanup for creating deadline comment * locale improvement * When modifying a deadline, the old deadline is saved with the comment * small improvments to xorm session handling when updating an issue deadline + style nitpicks * style nitpicks * Moved checking for if the user has write acces to middleware
7 years ago
Allow cross-repository dependencies on issues (#7901) * in progress changes for #7405, added ability to add cross-repo dependencies * removed unused repolink var * fixed query that was breaking ci tests; fixed check in issue dependency add so that the id of the issue and dependency is checked rather than the indexes * reverted removal of string in local files becasue these are done via crowdin, not updated manually * removed 'Select("issue.*")' from getBlockedByDependencies and getBlockingDependencies based on comments in PR review * changed getBlockedByDependencies and getBlockingDependencies to use a more xorm-like query, also updated the sidebar as a result * simplified the getBlockingDependencies and getBlockedByDependencies methods; changed the sidebar to show the dependencies in a different format where you can see the name of the repository * made some changes to the issue view in the dependencies (issue name on top, repo full name on separate line). Change view of issue in the dependency search results (also showing the full repo name on separate line) * replace call to FindUserAccessibleRepoIDs with SearchRepositoryByName. The former was hardcoded to use isPrivate = false on the repo search, but this code needed it to be true. The SearchRepositoryByName method is used more in the code including on the user's dashboard * some more tweaks to the layout of the issues when showing dependencies and in the search box when you add new dependencies * added Name to the RepositoryMeta struct * updated swagger doc * fixed total count for link header on SearchIssues * fixed indentation * fixed aligment of remove icon on dependencies in issue sidebar * removed unnecessary nil check (unnecessary because issue.loadRepo is called prior to this block) * reverting .css change, somehow missed or forgot that less is used * updated less file and generated css; updated sidebar template with styles to line up delete and issue index * added ordering to the blocked by/depends on queries * fixed sorting in issue dependency search and the depends on/blocks views to show issues from the current repo first, then by created date descending; added a "all cross repository dependencies" setting to allow this feature to be turned off, if turned off, the issue dependency search will work the way it did before (restricted to the current repository) * re-applied my swagger changes after merge * fixed split string condition in issue search * changed ALLOW_CROSS_REPOSITORY_DEPENDENCIES description to sound more global than just the issue dependency search; returning 400 in the cross repo issue search api method if not enabled; fixed bug where the issue count did not respect the state parameter * when adding a dependency to an issue, added a check to make sure the issue and dependency are in the same repo if cross repo dependencies is not enabled * updated sortIssuesSession call in PullRequests, another commit moved this method from pull.go to pull_list.go so I had to re-apply my change here * fixed incorrect setting of user id parameter in search repos call
5 years ago
Allow cross-repository dependencies on issues (#7901) * in progress changes for #7405, added ability to add cross-repo dependencies * removed unused repolink var * fixed query that was breaking ci tests; fixed check in issue dependency add so that the id of the issue and dependency is checked rather than the indexes * reverted removal of string in local files becasue these are done via crowdin, not updated manually * removed 'Select("issue.*")' from getBlockedByDependencies and getBlockingDependencies based on comments in PR review * changed getBlockedByDependencies and getBlockingDependencies to use a more xorm-like query, also updated the sidebar as a result * simplified the getBlockingDependencies and getBlockedByDependencies methods; changed the sidebar to show the dependencies in a different format where you can see the name of the repository * made some changes to the issue view in the dependencies (issue name on top, repo full name on separate line). Change view of issue in the dependency search results (also showing the full repo name on separate line) * replace call to FindUserAccessibleRepoIDs with SearchRepositoryByName. The former was hardcoded to use isPrivate = false on the repo search, but this code needed it to be true. The SearchRepositoryByName method is used more in the code including on the user's dashboard * some more tweaks to the layout of the issues when showing dependencies and in the search box when you add new dependencies * added Name to the RepositoryMeta struct * updated swagger doc * fixed total count for link header on SearchIssues * fixed indentation * fixed aligment of remove icon on dependencies in issue sidebar * removed unnecessary nil check (unnecessary because issue.loadRepo is called prior to this block) * reverting .css change, somehow missed or forgot that less is used * updated less file and generated css; updated sidebar template with styles to line up delete and issue index * added ordering to the blocked by/depends on queries * fixed sorting in issue dependency search and the depends on/blocks views to show issues from the current repo first, then by created date descending; added a "all cross repository dependencies" setting to allow this feature to be turned off, if turned off, the issue dependency search will work the way it did before (restricted to the current repository) * re-applied my swagger changes after merge * fixed split string condition in issue search * changed ALLOW_CROSS_REPOSITORY_DEPENDENCIES description to sound more global than just the issue dependency search; returning 400 in the cross repo issue search api method if not enabled; fixed bug where the issue count did not respect the state parameter * when adding a dependency to an issue, added a check to make sure the issue and dependency are in the same repo if cross repo dependencies is not enabled * updated sortIssuesSession call in PullRequests, another commit moved this method from pull.go to pull_list.go so I had to re-apply my change here * fixed incorrect setting of user id parameter in search repos call
5 years ago
Allow cross-repository dependencies on issues (#7901) * in progress changes for #7405, added ability to add cross-repo dependencies * removed unused repolink var * fixed query that was breaking ci tests; fixed check in issue dependency add so that the id of the issue and dependency is checked rather than the indexes * reverted removal of string in local files becasue these are done via crowdin, not updated manually * removed 'Select("issue.*")' from getBlockedByDependencies and getBlockingDependencies based on comments in PR review * changed getBlockedByDependencies and getBlockingDependencies to use a more xorm-like query, also updated the sidebar as a result * simplified the getBlockingDependencies and getBlockedByDependencies methods; changed the sidebar to show the dependencies in a different format where you can see the name of the repository * made some changes to the issue view in the dependencies (issue name on top, repo full name on separate line). Change view of issue in the dependency search results (also showing the full repo name on separate line) * replace call to FindUserAccessibleRepoIDs with SearchRepositoryByName. The former was hardcoded to use isPrivate = false on the repo search, but this code needed it to be true. The SearchRepositoryByName method is used more in the code including on the user's dashboard * some more tweaks to the layout of the issues when showing dependencies and in the search box when you add new dependencies * added Name to the RepositoryMeta struct * updated swagger doc * fixed total count for link header on SearchIssues * fixed indentation * fixed aligment of remove icon on dependencies in issue sidebar * removed unnecessary nil check (unnecessary because issue.loadRepo is called prior to this block) * reverting .css change, somehow missed or forgot that less is used * updated less file and generated css; updated sidebar template with styles to line up delete and issue index * added ordering to the blocked by/depends on queries * fixed sorting in issue dependency search and the depends on/blocks views to show issues from the current repo first, then by created date descending; added a "all cross repository dependencies" setting to allow this feature to be turned off, if turned off, the issue dependency search will work the way it did before (restricted to the current repository) * re-applied my swagger changes after merge * fixed split string condition in issue search * changed ALLOW_CROSS_REPOSITORY_DEPENDENCIES description to sound more global than just the issue dependency search; returning 400 in the cross repo issue search api method if not enabled; fixed bug where the issue count did not respect the state parameter * when adding a dependency to an issue, added a check to make sure the issue and dependency are in the same repo if cross repo dependencies is not enabled * updated sortIssuesSession call in PullRequests, another commit moved this method from pull.go to pull_list.go so I had to re-apply my change here * fixed incorrect setting of user id parameter in search repos call
5 years ago
Allow cross-repository dependencies on issues (#7901) * in progress changes for #7405, added ability to add cross-repo dependencies * removed unused repolink var * fixed query that was breaking ci tests; fixed check in issue dependency add so that the id of the issue and dependency is checked rather than the indexes * reverted removal of string in local files becasue these are done via crowdin, not updated manually * removed 'Select("issue.*")' from getBlockedByDependencies and getBlockingDependencies based on comments in PR review * changed getBlockedByDependencies and getBlockingDependencies to use a more xorm-like query, also updated the sidebar as a result * simplified the getBlockingDependencies and getBlockedByDependencies methods; changed the sidebar to show the dependencies in a different format where you can see the name of the repository * made some changes to the issue view in the dependencies (issue name on top, repo full name on separate line). Change view of issue in the dependency search results (also showing the full repo name on separate line) * replace call to FindUserAccessibleRepoIDs with SearchRepositoryByName. The former was hardcoded to use isPrivate = false on the repo search, but this code needed it to be true. The SearchRepositoryByName method is used more in the code including on the user's dashboard * some more tweaks to the layout of the issues when showing dependencies and in the search box when you add new dependencies * added Name to the RepositoryMeta struct * updated swagger doc * fixed total count for link header on SearchIssues * fixed indentation * fixed aligment of remove icon on dependencies in issue sidebar * removed unnecessary nil check (unnecessary because issue.loadRepo is called prior to this block) * reverting .css change, somehow missed or forgot that less is used * updated less file and generated css; updated sidebar template with styles to line up delete and issue index * added ordering to the blocked by/depends on queries * fixed sorting in issue dependency search and the depends on/blocks views to show issues from the current repo first, then by created date descending; added a "all cross repository dependencies" setting to allow this feature to be turned off, if turned off, the issue dependency search will work the way it did before (restricted to the current repository) * re-applied my swagger changes after merge * fixed split string condition in issue search * changed ALLOW_CROSS_REPOSITORY_DEPENDENCIES description to sound more global than just the issue dependency search; returning 400 in the cross repo issue search api method if not enabled; fixed bug where the issue count did not respect the state parameter * when adding a dependency to an issue, added a check to make sure the issue and dependency are in the same repo if cross repo dependencies is not enabled * updated sortIssuesSession call in PullRequests, another commit moved this method from pull.go to pull_list.go so I had to re-apply my change here * fixed incorrect setting of user id parameter in search repos call
5 years ago
Allow cross-repository dependencies on issues (#7901) * in progress changes for #7405, added ability to add cross-repo dependencies * removed unused repolink var * fixed query that was breaking ci tests; fixed check in issue dependency add so that the id of the issue and dependency is checked rather than the indexes * reverted removal of string in local files becasue these are done via crowdin, not updated manually * removed 'Select("issue.*")' from getBlockedByDependencies and getBlockingDependencies based on comments in PR review * changed getBlockedByDependencies and getBlockingDependencies to use a more xorm-like query, also updated the sidebar as a result * simplified the getBlockingDependencies and getBlockedByDependencies methods; changed the sidebar to show the dependencies in a different format where you can see the name of the repository * made some changes to the issue view in the dependencies (issue name on top, repo full name on separate line). Change view of issue in the dependency search results (also showing the full repo name on separate line) * replace call to FindUserAccessibleRepoIDs with SearchRepositoryByName. The former was hardcoded to use isPrivate = false on the repo search, but this code needed it to be true. The SearchRepositoryByName method is used more in the code including on the user's dashboard * some more tweaks to the layout of the issues when showing dependencies and in the search box when you add new dependencies * added Name to the RepositoryMeta struct * updated swagger doc * fixed total count for link header on SearchIssues * fixed indentation * fixed aligment of remove icon on dependencies in issue sidebar * removed unnecessary nil check (unnecessary because issue.loadRepo is called prior to this block) * reverting .css change, somehow missed or forgot that less is used * updated less file and generated css; updated sidebar template with styles to line up delete and issue index * added ordering to the blocked by/depends on queries * fixed sorting in issue dependency search and the depends on/blocks views to show issues from the current repo first, then by created date descending; added a "all cross repository dependencies" setting to allow this feature to be turned off, if turned off, the issue dependency search will work the way it did before (restricted to the current repository) * re-applied my swagger changes after merge * fixed split string condition in issue search * changed ALLOW_CROSS_REPOSITORY_DEPENDENCIES description to sound more global than just the issue dependency search; returning 400 in the cross repo issue search api method if not enabled; fixed bug where the issue count did not respect the state parameter * when adding a dependency to an issue, added a check to make sure the issue and dependency are in the same repo if cross repo dependencies is not enabled * updated sortIssuesSession call in PullRequests, another commit moved this method from pull.go to pull_list.go so I had to re-apply my change here * fixed incorrect setting of user id parameter in search repos call
5 years ago
Allow cross-repository dependencies on issues (#7901) * in progress changes for #7405, added ability to add cross-repo dependencies * removed unused repolink var * fixed query that was breaking ci tests; fixed check in issue dependency add so that the id of the issue and dependency is checked rather than the indexes * reverted removal of string in local files becasue these are done via crowdin, not updated manually * removed 'Select("issue.*")' from getBlockedByDependencies and getBlockingDependencies based on comments in PR review * changed getBlockedByDependencies and getBlockingDependencies to use a more xorm-like query, also updated the sidebar as a result * simplified the getBlockingDependencies and getBlockedByDependencies methods; changed the sidebar to show the dependencies in a different format where you can see the name of the repository * made some changes to the issue view in the dependencies (issue name on top, repo full name on separate line). Change view of issue in the dependency search results (also showing the full repo name on separate line) * replace call to FindUserAccessibleRepoIDs with SearchRepositoryByName. The former was hardcoded to use isPrivate = false on the repo search, but this code needed it to be true. The SearchRepositoryByName method is used more in the code including on the user's dashboard * some more tweaks to the layout of the issues when showing dependencies and in the search box when you add new dependencies * added Name to the RepositoryMeta struct * updated swagger doc * fixed total count for link header on SearchIssues * fixed indentation * fixed aligment of remove icon on dependencies in issue sidebar * removed unnecessary nil check (unnecessary because issue.loadRepo is called prior to this block) * reverting .css change, somehow missed or forgot that less is used * updated less file and generated css; updated sidebar template with styles to line up delete and issue index * added ordering to the blocked by/depends on queries * fixed sorting in issue dependency search and the depends on/blocks views to show issues from the current repo first, then by created date descending; added a "all cross repository dependencies" setting to allow this feature to be turned off, if turned off, the issue dependency search will work the way it did before (restricted to the current repository) * re-applied my swagger changes after merge * fixed split string condition in issue search * changed ALLOW_CROSS_REPOSITORY_DEPENDENCIES description to sound more global than just the issue dependency search; returning 400 in the cross repo issue search api method if not enabled; fixed bug where the issue count did not respect the state parameter * when adding a dependency to an issue, added a check to make sure the issue and dependency are in the same repo if cross repo dependencies is not enabled * updated sortIssuesSession call in PullRequests, another commit moved this method from pull.go to pull_list.go so I had to re-apply my change here * fixed incorrect setting of user id parameter in search repos call
5 years ago
Allow cross-repository dependencies on issues (#7901) * in progress changes for #7405, added ability to add cross-repo dependencies * removed unused repolink var * fixed query that was breaking ci tests; fixed check in issue dependency add so that the id of the issue and dependency is checked rather than the indexes * reverted removal of string in local files becasue these are done via crowdin, not updated manually * removed 'Select("issue.*")' from getBlockedByDependencies and getBlockingDependencies based on comments in PR review * changed getBlockedByDependencies and getBlockingDependencies to use a more xorm-like query, also updated the sidebar as a result * simplified the getBlockingDependencies and getBlockedByDependencies methods; changed the sidebar to show the dependencies in a different format where you can see the name of the repository * made some changes to the issue view in the dependencies (issue name on top, repo full name on separate line). Change view of issue in the dependency search results (also showing the full repo name on separate line) * replace call to FindUserAccessibleRepoIDs with SearchRepositoryByName. The former was hardcoded to use isPrivate = false on the repo search, but this code needed it to be true. The SearchRepositoryByName method is used more in the code including on the user's dashboard * some more tweaks to the layout of the issues when showing dependencies and in the search box when you add new dependencies * added Name to the RepositoryMeta struct * updated swagger doc * fixed total count for link header on SearchIssues * fixed indentation * fixed aligment of remove icon on dependencies in issue sidebar * removed unnecessary nil check (unnecessary because issue.loadRepo is called prior to this block) * reverting .css change, somehow missed or forgot that less is used * updated less file and generated css; updated sidebar template with styles to line up delete and issue index * added ordering to the blocked by/depends on queries * fixed sorting in issue dependency search and the depends on/blocks views to show issues from the current repo first, then by created date descending; added a "all cross repository dependencies" setting to allow this feature to be turned off, if turned off, the issue dependency search will work the way it did before (restricted to the current repository) * re-applied my swagger changes after merge * fixed split string condition in issue search * changed ALLOW_CROSS_REPOSITORY_DEPENDENCIES description to sound more global than just the issue dependency search; returning 400 in the cross repo issue search api method if not enabled; fixed bug where the issue count did not respect the state parameter * when adding a dependency to an issue, added a check to make sure the issue and dependency are in the same repo if cross repo dependencies is not enabled * updated sortIssuesSession call in PullRequests, another commit moved this method from pull.go to pull_list.go so I had to re-apply my change here * fixed incorrect setting of user id parameter in search repos call
5 years ago
Allow cross-repository dependencies on issues (#7901) * in progress changes for #7405, added ability to add cross-repo dependencies * removed unused repolink var * fixed query that was breaking ci tests; fixed check in issue dependency add so that the id of the issue and dependency is checked rather than the indexes * reverted removal of string in local files becasue these are done via crowdin, not updated manually * removed 'Select("issue.*")' from getBlockedByDependencies and getBlockingDependencies based on comments in PR review * changed getBlockedByDependencies and getBlockingDependencies to use a more xorm-like query, also updated the sidebar as a result * simplified the getBlockingDependencies and getBlockedByDependencies methods; changed the sidebar to show the dependencies in a different format where you can see the name of the repository * made some changes to the issue view in the dependencies (issue name on top, repo full name on separate line). Change view of issue in the dependency search results (also showing the full repo name on separate line) * replace call to FindUserAccessibleRepoIDs with SearchRepositoryByName. The former was hardcoded to use isPrivate = false on the repo search, but this code needed it to be true. The SearchRepositoryByName method is used more in the code including on the user's dashboard * some more tweaks to the layout of the issues when showing dependencies and in the search box when you add new dependencies * added Name to the RepositoryMeta struct * updated swagger doc * fixed total count for link header on SearchIssues * fixed indentation * fixed aligment of remove icon on dependencies in issue sidebar * removed unnecessary nil check (unnecessary because issue.loadRepo is called prior to this block) * reverting .css change, somehow missed or forgot that less is used * updated less file and generated css; updated sidebar template with styles to line up delete and issue index * added ordering to the blocked by/depends on queries * fixed sorting in issue dependency search and the depends on/blocks views to show issues from the current repo first, then by created date descending; added a "all cross repository dependencies" setting to allow this feature to be turned off, if turned off, the issue dependency search will work the way it did before (restricted to the current repository) * re-applied my swagger changes after merge * fixed split string condition in issue search * changed ALLOW_CROSS_REPOSITORY_DEPENDENCIES description to sound more global than just the issue dependency search; returning 400 in the cross repo issue search api method if not enabled; fixed bug where the issue count did not respect the state parameter * when adding a dependency to an issue, added a check to make sure the issue and dependency are in the same repo if cross repo dependencies is not enabled * updated sortIssuesSession call in PullRequests, another commit moved this method from pull.go to pull_list.go so I had to re-apply my change here * fixed incorrect setting of user id parameter in search repos call
5 years ago
Allow cross-repository dependencies on issues (#7901) * in progress changes for #7405, added ability to add cross-repo dependencies * removed unused repolink var * fixed query that was breaking ci tests; fixed check in issue dependency add so that the id of the issue and dependency is checked rather than the indexes * reverted removal of string in local files becasue these are done via crowdin, not updated manually * removed 'Select("issue.*")' from getBlockedByDependencies and getBlockingDependencies based on comments in PR review * changed getBlockedByDependencies and getBlockingDependencies to use a more xorm-like query, also updated the sidebar as a result * simplified the getBlockingDependencies and getBlockedByDependencies methods; changed the sidebar to show the dependencies in a different format where you can see the name of the repository * made some changes to the issue view in the dependencies (issue name on top, repo full name on separate line). Change view of issue in the dependency search results (also showing the full repo name on separate line) * replace call to FindUserAccessibleRepoIDs with SearchRepositoryByName. The former was hardcoded to use isPrivate = false on the repo search, but this code needed it to be true. The SearchRepositoryByName method is used more in the code including on the user's dashboard * some more tweaks to the layout of the issues when showing dependencies and in the search box when you add new dependencies * added Name to the RepositoryMeta struct * updated swagger doc * fixed total count for link header on SearchIssues * fixed indentation * fixed aligment of remove icon on dependencies in issue sidebar * removed unnecessary nil check (unnecessary because issue.loadRepo is called prior to this block) * reverting .css change, somehow missed or forgot that less is used * updated less file and generated css; updated sidebar template with styles to line up delete and issue index * added ordering to the blocked by/depends on queries * fixed sorting in issue dependency search and the depends on/blocks views to show issues from the current repo first, then by created date descending; added a "all cross repository dependencies" setting to allow this feature to be turned off, if turned off, the issue dependency search will work the way it did before (restricted to the current repository) * re-applied my swagger changes after merge * fixed split string condition in issue search * changed ALLOW_CROSS_REPOSITORY_DEPENDENCIES description to sound more global than just the issue dependency search; returning 400 in the cross repo issue search api method if not enabled; fixed bug where the issue count did not respect the state parameter * when adding a dependency to an issue, added a check to make sure the issue and dependency are in the same repo if cross repo dependencies is not enabled * updated sortIssuesSession call in PullRequests, another commit moved this method from pull.go to pull_list.go so I had to re-apply my change here * fixed incorrect setting of user id parameter in search repos call
5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824
  1. // Copyright 2014 The Gogs Authors. All rights reserved.
  2. // Copyright 2020 The Gitea Authors. All rights reserved.
  3. // Use of this source code is governed by a MIT-style
  4. // license that can be found in the LICENSE file.
  5. package models
  6. import (
  7. "fmt"
  8. "path"
  9. "regexp"
  10. "sort"
  11. "strconv"
  12. "strings"
  13. "code.gitea.io/gitea/modules/base"
  14. "code.gitea.io/gitea/modules/log"
  15. "code.gitea.io/gitea/modules/setting"
  16. "code.gitea.io/gitea/modules/structs"
  17. api "code.gitea.io/gitea/modules/structs"
  18. "code.gitea.io/gitea/modules/timeutil"
  19. "code.gitea.io/gitea/modules/util"
  20. "github.com/unknwon/com"
  21. "xorm.io/builder"
  22. "xorm.io/xorm"
  23. )
  24. // Issue represents an issue or pull request of repository.
  25. type Issue struct {
  26. ID int64 `xorm:"pk autoincr"`
  27. RepoID int64 `xorm:"INDEX UNIQUE(repo_index)"`
  28. Repo *Repository `xorm:"-"`
  29. Index int64 `xorm:"UNIQUE(repo_index)"` // Index in one repository.
  30. PosterID int64 `xorm:"INDEX"`
  31. Poster *User `xorm:"-"`
  32. OriginalAuthor string
  33. OriginalAuthorID int64 `xorm:"index"`
  34. Title string `xorm:"name"`
  35. Content string `xorm:"TEXT"`
  36. RenderedContent string `xorm:"-"`
  37. Labels []*Label `xorm:"-"`
  38. MilestoneID int64 `xorm:"INDEX"`
  39. Milestone *Milestone `xorm:"-"`
  40. Priority int
  41. AssigneeID int64 `xorm:"-"`
  42. Assignee *User `xorm:"-"`
  43. IsClosed bool `xorm:"INDEX"`
  44. IsRead bool `xorm:"-"`
  45. IsPull bool `xorm:"INDEX"` // Indicates whether is a pull request or not.
  46. PullRequest *PullRequest `xorm:"-"`
  47. NumComments int
  48. Ref string
  49. DeadlineUnix timeutil.TimeStamp `xorm:"INDEX"`
  50. CreatedUnix timeutil.TimeStamp `xorm:"INDEX created"`
  51. UpdatedUnix timeutil.TimeStamp `xorm:"INDEX updated"`
  52. ClosedUnix timeutil.TimeStamp `xorm:"INDEX"`
  53. Attachments []*Attachment `xorm:"-"`
  54. Comments []*Comment `xorm:"-"`
  55. Reactions ReactionList `xorm:"-"`
  56. TotalTrackedTime int64 `xorm:"-"`
  57. Assignees []*User `xorm:"-"`
  58. // IsLocked limits commenting abilities to users on an issue
  59. // with write access
  60. IsLocked bool `xorm:"NOT NULL DEFAULT false"`
  61. }
  62. var (
  63. issueTasksPat *regexp.Regexp
  64. issueTasksDonePat *regexp.Regexp
  65. )
  66. const issueTasksRegexpStr = `(^\s*[-*]\s\[[\sx]\]\s.)|(\n\s*[-*]\s\[[\sx]\]\s.)`
  67. const issueTasksDoneRegexpStr = `(^\s*[-*]\s\[[x]\]\s.)|(\n\s*[-*]\s\[[x]\]\s.)`
  68. const issueMaxDupIndexAttempts = 3
  69. func init() {
  70. issueTasksPat = regexp.MustCompile(issueTasksRegexpStr)
  71. issueTasksDonePat = regexp.MustCompile(issueTasksDoneRegexpStr)
  72. }
  73. func (issue *Issue) loadTotalTimes(e Engine) (err error) {
  74. opts := FindTrackedTimesOptions{IssueID: issue.ID}
  75. issue.TotalTrackedTime, err = opts.ToSession(e).SumInt(&TrackedTime{}, "time")
  76. if err != nil {
  77. return err
  78. }
  79. return nil
  80. }
  81. // IsOverdue checks if the issue is overdue
  82. func (issue *Issue) IsOverdue() bool {
  83. return timeutil.TimeStampNow() >= issue.DeadlineUnix
  84. }
  85. // LoadRepo loads issue's repository
  86. func (issue *Issue) LoadRepo() error {
  87. return issue.loadRepo(x)
  88. }
  89. func (issue *Issue) loadRepo(e Engine) (err error) {
  90. if issue.Repo == nil {
  91. issue.Repo, err = getRepositoryByID(e, issue.RepoID)
  92. if err != nil {
  93. return fmt.Errorf("getRepositoryByID [%d]: %v", issue.RepoID, err)
  94. }
  95. }
  96. return nil
  97. }
  98. // IsTimetrackerEnabled returns true if the repo enables timetracking
  99. func (issue *Issue) IsTimetrackerEnabled() bool {
  100. return issue.isTimetrackerEnabled(x)
  101. }
  102. func (issue *Issue) isTimetrackerEnabled(e Engine) bool {
  103. if err := issue.loadRepo(e); err != nil {
  104. log.Error(fmt.Sprintf("loadRepo: %v", err))
  105. return false
  106. }
  107. return issue.Repo.IsTimetrackerEnabled()
  108. }
  109. // GetPullRequest returns the issue pull request
  110. func (issue *Issue) GetPullRequest() (pr *PullRequest, err error) {
  111. if !issue.IsPull {
  112. return nil, fmt.Errorf("Issue is not a pull request")
  113. }
  114. pr, err = getPullRequestByIssueID(x, issue.ID)
  115. if err != nil {
  116. return nil, err
  117. }
  118. pr.Issue = issue
  119. return
  120. }
  121. func (issue *Issue) loadLabels(e Engine) (err error) {
  122. if issue.Labels == nil {
  123. issue.Labels, err = getLabelsByIssueID(e, issue.ID)
  124. if err != nil {
  125. return fmt.Errorf("getLabelsByIssueID [%d]: %v", issue.ID, err)
  126. }
  127. }
  128. return nil
  129. }
  130. // LoadPoster loads poster
  131. func (issue *Issue) LoadPoster() error {
  132. return issue.loadPoster(x)
  133. }
  134. func (issue *Issue) loadPoster(e Engine) (err error) {
  135. if issue.Poster == nil {
  136. issue.Poster, err = getUserByID(e, issue.PosterID)
  137. if err != nil {
  138. issue.PosterID = -1
  139. issue.Poster = NewGhostUser()
  140. if !IsErrUserNotExist(err) {
  141. return fmt.Errorf("getUserByID.(poster) [%d]: %v", issue.PosterID, err)
  142. }
  143. err = nil
  144. return
  145. }
  146. }
  147. return
  148. }
  149. func (issue *Issue) loadPullRequest(e Engine) (err error) {
  150. if issue.IsPull && issue.PullRequest == nil {
  151. issue.PullRequest, err = getPullRequestByIssueID(e, issue.ID)
  152. if err != nil {
  153. if IsErrPullRequestNotExist(err) {
  154. return err
  155. }
  156. return fmt.Errorf("getPullRequestByIssueID [%d]: %v", issue.ID, err)
  157. }
  158. issue.PullRequest.Issue = issue
  159. }
  160. return nil
  161. }
  162. // LoadPullRequest loads pull request info
  163. func (issue *Issue) LoadPullRequest() error {
  164. return issue.loadPullRequest(x)
  165. }
  166. func (issue *Issue) loadComments(e Engine) (err error) {
  167. return issue.loadCommentsByType(e, CommentTypeUnknown)
  168. }
  169. // LoadDiscussComments loads discuss comments
  170. func (issue *Issue) LoadDiscussComments() error {
  171. return issue.loadCommentsByType(x, CommentTypeComment)
  172. }
  173. func (issue *Issue) loadCommentsByType(e Engine, tp CommentType) (err error) {
  174. if issue.Comments != nil {
  175. return nil
  176. }
  177. issue.Comments, err = findComments(e, FindCommentsOptions{
  178. IssueID: issue.ID,
  179. Type: tp,
  180. })
  181. return err
  182. }
  183. func (issue *Issue) loadReactions(e Engine) (err error) {
  184. if issue.Reactions != nil {
  185. return nil
  186. }
  187. reactions, err := findReactions(e, FindReactionsOptions{
  188. IssueID: issue.ID,
  189. })
  190. if err != nil {
  191. return err
  192. }
  193. // Load reaction user data
  194. if _, err := ReactionList(reactions).loadUsers(e); err != nil {
  195. return err
  196. }
  197. // Cache comments to map
  198. comments := make(map[int64]*Comment)
  199. for _, comment := range issue.Comments {
  200. comments[comment.ID] = comment
  201. }
  202. // Add reactions either to issue or comment
  203. for _, react := range reactions {
  204. if react.CommentID == 0 {
  205. issue.Reactions = append(issue.Reactions, react)
  206. } else if comment, ok := comments[react.CommentID]; ok {
  207. comment.Reactions = append(comment.Reactions, react)
  208. }
  209. }
  210. return nil
  211. }
  212. func (issue *Issue) loadMilestone(e Engine) (err error) {
  213. if issue.Milestone == nil && issue.MilestoneID > 0 {
  214. issue.Milestone, err = getMilestoneByRepoID(e, issue.RepoID, issue.MilestoneID)
  215. if err != nil && !IsErrMilestoneNotExist(err) {
  216. return fmt.Errorf("getMilestoneByRepoID [repo_id: %d, milestone_id: %d]: %v", issue.RepoID, issue.MilestoneID, err)
  217. }
  218. }
  219. return nil
  220. }
  221. func (issue *Issue) loadAttributes(e Engine) (err error) {
  222. if err = issue.loadRepo(e); err != nil {
  223. return
  224. }
  225. if err = issue.loadPoster(e); err != nil {
  226. return
  227. }
  228. if err = issue.loadLabels(e); err != nil {
  229. return
  230. }
  231. if err = issue.loadMilestone(e); err != nil {
  232. return
  233. }
  234. if err = issue.loadAssignees(e); err != nil {
  235. return
  236. }
  237. if err = issue.loadPullRequest(e); err != nil && !IsErrPullRequestNotExist(err) {
  238. // It is possible pull request is not yet created.
  239. return err
  240. }
  241. if issue.Attachments == nil {
  242. issue.Attachments, err = getAttachmentsByIssueID(e, issue.ID)
  243. if err != nil {
  244. return fmt.Errorf("getAttachmentsByIssueID [%d]: %v", issue.ID, err)
  245. }
  246. }
  247. if err = issue.loadComments(e); err != nil {
  248. return err
  249. }
  250. if err = CommentList(issue.Comments).loadAttributes(e); err != nil {
  251. return err
  252. }
  253. if issue.isTimetrackerEnabled(e) {
  254. if err = issue.loadTotalTimes(e); err != nil {
  255. return err
  256. }
  257. }
  258. return issue.loadReactions(e)
  259. }
  260. // LoadAttributes loads the attribute of this issue.
  261. func (issue *Issue) LoadAttributes() error {
  262. return issue.loadAttributes(x)
  263. }
  264. // LoadMilestone load milestone of this issue.
  265. func (issue *Issue) LoadMilestone() error {
  266. return issue.loadMilestone(x)
  267. }
  268. // GetIsRead load the `IsRead` field of the issue
  269. func (issue *Issue) GetIsRead(userID int64) error {
  270. issueUser := &IssueUser{IssueID: issue.ID, UID: userID}
  271. if has, err := x.Get(issueUser); err != nil {
  272. return err
  273. } else if !has {
  274. issue.IsRead = false
  275. return nil
  276. }
  277. issue.IsRead = issueUser.IsRead
  278. return nil
  279. }
  280. // APIURL returns the absolute APIURL to this issue.
  281. func (issue *Issue) APIURL() string {
  282. return issue.Repo.APIURL() + "/" + path.Join("issues", fmt.Sprint(issue.Index))
  283. }
  284. // HTMLURL returns the absolute URL to this issue.
  285. func (issue *Issue) HTMLURL() string {
  286. var path string
  287. if issue.IsPull {
  288. path = "pulls"
  289. } else {
  290. path = "issues"
  291. }
  292. return fmt.Sprintf("%s/%s/%d", issue.Repo.HTMLURL(), path, issue.Index)
  293. }
  294. // DiffURL returns the absolute URL to this diff
  295. func (issue *Issue) DiffURL() string {
  296. if issue.IsPull {
  297. return fmt.Sprintf("%s/pulls/%d.diff", issue.Repo.HTMLURL(), issue.Index)
  298. }
  299. return ""
  300. }
  301. // PatchURL returns the absolute URL to this patch
  302. func (issue *Issue) PatchURL() string {
  303. if issue.IsPull {
  304. return fmt.Sprintf("%s/pulls/%d.patch", issue.Repo.HTMLURL(), issue.Index)
  305. }
  306. return ""
  307. }
  308. // State returns string representation of issue status.
  309. func (issue *Issue) State() api.StateType {
  310. if issue.IsClosed {
  311. return api.StateClosed
  312. }
  313. return api.StateOpen
  314. }
  315. // APIFormat assumes some fields assigned with values:
  316. // Required - Poster, Labels,
  317. // Optional - Milestone, Assignee, PullRequest
  318. func (issue *Issue) APIFormat() *api.Issue {
  319. return issue.apiFormat(x)
  320. }
  321. func (issue *Issue) apiFormat(e Engine) *api.Issue {
  322. issue.loadLabels(e)
  323. apiLabels := make([]*api.Label, len(issue.Labels))
  324. for i := range issue.Labels {
  325. apiLabels[i] = issue.Labels[i].APIFormat()
  326. }
  327. issue.loadPoster(e)
  328. issue.loadRepo(e)
  329. apiIssue := &api.Issue{
  330. ID: issue.ID,
  331. URL: issue.APIURL(),
  332. HTMLURL: issue.HTMLURL(),
  333. Index: issue.Index,
  334. Poster: issue.Poster.APIFormat(),
  335. Title: issue.Title,
  336. Body: issue.Content,
  337. Labels: apiLabels,
  338. State: issue.State(),
  339. Comments: issue.NumComments,
  340. Created: issue.CreatedUnix.AsTime(),
  341. Updated: issue.UpdatedUnix.AsTime(),
  342. }
  343. apiIssue.Repo = &api.RepositoryMeta{
  344. ID: issue.Repo.ID,
  345. Name: issue.Repo.Name,
  346. FullName: issue.Repo.FullName(),
  347. }
  348. if issue.ClosedUnix != 0 {
  349. apiIssue.Closed = issue.ClosedUnix.AsTimePtr()
  350. }
  351. if issue.Milestone != nil {
  352. apiIssue.Milestone = issue.Milestone.APIFormat()
  353. }
  354. issue.loadAssignees(e)
  355. if len(issue.Assignees) > 0 {
  356. for _, assignee := range issue.Assignees {
  357. apiIssue.Assignees = append(apiIssue.Assignees, assignee.APIFormat())
  358. }
  359. apiIssue.Assignee = issue.Assignees[0].APIFormat() // For compatibility, we're keeping the first assignee as `apiIssue.Assignee`
  360. }
  361. if issue.IsPull {
  362. issue.loadPullRequest(e)
  363. apiIssue.PullRequest = &api.PullRequestMeta{
  364. HasMerged: issue.PullRequest.HasMerged,
  365. }
  366. if issue.PullRequest.HasMerged {
  367. apiIssue.PullRequest.Merged = issue.PullRequest.MergedUnix.AsTimePtr()
  368. }
  369. }
  370. if issue.DeadlineUnix != 0 {
  371. apiIssue.Deadline = issue.DeadlineUnix.AsTimePtr()
  372. }
  373. return apiIssue
  374. }
  375. // HashTag returns unique hash tag for issue.
  376. func (issue *Issue) HashTag() string {
  377. return "issue-" + com.ToStr(issue.ID)
  378. }
  379. // IsPoster returns true if given user by ID is the poster.
  380. func (issue *Issue) IsPoster(uid int64) bool {
  381. return issue.PosterID == uid
  382. }
  383. func (issue *Issue) hasLabel(e Engine, labelID int64) bool {
  384. return hasIssueLabel(e, issue.ID, labelID)
  385. }
  386. // HasLabel returns true if issue has been labeled by given ID.
  387. func (issue *Issue) HasLabel(labelID int64) bool {
  388. return issue.hasLabel(x, labelID)
  389. }
  390. // ReplyReference returns tokenized address to use for email reply headers
  391. func (issue *Issue) ReplyReference() string {
  392. var path string
  393. if issue.IsPull {
  394. path = "pulls"
  395. } else {
  396. path = "issues"
  397. }
  398. return fmt.Sprintf("%s/%s/%d@%s", issue.Repo.FullName(), path, issue.Index, setting.Domain)
  399. }
  400. func (issue *Issue) addLabel(e *xorm.Session, label *Label, doer *User) error {
  401. return newIssueLabel(e, issue, label, doer)
  402. }
  403. func (issue *Issue) addLabels(e *xorm.Session, labels []*Label, doer *User) error {
  404. return newIssueLabels(e, issue, labels, doer)
  405. }
  406. func (issue *Issue) getLabels(e Engine) (err error) {
  407. if len(issue.Labels) > 0 {
  408. return nil
  409. }
  410. issue.Labels, err = getLabelsByIssueID(e, issue.ID)
  411. if err != nil {
  412. return fmt.Errorf("getLabelsByIssueID: %v", err)
  413. }
  414. return nil
  415. }
  416. func (issue *Issue) removeLabel(e *xorm.Session, doer *User, label *Label) error {
  417. return deleteIssueLabel(e, issue, label, doer)
  418. }
  419. func (issue *Issue) clearLabels(e *xorm.Session, doer *User) (err error) {
  420. if err = issue.getLabels(e); err != nil {
  421. return fmt.Errorf("getLabels: %v", err)
  422. }
  423. for i := range issue.Labels {
  424. if err = issue.removeLabel(e, doer, issue.Labels[i]); err != nil {
  425. return fmt.Errorf("removeLabel: %v", err)
  426. }
  427. }
  428. return nil
  429. }
  430. // ClearLabels removes all issue labels as the given user.
  431. // Triggers appropriate WebHooks, if any.
  432. func (issue *Issue) ClearLabels(doer *User) (err error) {
  433. sess := x.NewSession()
  434. defer sess.Close()
  435. if err = sess.Begin(); err != nil {
  436. return err
  437. }
  438. if err := issue.loadRepo(sess); err != nil {
  439. return err
  440. } else if err = issue.loadPullRequest(sess); err != nil {
  441. return err
  442. }
  443. perm, err := getUserRepoPermission(sess, issue.Repo, doer)
  444. if err != nil {
  445. return err
  446. }
  447. if !perm.CanWriteIssuesOrPulls(issue.IsPull) {
  448. return ErrLabelNotExist{}
  449. }
  450. if err = issue.clearLabels(sess, doer); err != nil {
  451. return err
  452. }
  453. if err = sess.Commit(); err != nil {
  454. return fmt.Errorf("Commit: %v", err)
  455. }
  456. return nil
  457. }
  458. type labelSorter []*Label
  459. func (ts labelSorter) Len() int {
  460. return len([]*Label(ts))
  461. }
  462. func (ts labelSorter) Less(i, j int) bool {
  463. return []*Label(ts)[i].ID < []*Label(ts)[j].ID
  464. }
  465. func (ts labelSorter) Swap(i, j int) {
  466. []*Label(ts)[i], []*Label(ts)[j] = []*Label(ts)[j], []*Label(ts)[i]
  467. }
  468. // ReplaceLabels removes all current labels and add new labels to the issue.
  469. // Triggers appropriate WebHooks, if any.
  470. func (issue *Issue) ReplaceLabels(labels []*Label, doer *User) (err error) {
  471. sess := x.NewSession()
  472. defer sess.Close()
  473. if err = sess.Begin(); err != nil {
  474. return err
  475. }
  476. if err = issue.loadLabels(sess); err != nil {
  477. return err
  478. }
  479. sort.Sort(labelSorter(labels))
  480. sort.Sort(labelSorter(issue.Labels))
  481. var toAdd, toRemove []*Label
  482. addIndex, removeIndex := 0, 0
  483. for addIndex < len(labels) && removeIndex < len(issue.Labels) {
  484. addLabel := labels[addIndex]
  485. removeLabel := issue.Labels[removeIndex]
  486. if addLabel.ID == removeLabel.ID {
  487. addIndex++
  488. removeIndex++
  489. } else if addLabel.ID < removeLabel.ID {
  490. toAdd = append(toAdd, addLabel)
  491. addIndex++
  492. } else {
  493. toRemove = append(toRemove, removeLabel)
  494. removeIndex++
  495. }
  496. }
  497. toAdd = append(toAdd, labels[addIndex:]...)
  498. toRemove = append(toRemove, issue.Labels[removeIndex:]...)
  499. if len(toAdd) > 0 {
  500. if err = issue.addLabels(sess, toAdd, doer); err != nil {
  501. return fmt.Errorf("addLabels: %v", err)
  502. }
  503. }
  504. for _, l := range toRemove {
  505. if err = issue.removeLabel(sess, doer, l); err != nil {
  506. return fmt.Errorf("removeLabel: %v", err)
  507. }
  508. }
  509. return sess.Commit()
  510. }
  511. // ReadBy sets issue to be read by given user.
  512. func (issue *Issue) ReadBy(userID int64) error {
  513. if err := UpdateIssueUserByRead(userID, issue.ID); err != nil {
  514. return err
  515. }
  516. return setNotificationStatusReadIfUnread(x, userID, issue.ID)
  517. }
  518. func updateIssueCols(e Engine, issue *Issue, cols ...string) error {
  519. if _, err := e.ID(issue.ID).Cols(cols...).Update(issue); err != nil {
  520. return err
  521. }
  522. return nil
  523. }
  524. func (issue *Issue) changeStatus(e *xorm.Session, doer *User, isClosed bool) (*Comment, error) {
  525. // Reload the issue
  526. currentIssue, err := getIssueByID(e, issue.ID)
  527. if err != nil {
  528. return nil, err
  529. }
  530. // Nothing should be performed if current status is same as target status
  531. if currentIssue.IsClosed == isClosed {
  532. if !issue.IsPull {
  533. return nil, ErrIssueWasClosed{
  534. ID: issue.ID,
  535. }
  536. }
  537. return nil, ErrPullWasClosed{
  538. ID: issue.ID,
  539. }
  540. }
  541. // Check for open dependencies
  542. if isClosed && issue.Repo.isDependenciesEnabled(e) {
  543. // only check if dependencies are enabled and we're about to close an issue, otherwise reopening an issue would fail when there are unsatisfied dependencies
  544. noDeps, err := issueNoDependenciesLeft(e, issue)
  545. if err != nil {
  546. return nil, err
  547. }
  548. if !noDeps {
  549. return nil, ErrDependenciesLeft{issue.ID}
  550. }
  551. }
  552. issue.IsClosed = isClosed
  553. if isClosed {
  554. issue.ClosedUnix = timeutil.TimeStampNow()
  555. } else {
  556. issue.ClosedUnix = 0
  557. }
  558. if err = updateIssueCols(e, issue, "is_closed", "closed_unix"); err != nil {
  559. return nil, err
  560. }
  561. // Update issue count of labels
  562. if err = issue.getLabels(e); err != nil {
  563. return nil, err
  564. }
  565. for idx := range issue.Labels {
  566. if err = updateLabel(e, issue.Labels[idx]); err != nil {
  567. return nil, err
  568. }
  569. }
  570. // Update issue count of milestone
  571. if err := updateMilestoneClosedNum(e, issue.MilestoneID); err != nil {
  572. return nil, err
  573. }
  574. // New action comment
  575. cmtType := CommentTypeClose
  576. if !issue.IsClosed {
  577. cmtType = CommentTypeReopen
  578. }
  579. return createComment(e, &CreateCommentOptions{
  580. Type: cmtType,
  581. Doer: doer,
  582. Repo: issue.Repo,
  583. Issue: issue,
  584. })
  585. }
  586. // ChangeStatus changes issue status to open or closed.
  587. func (issue *Issue) ChangeStatus(doer *User, isClosed bool) (*Comment, error) {
  588. sess := x.NewSession()
  589. defer sess.Close()
  590. if err := sess.Begin(); err != nil {
  591. return nil, err
  592. }
  593. if err := issue.loadRepo(sess); err != nil {
  594. return nil, err
  595. }
  596. if err := issue.loadPoster(sess); err != nil {
  597. return nil, err
  598. }
  599. comment, err := issue.changeStatus(sess, doer, isClosed)
  600. if err != nil {
  601. return nil, err
  602. }
  603. if err = sess.Commit(); err != nil {
  604. return nil, fmt.Errorf("Commit: %v", err)
  605. }
  606. return comment, nil
  607. }
  608. // ChangeTitle changes the title of this issue, as the given user.
  609. func (issue *Issue) ChangeTitle(doer *User, oldTitle string) (err error) {
  610. sess := x.NewSession()
  611. defer sess.Close()
  612. if err = sess.Begin(); err != nil {
  613. return err
  614. }
  615. if err = updateIssueCols(sess, issue, "name"); err != nil {
  616. return fmt.Errorf("updateIssueCols: %v", err)
  617. }
  618. if err = issue.loadRepo(sess); err != nil {
  619. return fmt.Errorf("loadRepo: %v", err)
  620. }
  621. var opts = &CreateCommentOptions{
  622. Type: CommentTypeChangeTitle,
  623. Doer: doer,
  624. Repo: issue.Repo,
  625. Issue: issue,
  626. OldTitle: oldTitle,
  627. NewTitle: issue.Title,
  628. }
  629. if _, err = createComment(sess, opts); err != nil {
  630. return fmt.Errorf("createComment: %v", err)
  631. }
  632. if err = issue.addCrossReferences(sess, doer, true); err != nil {
  633. return err
  634. }
  635. return sess.Commit()
  636. }
  637. // AddDeletePRBranchComment adds delete branch comment for pull request issue
  638. func AddDeletePRBranchComment(doer *User, repo *Repository, issueID int64, branchName string) error {
  639. issue, err := getIssueByID(x, issueID)
  640. if err != nil {
  641. return err
  642. }
  643. sess := x.NewSession()
  644. defer sess.Close()
  645. if err := sess.Begin(); err != nil {
  646. return err
  647. }
  648. var opts = &CreateCommentOptions{
  649. Type: CommentTypeDeleteBranch,
  650. Doer: doer,
  651. Repo: repo,
  652. Issue: issue,
  653. CommitSHA: branchName,
  654. }
  655. if _, err = createComment(sess, opts); err != nil {
  656. return err
  657. }
  658. return sess.Commit()
  659. }
  660. // UpdateAttachments update attachments by UUIDs for the issue
  661. func (issue *Issue) UpdateAttachments(uuids []string) (err error) {
  662. sess := x.NewSession()
  663. defer sess.Close()
  664. if err = sess.Begin(); err != nil {
  665. return err
  666. }
  667. attachments, err := getAttachmentsByUUIDs(sess, uuids)
  668. if err != nil {
  669. return fmt.Errorf("getAttachmentsByUUIDs [uuids: %v]: %v", uuids, err)
  670. }
  671. for i := 0; i < len(attachments); i++ {
  672. attachments[i].IssueID = issue.ID
  673. if err := updateAttachment(sess, attachments[i]); err != nil {
  674. return fmt.Errorf("update attachment [id: %d]: %v", attachments[i].ID, err)
  675. }
  676. }
  677. return sess.Commit()
  678. }
  679. // ChangeContent changes issue content, as the given user.
  680. func (issue *Issue) ChangeContent(doer *User, content string) (err error) {
  681. issue.Content = content
  682. sess := x.NewSession()
  683. defer sess.Close()
  684. if err = sess.Begin(); err != nil {
  685. return err
  686. }
  687. if err = updateIssueCols(sess, issue, "content"); err != nil {
  688. return fmt.Errorf("UpdateIssueCols: %v", err)
  689. }
  690. if err = issue.addCrossReferences(sess, doer, true); err != nil {
  691. return err
  692. }
  693. return sess.Commit()
  694. }
  695. // GetTasks returns the amount of tasks in the issues content
  696. func (issue *Issue) GetTasks() int {
  697. return len(issueTasksPat.FindAllStringIndex(issue.Content, -1))
  698. }
  699. // GetTasksDone returns the amount of completed tasks in the issues content
  700. func (issue *Issue) GetTasksDone() int {
  701. return len(issueTasksDonePat.FindAllStringIndex(issue.Content, -1))
  702. }
  703. // GetLastEventTimestamp returns the last user visible event timestamp, either the creation of this issue or the close.
  704. func (issue *Issue) GetLastEventTimestamp() timeutil.TimeStamp {
  705. if issue.IsClosed {
  706. return issue.ClosedUnix
  707. }
  708. return issue.CreatedUnix
  709. }
  710. // GetLastEventLabel returns the localization label for the current issue.
  711. func (issue *Issue) GetLastEventLabel() string {
  712. if issue.IsClosed {
  713. if issue.IsPull && issue.PullRequest.HasMerged {
  714. return "repo.pulls.merged_by"
  715. }
  716. return "repo.issues.closed_by"
  717. }
  718. return "repo.issues.opened_by"
  719. }
  720. // GetLastEventLabelFake returns the localization label for the current issue without providing a link in the username.
  721. func (issue *Issue) GetLastEventLabelFake() string {
  722. if issue.IsClosed {
  723. if issue.IsPull && issue.PullRequest.HasMerged {
  724. return "repo.pulls.merged_by_fake"
  725. }
  726. return "repo.issues.closed_by_fake"
  727. }
  728. return "repo.issues.opened_by_fake"
  729. }
  730. // NewIssueOptions represents the options of a new issue.
  731. type NewIssueOptions struct {
  732. Repo *Repository
  733. Issue *Issue
  734. LabelIDs []int64
  735. Attachments []string // In UUID format.
  736. IsPull bool
  737. }
  738. func newIssue(e *xorm.Session, doer *User, opts NewIssueOptions) (err error) {
  739. opts.Issue.Title = strings.TrimSpace(opts.Issue.Title)
  740. if opts.Issue.MilestoneID > 0 {
  741. milestone, err := getMilestoneByRepoID(e, opts.Issue.RepoID, opts.Issue.MilestoneID)
  742. if err != nil && !IsErrMilestoneNotExist(err) {
  743. return fmt.Errorf("getMilestoneByID: %v", err)
  744. }
  745. // Assume milestone is invalid and drop silently.
  746. opts.Issue.MilestoneID = 0
  747. if milestone != nil {
  748. opts.Issue.MilestoneID = milestone.ID
  749. opts.Issue.Milestone = milestone
  750. }
  751. }
  752. // Milestone validation should happen before insert actual object.
  753. if _, err := e.SetExpr("`index`", "coalesce(MAX(`index`),0)+1").
  754. Where("repo_id=?", opts.Issue.RepoID).
  755. Insert(opts.Issue); err != nil {
  756. return ErrNewIssueInsert{err}
  757. }
  758. inserted, err := getIssueByID(e, opts.Issue.ID)
  759. if err != nil {
  760. return err
  761. }
  762. // Patch Index with the value calculated by the database
  763. opts.Issue.Index = inserted.Index
  764. if opts.Issue.MilestoneID > 0 {
  765. if _, err = e.Exec("UPDATE `milestone` SET num_issues=num_issues+1 WHERE id=?", opts.Issue.MilestoneID); err != nil {
  766. return err
  767. }
  768. var opts = &CreateCommentOptions{
  769. Type: CommentTypeMilestone,
  770. Doer: doer,
  771. Repo: opts.Repo,
  772. Issue: opts.Issue,
  773. OldMilestoneID: 0,
  774. MilestoneID: opts.Issue.MilestoneID,
  775. }
  776. if _, err = createComment(e, opts); err != nil {
  777. return err
  778. }
  779. }
  780. if opts.IsPull {
  781. _, err = e.Exec("UPDATE `repository` SET num_pulls = num_pulls + 1 WHERE id = ?", opts.Issue.RepoID)
  782. } else {
  783. _, err = e.Exec("UPDATE `repository` SET num_issues = num_issues + 1 WHERE id = ?", opts.Issue.RepoID)
  784. }
  785. if err != nil {
  786. return err
  787. }
  788. if len(opts.LabelIDs) > 0 {
  789. // During the session, SQLite3 driver cannot handle retrieve objects after update something.
  790. // So we have to get all needed labels first.
  791. labels := make([]*Label, 0, len(opts.LabelIDs))
  792. if err = e.In("id", opts.LabelIDs).Find(&labels); err != nil {
  793. return fmt.Errorf("find all labels [label_ids: %v]: %v", opts.LabelIDs, err)
  794. }
  795. if err = opts.Issue.loadPoster(e); err != nil {
  796. return err
  797. }
  798. for _, label := range labels {
  799. // Silently drop invalid labels.
  800. if label.RepoID != opts.Repo.ID {
  801. continue
  802. }
  803. if err = opts.Issue.addLabel(e, label, opts.Issue.Poster); err != nil {
  804. return fmt.Errorf("addLabel [id: %d]: %v", label.ID, err)
  805. }
  806. }
  807. }
  808. if err = newIssueUsers(e, opts.Repo, opts.Issue); err != nil {
  809. return err
  810. }
  811. if len(opts.Attachments) > 0 {
  812. attachments, err := getAttachmentsByUUIDs(e, opts.Attachments)
  813. if err != nil {
  814. return fmt.Errorf("getAttachmentsByUUIDs [uuids: %v]: %v", opts.Attachments, err)
  815. }
  816. for i := 0; i < len(attachments); i++ {
  817. attachments[i].IssueID = opts.Issue.ID
  818. if _, err = e.ID(attachments[i].ID).Update(attachments[i]); err != nil {
  819. return fmt.Errorf("update attachment [id: %d]: %v", attachments[i].ID, err)
  820. }
  821. }
  822. }
  823. if err = opts.Issue.loadAttributes(e); err != nil {
  824. return err
  825. }
  826. return opts.Issue.addCrossReferences(e, doer, false)
  827. }
  828. // NewIssue creates new issue with labels for repository.
  829. func NewIssue(repo *Repository, issue *Issue, labelIDs []int64, uuids []string) (err error) {
  830. // Retry several times in case INSERT fails due to duplicate key for (repo_id, index); see #7887
  831. i := 0
  832. for {
  833. if err = newIssueAttempt(repo, issue, labelIDs, uuids); err == nil {
  834. return nil
  835. }
  836. if !IsErrNewIssueInsert(err) {
  837. return err
  838. }
  839. if i++; i == issueMaxDupIndexAttempts {
  840. break
  841. }
  842. log.Error("NewIssue: error attempting to insert the new issue; will retry. Original error: %v", err)
  843. }
  844. return fmt.Errorf("NewIssue: too many errors attempting to insert the new issue. Last error was: %v", err)
  845. }
  846. func newIssueAttempt(repo *Repository, issue *Issue, labelIDs []int64, uuids []string) (err error) {
  847. sess := x.NewSession()
  848. defer sess.Close()
  849. if err = sess.Begin(); err != nil {
  850. return err
  851. }
  852. if err = newIssue(sess, issue.Poster, NewIssueOptions{
  853. Repo: repo,
  854. Issue: issue,
  855. LabelIDs: labelIDs,
  856. Attachments: uuids,
  857. }); err != nil {
  858. if IsErrUserDoesNotHaveAccessToRepo(err) || IsErrNewIssueInsert(err) {
  859. return err
  860. }
  861. return fmt.Errorf("newIssue: %v", err)
  862. }
  863. if err = sess.Commit(); err != nil {
  864. return fmt.Errorf("Commit: %v", err)
  865. }
  866. return nil
  867. }
  868. // GetIssueByIndex returns raw issue without loading attributes by index in a repository.
  869. func GetIssueByIndex(repoID, index int64) (*Issue, error) {
  870. issue := &Issue{
  871. RepoID: repoID,
  872. Index: index,
  873. }
  874. has, err := x.Get(issue)
  875. if err != nil {
  876. return nil, err
  877. } else if !has {
  878. return nil, ErrIssueNotExist{0, repoID, index}
  879. }
  880. return issue, nil
  881. }
  882. // GetIssueWithAttrsByIndex returns issue by index in a repository.
  883. func GetIssueWithAttrsByIndex(repoID, index int64) (*Issue, error) {
  884. issue, err := GetIssueByIndex(repoID, index)
  885. if err != nil {
  886. return nil, err
  887. }
  888. return issue, issue.LoadAttributes()
  889. }
  890. func getIssueByID(e Engine, id int64) (*Issue, error) {
  891. issue := new(Issue)
  892. has, err := e.ID(id).Get(issue)
  893. if err != nil {
  894. return nil, err
  895. } else if !has {
  896. return nil, ErrIssueNotExist{id, 0, 0}
  897. }
  898. return issue, nil
  899. }
  900. // GetIssueWithAttrsByID returns an issue with attributes by given ID.
  901. func GetIssueWithAttrsByID(id int64) (*Issue, error) {
  902. issue, err := getIssueByID(x, id)
  903. if err != nil {
  904. return nil, err
  905. }
  906. return issue, issue.loadAttributes(x)
  907. }
  908. // GetIssueByID returns an issue by given ID.
  909. func GetIssueByID(id int64) (*Issue, error) {
  910. return getIssueByID(x, id)
  911. }
  912. func getIssuesByIDs(e Engine, issueIDs []int64) ([]*Issue, error) {
  913. issues := make([]*Issue, 0, 10)
  914. return issues, e.In("id", issueIDs).Find(&issues)
  915. }
  916. func getIssueIDsByRepoID(e Engine, repoID int64) ([]int64, error) {
  917. var ids = make([]int64, 0, 10)
  918. err := e.Table("issue").Where("repo_id = ?", repoID).Find(&ids)
  919. return ids, err
  920. }
  921. // GetIssueIDsByRepoID returns all issue ids by repo id
  922. func GetIssueIDsByRepoID(repoID int64) ([]int64, error) {
  923. return getIssueIDsByRepoID(x, repoID)
  924. }
  925. // GetIssuesByIDs return issues with the given IDs.
  926. func GetIssuesByIDs(issueIDs []int64) ([]*Issue, error) {
  927. return getIssuesByIDs(x, issueIDs)
  928. }
  929. // IssuesOptions represents options of an issue.
  930. type IssuesOptions struct {
  931. RepoIDs []int64 // include all repos if empty
  932. AssigneeID int64
  933. PosterID int64
  934. MentionedID int64
  935. MilestoneID int64
  936. Page int
  937. PageSize int
  938. IsClosed util.OptionalBool
  939. IsPull util.OptionalBool
  940. LabelIDs []int64
  941. SortType string
  942. IssueIDs []int64
  943. // prioritize issues from this repo
  944. PriorityRepoID int64
  945. }
  946. // sortIssuesSession sort an issues-related session based on the provided
  947. // sortType string
  948. func sortIssuesSession(sess *xorm.Session, sortType string, priorityRepoID int64) {
  949. switch sortType {
  950. case "oldest":
  951. sess.Asc("issue.created_unix")
  952. case "recentupdate":
  953. sess.Desc("issue.updated_unix")
  954. case "leastupdate":
  955. sess.Asc("issue.updated_unix")
  956. case "mostcomment":
  957. sess.Desc("issue.num_comments")
  958. case "leastcomment":
  959. sess.Asc("issue.num_comments")
  960. case "priority":
  961. sess.Desc("issue.priority")
  962. case "nearduedate":
  963. // 253370764800 is 01/01/9999 @ 12:00am (UTC)
  964. sess.OrderBy("CASE WHEN issue.deadline_unix = 0 THEN 253370764800 ELSE issue.deadline_unix END ASC")
  965. case "farduedate":
  966. sess.Desc("issue.deadline_unix")
  967. case "priorityrepo":
  968. sess.OrderBy("CASE WHEN issue.repo_id = " + strconv.FormatInt(priorityRepoID, 10) + " THEN 1 ELSE 2 END, issue.created_unix DESC")
  969. default:
  970. sess.Desc("issue.created_unix")
  971. }
  972. }
  973. func (opts *IssuesOptions) setupSession(sess *xorm.Session) {
  974. if opts.Page >= 0 && opts.PageSize > 0 {
  975. var start int
  976. if opts.Page == 0 {
  977. start = 0
  978. } else {
  979. start = (opts.Page - 1) * opts.PageSize
  980. }
  981. sess.Limit(opts.PageSize, start)
  982. }
  983. if len(opts.IssueIDs) > 0 {
  984. sess.In("issue.id", opts.IssueIDs)
  985. }
  986. if len(opts.RepoIDs) > 0 {
  987. // In case repository IDs are provided but actually no repository has issue.
  988. sess.In("issue.repo_id", opts.RepoIDs)
  989. }
  990. switch opts.IsClosed {
  991. case util.OptionalBoolTrue:
  992. sess.And("issue.is_closed=?", true)
  993. case util.OptionalBoolFalse:
  994. sess.And("issue.is_closed=?", false)
  995. }
  996. if opts.AssigneeID > 0 {
  997. sess.Join("INNER", "issue_assignees", "issue.id = issue_assignees.issue_id").
  998. And("issue_assignees.assignee_id = ?", opts.AssigneeID)
  999. }
  1000. if opts.PosterID > 0 {
  1001. sess.And("issue.poster_id=?", opts.PosterID)
  1002. }
  1003. if opts.MentionedID > 0 {
  1004. sess.Join("INNER", "issue_user", "issue.id = issue_user.issue_id").
  1005. And("issue_user.is_mentioned = ?", true).
  1006. And("issue_user.uid = ?", opts.MentionedID)
  1007. }
  1008. if opts.MilestoneID > 0 {
  1009. sess.And("issue.milestone_id=?", opts.MilestoneID)
  1010. }
  1011. switch opts.IsPull {
  1012. case util.OptionalBoolTrue:
  1013. sess.And("issue.is_pull=?", true)
  1014. case util.OptionalBoolFalse:
  1015. sess.And("issue.is_pull=?", false)
  1016. }
  1017. if opts.LabelIDs != nil {
  1018. for i, labelID := range opts.LabelIDs {
  1019. if labelID > 0 {
  1020. sess.Join("INNER", fmt.Sprintf("issue_label il%d", i),
  1021. fmt.Sprintf("issue.id = il%[1]d.issue_id AND il%[1]d.label_id = %[2]d", i, labelID))
  1022. } else {
  1023. sess.Where("issue.id not in (select issue_id from issue_label where label_id = ?)", -labelID)
  1024. }
  1025. }
  1026. }
  1027. }
  1028. // CountIssuesByRepo map from repoID to number of issues matching the options
  1029. func CountIssuesByRepo(opts *IssuesOptions) (map[int64]int64, error) {
  1030. sess := x.NewSession()
  1031. defer sess.Close()
  1032. opts.setupSession(sess)
  1033. countsSlice := make([]*struct {
  1034. RepoID int64
  1035. Count int64
  1036. }, 0, 10)
  1037. if err := sess.GroupBy("issue.repo_id").
  1038. Select("issue.repo_id AS repo_id, COUNT(*) AS count").
  1039. Table("issue").
  1040. Find(&countsSlice); err != nil {
  1041. return nil, err
  1042. }
  1043. countMap := make(map[int64]int64, len(countsSlice))
  1044. for _, c := range countsSlice {
  1045. countMap[c.RepoID] = c.Count
  1046. }
  1047. return countMap, nil
  1048. }
  1049. // Issues returns a list of issues by given conditions.
  1050. func Issues(opts *IssuesOptions) ([]*Issue, error) {
  1051. sess := x.NewSession()
  1052. defer sess.Close()
  1053. opts.setupSession(sess)
  1054. sortIssuesSession(sess, opts.SortType, opts.PriorityRepoID)
  1055. issues := make([]*Issue, 0, setting.UI.IssuePagingNum)
  1056. if err := sess.Find(&issues); err != nil {
  1057. return nil, fmt.Errorf("Find: %v", err)
  1058. }
  1059. sess.Close()
  1060. if err := IssueList(issues).LoadAttributes(); err != nil {
  1061. return nil, fmt.Errorf("LoadAttributes: %v", err)
  1062. }
  1063. return issues, nil
  1064. }
  1065. // GetParticipantsIDsByIssueID returns the IDs of all users who participated in comments of an issue,
  1066. // but skips joining with `user` for performance reasons.
  1067. // User permissions must be verified elsewhere if required.
  1068. func GetParticipantsIDsByIssueID(issueID int64) ([]int64, error) {
  1069. userIDs := make([]int64, 0, 5)
  1070. return userIDs, x.Table("comment").
  1071. Cols("poster_id").
  1072. Where("issue_id = ?", issueID).
  1073. And("type in (?,?,?)", CommentTypeComment, CommentTypeCode, CommentTypeReview).
  1074. Distinct("poster_id").
  1075. Find(&userIDs)
  1076. }
  1077. // GetParticipantsByIssueID returns all users who are participated in comments of an issue.
  1078. func GetParticipantsByIssueID(issueID int64) ([]*User, error) {
  1079. return getParticipantsByIssueID(x, issueID)
  1080. }
  1081. func getParticipantsByIssueID(e Engine, issueID int64) ([]*User, error) {
  1082. userIDs := make([]int64, 0, 5)
  1083. if err := e.Table("comment").Cols("poster_id").
  1084. Where("`comment`.issue_id = ?", issueID).
  1085. And("`comment`.type in (?,?,?)", CommentTypeComment, CommentTypeCode, CommentTypeReview).
  1086. And("`user`.is_active = ?", true).
  1087. And("`user`.prohibit_login = ?", false).
  1088. Join("INNER", "`user`", "`user`.id = `comment`.poster_id").
  1089. Distinct("poster_id").
  1090. Find(&userIDs); err != nil {
  1091. return nil, fmt.Errorf("get poster IDs: %v", err)
  1092. }
  1093. if len(userIDs) == 0 {
  1094. return nil, nil
  1095. }
  1096. users := make([]*User, 0, len(userIDs))
  1097. return users, e.In("id", userIDs).Find(&users)
  1098. }
  1099. // UpdateIssueMentions updates issue-user relations for mentioned users.
  1100. func UpdateIssueMentions(ctx DBContext, issueID int64, mentions []*User) error {
  1101. if len(mentions) == 0 {
  1102. return nil
  1103. }
  1104. ids := make([]int64, len(mentions))
  1105. for i, u := range mentions {
  1106. ids[i] = u.ID
  1107. }
  1108. if err := UpdateIssueUsersByMentions(ctx, issueID, ids); err != nil {
  1109. return fmt.Errorf("UpdateIssueUsersByMentions: %v", err)
  1110. }
  1111. return nil
  1112. }
  1113. // IssueStats represents issue statistic information.
  1114. type IssueStats struct {
  1115. OpenCount, ClosedCount int64
  1116. YourRepositoriesCount int64
  1117. AssignCount int64
  1118. CreateCount int64
  1119. MentionCount int64
  1120. }
  1121. // Filter modes.
  1122. const (
  1123. FilterModeAll = iota
  1124. FilterModeAssign
  1125. FilterModeCreate
  1126. FilterModeMention
  1127. )
  1128. func parseCountResult(results []map[string][]byte) int64 {
  1129. if len(results) == 0 {
  1130. return 0
  1131. }
  1132. for _, result := range results[0] {
  1133. return com.StrTo(string(result)).MustInt64()
  1134. }
  1135. return 0
  1136. }
  1137. // IssueStatsOptions contains parameters accepted by GetIssueStats.
  1138. type IssueStatsOptions struct {
  1139. RepoID int64
  1140. Labels string
  1141. MilestoneID int64
  1142. AssigneeID int64
  1143. MentionedID int64
  1144. PosterID int64
  1145. IsPull util.OptionalBool
  1146. IssueIDs []int64
  1147. }
  1148. // GetIssueStats returns issue statistic information by given conditions.
  1149. func GetIssueStats(opts *IssueStatsOptions) (*IssueStats, error) {
  1150. stats := &IssueStats{}
  1151. countSession := func(opts *IssueStatsOptions) *xorm.Session {
  1152. sess := x.
  1153. Where("issue.repo_id = ?", opts.RepoID)
  1154. if len(opts.IssueIDs) > 0 {
  1155. sess.In("issue.id", opts.IssueIDs)
  1156. }
  1157. if len(opts.Labels) > 0 && opts.Labels != "0" {
  1158. labelIDs, err := base.StringsToInt64s(strings.Split(opts.Labels, ","))
  1159. if err != nil {
  1160. log.Warn("Malformed Labels argument: %s", opts.Labels)
  1161. } else {
  1162. for i, labelID := range labelIDs {
  1163. if labelID > 0 {
  1164. sess.Join("INNER", fmt.Sprintf("issue_label il%d", i),
  1165. fmt.Sprintf("issue.id = il%[1]d.issue_id AND il%[1]d.label_id = %[2]d", i, labelID))
  1166. } else {
  1167. sess.Where("issue.id NOT IN (SELECT issue_id FROM issue_label WHERE label_id = ?)", -labelID)
  1168. }
  1169. }
  1170. }
  1171. }
  1172. if opts.MilestoneID > 0 {
  1173. sess.And("issue.milestone_id = ?", opts.MilestoneID)
  1174. }
  1175. if opts.AssigneeID > 0 {
  1176. sess.Join("INNER", "issue_assignees", "issue.id = issue_assignees.issue_id").
  1177. And("issue_assignees.assignee_id = ?", opts.AssigneeID)
  1178. }
  1179. if opts.PosterID > 0 {
  1180. sess.And("issue.poster_id = ?", opts.PosterID)
  1181. }
  1182. if opts.MentionedID > 0 {
  1183. sess.Join("INNER", "issue_user", "issue.id = issue_user.issue_id").
  1184. And("issue_user.uid = ?", opts.MentionedID).
  1185. And("issue_user.is_mentioned = ?", true)
  1186. }
  1187. switch opts.IsPull {
  1188. case util.OptionalBoolTrue:
  1189. sess.And("issue.is_pull=?", true)
  1190. case util.OptionalBoolFalse:
  1191. sess.And("issue.is_pull=?", false)
  1192. }
  1193. return sess
  1194. }
  1195. var err error
  1196. stats.OpenCount, err = countSession(opts).
  1197. And("issue.is_closed = ?", false).
  1198. Count(new(Issue))
  1199. if err != nil {
  1200. return stats, err
  1201. }
  1202. stats.ClosedCount, err = countSession(opts).
  1203. And("issue.is_closed = ?", true).
  1204. Count(new(Issue))
  1205. return stats, err
  1206. }
  1207. // UserIssueStatsOptions contains parameters accepted by GetUserIssueStats.
  1208. type UserIssueStatsOptions struct {
  1209. UserID int64
  1210. RepoIDs []int64
  1211. UserRepoIDs []int64
  1212. FilterMode int
  1213. IsPull bool
  1214. IsClosed bool
  1215. }
  1216. // GetUserIssueStats returns issue statistic information for dashboard by given conditions.
  1217. func GetUserIssueStats(opts UserIssueStatsOptions) (*IssueStats, error) {
  1218. var err error
  1219. stats := &IssueStats{}
  1220. cond := builder.NewCond()
  1221. cond = cond.And(builder.Eq{"issue.is_pull": opts.IsPull})
  1222. if len(opts.RepoIDs) > 0 {
  1223. cond = cond.And(builder.In("issue.repo_id", opts.RepoIDs))
  1224. }
  1225. switch opts.FilterMode {
  1226. case FilterModeAll:
  1227. stats.OpenCount, err = x.Where(cond).And("issue.is_closed = ?", false).
  1228. And(builder.In("issue.repo_id", opts.UserRepoIDs)).
  1229. Count(new(Issue))
  1230. if err != nil {
  1231. return nil, err
  1232. }
  1233. stats.ClosedCount, err = x.Where(cond).And("issue.is_closed = ?", true).
  1234. And(builder.In("issue.repo_id", opts.UserRepoIDs)).
  1235. Count(new(Issue))
  1236. if err != nil {
  1237. return nil, err
  1238. }
  1239. case FilterModeAssign:
  1240. stats.OpenCount, err = x.Where(cond).And("issue.is_closed = ?", false).
  1241. Join("INNER", "issue_assignees", "issue.id = issue_assignees.issue_id").
  1242. And("issue_assignees.assignee_id = ?", opts.UserID).
  1243. Count(new(Issue))
  1244. if err != nil {
  1245. return nil, err
  1246. }
  1247. stats.ClosedCount, err = x.Where(cond).And("issue.is_closed = ?", true).
  1248. Join("INNER", "issue_assignees", "issue.id = issue_assignees.issue_id").
  1249. And("issue_assignees.assignee_id = ?", opts.UserID).
  1250. Count(new(Issue))
  1251. if err != nil {
  1252. return nil, err
  1253. }
  1254. case FilterModeCreate:
  1255. stats.OpenCount, err = x.Where(cond).And("issue.is_closed = ?", false).
  1256. And("issue.poster_id = ?", opts.UserID).
  1257. Count(new(Issue))
  1258. if err != nil {
  1259. return nil, err
  1260. }
  1261. stats.ClosedCount, err = x.Where(cond).And("issue.is_closed = ?", true).
  1262. And("issue.poster_id = ?", opts.UserID).
  1263. Count(new(Issue))
  1264. if err != nil {
  1265. return nil, err
  1266. }
  1267. case FilterModeMention:
  1268. stats.OpenCount, err = x.Where(cond).And("issue.is_closed = ?", false).
  1269. Join("INNER", "issue_user", "issue.id = issue_user.issue_id and issue_user.is_mentioned = ?", true).
  1270. And("issue_user.uid = ?", opts.UserID).
  1271. Count(new(Issue))
  1272. if err != nil {
  1273. return nil, err
  1274. }
  1275. stats.ClosedCount, err = x.Where(cond).And("issue.is_closed = ?", true).
  1276. Join("INNER", "issue_user", "issue.id = issue_user.issue_id and issue_user.is_mentioned = ?", true).
  1277. And("issue_user.uid = ?", opts.UserID).
  1278. Count(new(Issue))
  1279. if err != nil {
  1280. return nil, err
  1281. }
  1282. }
  1283. cond = cond.And(builder.Eq{"issue.is_closed": opts.IsClosed})
  1284. stats.AssignCount, err = x.Where(cond).
  1285. Join("INNER", "issue_assignees", "issue.id = issue_assignees.issue_id").
  1286. And("issue_assignees.assignee_id = ?", opts.UserID).
  1287. Count(new(Issue))
  1288. if err != nil {
  1289. return nil, err
  1290. }
  1291. stats.CreateCount, err = x.Where(cond).
  1292. And("poster_id = ?", opts.UserID).
  1293. Count(new(Issue))
  1294. if err != nil {
  1295. return nil, err
  1296. }
  1297. stats.MentionCount, err = x.Where(cond).
  1298. Join("INNER", "issue_user", "issue.id = issue_user.issue_id and issue_user.is_mentioned = ?", true).
  1299. And("issue_user.uid = ?", opts.UserID).
  1300. Count(new(Issue))
  1301. if err != nil {
  1302. return nil, err
  1303. }
  1304. stats.YourRepositoriesCount, err = x.Where(cond).
  1305. And(builder.In("issue.repo_id", opts.UserRepoIDs)).
  1306. Count(new(Issue))
  1307. if err != nil {
  1308. return nil, err
  1309. }
  1310. return stats, nil
  1311. }
  1312. // GetRepoIssueStats returns number of open and closed repository issues by given filter mode.
  1313. func GetRepoIssueStats(repoID, uid int64, filterMode int, isPull bool) (numOpen int64, numClosed int64) {
  1314. countSession := func(isClosed, isPull bool, repoID int64) *xorm.Session {
  1315. sess := x.
  1316. Where("is_closed = ?", isClosed).
  1317. And("is_pull = ?", isPull).
  1318. And("repo_id = ?", repoID)
  1319. return sess
  1320. }
  1321. openCountSession := countSession(false, isPull, repoID)
  1322. closedCountSession := countSession(true, isPull, repoID)
  1323. switch filterMode {
  1324. case FilterModeAssign:
  1325. openCountSession.Join("INNER", "issue_assignees", "issue.id = issue_assignees.issue_id").
  1326. And("issue_assignees.assignee_id = ?", uid)
  1327. closedCountSession.Join("INNER", "issue_assignees", "issue.id = issue_assignees.issue_id").
  1328. And("issue_assignees.assignee_id = ?", uid)
  1329. case FilterModeCreate:
  1330. openCountSession.And("poster_id = ?", uid)
  1331. closedCountSession.And("poster_id = ?", uid)
  1332. }
  1333. openResult, _ := openCountSession.Count(new(Issue))
  1334. closedResult, _ := closedCountSession.Count(new(Issue))
  1335. return openResult, closedResult
  1336. }
  1337. // SearchIssueIDsByKeyword search issues on database
  1338. func SearchIssueIDsByKeyword(kw string, repoIDs []int64, limit, start int) (int64, []int64, error) {
  1339. var repoCond = builder.In("repo_id", repoIDs)
  1340. var subQuery = builder.Select("id").From("issue").Where(repoCond)
  1341. var cond = builder.And(
  1342. repoCond,
  1343. builder.Or(
  1344. builder.Like{"name", kw},
  1345. builder.Like{"content", kw},
  1346. builder.In("id", builder.Select("issue_id").
  1347. From("comment").
  1348. Where(builder.And(
  1349. builder.Eq{"type": CommentTypeComment},
  1350. builder.In("issue_id", subQuery),
  1351. builder.Like{"content", kw},
  1352. )),
  1353. ),
  1354. ),
  1355. )
  1356. var ids = make([]int64, 0, limit)
  1357. err := x.Distinct("id").Table("issue").Where(cond).Limit(limit, start).Find(&ids)
  1358. if err != nil {
  1359. return 0, nil, err
  1360. }
  1361. total, err := x.Distinct("id").Table("issue").Where(cond).Count()
  1362. if err != nil {
  1363. return 0, nil, err
  1364. }
  1365. return total, ids, nil
  1366. }
  1367. // UpdateIssueByAPI updates all allowed fields of given issue.
  1368. func UpdateIssueByAPI(issue *Issue) error {
  1369. sess := x.NewSession()
  1370. defer sess.Close()
  1371. if err := sess.Begin(); err != nil {
  1372. return err
  1373. }
  1374. if _, err := sess.ID(issue.ID).Cols(
  1375. "name", "is_closed", "content", "milestone_id", "priority",
  1376. "deadline_unix", "updated_unix", "closed_unix", "is_locked").
  1377. Update(issue); err != nil {
  1378. return err
  1379. }
  1380. if err := issue.loadPoster(sess); err != nil {
  1381. return err
  1382. }
  1383. if err := issue.addCrossReferences(sess, issue.Poster, true); err != nil {
  1384. return err
  1385. }
  1386. return sess.Commit()
  1387. }
  1388. // UpdateIssueDeadline updates an issue deadline and adds comments. Setting a deadline to 0 means deleting it.
  1389. func UpdateIssueDeadline(issue *Issue, deadlineUnix timeutil.TimeStamp, doer *User) (err error) {
  1390. // if the deadline hasn't changed do nothing
  1391. if issue.DeadlineUnix == deadlineUnix {
  1392. return nil
  1393. }
  1394. sess := x.NewSession()
  1395. defer sess.Close()
  1396. if err := sess.Begin(); err != nil {
  1397. return err
  1398. }
  1399. // Update the deadline
  1400. if err = updateIssueCols(sess, &Issue{ID: issue.ID, DeadlineUnix: deadlineUnix}, "deadline_unix"); err != nil {
  1401. return err
  1402. }
  1403. // Make the comment
  1404. if _, err = createDeadlineComment(sess, doer, issue, deadlineUnix); err != nil {
  1405. return fmt.Errorf("createRemovedDueDateComment: %v", err)
  1406. }
  1407. return sess.Commit()
  1408. }
  1409. // DependencyInfo represents high level information about an issue which is a dependency of another issue.
  1410. type DependencyInfo struct {
  1411. Issue `xorm:"extends"`
  1412. Repository `xorm:"extends"`
  1413. }
  1414. // Get Blocked By Dependencies, aka all issues this issue is blocked by.
  1415. func (issue *Issue) getBlockedByDependencies(e Engine) (issueDeps []*DependencyInfo, err error) {
  1416. return issueDeps, e.
  1417. Table("issue").
  1418. Join("INNER", "repository", "repository.id = issue.repo_id").
  1419. Join("INNER", "issue_dependency", "issue_dependency.dependency_id = issue.id").
  1420. Where("issue_id = ?", issue.ID).
  1421. //sort by repo id then created date, with the issues of the same repo at the beginning of the list
  1422. OrderBy("CASE WHEN issue.repo_id = " + strconv.FormatInt(issue.RepoID, 10) + " THEN 0 ELSE issue.repo_id END, issue.created_unix DESC").
  1423. Find(&issueDeps)
  1424. }
  1425. // Get Blocking Dependencies, aka all issues this issue blocks.
  1426. func (issue *Issue) getBlockingDependencies(e Engine) (issueDeps []*DependencyInfo, err error) {
  1427. return issueDeps, e.
  1428. Table("issue").
  1429. Join("INNER", "repository", "repository.id = issue.repo_id").
  1430. Join("INNER", "issue_dependency", "issue_dependency.issue_id = issue.id").
  1431. Where("dependency_id = ?", issue.ID).
  1432. //sort by repo id then created date, with the issues of the same repo at the beginning of the list
  1433. OrderBy("CASE WHEN issue.repo_id = " + strconv.FormatInt(issue.RepoID, 10) + " THEN 0 ELSE issue.repo_id END, issue.created_unix DESC").
  1434. Find(&issueDeps)
  1435. }
  1436. // BlockedByDependencies finds all Dependencies an issue is blocked by
  1437. func (issue *Issue) BlockedByDependencies() ([]*DependencyInfo, error) {
  1438. return issue.getBlockedByDependencies(x)
  1439. }
  1440. // BlockingDependencies returns all blocking dependencies, aka all other issues a given issue blocks
  1441. func (issue *Issue) BlockingDependencies() ([]*DependencyInfo, error) {
  1442. return issue.getBlockingDependencies(x)
  1443. }
  1444. func (issue *Issue) updateClosedNum(e Engine) (err error) {
  1445. if issue.IsPull {
  1446. _, err = e.Exec("UPDATE `repository` SET num_closed_pulls=(SELECT count(*) FROM issue WHERE repo_id=? AND is_pull=? AND is_closed=?) WHERE id=?",
  1447. issue.RepoID,
  1448. true,
  1449. true,
  1450. issue.RepoID,
  1451. )
  1452. } else {
  1453. _, err = e.Exec("UPDATE `repository` SET num_closed_issues=(SELECT count(*) FROM issue WHERE repo_id=? AND is_pull=? AND is_closed=?) WHERE id=?",
  1454. issue.RepoID,
  1455. false,
  1456. true,
  1457. issue.RepoID,
  1458. )
  1459. }
  1460. return
  1461. }
  1462. // ResolveMentionsByVisibility returns the users mentioned in an issue, removing those that
  1463. // don't have access to reading it. Teams are expanded into their users, but organizations are ignored.
  1464. func (issue *Issue) ResolveMentionsByVisibility(ctx DBContext, doer *User, mentions []string) (users []*User, err error) {
  1465. if len(mentions) == 0 {
  1466. return
  1467. }
  1468. if err = issue.loadRepo(ctx.e); err != nil {
  1469. return
  1470. }
  1471. resolved := make(map[string]bool, 20)
  1472. names := make([]string, 0, 20)
  1473. resolved[doer.LowerName] = true
  1474. for _, name := range mentions {
  1475. name := strings.ToLower(name)
  1476. if _, ok := resolved[name]; ok {
  1477. continue
  1478. }
  1479. resolved[name] = false
  1480. names = append(names, name)
  1481. }
  1482. if err := issue.Repo.getOwner(ctx.e); err != nil {
  1483. return nil, err
  1484. }
  1485. if issue.Repo.Owner.IsOrganization() {
  1486. // Since there can be users with names that match the name of a team,
  1487. // if the team exists and can read the issue, the team takes precedence.
  1488. teams := make([]*Team, 0, len(names))
  1489. if err := ctx.e.
  1490. Join("INNER", "team_repo", "team_repo.team_id = team.id").
  1491. Where("team_repo.repo_id=?", issue.Repo.ID).
  1492. In("team.lower_name", names).
  1493. Find(&teams); err != nil {
  1494. return nil, fmt.Errorf("find mentioned teams: %v", err)
  1495. }
  1496. if len(teams) != 0 {
  1497. checked := make([]int64, 0, len(teams))
  1498. unittype := UnitTypeIssues
  1499. if issue.IsPull {
  1500. unittype = UnitTypePullRequests
  1501. }
  1502. for _, team := range teams {
  1503. if team.Authorize >= AccessModeOwner {
  1504. checked = append(checked, team.ID)
  1505. resolved[team.LowerName] = true
  1506. continue
  1507. }
  1508. has, err := ctx.e.Get(&TeamUnit{OrgID: issue.Repo.Owner.ID, TeamID: team.ID, Type: unittype})
  1509. if err != nil {
  1510. return nil, fmt.Errorf("get team units (%d): %v", team.ID, err)
  1511. }
  1512. if has {
  1513. checked = append(checked, team.ID)
  1514. resolved[team.LowerName] = true
  1515. }
  1516. }
  1517. if len(checked) != 0 {
  1518. teamusers := make([]*User, 0, 20)
  1519. if err := ctx.e.
  1520. Join("INNER", "team_user", "team_user.uid = `user`.id").
  1521. In("`team_user`.team_id", checked).
  1522. And("`user`.is_active = ?", true).
  1523. And("`user`.prohibit_login = ?", false).
  1524. Find(&teamusers); err != nil {
  1525. return nil, fmt.Errorf("get teams users: %v", err)
  1526. }
  1527. if len(teamusers) > 0 {
  1528. users = make([]*User, 0, len(teamusers))
  1529. for _, user := range teamusers {
  1530. if already, ok := resolved[user.LowerName]; !ok || !already {
  1531. users = append(users, user)
  1532. resolved[user.LowerName] = true
  1533. }
  1534. }
  1535. }
  1536. }
  1537. }
  1538. // Remove names already in the list to avoid querying the database if pending names remain
  1539. names = make([]string, 0, len(resolved))
  1540. for name, already := range resolved {
  1541. if !already {
  1542. names = append(names, name)
  1543. }
  1544. }
  1545. if len(names) == 0 {
  1546. return
  1547. }
  1548. }
  1549. unchecked := make([]*User, 0, len(names))
  1550. if err := ctx.e.
  1551. Where("`user`.is_active = ?", true).
  1552. And("`user`.prohibit_login = ?", false).
  1553. In("`user`.lower_name", names).
  1554. Find(&unchecked); err != nil {
  1555. return nil, fmt.Errorf("find mentioned users: %v", err)
  1556. }
  1557. for _, user := range unchecked {
  1558. if already := resolved[user.LowerName]; already || user.IsOrganization() {
  1559. continue
  1560. }
  1561. // Normal users must have read access to the referencing issue
  1562. perm, err := getUserRepoPermission(ctx.e, issue.Repo, user)
  1563. if err != nil {
  1564. return nil, fmt.Errorf("getUserRepoPermission [%d]: %v", user.ID, err)
  1565. }
  1566. if !perm.CanReadIssuesOrPulls(issue.IsPull) {
  1567. continue
  1568. }
  1569. users = append(users, user)
  1570. }
  1571. return
  1572. }
  1573. // UpdateIssuesMigrationsByType updates all migrated repositories' issues from gitServiceType to replace originalAuthorID to posterID
  1574. func UpdateIssuesMigrationsByType(gitServiceType structs.GitServiceType, originalAuthorID string, posterID int64) error {
  1575. _, err := x.Table("issue").
  1576. Where("repo_id IN (SELECT id FROM repository WHERE original_service_type = ?)", gitServiceType).
  1577. And("original_author_id = ?", originalAuthorID).
  1578. Update(map[string]interface{}{
  1579. "poster_id": posterID,
  1580. "original_author": "",
  1581. "original_author_id": 0,
  1582. })
  1583. return err
  1584. }