mirror of https://codeberg.org/gitnex/GitNex.git
Add option to update PR (#973)
### Describe what your pull request does and which issue you’re targeting <!-- Create a new issue, if it doesn't exist yet --> Closes #967 <br><br> <!-- Make sure you are targeting the "main" branch, pull requests on release branches are only allowed for bug fixes. --> - [X] I carefully read the [contribution guidelines](https://codeberg.org/GitNex/GitNex/src/branch/main/CONTRIBUTING.md). - [X] I'm following the code standards as defined [here](https://codeberg.org/gitnex/GitNex/wiki/Code-Standards). - [X] By submitting this pull request, I permit GitNex to license my work under the [GNU General Public License v3](https://codeberg.org/GitNex/GitNex/src/branch/main/LICENSE). Co-authored-by: qwerty287 <ndev@web.de> Co-authored-by: M M Arif <mmarif@swatian.com> Reviewed-on: https://codeberg.org/gitnex/GitNex/pulls/973 Reviewed-by: M M Arif <mmarif@noreply.codeberg.org> Co-authored-by: qwerty287 <qwerty287@noreply.codeberg.org> Co-committed-by: qwerty287 <qwerty287@noreply.codeberg.org>
This commit is contained in:
parent
77d1d448ba
commit
95aea16a07
|
@ -109,7 +109,7 @@ dependencies {
|
|||
implementation "androidx.work:work-runtime:$work_version"
|
||||
implementation "io.mikael:urlbuilder:2.0.9"
|
||||
implementation "org.codeberg.gitnex-garage:emoji-java:v5.1.2"
|
||||
implementation "org.codeberg.gitnex:tea4j:1.0.18"
|
||||
implementation "org.codeberg.gitnex:tea4j:1.0.20"
|
||||
coreLibraryDesugaring "com.android.tools:desugar_jdk_libs:1.1.5"
|
||||
implementation 'androidx.biometric:biometric:1.1.0'
|
||||
implementation 'com.github.chrisvest:stormpot:2.4.2'
|
||||
|
|
|
@ -10,6 +10,7 @@ import org.mian.gitnex.helpers.Authorization;
|
|||
import org.mian.gitnex.helpers.Toasty;
|
||||
import retrofit2.Call;
|
||||
import retrofit2.Callback;
|
||||
import retrofit2.Response;
|
||||
|
||||
/**
|
||||
* Author qwerty287
|
||||
|
@ -59,4 +60,43 @@ public class PullRequestActions {
|
|||
});
|
||||
}
|
||||
|
||||
public static void updatePr(Context context, String repoOwner, String repoName, String index, Boolean rebase) {
|
||||
String strategy;
|
||||
if(rebase == null) {
|
||||
strategy = null;
|
||||
}
|
||||
else if(!rebase) {
|
||||
strategy = "merge";
|
||||
}
|
||||
else {
|
||||
strategy = "rebase";
|
||||
}
|
||||
RetrofitClient.getApiInterface(context).updatePullRequest(Authorization.get(context), repoOwner, repoName, Integer.parseInt(index), strategy)
|
||||
.enqueue(new Callback<Void>() {
|
||||
|
||||
@Override
|
||||
public void onResponse(@NonNull Call call, @NonNull Response response) {
|
||||
if(response.isSuccessful()) {
|
||||
Toasty.success(context, context.getString(R.string.updatePrSuccess));
|
||||
}
|
||||
else {
|
||||
if(response.code() == 403) {
|
||||
Toasty.error(context, context.getString(R.string.authorizeError));
|
||||
}
|
||||
else if(response.code() == 409) {
|
||||
Toasty.error(context, context.getString(R.string.updatePrConflict));
|
||||
}
|
||||
else {
|
||||
Toasty.error(context, context.getString(R.string.genericError));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(@NonNull Call call, @NonNull Throwable t) {
|
||||
Toasty.error(context, context.getString(R.string.genericError));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -56,6 +56,7 @@ public class BottomSheetSingleIssueFragment extends BottomSheetDialogFragment {
|
|||
TextView addRemoveAssignees = bottomSheetSingleIssueBinding.addRemoveAssignees;
|
||||
TextView copyIssueUrl = bottomSheetSingleIssueBinding.copyIssueUrl;
|
||||
TextView openFilesDiff = bottomSheetSingleIssueBinding.openFilesDiff;
|
||||
TextView updatePullRequest = bottomSheetSingleIssueBinding.updatePullRequest;
|
||||
TextView mergePullRequest = bottomSheetSingleIssueBinding.mergePullRequest;
|
||||
TextView deletePullRequestBranch = bottomSheetSingleIssueBinding.deletePrHeadBranch;
|
||||
TextView shareIssue = bottomSheetSingleIssueBinding.shareIssue;
|
||||
|
@ -92,10 +93,12 @@ public class BottomSheetSingleIssueFragment extends BottomSheetDialogFragment {
|
|||
shareIssue.setText(R.string.sharePr);
|
||||
|
||||
if(tinyDB.getBoolean("prMerged") || tinyDB.getString("repoPrState").equals("closed")) {
|
||||
updatePullRequest.setVisibility(View.GONE);
|
||||
mergePullRequest.setVisibility(View.GONE);
|
||||
deletePullRequestBranch.setVisibility(View.VISIBLE);
|
||||
}
|
||||
else {
|
||||
updatePullRequest.setVisibility(View.VISIBLE);
|
||||
mergePullRequest.setVisibility(View.VISIBLE);
|
||||
deletePullRequestBranch.setVisibility(View.GONE);
|
||||
}
|
||||
|
@ -113,10 +116,21 @@ public class BottomSheetSingleIssueFragment extends BottomSheetDialogFragment {
|
|||
}
|
||||
else {
|
||||
|
||||
updatePullRequest.setVisibility(View.GONE);
|
||||
mergePullRequest.setVisibility(View.GONE);
|
||||
deletePullRequestBranch.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
updatePullRequest.setOnClickListener(v -> {
|
||||
if(new Version(tinyDB.getString("giteaVersion")).higherOrEqual("1.16.0")) {
|
||||
AlertDialogs.selectPullUpdateStrategy(requireContext(), parts[0], parts[1], tinyDB.getString("issueNumber"));
|
||||
}
|
||||
else {
|
||||
PullRequestActions.updatePr(requireContext(), parts[0], parts[1], tinyDB.getString("issueNumber"), null);
|
||||
}
|
||||
dismiss();
|
||||
});
|
||||
|
||||
mergePullRequest.setOnClickListener(v13 -> {
|
||||
|
||||
startActivity(new Intent(ctx, MergePullRequestActivity.class));
|
||||
|
|
|
@ -1,10 +1,15 @@
|
|||
package org.mian.gitnex.helpers;
|
||||
|
||||
import android.app.Dialog;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.drawable.ColorDrawable;
|
||||
import android.widget.Button;
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
import org.mian.gitnex.R;
|
||||
import org.mian.gitnex.actions.CollaboratorActions;
|
||||
import org.mian.gitnex.actions.PullRequestActions;
|
||||
import org.mian.gitnex.actions.TeamActions;
|
||||
import org.mian.gitnex.activities.CreateLabelActivity;
|
||||
import org.mian.gitnex.activities.LoginActivity;
|
||||
|
@ -112,4 +117,27 @@ public class AlertDialogs {
|
|||
|
||||
}
|
||||
|
||||
public static void selectPullUpdateStrategy(Context context, String repoOwner, String repo, String issueNumber) {
|
||||
Dialog dialog = new Dialog(context, R.style.ThemeOverlay_MaterialComponents_Dialog_Alert);
|
||||
|
||||
if (dialog.getWindow() != null) {
|
||||
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
|
||||
}
|
||||
|
||||
dialog.setContentView(R.layout.custom_pr_update_strategy_dialog);
|
||||
Button mergeBtn = dialog.findViewById(R.id.updatePullMerge);
|
||||
Button rebaseBtn = dialog.findViewById(R.id.updatePullRebase);
|
||||
Button cancelBtn = dialog.findViewById(R.id.cancelPullUpdate);
|
||||
mergeBtn.setOnClickListener((v) -> {
|
||||
PullRequestActions.updatePr(context, repoOwner, repo, issueNumber, false);
|
||||
dialog.dismiss();
|
||||
});
|
||||
rebaseBtn.setOnClickListener((v) -> {
|
||||
PullRequestActions.updatePr(context, repoOwner, repo, issueNumber, true);
|
||||
dialog.dismiss();
|
||||
});
|
||||
cancelBtn.setOnClickListener((v) -> dialog.dismiss());
|
||||
dialog.show();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,27 @@
|
|||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24">
|
||||
<path
|
||||
android:pathData="M23,4l0,6l-6,0"
|
||||
android:strokeLineJoin="round"
|
||||
android:strokeWidth="2"
|
||||
android:fillColor="#00000000"
|
||||
android:strokeColor="?attr/iconsColor"
|
||||
android:strokeLineCap="round"/>
|
||||
<path
|
||||
android:pathData="M1,20l0,-6l6,0"
|
||||
android:strokeLineJoin="round"
|
||||
android:strokeWidth="2"
|
||||
android:fillColor="#00000000"
|
||||
android:strokeColor="?attr/iconsColor"
|
||||
android:strokeLineCap="round"/>
|
||||
<path
|
||||
android:pathData="M3.51,9a9,9 0,0 1,14.85 -3.36L23,10M1,14l4.64,4.36A9,9 0,0 0,20.49 15"
|
||||
android:strokeLineJoin="round"
|
||||
android:strokeWidth="2"
|
||||
android:fillColor="#00000000"
|
||||
android:strokeColor="?attr/iconsColor"
|
||||
android:strokeLineCap="round"/>
|
||||
</vector>
|
|
@ -58,6 +58,21 @@
|
|||
android:textSize="16sp"
|
||||
app:drawableStartCompat="@drawable/ic_pull_request" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/updatePullRequest"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:background="?android:attr/selectableItemBackground"
|
||||
android:focusable="true"
|
||||
android:clickable="true"
|
||||
android:drawablePadding="24dp"
|
||||
android:padding="12dp"
|
||||
android:text="@string/updatePullRequestText"
|
||||
android:textColor="?attr/primaryTextColor"
|
||||
android:textSize="16sp"
|
||||
app:drawableStartCompat="@drawable/ic_update" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/deletePrHeadBranch"
|
||||
android:layout_width="match_parent"
|
||||
|
|
|
@ -0,0 +1,71 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@drawable/shape_custom_dialog">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/selectStrategy"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:textSize="20sp"
|
||||
android:text="@string/selectUpdateStrategy"
|
||||
android:textColor="?attr/primaryTextColor"
|
||||
android:padding="16dp"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<View
|
||||
android:id="@+id/dividerTop"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="1dp"
|
||||
android:background="?attr/dividerColor"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/selectStrategy" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/updatePullMerge"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="60dp"
|
||||
android:layout_margin="16dp"
|
||||
android:textColor="@color/colorWhite"
|
||||
android:text="@string/updateStrategyMerge"
|
||||
app:layout_constraintEnd_toStartOf="@id/updatePullRebase"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/selectStrategy" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/updatePullRebase"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="60dp"
|
||||
android:layout_margin="16dp"
|
||||
android:textColor="@color/colorWhite"
|
||||
android:text="@string/updateStrategyRebase"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toEndOf="@id/updatePullMerge"
|
||||
app:layout_constraintTop_toBottomOf="@id/selectStrategy" />
|
||||
|
||||
<View
|
||||
android:id="@+id/dividerBottom"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="1dp"
|
||||
android:layout_marginTop="16dp"
|
||||
android:background="?attr/dividerColor"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/updatePullMerge" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/cancelPullUpdate"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="60dp"
|
||||
style="?android:attr/button"
|
||||
android:layout_alignParentStart="true"
|
||||
android:text="@string/cancelButton"
|
||||
android:textColor="@color/colorWhite"
|
||||
android:layout_margin="16dp"
|
||||
android:textSize="16sp"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/dividerBottom"
|
||||
app:layout_constraintBottom_toBottomOf="parent" />
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
|
@ -558,6 +558,7 @@
|
|||
<string name="fileDiffViewHeader">%1$s Files Changed</string>
|
||||
<string name="fileDiffViewHeaderSingle">%1$s File Changed</string>
|
||||
<string name="openFileDiffText">Files Changed</string>
|
||||
<string name="updatePullRequestText">Update Pull Request</string>
|
||||
<string name="mergePullRequestText">Merge Pull Request</string>
|
||||
<string name="deletePrHeadBranch">Delete head branch</string>
|
||||
<string name="deleteBranchSuccess">Branch deleted successfully</string>
|
||||
|
@ -760,4 +761,9 @@
|
|||
<string name="nowFollowUser">You now follow @%s</string>
|
||||
<string name="unfollowingFailed">Couldn\'t unfollow user</string>
|
||||
<string name="followingFailed">Couldn\'t follow user</string>
|
||||
<string name="updatePrConflict">The pull request conflicts with the base branch. Please resolve the conflicts and try again.</string>
|
||||
<string name="updatePrSuccess">Pull Request updated successfully</string>
|
||||
<string name="updateStrategyMerge">Merge</string>
|
||||
<string name="updateStrategyRebase">Rebase</string>
|
||||
<string name="selectUpdateStrategy">Select Update Strategy</string>
|
||||
</resources>
|
||||
|
|
Loading…
Reference in New Issue