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

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