-
Notifications
You must be signed in to change notification settings - Fork 86
feat: support multi-branching within Studio #16970
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| using System; | ||
| using Altinn.Studio.Designer.Models; | ||
|
|
||
| namespace Altinn.Studio.Designer.Exceptions | ||
| { | ||
| /// <summary> | ||
| /// Exception thrown when attempting to checkout a branch with uncommitted changes | ||
| /// </summary> | ||
| public class UncommittedChangesException : Exception | ||
| { | ||
| /// <summary> | ||
| /// Gets the uncommitted changes error details | ||
| /// </summary> | ||
| public UncommittedChangesError ErrorDetails { get; } | ||
|
|
||
| /// <summary> | ||
| /// Initializes a new instance of the <see cref="UncommittedChangesException"/> class. | ||
| /// </summary> | ||
| /// <param name="errorDetails">The uncommitted changes error details</param> | ||
| public UncommittedChangesException(UncommittedChangesError errorDetails) | ||
| : base(errorDetails.Message) | ||
| { | ||
| ErrorDetails = errorDetails; | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,5 +6,7 @@ public class GitErrorCodes | |
| public const string NonFastForwardError = "GT_01"; | ||
| public const string RepositoryNotFound = "GT_02"; | ||
| public const string GiteaSessionExpired = "GT_03"; | ||
| public const string UncommittedChanges = "GT_04"; | ||
| public const string BranchNotFound = "GT_05"; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: Looks like |
||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -33,6 +33,12 @@ public override void OnException(ExceptionContext context) | |
| { | ||
| context.Result = new ObjectResult(ProblemDetailsUtils.GenerateProblemDetails(context.Exception, GitErrorCodes.GiteaSessionExpired, HttpStatusCode.Unauthorized)) { StatusCode = (int)HttpStatusCode.Unauthorized }; | ||
| } | ||
|
|
||
| if (context.Exception is Exceptions.UncommittedChangesException uncommittedChangesException) | ||
| { | ||
| context.Result = new ObjectResult(uncommittedChangesException.ErrorDetails) { StatusCode = (int)HttpStatusCode.Conflict }; | ||
| context.ExceptionHandled = true; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Have you considered if the line |
||
| } | ||
framitdavid marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,103 @@ | ||||||
| #nullable disable | ||||||
| namespace Altinn.Studio.Designer.Models | ||||||
| { | ||||||
| /// <summary> | ||||||
| /// Request model for creating a new branch | ||||||
| /// </summary> | ||||||
| public class CreateBranchRequest | ||||||
| { | ||||||
| /// <summary> | ||||||
| /// Gets or sets the name of the branch to create | ||||||
| /// </summary> | ||||||
| public string BranchName { get; set; } | ||||||
| } | ||||||
|
|
||||||
| /// <summary> | ||||||
| /// Request model for checking out a branch | ||||||
| /// </summary> | ||||||
| public class CheckoutBranchRequest | ||||||
| { | ||||||
| /// <summary> | ||||||
| /// Gets or sets the name of the branch to checkout | ||||||
| /// </summary> | ||||||
| public string BranchName { get; set; } | ||||||
| } | ||||||
|
|
||||||
| /// <summary> | ||||||
| /// Information about the current branch | ||||||
| /// </summary> | ||||||
| public class CurrentBranchInfo | ||||||
| { | ||||||
| /// <summary> | ||||||
| /// Gets or sets the name of the current branch | ||||||
| /// </summary> | ||||||
| public string BranchName { get; set; } | ||||||
|
|
||||||
| /// <summary> | ||||||
| /// Gets or sets the SHA of the current commit | ||||||
| /// </summary> | ||||||
| public string CommitSha { get; set; } | ||||||
|
|
||||||
| /// <summary> | ||||||
| /// Gets or sets whether the branch is tracking a remote branch | ||||||
| /// </summary> | ||||||
| public bool IsTracking { get; set; } | ||||||
|
|
||||||
| /// <summary> | ||||||
| /// Gets or sets the name of the tracked remote branch | ||||||
| /// </summary> | ||||||
| public string RemoteName { get; set; } | ||||||
| } | ||||||
|
|
||||||
| /// <summary> | ||||||
| /// Error response for uncommitted changes | ||||||
| /// </summary> | ||||||
| public class UncommittedChangesError | ||||||
| { | ||||||
| /// <summary> | ||||||
| /// Gets or sets the error code | ||||||
| /// </summary> | ||||||
| public string ErrorCode { get; set; } = Filters.Git.GitErrorCodes.UncommittedChanges; | ||||||
|
|
||||||
| /// <summary> | ||||||
| /// Gets or sets the error type | ||||||
| /// </summary> | ||||||
| public string Error { get; set; } | ||||||
|
|
||||||
| /// <summary> | ||||||
| /// Gets or sets the error message | ||||||
| /// </summary> | ||||||
| public string Message { get; set; } | ||||||
|
|
||||||
| /// <summary> | ||||||
| /// Gets or sets the list of uncommitted files | ||||||
| /// </summary> | ||||||
| public System.Collections.Generic.List<UncommittedFile> UncommittedFiles { get; set; } | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: If you add
Suggested change
|
||||||
|
|
||||||
| /// <summary> | ||||||
| /// Gets or sets the current branch name | ||||||
| /// </summary> | ||||||
| public string CurrentBranch { get; set; } | ||||||
|
|
||||||
| /// <summary> | ||||||
| /// Gets or sets the target branch name | ||||||
| /// </summary> | ||||||
| public string TargetBranch { get; set; } | ||||||
| } | ||||||
|
|
||||||
| /// <summary> | ||||||
| /// Information about an uncommitted file | ||||||
| /// </summary> | ||||||
| public class UncommittedFile | ||||||
| { | ||||||
| /// <summary> | ||||||
| /// Gets or sets the file path | ||||||
| /// </summary> | ||||||
| public string FilePath { get; set; } | ||||||
|
|
||||||
| /// <summary> | ||||||
| /// Gets or sets the file status | ||||||
| /// </summary> | ||||||
| public string Status { get; set; } | ||||||
| } | ||||||
| } | ||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add basic validation for CreateBranch request to avoid null/empty branch names
CreateBranchcurrently assumesrequestandrequest.BranchNameare non-null and non-empty; sending an empty body or whitespace branch name will either cause a null-reference or push validation down into_sourceControl.CreateBranch, likely surfacing as a 500.CheckoutBranchalready guards this case.Consider aligning
CreateBranchwithCheckoutBranchby validating upfront:This keeps the API surface consistent and prevents avoidable 500s on bad input.
🤖 Prompt for AI Agents