Compare commits
15
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
491a220fbb | ||
|
|
720c54433a | ||
|
|
f57a8c502d | ||
|
|
c97e3d505f | ||
|
|
2bb7ac11df | ||
|
|
8709e9f38d | ||
|
|
7997ff0980 | ||
|
|
2359c7d586 | ||
|
|
4ada3798b6 | ||
|
|
07ac73dcb2 | ||
|
|
bb475a2350 | ||
|
|
63f7463ced | ||
|
|
0175c9e5a5 | ||
|
|
9f9bf14bbe | ||
|
|
a7783d46cf |
@@ -22,6 +22,8 @@ jobs:
|
|||||||
- name: Detect Android and Linux changes
|
- name: Detect Android and Linux changes
|
||||||
id: diff
|
id: diff
|
||||||
shell: bash
|
shell: bash
|
||||||
|
env:
|
||||||
|
FORGEJO_TOKEN: ${{ github.token }}
|
||||||
run: |
|
run: |
|
||||||
# On workflow_dispatch always build everything
|
# On workflow_dispatch always build everything
|
||||||
if [ "$GITHUB_EVENT_NAME" = "workflow_dispatch" ]; then
|
if [ "$GITHUB_EVENT_NAME" = "workflow_dispatch" ]; then
|
||||||
@@ -30,6 +32,38 @@ jobs:
|
|||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
HEAD_SHA=$(git rev-parse HEAD)
|
||||||
|
|
||||||
|
# Skip if this exact commit was already successfully deployed (prevents
|
||||||
|
# hourly schedule from redeploying the same commit on every tick).
|
||||||
|
LAST_DEPLOYED_SHA=$(python3 - << 'PYEOF'
|
||||||
|
import json, os, sys, urllib.request
|
||||||
|
token = os.environ.get("FORGEJO_TOKEN", "")
|
||||||
|
server = os.environ.get("GITHUB_SERVER_URL", "").rstrip("/")
|
||||||
|
repo = os.environ.get("GITHUB_REPOSITORY", "")
|
||||||
|
url = f"{server}/api/v1/repos/{repo}/actions/runs?workflow_id=deploy.yml&status=success&limit=5"
|
||||||
|
req = urllib.request.Request(url, headers={"Authorization": f"token {token}"})
|
||||||
|
try:
|
||||||
|
with urllib.request.urlopen(req) as r:
|
||||||
|
data = json.loads(r.read())
|
||||||
|
runs = [
|
||||||
|
r for r in data.get("workflow_runs", [])
|
||||||
|
if r.get("workflow_id") == "deploy.yml" and r.get("status") == "success"
|
||||||
|
]
|
||||||
|
print(runs[0].get("commit_sha") or "")
|
||||||
|
except Exception as e:
|
||||||
|
print(f"API check failed: {e}", file=sys.stderr)
|
||||||
|
print("")
|
||||||
|
PYEOF
|
||||||
|
)
|
||||||
|
|
||||||
|
if [ -n "$LAST_DEPLOYED_SHA" ] && [ "$HEAD_SHA" = "$LAST_DEPLOYED_SHA" ]; then
|
||||||
|
echo "HEAD $HEAD_SHA already successfully deployed — skipping"
|
||||||
|
echo "android=false" >> "$GITHUB_OUTPUT"
|
||||||
|
echo "linux=false" >> "$GITHUB_OUTPUT"
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
# Diff the HEAD commit against its parent; fall back to listing HEAD's files
|
# Diff the HEAD commit against its parent; fall back to listing HEAD's files
|
||||||
# when the parent is unavailable (initial commit, shallow clone).
|
# when the parent is unavailable (initial commit, shallow clone).
|
||||||
CHANGED=$(git diff --name-only HEAD~1 HEAD 2>/dev/null \
|
CHANGED=$(git diff --name-only HEAD~1 HEAD 2>/dev/null \
|
||||||
@@ -49,44 +83,6 @@ jobs:
|
|||||||
&& echo "linux=true" >> "$GITHUB_OUTPUT" \
|
&& echo "linux=true" >> "$GITHUB_OUTPUT" \
|
||||||
|| echo "linux=false" >> "$GITHUB_OUTPUT"
|
|| echo "linux=false" >> "$GITHUB_OUTPUT"
|
||||||
|
|
||||||
test-android-firebase:
|
|
||||||
name: Android Instrumented Tests (Firebase Test Lab)
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
timeout-minutes: 60
|
|
||||||
needs: [check-changes]
|
|
||||||
if: needs.check-changes.outputs.android == 'true'
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v4
|
|
||||||
with:
|
|
||||||
fetch-depth: 1
|
|
||||||
|
|
||||||
- name: Check runner tools
|
|
||||||
run: |
|
|
||||||
command -v dagger >/dev/null 2>&1 || { echo "ERROR: dagger is not installed in the runner image. Add it to .forgejo/Dockerfile."; exit 1; }
|
|
||||||
command -v task >/dev/null 2>&1 || { echo "ERROR: task is not installed in the runner image. Add it to .forgejo/Dockerfile."; exit 1; }
|
|
||||||
dpkg -s stunnel4 netcat-openbsd >/dev/null 2>&1 || { echo "ERROR: stunnel4/netcat-openbsd are not installed in the runner image. Add them to .forgejo/Dockerfile."; exit 1; }
|
|
||||||
|
|
||||||
- name: Setup Dagger Remote Engine (via stunnel)
|
|
||||||
env:
|
|
||||||
DAGGER_STUNNEL_URL: ${{ secrets.DAGGER_STUNNEL_URL }}
|
|
||||||
DAGGER_CA_CERT: ${{ secrets.DAGGER_CA_CERT }}
|
|
||||||
DAGGER_CLIENT_CERT: ${{ secrets.DAGGER_CLIENT_CERT }}
|
|
||||||
DAGGER_CLIENT_KEY: ${{ secrets.DAGGER_CLIENT_KEY }}
|
|
||||||
run: scripts/setup_dagger_remote.sh
|
|
||||||
|
|
||||||
- name: Run Android Tests on Firebase Test Lab
|
|
||||||
if: ${{ secrets.FIREBASE_TEST_LAB_SERVICE_ACCOUNT_KEY != '' }}
|
|
||||||
env:
|
|
||||||
FIREBASE_TEST_LAB_SERVICE_ACCOUNT_KEY: ${{ secrets.FIREBASE_TEST_LAB_SERVICE_ACCOUNT_KEY }}
|
|
||||||
FIREBASE_PROJECT_ID: ${{ vars.FIREBASE_PROJECT_ID }}
|
|
||||||
DAGGER_NO_NAG: "1"
|
|
||||||
run: task test-android-firebase
|
|
||||||
|
|
||||||
- name: Cleanup TLS credentials
|
|
||||||
if: always()
|
|
||||||
run: rm -rf /tmp/dagger-tls /tmp/stunnel-dagger.conf /tmp/stunnel.pid
|
|
||||||
|
|
||||||
deploy-playstore:
|
deploy-playstore:
|
||||||
name: Build & Deploy to Play Store
|
name: Build & Deploy to Play Store
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
@@ -136,7 +132,7 @@ jobs:
|
|||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
with:
|
with:
|
||||||
fetch-depth: 1
|
fetch-depth: 100
|
||||||
|
|
||||||
- name: Check runner tools
|
- name: Check runner tools
|
||||||
run: |
|
run: |
|
||||||
@@ -178,7 +174,7 @@ jobs:
|
|||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
with:
|
with:
|
||||||
fetch-depth: 1
|
fetch-depth: 100
|
||||||
|
|
||||||
- name: Check runner tools
|
- name: Check runner tools
|
||||||
run: |
|
run: |
|
||||||
@@ -253,10 +249,9 @@ jobs:
|
|||||||
label-deploy-health:
|
label-deploy-health:
|
||||||
name: Update Deploy Health Label
|
name: Update Deploy Health Label
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
needs: [test-android-firebase, deploy-playstore, deploy-apk, build-linux]
|
needs: [deploy-playstore, deploy-apk, build-linux]
|
||||||
if: |
|
if: |
|
||||||
always() && vars.DEPLOY_HEALTH_ISSUE != '' && (
|
always() && vars.DEPLOY_HEALTH_ISSUE != '' && (
|
||||||
needs.test-android-firebase.result == 'success' || needs.test-android-firebase.result == 'failure' ||
|
|
||||||
needs.deploy-playstore.result == 'success' || needs.deploy-playstore.result == 'failure' ||
|
needs.deploy-playstore.result == 'success' || needs.deploy-playstore.result == 'failure' ||
|
||||||
needs.deploy-apk.result == 'success' || needs.deploy-apk.result == 'failure' ||
|
needs.deploy-apk.result == 'success' || needs.deploy-apk.result == 'failure' ||
|
||||||
needs.build-linux.result == 'success' || needs.build-linux.result == 'failure'
|
needs.build-linux.result == 'success' || needs.build-linux.result == 'failure'
|
||||||
@@ -269,7 +264,7 @@ jobs:
|
|||||||
FORGEJO_TOKEN: ${{ github.token }}
|
FORGEJO_TOKEN: ${{ github.token }}
|
||||||
FORGEJO_URL: ${{ github.server_url }}
|
FORGEJO_URL: ${{ github.server_url }}
|
||||||
DEPLOY_HEALTH_ISSUE: ${{ vars.DEPLOY_HEALTH_ISSUE }}
|
DEPLOY_HEALTH_ISSUE: ${{ vars.DEPLOY_HEALTH_ISSUE }}
|
||||||
ALL_SUCCEEDED: ${{ (needs.test-android-firebase.result == 'success' || needs.test-android-firebase.result == 'skipped') && (needs.deploy-playstore.result == 'success' || needs.deploy-playstore.result == 'skipped') && (needs.deploy-apk.result == 'success' || needs.deploy-apk.result == 'skipped') && (needs.build-linux.result == 'success' || needs.build-linux.result == 'skipped') }}
|
ALL_SUCCEEDED: ${{ (needs.deploy-playstore.result == 'success' || needs.deploy-playstore.result == 'skipped') && (needs.deploy-apk.result == 'success' || needs.deploy-apk.result == 'skipped') && (needs.build-linux.result == 'success' || needs.build-linux.result == 'skipped') }}
|
||||||
run: |
|
run: |
|
||||||
python3 - << 'PYEOF'
|
python3 - << 'PYEOF'
|
||||||
import os, json, urllib.request, urllib.error
|
import os, json, urllib.request, urllib.error
|
||||||
|
|||||||
@@ -0,0 +1,132 @@
|
|||||||
|
name: Firebase Tests
|
||||||
|
|
||||||
|
on:
|
||||||
|
schedule:
|
||||||
|
- cron: '0 3 * * *' # once per day at 3 AM
|
||||||
|
workflow_dispatch:
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
check-changes:
|
||||||
|
name: Detect Firebase-Relevant Changes
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
timeout-minutes: 5
|
||||||
|
outputs:
|
||||||
|
has_changes: ${{ steps.diff.outputs.has_changes }}
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
fetch-depth: 0
|
||||||
|
|
||||||
|
- name: Detect Firebase-relevant changes in last 24 hours
|
||||||
|
id: diff
|
||||||
|
shell: bash
|
||||||
|
run: |
|
||||||
|
# On workflow_dispatch always run
|
||||||
|
if [ "$GITHUB_EVENT_NAME" = "workflow_dispatch" ]; then
|
||||||
|
echo "has_changes=true" >> "$GITHUB_OUTPUT"
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
SINCE=$(date -u -d '24 hours ago' '+%Y-%m-%dT%H:%M:%S')
|
||||||
|
CHANGED=$(git log --since="$SINCE" --name-only --format= -- \
|
||||||
|
'android/' 'integration_test/' 'lib/' 'pubspec.yaml' 'pubspec.lock' 'drift_schemas/' \
|
||||||
|
| sort -u | grep -v '^$')
|
||||||
|
|
||||||
|
if [ -n "$CHANGED" ]; then
|
||||||
|
echo "Firebase-relevant files changed since $SINCE:"
|
||||||
|
echo "$CHANGED"
|
||||||
|
echo "has_changes=true" >> "$GITHUB_OUTPUT"
|
||||||
|
else
|
||||||
|
echo "No Firebase-relevant changes in the last 24 hours — skipping tests"
|
||||||
|
echo "has_changes=false" >> "$GITHUB_OUTPUT"
|
||||||
|
fi
|
||||||
|
|
||||||
|
test-android-firebase:
|
||||||
|
name: Android Instrumented Tests (Firebase Test Lab)
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
timeout-minutes: 60
|
||||||
|
needs: [check-changes]
|
||||||
|
if: needs.check-changes.outputs.has_changes == 'true'
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
fetch-depth: 1
|
||||||
|
|
||||||
|
- name: Check runner tools
|
||||||
|
run: |
|
||||||
|
command -v dagger >/dev/null 2>&1 || { echo "ERROR: dagger is not installed in the runner image. Add it to .forgejo/Dockerfile."; exit 1; }
|
||||||
|
command -v task >/dev/null 2>&1 || { echo "ERROR: task is not installed in the runner image. Add it to .forgejo/Dockerfile."; exit 1; }
|
||||||
|
dpkg -s stunnel4 netcat-openbsd >/dev/null 2>&1 || { echo "ERROR: stunnel4/netcat-openbsd are not installed in the runner image. Add them to .forgejo/Dockerfile."; exit 1; }
|
||||||
|
|
||||||
|
- name: Setup Dagger Remote Engine (via stunnel)
|
||||||
|
env:
|
||||||
|
DAGGER_STUNNEL_URL: ${{ secrets.DAGGER_STUNNEL_URL }}
|
||||||
|
DAGGER_CA_CERT: ${{ secrets.DAGGER_CA_CERT }}
|
||||||
|
DAGGER_CLIENT_CERT: ${{ secrets.DAGGER_CLIENT_CERT }}
|
||||||
|
DAGGER_CLIENT_KEY: ${{ secrets.DAGGER_CLIENT_KEY }}
|
||||||
|
run: scripts/setup_dagger_remote.sh
|
||||||
|
|
||||||
|
- name: Run Android Tests on Firebase Test Lab
|
||||||
|
if: ${{ secrets.FIREBASE_TEST_LAB_SERVICE_ACCOUNT_KEY != '' }}
|
||||||
|
env:
|
||||||
|
FIREBASE_TEST_LAB_SERVICE_ACCOUNT_KEY: ${{ secrets.FIREBASE_TEST_LAB_SERVICE_ACCOUNT_KEY }}
|
||||||
|
FIREBASE_PROJECT_ID: ${{ vars.FIREBASE_PROJECT_ID }}
|
||||||
|
DAGGER_NO_NAG: "1"
|
||||||
|
run: task test-android-firebase
|
||||||
|
|
||||||
|
- name: Cleanup TLS credentials
|
||||||
|
if: always()
|
||||||
|
run: rm -rf /tmp/dagger-tls /tmp/stunnel-dagger.conf /tmp/stunnel.pid
|
||||||
|
|
||||||
|
- name: Create issue on test failure
|
||||||
|
if: failure()
|
||||||
|
env:
|
||||||
|
FORGEJO_TOKEN: ${{ github.token }}
|
||||||
|
FORGEJO_URL: ${{ github.server_url }}
|
||||||
|
RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
|
||||||
|
run: |
|
||||||
|
python3 - << 'PYEOF'
|
||||||
|
import os, json, urllib.request, urllib.error
|
||||||
|
|
||||||
|
token = os.environ["FORGEJO_TOKEN"]
|
||||||
|
url_base = os.environ["FORGEJO_URL"].rstrip("/")
|
||||||
|
run_url = os.environ["RUN_URL"]
|
||||||
|
|
||||||
|
headers = {"Authorization": f"token {token}", "Content-Type": "application/json"}
|
||||||
|
api = f"{url_base}/api/v1/repos/guettli/sharedinbox"
|
||||||
|
|
||||||
|
def api_get(path):
|
||||||
|
req = urllib.request.Request(f"{api}{path}", headers=headers)
|
||||||
|
with urllib.request.urlopen(req) as r:
|
||||||
|
return json.loads(r.read())
|
||||||
|
|
||||||
|
def api_post(path, body):
|
||||||
|
data = json.dumps(body).encode()
|
||||||
|
req = urllib.request.Request(f"{api}{path}", data=data, headers=headers, method="POST")
|
||||||
|
with urllib.request.urlopen(req) as r:
|
||||||
|
return json.loads(r.read())
|
||||||
|
|
||||||
|
repo_labels = api_get("/labels")
|
||||||
|
label_map = {l["name"]: l["id"] for l in repo_labels}
|
||||||
|
|
||||||
|
label_ids = [label_map["Ready"]] if "Ready" in label_map else []
|
||||||
|
|
||||||
|
title = "Firebase Tests failed — find root cause and fix"
|
||||||
|
body = (
|
||||||
|
"Firebase instrumented tests failed in the daily run.\n\n"
|
||||||
|
f"**Failed run:** {run_url}\n\n"
|
||||||
|
"## Steps to resolve\n\n"
|
||||||
|
"1. **Find the root cause**: Check the test run logs linked above and identify which test(s) failed and why.\n"
|
||||||
|
"2. **Fix if possible**: If the failure is caused by a code bug, create a fix. If it is a flaky or infrastructure issue, document the findings.\n"
|
||||||
|
"3. Close this issue once the root cause is resolved and the tests pass.\n"
|
||||||
|
)
|
||||||
|
|
||||||
|
issue = api_post("/issues", {
|
||||||
|
"title": title,
|
||||||
|
"body": body,
|
||||||
|
"labels": label_ids,
|
||||||
|
})
|
||||||
|
print(f"Created issue #{issue['number']}: {issue['html_url']}")
|
||||||
|
PYEOF
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
name: Renovate
|
||||||
|
|
||||||
|
on:
|
||||||
|
schedule:
|
||||||
|
- cron: '0 6 * * *'
|
||||||
|
workflow_dispatch:
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
renovate:
|
||||||
|
name: Renovate
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
timeout-minutes: 30
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Check runner tools
|
||||||
|
run: |
|
||||||
|
command -v dagger >/dev/null 2>&1 || { echo "ERROR: dagger is not installed in the runner image. Add it to .forgejo/Dockerfile."; exit 1; }
|
||||||
|
command -v task >/dev/null 2>&1 || { echo "ERROR: task is not installed in the runner image. Add it to .forgejo/Dockerfile."; exit 1; }
|
||||||
|
dpkg -s stunnel4 netcat-openbsd >/dev/null 2>&1 || { echo "ERROR: stunnel4/netcat-openbsd are not installed in the runner image. Add them to .forgejo/Dockerfile."; exit 1; }
|
||||||
|
|
||||||
|
- name: Setup Dagger Remote Engine (via stunnel)
|
||||||
|
env:
|
||||||
|
DAGGER_STUNNEL_URL: ${{ secrets.DAGGER_STUNNEL_URL }}
|
||||||
|
DAGGER_CA_CERT: ${{ secrets.DAGGER_CA_CERT }}
|
||||||
|
DAGGER_CLIENT_CERT: ${{ secrets.DAGGER_CLIENT_CERT }}
|
||||||
|
DAGGER_CLIENT_KEY: ${{ secrets.DAGGER_CLIENT_KEY }}
|
||||||
|
run: scripts/setup_dagger_remote.sh
|
||||||
|
|
||||||
|
- name: Run Renovate
|
||||||
|
env:
|
||||||
|
DAGGER_NO_NAG: "1"
|
||||||
|
RENOVATE_FORGEJO_TOKEN: ${{ secrets.RENOVATE_FORGEJO_TOKEN }}
|
||||||
|
run: task renovate
|
||||||
|
|
||||||
|
- name: Cleanup TLS credentials
|
||||||
|
if: always()
|
||||||
|
run: rm -rf /tmp/dagger-tls /tmp/stunnel-dagger.conf /tmp/stunnel.pid
|
||||||
+10
-2
@@ -224,7 +224,7 @@ tasks:
|
|||||||
desc: Build AAB via Dagger (cached, versionCode=1 placeholder) and export locally
|
desc: Build AAB via Dagger (cached, versionCode=1 placeholder) and export locally
|
||||||
cmds:
|
cmds:
|
||||||
- mkdir -p build/app/outputs/bundle/release
|
- mkdir -p build/app/outputs/bundle/release
|
||||||
- dagger call --progress=plain -q -m ci --source=. build-android-release -o build/app/outputs/bundle/release/app-release.aab
|
- HASH=$(git rev-parse --short HEAD) && dagger call --progress=plain -q -m ci --source=. build-android-release --commit-hash "$HASH" -o build/app/outputs/bundle/release/app-release.aab
|
||||||
|
|
||||||
upload-android-bundle:
|
upload-android-bundle:
|
||||||
desc: Upload AAB from build/ to Play Store via Dagger
|
desc: Upload AAB from build/ to Play Store via Dagger
|
||||||
@@ -247,7 +247,7 @@ tasks:
|
|||||||
- sh: test -n "$ANDROID_KEYSTORE_PASSWORD"
|
- sh: test -n "$ANDROID_KEYSTORE_PASSWORD"
|
||||||
msg: "ANDROID_KEYSTORE_PASSWORD is not set"
|
msg: "ANDROID_KEYSTORE_PASSWORD is not set"
|
||||||
cmds:
|
cmds:
|
||||||
- dagger call --progress=plain -q -m ci --source=. publish-android --play-store-config env:PLAY_STORE_CONFIG_JSON --keystore-base64 env:ANDROID_KEYSTORE_BASE64 --keystore-password env:ANDROID_KEYSTORE_PASSWORD
|
- HASH=$(git rev-parse --short HEAD) && dagger call --progress=plain -q -m ci --source=. publish-android --play-store-config env:PLAY_STORE_CONFIG_JSON --keystore-base64 env:ANDROID_KEYSTORE_BASE64 --keystore-password env:ANDROID_KEYSTORE_PASSWORD --commit-hash "$HASH"
|
||||||
|
|
||||||
deploy-apk:
|
deploy-apk:
|
||||||
desc: Build and deploy Android APK via Dagger
|
desc: Build and deploy Android APK via Dagger
|
||||||
@@ -336,6 +336,14 @@ tasks:
|
|||||||
- |
|
- |
|
||||||
dagger query '{ engine { localCache { prune(maxUsedSpace: "75gb", targetSpace: "50gb") } } }'
|
dagger query '{ engine { localCache { prune(maxUsedSpace: "75gb", targetSpace: "50gb") } } }'
|
||||||
|
|
||||||
|
renovate:
|
||||||
|
desc: Run Renovate bot against the repository via Dagger
|
||||||
|
preconditions:
|
||||||
|
- sh: test -n "$RENOVATE_FORGEJO_TOKEN"
|
||||||
|
msg: "RENOVATE_FORGEJO_TOKEN is not set"
|
||||||
|
cmds:
|
||||||
|
- dagger call --progress=plain -q -m ci --source=. renovate --renovate-token env:RENOVATE_FORGEJO_TOKEN
|
||||||
|
|
||||||
integration-android:
|
integration-android:
|
||||||
desc: UI integration tests on a connected Android emulator (Stalwart on host, emulator reaches it via 10.0.2.2)
|
desc: UI integration tests on a connected Android emulator (Stalwart on host, emulator reaches it via 10.0.2.2)
|
||||||
deps: [_preflight, _android-sdk-check, _android-avd-setup]
|
deps: [_preflight, _android-sdk-check, _android-avd-setup]
|
||||||
|
|||||||
@@ -15,6 +15,11 @@ import io.flutter.embedding.engine.FlutterEngine;
|
|||||||
public final class GeneratedPluginRegistrant {
|
public final class GeneratedPluginRegistrant {
|
||||||
private static final String TAG = "GeneratedPluginRegistrant";
|
private static final String TAG = "GeneratedPluginRegistrant";
|
||||||
public static void registerWith(@NonNull FlutterEngine flutterEngine) {
|
public static void registerWith(@NonNull FlutterEngine flutterEngine) {
|
||||||
|
try {
|
||||||
|
flutterEngine.getPlugins().add(new dev.fluttercommunity.plus.device_info.DeviceInfoPlusPlugin());
|
||||||
|
} catch (Exception e) {
|
||||||
|
Log.e(TAG, "Error registering plugin device_info_plus, dev.fluttercommunity.plus.device_info.DeviceInfoPlusPlugin", e);
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
flutterEngine.getPlugins().add(new com.mr.flutter.plugin.filepicker.FilePickerPlugin());
|
flutterEngine.getPlugins().add(new com.mr.flutter.plugin.filepicker.FilePickerPlugin());
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
|||||||
+70
-13
@@ -286,6 +286,21 @@ func (m *Ci) firebaseSrc() *dagger.Directory {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// androidBase wraps setup(androidSrc()) with the Gradle named-cache so that
|
||||||
|
// Gradle dependencies survive across Dagger execution-cache misses.
|
||||||
|
func (m *Ci) androidBase() *dagger.Container {
|
||||||
|
return m.setup(m.androidSrc()).
|
||||||
|
WithMountedCache("/home/ci/.gradle", dag.CacheVolume("gradle-cache"),
|
||||||
|
dagger.ContainerWithMountedCacheOpts{Owner: "ci"})
|
||||||
|
}
|
||||||
|
|
||||||
|
// firebaseBase wraps setup(firebaseSrc()) with the Gradle named-cache.
|
||||||
|
func (m *Ci) firebaseBase() *dagger.Container {
|
||||||
|
return m.setup(m.firebaseSrc()).
|
||||||
|
WithMountedCache("/home/ci/.gradle", dag.CacheVolume("gradle-cache"),
|
||||||
|
dagger.ContainerWithMountedCacheOpts{Owner: "ci"})
|
||||||
|
}
|
||||||
|
|
||||||
// linuxSrc is the source subset for Linux builds and integration tests.
|
// linuxSrc is the source subset for Linux builds and integration tests.
|
||||||
func (m *Ci) linuxSrc() *dagger.Directory {
|
func (m *Ci) linuxSrc() *dagger.Directory {
|
||||||
return m.Source.Filter(dagger.DirectoryFilterOpts{
|
return m.Source.Filter(dagger.DirectoryFilterOpts{
|
||||||
@@ -584,9 +599,17 @@ func (m *Ci) BuildLinux() *dagger.Directory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// BuildLinuxRelease builds the Linux release bundle.
|
// BuildLinuxRelease builds the Linux release bundle.
|
||||||
func (m *Ci) BuildLinuxRelease() *dagger.Directory {
|
func (m *Ci) BuildLinuxRelease(
|
||||||
|
// Git commit hash injected as GIT_HASH dart-define so the About page can display it.
|
||||||
|
// +optional
|
||||||
|
commitHash string,
|
||||||
|
) *dagger.Directory {
|
||||||
|
args := []string{"flutter", "build", "linux", "--release"}
|
||||||
|
if commitHash != "" {
|
||||||
|
args = append(args, "--dart-define=GIT_HASH="+commitHash)
|
||||||
|
}
|
||||||
return m.setup(m.linuxSrc()).
|
return m.setup(m.linuxSrc()).
|
||||||
WithExec([]string{"flutter", "build", "linux", "--release"}).
|
WithExec(args).
|
||||||
Directory("build/linux/x64/release/bundle")
|
Directory("build/linux/x64/release/bundle")
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -599,7 +622,7 @@ func (m *Ci) DeployLinux(
|
|||||||
sshHost string,
|
sshHost string,
|
||||||
commitHash string,
|
commitHash string,
|
||||||
) (string, error) {
|
) (string, error) {
|
||||||
bundle := m.BuildLinuxRelease()
|
bundle := m.BuildLinuxRelease(commitHash)
|
||||||
|
|
||||||
datePath := time.Now().Format("2006/01/02")
|
datePath := time.Now().Format("2006/01/02")
|
||||||
remoteDir := fmt.Sprintf("public_html/builds/%s", datePath)
|
remoteDir := fmt.Sprintf("public_html/builds/%s", datePath)
|
||||||
@@ -615,16 +638,27 @@ func (m *Ci) DeployLinux(
|
|||||||
|
|
||||||
// setupKeystore decodes the base64 keystore into the android build container.
|
// setupKeystore decodes the base64 keystore into the android build container.
|
||||||
func (m *Ci) setupKeystore(keystoreBase64 *dagger.Secret, keystorePassword *dagger.Secret) *dagger.Container {
|
func (m *Ci) setupKeystore(keystoreBase64 *dagger.Secret, keystorePassword *dagger.Secret) *dagger.Container {
|
||||||
return m.setup(m.androidSrc()).
|
return m.androidBase().
|
||||||
WithSecretVariable("ANDROID_KEYSTORE_BASE64", keystoreBase64).
|
WithSecretVariable("ANDROID_KEYSTORE_BASE64", keystoreBase64).
|
||||||
WithSecretVariable("ANDROID_KEYSTORE_PASSWORD", keystorePassword).
|
WithSecretVariable("ANDROID_KEYSTORE_PASSWORD", keystorePassword).
|
||||||
WithExec([]string{"/bin/sh", "-c", `echo "$ANDROID_KEYSTORE_BASE64" | base64 -d > android/app/upload-keystore.jks`})
|
WithExec([]string{"/bin/sh", "-c", `echo "$ANDROID_KEYSTORE_BASE64" | base64 -d > android/app/upload-keystore.jks`})
|
||||||
}
|
}
|
||||||
|
|
||||||
// BuildAndroidApk builds a release APK signed with the upload key.
|
// BuildAndroidApk builds a release APK signed with the upload key.
|
||||||
func (m *Ci) BuildAndroidApk(keystoreBase64 *dagger.Secret, keystorePassword *dagger.Secret, buildNumber string) *dagger.File {
|
func (m *Ci) BuildAndroidApk(
|
||||||
|
keystoreBase64 *dagger.Secret,
|
||||||
|
keystorePassword *dagger.Secret,
|
||||||
|
buildNumber string,
|
||||||
|
// Git commit hash injected as GIT_HASH dart-define so the About page can display it.
|
||||||
|
// +optional
|
||||||
|
commitHash string,
|
||||||
|
) *dagger.File {
|
||||||
|
args := []string{"flutter", "build", "apk", "--release", "--no-pub", "--build-number", buildNumber}
|
||||||
|
if commitHash != "" {
|
||||||
|
args = append(args, "--dart-define=GIT_HASH="+commitHash)
|
||||||
|
}
|
||||||
return m.setupKeystore(keystoreBase64, keystorePassword).
|
return m.setupKeystore(keystoreBase64, keystorePassword).
|
||||||
WithExec([]string{"flutter", "build", "apk", "--release", "--no-pub", "--build-number", buildNumber}).
|
WithExec(args).
|
||||||
File("build/app/outputs/flutter-apk/app-release.apk")
|
File("build/app/outputs/flutter-apk/app-release.apk")
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -640,7 +674,7 @@ func (m *Ci) DeployApk(
|
|||||||
keystorePassword *dagger.Secret,
|
keystorePassword *dagger.Secret,
|
||||||
buildNumber string,
|
buildNumber string,
|
||||||
) (string, error) {
|
) (string, error) {
|
||||||
apk := m.BuildAndroidApk(keystoreBase64, keystorePassword, buildNumber)
|
apk := m.BuildAndroidApk(keystoreBase64, keystorePassword, buildNumber, commitHash)
|
||||||
|
|
||||||
datePath := time.Now().Format("2006/01/02")
|
datePath := time.Now().Format("2006/01/02")
|
||||||
remoteDir := fmt.Sprintf("public_html/builds/%s", datePath)
|
remoteDir := fmt.Sprintf("public_html/builds/%s", datePath)
|
||||||
@@ -656,8 +690,7 @@ func (m *Ci) DeployApk(
|
|||||||
// BuildAndroidDebugApks builds the debug app APK and the androidTest APK needed for Firebase Test Lab.
|
// BuildAndroidDebugApks builds the debug app APK and the androidTest APK needed for Firebase Test Lab.
|
||||||
// Returns a flat directory with app-debug.apk and app-debug-androidTest.apk.
|
// Returns a flat directory with app-debug.apk and app-debug-androidTest.apk.
|
||||||
func (m *Ci) BuildAndroidDebugApks() *dagger.Directory {
|
func (m *Ci) BuildAndroidDebugApks() *dagger.Directory {
|
||||||
built := m.setup(m.firebaseSrc()).
|
built := m.firebaseBase().
|
||||||
WithMountedCache("/home/ci/.gradle", dag.CacheVolume("gradle-cache"), dagger.ContainerWithMountedCacheOpts{Owner: "ci"}).
|
|
||||||
WithExec([]string{"flutter", "build", "apk", "--debug", "--no-pub"}).
|
WithExec([]string{"flutter", "build", "apk", "--debug", "--no-pub"}).
|
||||||
WithWorkdir("/src/android").
|
WithWorkdir("/src/android").
|
||||||
// --no-daemon avoids connecting to a stale daemon whose registry file was
|
// --no-daemon avoids connecting to a stale daemon whose registry file was
|
||||||
@@ -716,9 +749,17 @@ func (m *Ci) TestAndroidFirebase(
|
|||||||
|
|
||||||
// BuildAndroidRelease builds the AAB with a fixed build-number so Dagger can cache it.
|
// BuildAndroidRelease builds the AAB with a fixed build-number so Dagger can cache it.
|
||||||
// versionCode and signing are applied separately via StampAndroidVersionCode + SignAndroidBundle.
|
// versionCode and signing are applied separately via StampAndroidVersionCode + SignAndroidBundle.
|
||||||
func (m *Ci) BuildAndroidRelease() *dagger.File {
|
func (m *Ci) BuildAndroidRelease(
|
||||||
return m.setup(m.androidSrc()).
|
// Git commit hash injected as GIT_HASH dart-define so the About page can display it.
|
||||||
WithExec([]string{"flutter", "build", "appbundle", "--release", "--no-pub", "--build-number", "1"}).
|
// +optional
|
||||||
|
commitHash string,
|
||||||
|
) *dagger.File {
|
||||||
|
args := []string{"flutter", "build", "appbundle", "--release", "--no-pub", "--build-number", "1"}
|
||||||
|
if commitHash != "" {
|
||||||
|
args = append(args, "--dart-define=GIT_HASH="+commitHash)
|
||||||
|
}
|
||||||
|
return m.androidBase().
|
||||||
|
WithExec(args).
|
||||||
File("build/app/outputs/bundle/release/app-release.aab")
|
File("build/app/outputs/bundle/release/app-release.aab")
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -790,14 +831,30 @@ func (m *Ci) PublishAndroid(
|
|||||||
playStoreConfig *dagger.Secret,
|
playStoreConfig *dagger.Secret,
|
||||||
keystoreBase64 *dagger.Secret,
|
keystoreBase64 *dagger.Secret,
|
||||||
keystorePassword *dagger.Secret,
|
keystorePassword *dagger.Secret,
|
||||||
|
// Git commit hash injected as GIT_HASH dart-define so the About page can display it.
|
||||||
|
// +optional
|
||||||
|
commitHash string,
|
||||||
) (string, error) {
|
) (string, error) {
|
||||||
versionCode := int(time.Now().Unix())
|
versionCode := int(time.Now().Unix())
|
||||||
aab := m.BuildAndroidRelease()
|
aab := m.BuildAndroidRelease(commitHash)
|
||||||
stamped := m.StampAndroidVersionCode(aab, versionCode)
|
stamped := m.StampAndroidVersionCode(aab, versionCode)
|
||||||
signed := m.SignAndroidBundle(stamped, keystoreBase64, keystorePassword)
|
signed := m.SignAndroidBundle(stamped, keystoreBase64, keystorePassword)
|
||||||
return m.UploadToPlayStore(ctx, signed, playStoreConfig)
|
return m.UploadToPlayStore(ctx, signed, playStoreConfig)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Renovate runs Renovate bot against the repository on Forgejo/Codeberg.
|
||||||
|
func (m *Ci) Renovate(ctx context.Context, renovateToken *dagger.Secret) (string, error) {
|
||||||
|
return dag.Container().
|
||||||
|
From("renovate/renovate:39").
|
||||||
|
WithSecretVariable("RENOVATE_TOKEN", renovateToken).
|
||||||
|
WithEnvVariable("RENOVATE_PLATFORM", "forgejo").
|
||||||
|
WithEnvVariable("RENOVATE_ENDPOINT", "https://codeberg.org").
|
||||||
|
WithEnvVariable("RENOVATE_REPOSITORIES", "guettli/sharedinbox").
|
||||||
|
WithEnvVariable("LOG_LEVEL", "info").
|
||||||
|
WithExec([]string{"renovate"}).
|
||||||
|
Stdout(ctx)
|
||||||
|
}
|
||||||
|
|
||||||
// Graph returns a Mermaid diagram of the CI pipeline structure.
|
// Graph returns a Mermaid diagram of the CI pipeline structure.
|
||||||
// Paste the output into any Mermaid renderer (codeberg, github, mermaid.live)
|
// Paste the output into any Mermaid renderer (codeberg, github, mermaid.live)
|
||||||
// or save it as a .md file to get a rendered diagram.
|
// or save it as a .md file to get a rendered diagram.
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
const int dbSchemaVersion = 33;
|
||||||
@@ -19,6 +19,8 @@ class SyncLogEntry {
|
|||||||
required this.id,
|
required this.id,
|
||||||
required this.result,
|
required this.result,
|
||||||
this.errorMessage,
|
this.errorMessage,
|
||||||
|
this.stackTrace,
|
||||||
|
this.isPermanent = false,
|
||||||
required this.protocol,
|
required this.protocol,
|
||||||
required this.emailsFetched,
|
required this.emailsFetched,
|
||||||
required this.emailsSkipped,
|
required this.emailsSkipped,
|
||||||
@@ -34,6 +36,8 @@ class SyncLogEntry {
|
|||||||
final int id;
|
final int id;
|
||||||
final String result; // 'ok' or 'error'
|
final String result; // 'ok' or 'error'
|
||||||
final String? errorMessage;
|
final String? errorMessage;
|
||||||
|
final String? stackTrace;
|
||||||
|
final bool isPermanent;
|
||||||
final String protocol; // 'imap' or 'jmap'
|
final String protocol; // 'imap' or 'jmap'
|
||||||
final int emailsFetched;
|
final int emailsFetched;
|
||||||
final int emailsSkipped;
|
final int emailsSkipped;
|
||||||
@@ -54,6 +58,8 @@ abstract class SyncLogRepository {
|
|||||||
required String accountId,
|
required String accountId,
|
||||||
required bool success,
|
required bool success,
|
||||||
String? errorMessage,
|
String? errorMessage,
|
||||||
|
String? stackTrace,
|
||||||
|
bool isPermanent = false,
|
||||||
required String protocol,
|
required String protocol,
|
||||||
required int emailsFetched,
|
required int emailsFetched,
|
||||||
required int emailsSkipped,
|
required int emailsSkipped,
|
||||||
@@ -81,6 +87,8 @@ class NoOpSyncLogRepository implements SyncLogRepository {
|
|||||||
required String accountId,
|
required String accountId,
|
||||||
required bool success,
|
required bool success,
|
||||||
String? errorMessage,
|
String? errorMessage,
|
||||||
|
String? stackTrace,
|
||||||
|
bool isPermanent = false,
|
||||||
required String protocol,
|
required String protocol,
|
||||||
required int emailsFetched,
|
required int emailsFetched,
|
||||||
required int emailsSkipped,
|
required int emailsSkipped,
|
||||||
|
|||||||
@@ -260,6 +260,8 @@ class _AccountSync implements _SyncLoop {
|
|||||||
accountId: account.id,
|
accountId: account.id,
|
||||||
success: false,
|
success: false,
|
||||||
errorMessage: e.toString(),
|
errorMessage: e.toString(),
|
||||||
|
stackTrace: st.toString(),
|
||||||
|
isPermanent: isPermanent,
|
||||||
protocol: 'imap',
|
protocol: 'imap',
|
||||||
emailsFetched: 0,
|
emailsFetched: 0,
|
||||||
emailsSkipped: 0,
|
emailsSkipped: 0,
|
||||||
@@ -513,6 +515,8 @@ class _JmapAccountSync implements _SyncLoop {
|
|||||||
accountId: account.id,
|
accountId: account.id,
|
||||||
success: false,
|
success: false,
|
||||||
errorMessage: e.toString(),
|
errorMessage: e.toString(),
|
||||||
|
stackTrace: st.toString(),
|
||||||
|
isPermanent: isPermanent,
|
||||||
protocol: 'jmap',
|
protocol: 'jmap',
|
||||||
emailsFetched: 0,
|
emailsFetched: 0,
|
||||||
emailsSkipped: 0,
|
emailsSkipped: 0,
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import 'package:drift/native.dart';
|
|||||||
import 'package:flutter/services.dart';
|
import 'package:flutter/services.dart';
|
||||||
import 'package:path/path.dart' as p;
|
import 'package:path/path.dart' as p;
|
||||||
import 'package:path_provider/path_provider.dart';
|
import 'package:path_provider/path_provider.dart';
|
||||||
|
import 'package:sharedinbox/core/db_schema_version.dart';
|
||||||
|
|
||||||
part 'database.g.dart';
|
part 'database.g.dart';
|
||||||
|
|
||||||
@@ -192,6 +193,9 @@ class SyncLogs extends Table {
|
|||||||
DateTimeColumn get finishedAt => dateTime()();
|
DateTimeColumn get finishedAt => dateTime()();
|
||||||
// Added in schema v13: raw protocol log when account.verbose == true.
|
// Added in schema v13: raw protocol log when account.verbose == true.
|
||||||
TextColumn get protocolLog => text().nullable()();
|
TextColumn get protocolLog => text().nullable()();
|
||||||
|
// Added in schema v33: stack trace and permanent flag for error entries.
|
||||||
|
TextColumn get errorStackTrace => text().nullable()();
|
||||||
|
BoolColumn get isPermanent => boolean().withDefault(const Constant(false))();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Per-mailbox breakdown for a single sync cycle.
|
/// Per-mailbox breakdown for a single sync cycle.
|
||||||
@@ -329,7 +333,7 @@ class AppDatabase extends _$AppDatabase {
|
|||||||
AppDatabase([QueryExecutor? executor]) : super(executor ?? _openConnection());
|
AppDatabase([QueryExecutor? executor]) : super(executor ?? _openConnection());
|
||||||
|
|
||||||
@override
|
@override
|
||||||
int get schemaVersion => 32;
|
int get schemaVersion => dbSchemaVersion;
|
||||||
|
|
||||||
Future<void> _createEmailFts() async {
|
Future<void> _createEmailFts() async {
|
||||||
await customStatement('''
|
await customStatement('''
|
||||||
@@ -570,6 +574,10 @@ class AppDatabase extends _$AppDatabase {
|
|||||||
if (from < 32) {
|
if (from < 32) {
|
||||||
await m.createTable(localSieveApplied);
|
await m.createTable(localSieveApplied);
|
||||||
}
|
}
|
||||||
|
if (from >= 7 && from < 33) {
|
||||||
|
await m.addColumn(syncLogs, syncLogs.errorStackTrace);
|
||||||
|
await m.addColumn(syncLogs, syncLogs.isPermanent);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,6 +13,8 @@ class SyncLogRepositoryImpl implements SyncLogRepository {
|
|||||||
required String accountId,
|
required String accountId,
|
||||||
required bool success,
|
required bool success,
|
||||||
String? errorMessage,
|
String? errorMessage,
|
||||||
|
String? stackTrace,
|
||||||
|
bool isPermanent = false,
|
||||||
required String protocol,
|
required String protocol,
|
||||||
required int emailsFetched,
|
required int emailsFetched,
|
||||||
required int emailsSkipped,
|
required int emailsSkipped,
|
||||||
@@ -30,6 +32,8 @@ class SyncLogRepositoryImpl implements SyncLogRepository {
|
|||||||
accountId: accountId,
|
accountId: accountId,
|
||||||
result: success ? 'ok' : 'error',
|
result: success ? 'ok' : 'error',
|
||||||
errorMessage: Value(errorMessage),
|
errorMessage: Value(errorMessage),
|
||||||
|
errorStackTrace: Value(stackTrace),
|
||||||
|
isPermanent: Value(isPermanent),
|
||||||
protocol: Value(protocol),
|
protocol: Value(protocol),
|
||||||
itemsSynced: Value(emailsFetched),
|
itemsSynced: Value(emailsFetched),
|
||||||
emailsSkipped: Value(emailsSkipped),
|
emailsSkipped: Value(emailsSkipped),
|
||||||
@@ -75,6 +79,8 @@ class SyncLogRepositoryImpl implements SyncLogRepository {
|
|||||||
id: r.id,
|
id: r.id,
|
||||||
result: r.result,
|
result: r.result,
|
||||||
errorMessage: r.errorMessage,
|
errorMessage: r.errorMessage,
|
||||||
|
stackTrace: r.errorStackTrace,
|
||||||
|
isPermanent: r.isPermanent,
|
||||||
protocol: r.protocol,
|
protocol: r.protocol,
|
||||||
emailsFetched: r.itemsSynced,
|
emailsFetched: r.itemsSynced,
|
||||||
emailsSkipped: r.emailsSkipped,
|
emailsSkipped: r.emailsSkipped,
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
import 'dart:io';
|
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter/services.dart';
|
import 'package:flutter/services.dart';
|
||||||
@@ -8,6 +7,7 @@ import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|||||||
import 'package:package_info_plus/package_info_plus.dart';
|
import 'package:package_info_plus/package_info_plus.dart';
|
||||||
import 'package:sharedinbox/core/models/account.dart';
|
import 'package:sharedinbox/core/models/account.dart';
|
||||||
import 'package:sharedinbox/di.dart';
|
import 'package:sharedinbox/di.dart';
|
||||||
|
import 'package:sharedinbox/ui/utils/about_markdown.dart';
|
||||||
import 'package:url_launcher/url_launcher.dart';
|
import 'package:url_launcher/url_launcher.dart';
|
||||||
|
|
||||||
class AboutScreen extends ConsumerStatefulWidget {
|
class AboutScreen extends ConsumerStatefulWidget {
|
||||||
@@ -19,57 +19,22 @@ class AboutScreen extends ConsumerStatefulWidget {
|
|||||||
|
|
||||||
class _AboutScreenState extends ConsumerState<AboutScreen> {
|
class _AboutScreenState extends ConsumerState<AboutScreen> {
|
||||||
final Future<PackageInfo> _packageInfoFuture = PackageInfo.fromPlatform();
|
final Future<PackageInfo> _packageInfoFuture = PackageInfo.fromPlatform();
|
||||||
|
late final Future<String?> _deviceModelFuture;
|
||||||
late final Stream<List<Account>> _accountsStream;
|
late final Stream<List<Account>> _accountsStream;
|
||||||
|
String? _deviceModel;
|
||||||
static const _gitHash = String.fromEnvironment('GIT_HASH');
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
_accountsStream = ref.read(accountRepositoryProvider).observeAccounts();
|
_accountsStream = ref.read(accountRepositoryProvider).observeAccounts();
|
||||||
|
_deviceModelFuture = getDeviceModel();
|
||||||
|
unawaited(
|
||||||
|
_deviceModelFuture.then((model) {
|
||||||
|
if (mounted) setState(() => _deviceModel = model);
|
||||||
|
}),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
String _buildMarkdown(
|
|
||||||
BuildContext context,
|
|
||||||
PackageInfo? pkg,
|
|
||||||
int imapCount,
|
|
||||||
int jmapCount,
|
|
||||||
) {
|
|
||||||
final size = MediaQuery.of(context).size;
|
|
||||||
final pixelRatio = MediaQuery.of(context).devicePixelRatio;
|
|
||||||
final physW = (size.width * pixelRatio).toInt();
|
|
||||||
final physH = (size.height * pixelRatio).toInt();
|
|
||||||
final version =
|
|
||||||
pkg != null ? '${pkg.version}+${pkg.buildNumber}' : 'unknown';
|
|
||||||
final versionDisplay = _gitHash.isNotEmpty
|
|
||||||
? '[$version](https://codeberg.org/guettli/sharedinbox/commit/$_gitHash)'
|
|
||||||
: version;
|
|
||||||
final osName = _capitalize(Platform.operatingSystem);
|
|
||||||
final isDark = MediaQuery.of(context).platformBrightness == Brightness.dark;
|
|
||||||
|
|
||||||
final gitCommitLine = _gitHash.isNotEmpty
|
|
||||||
? '| Git Commit | [$_gitHash](https://codeberg.org/guettli/sharedinbox/commit/$_gitHash) |\n'
|
|
||||||
: '';
|
|
||||||
return '## [sharedinbox.de](https://sharedinbox.de)\n\n'
|
|
||||||
'| Property | Value |\n'
|
|
||||||
'|----------|-------|\n'
|
|
||||||
'| App Version | $versionDisplay |\n'
|
|
||||||
'$gitCommitLine'
|
|
||||||
'| Platform | ${Platform.operatingSystem} |\n'
|
|
||||||
'| $osName Version | ${Platform.operatingSystemVersion} |\n'
|
|
||||||
'| Resolution | ${physW}x$physH px'
|
|
||||||
' (logical: ${size.width.toInt()}x${size.height.toInt()} pt,'
|
|
||||||
' ratio: ${pixelRatio.toStringAsFixed(1)}x) |\n'
|
|
||||||
'| Dart Version | ${Platform.version.split(' ').first} |\n'
|
|
||||||
'| Processors | ${Platform.numberOfProcessors} |\n'
|
|
||||||
'| Dark Mode | ${isDark ? 'yes' : 'no'} |\n'
|
|
||||||
'| IMAP Accounts | $imapCount |\n'
|
|
||||||
'| JMAP Accounts | $jmapCount |\n';
|
|
||||||
}
|
|
||||||
|
|
||||||
static String _capitalize(String s) =>
|
|
||||||
s.isEmpty ? s : '${s[0].toUpperCase()}${s.substring(1)}';
|
|
||||||
|
|
||||||
Future<void> _copyToClipboard(
|
Future<void> _copyToClipboard(
|
||||||
BuildContext context,
|
BuildContext context,
|
||||||
int imapCount,
|
int imapCount,
|
||||||
@@ -79,10 +44,20 @@ class _AboutScreenState extends ConsumerState<AboutScreen> {
|
|||||||
try {
|
try {
|
||||||
pkg = await _packageInfoFuture;
|
pkg = await _packageInfoFuture;
|
||||||
} catch (_) {}
|
} catch (_) {}
|
||||||
|
String? deviceModel;
|
||||||
|
try {
|
||||||
|
deviceModel = await _deviceModelFuture;
|
||||||
|
} catch (_) {}
|
||||||
if (!context.mounted) return;
|
if (!context.mounted) return;
|
||||||
await Clipboard.setData(
|
await Clipboard.setData(
|
||||||
ClipboardData(
|
ClipboardData(
|
||||||
text: _buildMarkdown(context, pkg, imapCount, jmapCount),
|
text: buildAboutMarkdown(
|
||||||
|
context: context,
|
||||||
|
pkg: pkg,
|
||||||
|
imapCount: imapCount,
|
||||||
|
jmapCount: jmapCount,
|
||||||
|
deviceModel: deviceModel,
|
||||||
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
if (context.mounted) {
|
if (context.mounted) {
|
||||||
@@ -128,9 +103,19 @@ class _AboutScreenState extends ConsumerState<AboutScreen> {
|
|||||||
try {
|
try {
|
||||||
pkg = await _packageInfoFuture;
|
pkg = await _packageInfoFuture;
|
||||||
} catch (_) {}
|
} catch (_) {}
|
||||||
|
String? deviceModel;
|
||||||
|
try {
|
||||||
|
deviceModel = await _deviceModelFuture;
|
||||||
|
} catch (_) {}
|
||||||
if (!context.mounted) return;
|
if (!context.mounted) return;
|
||||||
final body = Uri.encodeComponent(
|
final body = Uri.encodeComponent(
|
||||||
_buildMarkdown(context, pkg, imapCount, jmapCount),
|
buildAboutMarkdown(
|
||||||
|
context: context,
|
||||||
|
pkg: pkg,
|
||||||
|
imapCount: imapCount,
|
||||||
|
jmapCount: jmapCount,
|
||||||
|
deviceModel: deviceModel,
|
||||||
|
),
|
||||||
);
|
);
|
||||||
final url = Uri.parse(
|
final url = Uri.parse(
|
||||||
'https://codeberg.org/guettli/sharedinbox/issues/new?body=$body',
|
'https://codeberg.org/guettli/sharedinbox/issues/new?body=$body',
|
||||||
@@ -181,11 +166,12 @@ class _AboutScreenState extends ConsumerState<AboutScreen> {
|
|||||||
return const Center(child: CircularProgressIndicator());
|
return const Center(child: CircularProgressIndicator());
|
||||||
}
|
}
|
||||||
return Markdown(
|
return Markdown(
|
||||||
data: _buildMarkdown(
|
data: buildAboutMarkdown(
|
||||||
context,
|
context: context,
|
||||||
snapshot.data,
|
pkg: snapshot.data,
|
||||||
imapCount,
|
imapCount: imapCount,
|
||||||
jmapCount,
|
jmapCount: jmapCount,
|
||||||
|
deviceModel: _deviceModel,
|
||||||
),
|
),
|
||||||
selectable: true,
|
selectable: true,
|
||||||
onTapLink: (text, href, title) {
|
onTapLink: (text, href, title) {
|
||||||
|
|||||||
@@ -360,7 +360,12 @@ class _EditAccountScreenState extends ConsumerState<EditAccountScreen> {
|
|||||||
: null,
|
: null,
|
||||||
),
|
),
|
||||||
const SizedBox(height: 8),
|
const SizedBox(height: 8),
|
||||||
FilledButton(onPressed: _save, child: const Text('Save')),
|
FilledButton(
|
||||||
|
onPressed: _hasStoredPassword || _passwordCtrl.text.isNotEmpty
|
||||||
|
? _save
|
||||||
|
: null,
|
||||||
|
child: const Text('Save'),
|
||||||
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -70,16 +70,9 @@ class _EmailDetailScreenState extends ConsumerState<EmailDetailScreen> {
|
|||||||
onPressed: header == null
|
onPressed: header == null
|
||||||
? null
|
? null
|
||||||
: () {
|
: () {
|
||||||
unawaited(_reply(context, header, body, replyAll: false));
|
unawaited(
|
||||||
},
|
_replyWithRecipientDialog(context, header, body),
|
||||||
),
|
);
|
||||||
IconButton(
|
|
||||||
icon: const Icon(Icons.reply_all),
|
|
||||||
tooltip: 'Reply all',
|
|
||||||
onPressed: header == null
|
|
||||||
? null
|
|
||||||
: () {
|
|
||||||
unawaited(_reply(context, header, body, replyAll: true));
|
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
IconButton(
|
IconButton(
|
||||||
@@ -121,6 +114,15 @@ class _EmailDetailScreenState extends ConsumerState<EmailDetailScreen> {
|
|||||||
tooltip: 'Snooze',
|
tooltip: 'Snooze',
|
||||||
onPressed: header == null ? null : () => _snooze(context, header),
|
onPressed: header == null ? null : () => _snooze(context, header),
|
||||||
),
|
),
|
||||||
|
IconButton(
|
||||||
|
icon: const Icon(Icons.report_outlined),
|
||||||
|
tooltip: 'Mark as spam',
|
||||||
|
onPressed: header == null
|
||||||
|
? null
|
||||||
|
: () {
|
||||||
|
unawaited(_markAsSpam(context, header));
|
||||||
|
},
|
||||||
|
),
|
||||||
IconButton(
|
IconButton(
|
||||||
icon: const Icon(Icons.delete),
|
icon: const Icon(Icons.delete),
|
||||||
tooltip: 'Delete',
|
tooltip: 'Delete',
|
||||||
@@ -303,17 +305,78 @@ class _EmailDetailScreenState extends ConsumerState<EmailDetailScreen> {
|
|||||||
return '\n\n— On $date, $from wrote:\n$quoted';
|
return '\n\n— On $date, $from wrote:\n$quoted';
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _reply(
|
Future<void> _replyWithRecipientDialog(
|
||||||
|
BuildContext context,
|
||||||
|
Email header,
|
||||||
|
EmailBody? body,
|
||||||
|
) async {
|
||||||
|
final account =
|
||||||
|
await ref.read(accountRepositoryProvider).getAccount(header.accountId);
|
||||||
|
final ownEmail = account?.email.toLowerCase() ?? '';
|
||||||
|
|
||||||
|
final seen = <String>{};
|
||||||
|
final candidates = <_Candidate>[];
|
||||||
|
|
||||||
|
void addIfNew(EmailAddress addr, _Placement defaultPlacement) {
|
||||||
|
final key = addr.email.toLowerCase();
|
||||||
|
if (key == ownEmail || seen.contains(key)) return;
|
||||||
|
seen.add(key);
|
||||||
|
candidates.add(_Candidate(addr, defaultPlacement));
|
||||||
|
}
|
||||||
|
|
||||||
|
for (final addr in header.from) {
|
||||||
|
addIfNew(addr, _Placement.to);
|
||||||
|
}
|
||||||
|
for (final addr in header.to) {
|
||||||
|
addIfNew(addr, _Placement.to);
|
||||||
|
}
|
||||||
|
for (final addr in header.cc) {
|
||||||
|
addIfNew(addr, _Placement.cc);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!context.mounted) return;
|
||||||
|
|
||||||
|
if (candidates.length <= 1) {
|
||||||
|
final to = candidates
|
||||||
|
.where((c) => c.placement == _Placement.to)
|
||||||
|
.map((c) => c.address.email)
|
||||||
|
.join(', ');
|
||||||
|
final cc = candidates
|
||||||
|
.where((c) => c.placement == _Placement.cc)
|
||||||
|
.map((c) => c.address.email)
|
||||||
|
.join(', ');
|
||||||
|
await _composeReply(context, header, body, to: to, cc: cc);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
final confirmed = await showDialog<List<_Candidate>>(
|
||||||
|
context: context,
|
||||||
|
builder: (ctx) => _ReplyAllDialog(candidates: candidates),
|
||||||
|
);
|
||||||
|
|
||||||
|
if (confirmed == null || !context.mounted) return;
|
||||||
|
|
||||||
|
final to = confirmed
|
||||||
|
.where((c) => c.placement == _Placement.to)
|
||||||
|
.map((c) => c.address.email)
|
||||||
|
.join(', ');
|
||||||
|
final cc = confirmed
|
||||||
|
.where((c) => c.placement == _Placement.cc)
|
||||||
|
.map((c) => c.address.email)
|
||||||
|
.join(', ');
|
||||||
|
await _composeReply(context, header, body, to: to, cc: cc);
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> _composeReply(
|
||||||
BuildContext context,
|
BuildContext context,
|
||||||
Email header,
|
Email header,
|
||||||
EmailBody? body, {
|
EmailBody? body, {
|
||||||
required bool replyAll,
|
required String to,
|
||||||
|
required String cc,
|
||||||
}) async {
|
}) async {
|
||||||
final to = header.from.isNotEmpty ? header.from.first.email : '';
|
|
||||||
final subject = (header.subject?.startsWith('Re:') ?? false)
|
final subject = (header.subject?.startsWith('Re:') ?? false)
|
||||||
? header.subject!
|
? header.subject!
|
||||||
: 'Re: ${header.subject ?? ''}';
|
: 'Re: ${header.subject ?? ''}';
|
||||||
final cc = replyAll ? header.to.map((a) => a.email).join(', ') : '';
|
|
||||||
final quoted = await _quotedBody(header, body);
|
final quoted = await _quotedBody(header, body);
|
||||||
if (!context.mounted) return;
|
if (!context.mounted) return;
|
||||||
unawaited(
|
unawaited(
|
||||||
@@ -330,6 +393,38 @@ class _EmailDetailScreenState extends ConsumerState<EmailDetailScreen> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<void> _markAsSpam(BuildContext context, Email header) async {
|
||||||
|
final mailboxRepo = ref.read(mailboxRepositoryProvider);
|
||||||
|
final junk = await mailboxRepo.findMailboxByRole(header.accountId, 'junk');
|
||||||
|
|
||||||
|
if (junk == null) {
|
||||||
|
if (!context.mounted) return;
|
||||||
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
|
const SnackBar(content: Text('No Junk folder found')),
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
await ref
|
||||||
|
.read(emailRepositoryProvider)
|
||||||
|
.moveEmail(widget.emailId, junk.path);
|
||||||
|
|
||||||
|
unawaited(
|
||||||
|
ref.read(undoServiceProvider.notifier).pushAction(
|
||||||
|
UndoAction(
|
||||||
|
id: DateTime.now().toIso8601String(),
|
||||||
|
accountId: header.accountId,
|
||||||
|
type: UndoType.move,
|
||||||
|
emailIds: [widget.emailId],
|
||||||
|
sourceMailboxPath: header.mailboxPath,
|
||||||
|
destinationMailboxPath: junk.path,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
if (context.mounted) context.pop();
|
||||||
|
}
|
||||||
|
|
||||||
Future<void> _forward(
|
Future<void> _forward(
|
||||||
BuildContext context,
|
BuildContext context,
|
||||||
Email header,
|
Email header,
|
||||||
@@ -670,6 +765,94 @@ class _EmailDetailScreenState extends ConsumerState<EmailDetailScreen> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
enum _Placement { to, cc, skip }
|
||||||
|
|
||||||
|
class _Candidate {
|
||||||
|
_Candidate(this.address, this.placement);
|
||||||
|
final EmailAddress address;
|
||||||
|
_Placement placement;
|
||||||
|
}
|
||||||
|
|
||||||
|
class _ReplyAllDialog extends StatefulWidget {
|
||||||
|
const _ReplyAllDialog({required this.candidates});
|
||||||
|
final List<_Candidate> candidates;
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<_ReplyAllDialog> createState() => _ReplyAllDialogState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _ReplyAllDialogState extends State<_ReplyAllDialog> {
|
||||||
|
late final List<_Candidate> _candidates;
|
||||||
|
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
super.initState();
|
||||||
|
_candidates = [
|
||||||
|
for (final c in widget.candidates) _Candidate(c.address, c.placement),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return AlertDialog(
|
||||||
|
title: const Text('Reply All'),
|
||||||
|
content: SizedBox(
|
||||||
|
width: double.maxFinite,
|
||||||
|
child: ListView(
|
||||||
|
shrinkWrap: true,
|
||||||
|
children: [
|
||||||
|
for (final c in _candidates)
|
||||||
|
Padding(
|
||||||
|
padding: const EdgeInsets.symmetric(vertical: 4),
|
||||||
|
child: Row(
|
||||||
|
children: [
|
||||||
|
Expanded(
|
||||||
|
child: Text(
|
||||||
|
c.address.toString(),
|
||||||
|
overflow: TextOverflow.ellipsis,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
const SizedBox(width: 8),
|
||||||
|
SegmentedButton<_Placement>(
|
||||||
|
showSelectedIcon: false,
|
||||||
|
segments: const [
|
||||||
|
ButtonSegment(
|
||||||
|
value: _Placement.to,
|
||||||
|
label: Text('To'),
|
||||||
|
),
|
||||||
|
ButtonSegment(
|
||||||
|
value: _Placement.cc,
|
||||||
|
label: Text('Cc'),
|
||||||
|
),
|
||||||
|
ButtonSegment(
|
||||||
|
value: _Placement.skip,
|
||||||
|
label: Text('Skip'),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
selected: {c.placement},
|
||||||
|
onSelectionChanged: (s) =>
|
||||||
|
setState(() => c.placement = s.first),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
actions: [
|
||||||
|
TextButton(
|
||||||
|
onPressed: () => Navigator.pop(context),
|
||||||
|
child: const Text('Cancel'),
|
||||||
|
),
|
||||||
|
TextButton(
|
||||||
|
onPressed: () => Navigator.pop(context, _candidates),
|
||||||
|
child: const Text('Reply'),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
class _MimeRow {
|
class _MimeRow {
|
||||||
const _MimeRow(this.depth, this.label);
|
const _MimeRow(this.depth, this.label);
|
||||||
final int depth;
|
final int depth;
|
||||||
|
|||||||
@@ -1,11 +1,15 @@
|
|||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter/services.dart';
|
||||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||||
import 'package:intl/intl.dart';
|
import 'package:intl/intl.dart';
|
||||||
|
import 'package:package_info_plus/package_info_plus.dart';
|
||||||
|
|
||||||
|
import 'package:sharedinbox/core/models/account.dart';
|
||||||
import 'package:sharedinbox/core/repositories/sync_log_repository.dart';
|
import 'package:sharedinbox/core/repositories/sync_log_repository.dart';
|
||||||
import 'package:sharedinbox/di.dart';
|
import 'package:sharedinbox/di.dart';
|
||||||
|
import 'package:sharedinbox/ui/utils/about_markdown.dart';
|
||||||
|
|
||||||
final _timeFmt = DateFormat('MMM d, HH:mm:ss');
|
final _timeFmt = DateFormat('MMM d, HH:mm:ss');
|
||||||
|
|
||||||
@@ -21,6 +25,57 @@ String _fmtBytes(int bytes) {
|
|||||||
return '${(bytes / (1024 * 1024)).toStringAsFixed(1)} MB';
|
return '${(bytes / (1024 * 1024)).toStringAsFixed(1)} MB';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String _buildSyncEntryMarkdown(SyncLogEntry entry) {
|
||||||
|
final buf = StringBuffer();
|
||||||
|
buf.writeln('## Sync Entry');
|
||||||
|
buf.writeln();
|
||||||
|
buf.writeln('| Property | Value |');
|
||||||
|
buf.writeln('|----------|-------|');
|
||||||
|
buf.writeln('| Started | ${_timeFmt.format(entry.startedAt)} |');
|
||||||
|
buf.writeln('| Finished | ${_timeFmt.format(entry.finishedAt)} |');
|
||||||
|
buf.writeln('| Duration | ${_fmtDuration(entry.duration)} |');
|
||||||
|
if (entry.protocol.isNotEmpty) {
|
||||||
|
buf.writeln('| Protocol | ${entry.protocol.toUpperCase()} |');
|
||||||
|
}
|
||||||
|
final statusLabel = entry.isOk
|
||||||
|
? 'OK'
|
||||||
|
: entry.isPermanent
|
||||||
|
? 'Error (permanent)'
|
||||||
|
: 'Error';
|
||||||
|
buf.writeln('| Status | $statusLabel |');
|
||||||
|
buf.writeln('| Emails fetched | ${entry.emailsFetched} |');
|
||||||
|
buf.writeln('| Emails up-to-date | ${entry.emailsSkipped} |');
|
||||||
|
buf.writeln('| Mailboxes synced | ${entry.mailboxesSynced} |');
|
||||||
|
buf.writeln('| Pending changes flushed | ${entry.pendingFlushed} |');
|
||||||
|
buf.writeln('| Data transferred | ${_fmtBytes(entry.bytesTransferred)} |');
|
||||||
|
if (entry.mailboxStats.isNotEmpty) {
|
||||||
|
buf.writeln();
|
||||||
|
buf.writeln('### Per mailbox');
|
||||||
|
buf.writeln();
|
||||||
|
buf.writeln('| Mailbox | Fetched | Up-to-date | Duration |');
|
||||||
|
buf.writeln('|---------|---------|------------|----------|');
|
||||||
|
for (final m in entry.mailboxStats) {
|
||||||
|
final dur = m.duration != null ? _fmtDuration(m.duration!) : '-';
|
||||||
|
buf.writeln('| ${m.mailboxPath} | ${m.fetched} | ${m.skipped} | $dur |');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (entry.errorMessage != null) {
|
||||||
|
buf.writeln();
|
||||||
|
buf.writeln('**Error:**');
|
||||||
|
buf.writeln();
|
||||||
|
buf.writeln(entry.errorMessage);
|
||||||
|
}
|
||||||
|
if (entry.stackTrace != null) {
|
||||||
|
buf.writeln();
|
||||||
|
buf.writeln('**Stack trace:**');
|
||||||
|
buf.writeln();
|
||||||
|
buf.writeln('```');
|
||||||
|
buf.write(entry.stackTrace);
|
||||||
|
buf.writeln('```');
|
||||||
|
}
|
||||||
|
return buf.toString();
|
||||||
|
}
|
||||||
|
|
||||||
class SyncLogScreen extends ConsumerStatefulWidget {
|
class SyncLogScreen extends ConsumerStatefulWidget {
|
||||||
const SyncLogScreen({super.key, required this.accountId});
|
const SyncLogScreen({super.key, required this.accountId});
|
||||||
|
|
||||||
@@ -69,6 +124,41 @@ class _SyncLogScreenState extends ConsumerState<SyncLogScreen> {
|
|||||||
ref.read(syncManagerProvider).syncNow(widget.accountId);
|
ref.read(syncManagerProvider).syncNow(widget.accountId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<void> _copyEntry(SyncLogEntry entry, BuildContext context) async {
|
||||||
|
final accounts =
|
||||||
|
await ref.read(accountRepositoryProvider).observeAccounts().first;
|
||||||
|
final imapCount = accounts.where((a) => a.type == AccountType.imap).length;
|
||||||
|
final jmapCount = accounts.where((a) => a.type == AccountType.jmap).length;
|
||||||
|
|
||||||
|
PackageInfo? pkg;
|
||||||
|
try {
|
||||||
|
pkg = await PackageInfo.fromPlatform();
|
||||||
|
} catch (_) {}
|
||||||
|
|
||||||
|
final deviceModel = await getDeviceModel();
|
||||||
|
|
||||||
|
if (!context.mounted) return;
|
||||||
|
|
||||||
|
final syncMd = _buildSyncEntryMarkdown(entry);
|
||||||
|
final aboutMd = buildAboutMarkdown(
|
||||||
|
context: context,
|
||||||
|
pkg: pkg,
|
||||||
|
imapCount: imapCount,
|
||||||
|
jmapCount: jmapCount,
|
||||||
|
deviceModel: deviceModel,
|
||||||
|
);
|
||||||
|
await Clipboard.setData(ClipboardData(text: '$syncMd\n$aboutMd'));
|
||||||
|
|
||||||
|
if (context.mounted) {
|
||||||
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
|
const SnackBar(
|
||||||
|
duration: Duration(seconds: 3),
|
||||||
|
content: Text('Copied to clipboard'),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
@@ -96,16 +186,20 @@ class _SyncLogScreenState extends ConsumerState<SyncLogScreen> {
|
|||||||
? const Center(child: Text('No sync entries yet'))
|
? const Center(child: Text('No sync entries yet'))
|
||||||
: ListView.builder(
|
: ListView.builder(
|
||||||
itemCount: _entries.length,
|
itemCount: _entries.length,
|
||||||
itemBuilder: (ctx, i) => _SyncLogTile(entry: _entries[i]),
|
itemBuilder: (ctx, i) => _SyncLogTile(
|
||||||
|
entry: _entries[i],
|
||||||
|
onCopy: () => _copyEntry(_entries[i], ctx),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class _SyncLogTile extends StatelessWidget {
|
class _SyncLogTile extends StatelessWidget {
|
||||||
const _SyncLogTile({required this.entry});
|
const _SyncLogTile({required this.entry, required this.onCopy});
|
||||||
|
|
||||||
final SyncLogEntry entry;
|
final SyncLogEntry entry;
|
||||||
|
final VoidCallback onCopy;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
@@ -115,6 +209,12 @@ class _SyncLogTile extends StatelessWidget {
|
|||||||
final theme = Theme.of(context);
|
final theme = Theme.of(context);
|
||||||
final errorColor = theme.colorScheme.error;
|
final errorColor = theme.colorScheme.error;
|
||||||
|
|
||||||
|
final subtitleText = entry.isOk
|
||||||
|
? '${entry.emailsFetched} new · ${entry.emailsSkipped} up-to-date · took $durationLabel'
|
||||||
|
: entry.isPermanent
|
||||||
|
? 'Error (permanent) · took $durationLabel'
|
||||||
|
: 'Error · took $durationLabel';
|
||||||
|
|
||||||
return ExpansionTile(
|
return ExpansionTile(
|
||||||
leading: Icon(
|
leading: Icon(
|
||||||
entry.isOk ? Icons.check_circle : Icons.error_outline,
|
entry.isOk ? Icons.check_circle : Icons.error_outline,
|
||||||
@@ -125,11 +225,20 @@ class _SyncLogTile extends StatelessWidget {
|
|||||||
style: entry.isOk ? null : TextStyle(color: errorColor),
|
style: entry.isOk ? null : TextStyle(color: errorColor),
|
||||||
),
|
),
|
||||||
subtitle: Text(
|
subtitle: Text(
|
||||||
entry.isOk
|
subtitleText,
|
||||||
? '${entry.emailsFetched} new · ${entry.emailsSkipped} up-to-date · took $durationLabel'
|
|
||||||
: 'Error · took $durationLabel',
|
|
||||||
style: TextStyle(fontSize: 12, color: entry.isOk ? null : errorColor),
|
style: TextStyle(fontSize: 12, color: entry.isOk ? null : errorColor),
|
||||||
),
|
),
|
||||||
|
trailing: Row(
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
children: [
|
||||||
|
IconButton(
|
||||||
|
icon: const Icon(Icons.copy, size: 18),
|
||||||
|
tooltip: 'Copy as markdown',
|
||||||
|
onPressed: onCopy,
|
||||||
|
),
|
||||||
|
const Icon(Icons.expand_more),
|
||||||
|
],
|
||||||
|
),
|
||||||
children: [
|
children: [
|
||||||
Padding(
|
Padding(
|
||||||
padding: const EdgeInsets.fromLTRB(72, 0, 16, 12),
|
padding: const EdgeInsets.fromLTRB(72, 0, 16, 12),
|
||||||
@@ -171,6 +280,31 @@ class _SyncLogTile extends StatelessWidget {
|
|||||||
style: TextStyle(color: errorColor, fontSize: 12),
|
style: TextStyle(color: errorColor, fontSize: 12),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
if (entry.stackTrace != null) ...[
|
||||||
|
const Padding(
|
||||||
|
padding: EdgeInsets.only(top: 6, bottom: 2),
|
||||||
|
child: Text(
|
||||||
|
'Stack trace',
|
||||||
|
style: TextStyle(fontSize: 12, color: Colors.grey),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
Container(
|
||||||
|
width: double.infinity,
|
||||||
|
padding: const EdgeInsets.all(8),
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: Colors.black87,
|
||||||
|
borderRadius: BorderRadius.circular(4),
|
||||||
|
),
|
||||||
|
child: Text(
|
||||||
|
entry.stackTrace!,
|
||||||
|
style: TextStyle(
|
||||||
|
fontSize: 10,
|
||||||
|
fontFamily: 'monospace',
|
||||||
|
color: Colors.red[300],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
if (entry.protocolLog != null) ...[
|
if (entry.protocolLog != null) ...[
|
||||||
const Padding(
|
const Padding(
|
||||||
padding: EdgeInsets.only(top: 6, bottom: 2),
|
padding: EdgeInsets.only(top: 6, bottom: 2),
|
||||||
|
|||||||
@@ -0,0 +1,75 @@
|
|||||||
|
import 'dart:io';
|
||||||
|
|
||||||
|
import 'package:device_info_plus/device_info_plus.dart';
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:package_info_plus/package_info_plus.dart';
|
||||||
|
import 'package:sharedinbox/core/db_schema_version.dart';
|
||||||
|
|
||||||
|
const _gitHash = String.fromEnvironment('GIT_HASH');
|
||||||
|
|
||||||
|
/// Builds the About markdown table used in [AboutScreen] and sync log copies.
|
||||||
|
String buildAboutMarkdown({
|
||||||
|
required BuildContext context,
|
||||||
|
PackageInfo? pkg,
|
||||||
|
required int imapCount,
|
||||||
|
required int jmapCount,
|
||||||
|
String? deviceModel,
|
||||||
|
}) {
|
||||||
|
final size = MediaQuery.of(context).size;
|
||||||
|
final pixelRatio = MediaQuery.of(context).devicePixelRatio;
|
||||||
|
final physW = (size.width * pixelRatio).toInt();
|
||||||
|
final physH = (size.height * pixelRatio).toInt();
|
||||||
|
final version = pkg != null ? '${pkg.version}+${pkg.buildNumber}' : 'unknown';
|
||||||
|
final versionDisplay = _gitHash.isNotEmpty
|
||||||
|
? '[$version](https://codeberg.org/guettli/sharedinbox/commit/$_gitHash)'
|
||||||
|
: version;
|
||||||
|
final osName = _capitalize(Platform.operatingSystem);
|
||||||
|
final isDark = MediaQuery.of(context).platformBrightness == Brightness.dark;
|
||||||
|
final locale = Localizations.localeOf(context).toString();
|
||||||
|
final textScale =
|
||||||
|
MediaQuery.of(context).textScaler.scale(1.0).toStringAsFixed(1);
|
||||||
|
|
||||||
|
final gitCommitLine = _gitHash.isNotEmpty
|
||||||
|
? '| Git Commit | [$_gitHash](https://codeberg.org/guettli/sharedinbox/commit/$_gitHash) |\n'
|
||||||
|
: '';
|
||||||
|
final deviceModelLine =
|
||||||
|
deviceModel != null ? '| Device Model | $deviceModel |\n' : '';
|
||||||
|
|
||||||
|
return '## [sharedinbox.de](https://sharedinbox.de)\n\n'
|
||||||
|
'| Property | Value |\n'
|
||||||
|
'|----------|-------|\n'
|
||||||
|
'| App Version | $versionDisplay |\n'
|
||||||
|
'$gitCommitLine'
|
||||||
|
'| Platform | ${Platform.operatingSystem} |\n'
|
||||||
|
'| $osName Version | ${Platform.operatingSystemVersion} |\n'
|
||||||
|
'$deviceModelLine'
|
||||||
|
'| Resolution | ${physW}x$physH px'
|
||||||
|
' (logical: ${size.width.toInt()}x${size.height.toInt()} pt,'
|
||||||
|
' ratio: ${pixelRatio.toStringAsFixed(1)}x) |\n'
|
||||||
|
'| Dart Version | ${Platform.version.split(' ').first} |\n'
|
||||||
|
'| Processors | ${Platform.numberOfProcessors} |\n'
|
||||||
|
'| Dark Mode | ${isDark ? 'yes' : 'no'} |\n'
|
||||||
|
'| Locale | $locale |\n'
|
||||||
|
'| Text Scale | $textScale× |\n'
|
||||||
|
'| DB Schema Version | $dbSchemaVersion |\n'
|
||||||
|
'| IMAP Accounts | $imapCount |\n'
|
||||||
|
'| JMAP Accounts | $jmapCount |\n';
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Fetches device model string, or null when unavailable.
|
||||||
|
Future<String?> getDeviceModel() async {
|
||||||
|
try {
|
||||||
|
final info = DeviceInfoPlugin();
|
||||||
|
if (Platform.isAndroid) {
|
||||||
|
final android = await info.androidInfo;
|
||||||
|
return '${android.manufacturer} / ${android.model}';
|
||||||
|
} else if (Platform.isIOS) {
|
||||||
|
final ios = await info.iosInfo;
|
||||||
|
return ios.utsname.machine;
|
||||||
|
}
|
||||||
|
} catch (_) {}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
String _capitalize(String s) =>
|
||||||
|
s.isEmpty ? s : '${s[0].toUpperCase()}${s.substring(1)}';
|
||||||
@@ -249,6 +249,22 @@ packages:
|
|||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "0.7.12"
|
version: "0.7.12"
|
||||||
|
device_info_plus:
|
||||||
|
dependency: "direct main"
|
||||||
|
description:
|
||||||
|
name: device_info_plus
|
||||||
|
sha256: "6a642e1daa10190af89ba6cb6386c0df7d071a3592080bfe1e44faa63ae1df65"
|
||||||
|
url: "https://pub.dev"
|
||||||
|
source: hosted
|
||||||
|
version: "13.1.0"
|
||||||
|
device_info_plus_platform_interface:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: device_info_plus_platform_interface
|
||||||
|
sha256: "04b173a92e2d9161dfead145667037c8d834db725ce2e7b942bfe18fd2f45a46"
|
||||||
|
url: "https://pub.dev"
|
||||||
|
source: hosted
|
||||||
|
version: "8.1.0"
|
||||||
drift:
|
drift:
|
||||||
dependency: "direct main"
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
@@ -1284,6 +1300,14 @@ packages:
|
|||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "6.3.0"
|
version: "6.3.0"
|
||||||
|
win32_registry:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: win32_registry
|
||||||
|
sha256: "73b1d78920a9d6e03f8b4e43e612b87bf3152a0e5c5e5150267762b7c4116904"
|
||||||
|
url: "https://pub.dev"
|
||||||
|
source: hosted
|
||||||
|
version: "3.0.3"
|
||||||
workmanager:
|
workmanager:
|
||||||
dependency: "direct main"
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
|
|||||||
@@ -61,6 +61,7 @@ dependencies:
|
|||||||
# App version metadata for crash reports
|
# App version metadata for crash reports
|
||||||
package_info_plus: ^10.1.0
|
package_info_plus: ^10.1.0
|
||||||
share_plus: ^13.1.0
|
share_plus: ^13.1.0
|
||||||
|
device_info_plus: ^13.1.0
|
||||||
|
|
||||||
dev_dependencies:
|
dev_dependencies:
|
||||||
flutter_test:
|
flutter_test:
|
||||||
|
|||||||
@@ -0,0 +1,10 @@
|
|||||||
|
{
|
||||||
|
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
|
||||||
|
"extends": [
|
||||||
|
"config:recommended"
|
||||||
|
],
|
||||||
|
"labels": ["dependencies"],
|
||||||
|
"github-actions": {
|
||||||
|
"fileMatch": ["^\\.forgejo/workflows/[^/]+\\.ya?ml$"]
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -42,6 +42,7 @@ import re
|
|||||||
import shlex
|
import shlex
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
|
import time
|
||||||
from datetime import datetime, timezone
|
from datetime import datetime, timezone
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
@@ -278,6 +279,41 @@ def _merge_pr(pr_number: int) -> None:
|
|||||||
_fgj("pr", "merge", str(pr_number), "--repo", REPO, "--merge-method", "squash")
|
_fgj("pr", "merge", str(pr_number), "--repo", REPO, "--merge-method", "squash")
|
||||||
|
|
||||||
|
|
||||||
|
def _handle_pr_still_open_after_merge(pr_number: int, branch: str, issue_num: int | None) -> str:
|
||||||
|
"""Handle a PR that is still open after a successful _merge_pr() call.
|
||||||
|
|
||||||
|
Returns one of:
|
||||||
|
"rebase-spawned" — merge conflict detected; rebase agent started, state written
|
||||||
|
"merged" — PR closed after a retry
|
||||||
|
"fallback" — all options exhausted; caller should set State/Question
|
||||||
|
"""
|
||||||
|
pr_data = _tea_get(f"repos/{REPO}/pulls/{pr_number}")
|
||||||
|
mergeable = (pr_data or {}).get("mergeable")
|
||||||
|
|
||||||
|
if mergeable is False:
|
||||||
|
prompt = (
|
||||||
|
f"Rebase branch `{branch}` onto main to resolve merge conflicts, then push. "
|
||||||
|
"Do not change any logic — only resolve conflicts and push."
|
||||||
|
)
|
||||||
|
session_name = f"rebase-pr-{pr_number}"
|
||||||
|
pid = _start_agent(prompt, session_name)
|
||||||
|
_write_state(pid, issue_num, "pending-ci", session_name=session_name)
|
||||||
|
print(f"PR #{pr_number} has merge conflicts — spawned rebase agent (pid={pid}).")
|
||||||
|
return "rebase-spawned"
|
||||||
|
|
||||||
|
for attempt in range(1, 3):
|
||||||
|
time.sleep(5)
|
||||||
|
try:
|
||||||
|
_merge_pr(pr_number)
|
||||||
|
except RuntimeError as e:
|
||||||
|
print(f"PR #{pr_number} merge retry {attempt} failed: {e}")
|
||||||
|
if not _find_pr_for_branch(branch):
|
||||||
|
print(f"PR #{pr_number} merged on retry {attempt}.")
|
||||||
|
return "merged"
|
||||||
|
|
||||||
|
return "fallback"
|
||||||
|
|
||||||
|
|
||||||
# ── state file ────────────────────────────────────────────────────────────────
|
# ── state file ────────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
|
||||||
@@ -676,6 +712,13 @@ def _run_loop() -> int:
|
|||||||
)
|
)
|
||||||
return 0
|
return 0
|
||||||
if _find_pr_for_branch(branch):
|
if _find_pr_for_branch(branch):
|
||||||
|
merge_result = _handle_pr_still_open_after_merge(pr_number, branch, pending_issue)
|
||||||
|
if merge_result == "rebase-spawned":
|
||||||
|
return 0
|
||||||
|
if merge_result == "merged":
|
||||||
|
_close_issue(pending_issue)
|
||||||
|
print(f"Merged PR #{pr_number} and closed {_issue_url(pending_issue)}.")
|
||||||
|
return 0
|
||||||
print(f"PR #{pr_number} is still open after merge attempt — setting to State/Question.")
|
print(f"PR #{pr_number} is still open after merge attempt — setting to State/Question.")
|
||||||
_set_labels(pending_issue, add=[LABEL_QUESTION], remove=[LABEL_IN_PROGRESS])
|
_set_labels(pending_issue, add=[LABEL_QUESTION], remove=[LABEL_IN_PROGRESS])
|
||||||
_comment_issue(
|
_comment_issue(
|
||||||
@@ -744,6 +787,16 @@ def _run_loop() -> int:
|
|||||||
# Verify the merge actually happened; fgj can exit 0 without merging
|
# Verify the merge actually happened; fgj can exit 0 without merging
|
||||||
# (e.g. branch-protection rules not satisfied).
|
# (e.g. branch-protection rules not satisfied).
|
||||||
if _find_pr_for_branch(branch):
|
if _find_pr_for_branch(branch):
|
||||||
|
merge_result = _handle_pr_still_open_after_merge(pr_number, branch, issue_num)
|
||||||
|
if merge_result == "rebase-spawned":
|
||||||
|
return 0
|
||||||
|
if merge_result == "merged":
|
||||||
|
if issue_num:
|
||||||
|
_close_issue(issue_num)
|
||||||
|
print(f"Catch-up: merged PR #{pr_number} and closed issue #{issue_num} after retry.")
|
||||||
|
else:
|
||||||
|
print(f"Catch-up: merged PR #{pr_number} after retry.")
|
||||||
|
return 0
|
||||||
print(
|
print(
|
||||||
f"Catch-up: PR #{pr_number} is still open after merge attempt "
|
f"Catch-up: PR #{pr_number} is still open after merge attempt "
|
||||||
"— skipping to avoid infinite retry."
|
"— skipping to avoid infinite retry."
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ const _minCoveragePercent = 80;
|
|||||||
|
|
||||||
// Pure-abstract interfaces: no executable code, Dart VM never instruments them.
|
// Pure-abstract interfaces: no executable code, Dart VM never instruments them.
|
||||||
const _noCode = {
|
const _noCode = {
|
||||||
|
'lib/core/db_schema_version.dart',
|
||||||
'lib/core/repositories/account_repository.dart',
|
'lib/core/repositories/account_repository.dart',
|
||||||
'lib/core/repositories/draft_repository.dart',
|
'lib/core/repositories/draft_repository.dart',
|
||||||
'lib/core/repositories/email_repository.dart',
|
'lib/core/repositories/email_repository.dart',
|
||||||
@@ -57,6 +58,7 @@ const _excluded = {
|
|||||||
'lib/ui/widgets/try_connection_button.dart',
|
'lib/ui/widgets/try_connection_button.dart',
|
||||||
'lib/ui/widgets/undo_shell.dart',
|
'lib/ui/widgets/undo_shell.dart',
|
||||||
'lib/ui/screens/about_screen.dart',
|
'lib/ui/screens/about_screen.dart',
|
||||||
|
'lib/ui/utils/about_markdown.dart',
|
||||||
'lib/ui/widgets/email_tile.dart',
|
'lib/ui/widgets/email_tile.dart',
|
||||||
'lib/core/sync/account_sync_manager.dart',
|
'lib/core/sync/account_sync_manager.dart',
|
||||||
'lib/core/sync/background_sync.dart',
|
'lib/core/sync/background_sync.dart',
|
||||||
|
|||||||
@@ -785,6 +785,90 @@ class TestCatchupSkipsQuestionIssues(unittest.TestCase):
|
|||||||
mock_merge.assert_called_once_with(50)
|
mock_merge.assert_called_once_with(50)
|
||||||
|
|
||||||
|
|
||||||
|
class TestMergeFailsOpen(unittest.TestCase):
|
||||||
|
"""Tests for auto-resolution when a PR is still open after the merge command."""
|
||||||
|
|
||||||
|
def _dead_state(self, issue: int, kind: str = "issue") -> dict:
|
||||||
|
return {
|
||||||
|
"pid": 999999999,
|
||||||
|
"issue": issue,
|
||||||
|
"started_at": "2026-01-01T00:00:00+00:00",
|
||||||
|
"type": kind,
|
||||||
|
}
|
||||||
|
|
||||||
|
def _open_pr(self, branch: str = "issue-10-fix") -> dict:
|
||||||
|
return {"number": 5, "head": {"ref": branch}, "created_at": "2026-01-01T00:00:00+00:00"}
|
||||||
|
|
||||||
|
def test_merge_fails_open_with_conflicts_spawns_rebase_agent(self):
|
||||||
|
"""mergeable=false → rebase agent spawned, state written as pending-ci."""
|
||||||
|
written_state = {}
|
||||||
|
|
||||||
|
def fake_write_state(pid, issue, kind, issue_title=None, session_name=None, ci_run_id=None):
|
||||||
|
written_state["pid"] = pid
|
||||||
|
written_state["issue"] = issue
|
||||||
|
written_state["kind"] = kind
|
||||||
|
written_state["session_name"] = session_name
|
||||||
|
|
||||||
|
with patch("agent_loop._read_state", return_value=self._dead_state(10)), \
|
||||||
|
patch("agent_loop._find_pr_for_branch", side_effect=[self._open_pr(), self._open_pr()]), \
|
||||||
|
patch("agent_loop._latest_ci_run_for_branch", return_value={"id": 1, "status": "success"}), \
|
||||||
|
patch("agent_loop._merge_pr"), \
|
||||||
|
patch("agent_loop._tea_get", return_value={"mergeable": False}), \
|
||||||
|
patch("agent_loop._start_agent", return_value=77) as mock_start, \
|
||||||
|
patch("agent_loop._write_state", side_effect=fake_write_state), \
|
||||||
|
patch("agent_loop._clear_state"):
|
||||||
|
result = agent_loop._run_loop()
|
||||||
|
|
||||||
|
self.assertEqual(result, 0)
|
||||||
|
mock_start.assert_called_once()
|
||||||
|
prompt = mock_start.call_args[0][0]
|
||||||
|
self.assertIn("Rebase branch", prompt)
|
||||||
|
self.assertIn("issue-10-fix", prompt)
|
||||||
|
self.assertEqual(written_state.get("kind"), "pending-ci")
|
||||||
|
self.assertEqual(written_state.get("issue"), 10)
|
||||||
|
|
||||||
|
def test_merge_fails_open_no_conflicts_retries_and_succeeds(self):
|
||||||
|
"""mergeable=true, second attempt succeeds → issue closed."""
|
||||||
|
with patch("agent_loop._read_state", return_value=self._dead_state(10)), \
|
||||||
|
patch("agent_loop._find_pr_for_branch",
|
||||||
|
side_effect=[self._open_pr(), self._open_pr(), None]), \
|
||||||
|
patch("agent_loop._latest_ci_run_for_branch", return_value={"id": 1, "status": "success"}), \
|
||||||
|
patch("agent_loop._merge_pr"), \
|
||||||
|
patch("agent_loop._tea_get", return_value={"mergeable": True}), \
|
||||||
|
patch("agent_loop.time.sleep"), \
|
||||||
|
patch("agent_loop._close_issue") as mock_close, \
|
||||||
|
patch("agent_loop._clear_state"):
|
||||||
|
result = agent_loop._run_loop()
|
||||||
|
|
||||||
|
self.assertEqual(result, 0)
|
||||||
|
mock_close.assert_called_once_with(10)
|
||||||
|
|
||||||
|
def test_merge_fails_open_no_conflicts_all_retries_exhausted(self):
|
||||||
|
"""All retries exhausted with PR still open → falls through to State/Question."""
|
||||||
|
with patch("agent_loop._read_state", return_value=self._dead_state(10)), \
|
||||||
|
patch("agent_loop._find_pr_for_branch",
|
||||||
|
side_effect=[self._open_pr(), self._open_pr(),
|
||||||
|
self._open_pr(), self._open_pr()]), \
|
||||||
|
patch("agent_loop._latest_ci_run_for_branch", return_value={"id": 1, "status": "success"}), \
|
||||||
|
patch("agent_loop._merge_pr"), \
|
||||||
|
patch("agent_loop._tea_get", return_value={"mergeable": True}), \
|
||||||
|
patch("agent_loop.time.sleep"), \
|
||||||
|
patch("agent_loop._set_labels") as mock_labels, \
|
||||||
|
patch("agent_loop._comment_issue") as mock_comment, \
|
||||||
|
patch("agent_loop._close_issue") as mock_close, \
|
||||||
|
patch("agent_loop._clear_state"):
|
||||||
|
result = agent_loop._run_loop()
|
||||||
|
|
||||||
|
self.assertEqual(result, 0)
|
||||||
|
mock_close.assert_not_called()
|
||||||
|
mock_labels.assert_called_once_with(
|
||||||
|
10,
|
||||||
|
add=[agent_loop.LABEL_QUESTION],
|
||||||
|
remove=[agent_loop.LABEL_IN_PROGRESS],
|
||||||
|
)
|
||||||
|
mock_comment.assert_called_once()
|
||||||
|
|
||||||
|
|
||||||
class TestHeartbeat(unittest.TestCase):
|
class TestHeartbeat(unittest.TestCase):
|
||||||
"""Tests for _update_heartbeat() and cmd_monitor()."""
|
"""Tests for _update_heartbeat() and cmd_monitor()."""
|
||||||
|
|
||||||
|
|||||||
@@ -288,6 +288,8 @@ class _FakeLogs implements SyncLogRepository {
|
|||||||
required String accountId,
|
required String accountId,
|
||||||
required bool success,
|
required bool success,
|
||||||
String? errorMessage,
|
String? errorMessage,
|
||||||
|
String? stackTrace,
|
||||||
|
bool isPermanent = false,
|
||||||
required String protocol,
|
required String protocol,
|
||||||
required int emailsFetched,
|
required int emailsFetched,
|
||||||
required int emailsSkipped,
|
required int emailsSkipped,
|
||||||
|
|||||||
@@ -181,6 +181,8 @@ class FakeSyncLogRepository implements SyncLogRepository {
|
|||||||
required String accountId,
|
required String accountId,
|
||||||
required bool success,
|
required bool success,
|
||||||
String? errorMessage,
|
String? errorMessage,
|
||||||
|
String? stackTrace,
|
||||||
|
bool isPermanent = false,
|
||||||
required String protocol,
|
required String protocol,
|
||||||
required int emailsFetched,
|
required int emailsFetched,
|
||||||
required int emailsSkipped,
|
required int emailsSkipped,
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ void main() {
|
|||||||
group('Migration', () {
|
group('Migration', () {
|
||||||
test('schemaVersion matches expected value', () async {
|
test('schemaVersion matches expected value', () async {
|
||||||
final db = AppDatabase(NativeDatabase.memory());
|
final db = AppDatabase(NativeDatabase.memory());
|
||||||
expect(db.schemaVersion, 32);
|
expect(db.schemaVersion, 33);
|
||||||
await db.close();
|
await db.close();
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -194,6 +194,11 @@ void main() {
|
|||||||
// v32: local_sieve_applied table.
|
// v32: local_sieve_applied table.
|
||||||
await db.customSelect('SELECT count(*) FROM local_sieve_applied').get();
|
await db.customSelect('SELECT count(*) FROM local_sieve_applied').get();
|
||||||
|
|
||||||
|
// v33: error_stack_trace and is_permanent columns on sync_logs.
|
||||||
|
final syncLogColumns = await _tableColumns(db, 'sync_logs');
|
||||||
|
expect(syncLogColumns, contains('error_stack_trace'));
|
||||||
|
expect(syncLogColumns, contains('is_permanent'));
|
||||||
|
|
||||||
await db.close();
|
await db.close();
|
||||||
if (dbFile.existsSync()) dbFile.deleteSync();
|
if (dbFile.existsSync()) dbFile.deleteSync();
|
||||||
});
|
});
|
||||||
@@ -381,11 +386,16 @@ void main() {
|
|||||||
await _tableColumns(db, 'sync_log_mailboxes');
|
await _tableColumns(db, 'sync_log_mailboxes');
|
||||||
expect(syncLogMailboxColumns, contains('duration_ms'));
|
expect(syncLogMailboxColumns, contains('duration_ms'));
|
||||||
|
|
||||||
|
// v33: error_stack_trace and is_permanent columns on sync_logs.
|
||||||
|
final syncLogColumns = await _tableColumns(db, 'sync_logs');
|
||||||
|
expect(syncLogColumns, contains('error_stack_trace'));
|
||||||
|
expect(syncLogColumns, contains('is_permanent'));
|
||||||
|
|
||||||
await db.close();
|
await db.close();
|
||||||
if (dbFile.existsSync()) dbFile.deleteSync();
|
if (dbFile.existsSync()) dbFile.deleteSync();
|
||||||
});
|
});
|
||||||
|
|
||||||
test('fresh install creates all tables at schemaVersion 32', () async {
|
test('fresh install creates all tables at schemaVersion 33', () async {
|
||||||
final db = AppDatabase(NativeDatabase.memory());
|
final db = AppDatabase(NativeDatabase.memory());
|
||||||
await db.select(db.accounts).get();
|
await db.select(db.accounts).get();
|
||||||
|
|
||||||
@@ -426,6 +436,11 @@ void main() {
|
|||||||
await _tableColumns(db, 'sync_log_mailboxes');
|
await _tableColumns(db, 'sync_log_mailboxes');
|
||||||
expect(syncLogMailboxColumns, contains('duration_ms'));
|
expect(syncLogMailboxColumns, contains('duration_ms'));
|
||||||
|
|
||||||
|
// v33: error_stack_trace and is_permanent columns on sync_logs.
|
||||||
|
final syncLogColumns = await _tableColumns(db, 'sync_logs');
|
||||||
|
expect(syncLogColumns, contains('error_stack_trace'));
|
||||||
|
expect(syncLogColumns, contains('is_permanent'));
|
||||||
|
|
||||||
await db.close();
|
await db.close();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -170,6 +170,8 @@ class _FakeSyncLog implements SyncLogRepository {
|
|||||||
required String accountId,
|
required String accountId,
|
||||||
required bool success,
|
required bool success,
|
||||||
String? errorMessage,
|
String? errorMessage,
|
||||||
|
String? stackTrace,
|
||||||
|
bool isPermanent = false,
|
||||||
required String protocol,
|
required String protocol,
|
||||||
required int emailsFetched,
|
required int emailsFetched,
|
||||||
required int emailsSkipped,
|
required int emailsSkipped,
|
||||||
|
|||||||
@@ -126,4 +126,34 @@ void main() {
|
|||||||
expect(rows.first.result, 'error');
|
expect(rows.first.result, 'error');
|
||||||
expect(rows.first.errorMessage, 'Connection refused');
|
expect(rows.first.errorMessage, 'Connection refused');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('stores and retrieves stackTrace and isPermanent on error entries',
|
||||||
|
() async {
|
||||||
|
final repo = SyncLogRepositoryImpl(db);
|
||||||
|
final start = DateTime(2024, 3, 1, 9);
|
||||||
|
final end = DateTime(2024, 3, 1, 9, 0, 1);
|
||||||
|
const fakeTrace = '#0 main (file:///app/lib/main.dart:10:5)';
|
||||||
|
|
||||||
|
await repo.log(
|
||||||
|
accountId: 'acc1',
|
||||||
|
success: false,
|
||||||
|
errorMessage: 'MissingPluginException',
|
||||||
|
stackTrace: fakeTrace,
|
||||||
|
isPermanent: true,
|
||||||
|
protocol: 'imap',
|
||||||
|
emailsFetched: 0,
|
||||||
|
emailsSkipped: 0,
|
||||||
|
mailboxesSynced: 0,
|
||||||
|
pendingFlushed: 0,
|
||||||
|
bytesTransferred: 0,
|
||||||
|
startedAt: start,
|
||||||
|
finishedAt: end,
|
||||||
|
);
|
||||||
|
|
||||||
|
final entries = await repo.observeSyncLogs('acc1').first;
|
||||||
|
final entry = entries.firstWhere((e) => e.startedAt == start);
|
||||||
|
expect(entry.stackTrace, fakeTrace);
|
||||||
|
expect(entry.isPermanent, true);
|
||||||
|
expect(entry.errorMessage, 'MissingPluginException');
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -80,6 +80,9 @@ void main() {
|
|||||||
expect(find.textContaining('Dark Mode'), findsWidgets);
|
expect(find.textContaining('Dark Mode'), findsWidgets);
|
||||||
expect(find.textContaining('IMAP Accounts'), findsWidgets);
|
expect(find.textContaining('IMAP Accounts'), findsWidgets);
|
||||||
expect(find.textContaining('JMAP Accounts'), findsWidgets);
|
expect(find.textContaining('JMAP Accounts'), findsWidgets);
|
||||||
|
expect(find.textContaining('Locale'), findsWidgets);
|
||||||
|
expect(find.textContaining('Text Scale'), findsWidgets);
|
||||||
|
expect(find.textContaining('DB Schema Version'), findsWidgets);
|
||||||
// Buttons are in the body, not in the AppBar actions
|
// Buttons are in the body, not in the AppBar actions
|
||||||
expect(find.byIcon(Icons.copy), findsOneWidget);
|
expect(find.byIcon(Icons.copy), findsOneWidget);
|
||||||
expect(find.byIcon(Icons.bug_report), findsOneWidget);
|
expect(find.byIcon(Icons.bug_report), findsOneWidget);
|
||||||
@@ -167,6 +170,9 @@ void main() {
|
|||||||
expect(clipboardText, contains('Dark Mode'));
|
expect(clipboardText, contains('Dark Mode'));
|
||||||
expect(clipboardText, contains('IMAP Accounts'));
|
expect(clipboardText, contains('IMAP Accounts'));
|
||||||
expect(clipboardText, contains('JMAP Accounts'));
|
expect(clipboardText, contains('JMAP Accounts'));
|
||||||
|
expect(clipboardText, contains('Locale'));
|
||||||
|
expect(clipboardText, contains('Text Scale'));
|
||||||
|
expect(clipboardText, contains('DB Schema Version'));
|
||||||
expect(
|
expect(
|
||||||
clipboardText,
|
clipboardText,
|
||||||
contains('[sharedinbox.de](https://sharedinbox.de)'),
|
contains('[sharedinbox.de](https://sharedinbox.de)'),
|
||||||
|
|||||||
@@ -163,6 +163,30 @@ void main() {
|
|||||||
expect(button.onPressed, isNotNull);
|
expect(button.onPressed, isNotNull);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
testWidgets('save button is disabled when no password stored or entered', (
|
||||||
|
tester,
|
||||||
|
) async {
|
||||||
|
tester.view.physicalSize = const Size(800, 1400);
|
||||||
|
tester.view.devicePixelRatio = 1.0;
|
||||||
|
addTearDown(tester.view.resetPhysicalSize);
|
||||||
|
addTearDown(tester.view.resetDevicePixelRatio);
|
||||||
|
|
||||||
|
await tester.pumpWidget(
|
||||||
|
buildApp(
|
||||||
|
initialLocation: '/accounts/acc-1/edit',
|
||||||
|
overrides: baseOverrides(
|
||||||
|
accounts: [kTestAccount],
|
||||||
|
hasStoredPassword: false,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
|
||||||
|
final button = tester
|
||||||
|
.widget<FilledButton>(find.widgetWithText(FilledButton, 'Save'));
|
||||||
|
expect(button.onPressed, isNull);
|
||||||
|
});
|
||||||
|
|
||||||
testWidgets('connection error shows error message', (tester) async {
|
testWidgets('connection error shows error message', (tester) async {
|
||||||
tester.view.physicalSize = const Size(800, 1400);
|
tester.view.physicalSize = const Size(800, 1400);
|
||||||
tester.view.devicePixelRatio = 1.0;
|
tester.view.devicePixelRatio = 1.0;
|
||||||
|
|||||||
@@ -179,6 +179,142 @@ void main() {
|
|||||||
expect(find.text('report.pdf'), findsOneWidget);
|
expect(find.text('report.pdf'), findsOneWidget);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
testWidgets('Reply All button is not present in app bar', (tester) async {
|
||||||
|
await tester.pumpWidget(
|
||||||
|
buildApp(
|
||||||
|
initialLocation: '/accounts/acc-1/mailboxes/INBOX/emails/acc-1%3A42',
|
||||||
|
overrides: _overrides(
|
||||||
|
body: const EmailBody(emailId: 'acc-1:42', attachments: []),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
|
||||||
|
expect(
|
||||||
|
find.byWidgetPredicate(
|
||||||
|
(w) => w is Tooltip && w.message == 'Reply all',
|
||||||
|
),
|
||||||
|
findsNothing,
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
testWidgets('Reply on single-recipient email navigates directly to compose',
|
||||||
|
(tester) async {
|
||||||
|
// testEmail has from=[bob], to=[alice]. After removing alice (own),
|
||||||
|
// only bob remains → no dialog, navigate straight to compose.
|
||||||
|
final email = testEmail();
|
||||||
|
await tester.pumpWidget(
|
||||||
|
buildApp(
|
||||||
|
initialLocation: '/accounts/acc-1/mailboxes/INBOX/emails/acc-1%3A42',
|
||||||
|
overrides: [
|
||||||
|
..._overrides(
|
||||||
|
body: const EmailBody(emailId: 'acc-1:42', attachments: []),
|
||||||
|
email: email,
|
||||||
|
),
|
||||||
|
draftRepositoryProvider.overrideWithValue(FakeDraftRepository()),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
|
||||||
|
await tester.tap(
|
||||||
|
find.byWidgetPredicate(
|
||||||
|
(w) => w is Tooltip && w.message == 'Reply',
|
||||||
|
),
|
||||||
|
);
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
|
||||||
|
// No dialog shown — straight navigation to compose.
|
||||||
|
expect(find.text('Reply All'), findsNothing);
|
||||||
|
});
|
||||||
|
|
||||||
|
testWidgets('Reply on multi-recipient email shows Reply All dialog',
|
||||||
|
(tester) async {
|
||||||
|
// Email with an extra Cc recipient so the dialog is triggered.
|
||||||
|
final email = Email(
|
||||||
|
id: 'acc-1:42',
|
||||||
|
accountId: 'acc-1',
|
||||||
|
mailboxPath: 'INBOX',
|
||||||
|
uid: 42,
|
||||||
|
subject: 'Hello world',
|
||||||
|
receivedAt: DateTime(2024, 6),
|
||||||
|
sentAt: DateTime(2024, 6),
|
||||||
|
from: const [EmailAddress(name: 'Bob', email: 'bob@example.com')],
|
||||||
|
to: const [EmailAddress(email: 'alice@example.com')],
|
||||||
|
cc: const [EmailAddress(name: 'Carol', email: 'carol@example.com')],
|
||||||
|
isSeen: false,
|
||||||
|
isFlagged: false,
|
||||||
|
hasAttachment: false,
|
||||||
|
);
|
||||||
|
await tester.pumpWidget(
|
||||||
|
buildApp(
|
||||||
|
initialLocation: '/accounts/acc-1/mailboxes/INBOX/emails/acc-1%3A42',
|
||||||
|
overrides: _overrides(
|
||||||
|
body: const EmailBody(emailId: 'acc-1:42', attachments: []),
|
||||||
|
email: email,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
|
||||||
|
await tester.tap(
|
||||||
|
find.byWidgetPredicate(
|
||||||
|
(w) => w is Tooltip && w.message == 'Reply',
|
||||||
|
),
|
||||||
|
);
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
|
||||||
|
// Dialog must appear with title 'Reply All'.
|
||||||
|
expect(find.text('Reply All'), findsOneWidget);
|
||||||
|
// Both non-own addresses should be listed in the dialog.
|
||||||
|
expect(find.textContaining('bob@example.com'), findsAtLeastNWidgets(1));
|
||||||
|
expect(find.textContaining('carol@example.com'), findsAtLeastNWidgets(1));
|
||||||
|
});
|
||||||
|
|
||||||
|
testWidgets('Mark as spam button is present in app bar', (tester) async {
|
||||||
|
await tester.pumpWidget(
|
||||||
|
buildApp(
|
||||||
|
initialLocation: '/accounts/acc-1/mailboxes/INBOX/emails/acc-1%3A42',
|
||||||
|
overrides: _overrides(
|
||||||
|
body: const EmailBody(emailId: 'acc-1:42', attachments: []),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
|
||||||
|
expect(
|
||||||
|
find.byWidgetPredicate(
|
||||||
|
(w) => w is Tooltip && w.message == 'Mark as spam',
|
||||||
|
),
|
||||||
|
findsOneWidget,
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
testWidgets(
|
||||||
|
'Mark as spam moves email to junk and shows snackbar when no junk folder',
|
||||||
|
(tester) async {
|
||||||
|
// FakeMailboxRepository has no mailboxes by default → findMailboxByRole
|
||||||
|
// returns null → snackbar shown.
|
||||||
|
await tester.pumpWidget(
|
||||||
|
buildApp(
|
||||||
|
initialLocation: '/accounts/acc-1/mailboxes/INBOX/emails/acc-1%3A42',
|
||||||
|
overrides: _overrides(
|
||||||
|
body: const EmailBody(emailId: 'acc-1:42', attachments: []),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
|
||||||
|
await tester.tap(
|
||||||
|
find.byWidgetPredicate(
|
||||||
|
(w) => w is Tooltip && w.message == 'Mark as spam',
|
||||||
|
),
|
||||||
|
);
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
|
||||||
|
expect(find.text('No Junk folder found'), findsOneWidget);
|
||||||
|
});
|
||||||
|
|
||||||
testWidgets('Show Raw Email dialog shows size of email', (tester) async {
|
testWidgets('Show Raw Email dialog shows size of email', (tester) async {
|
||||||
// 'A' * 2048 → fmtSize(2048) == '2.0 KB'
|
// 'A' * 2048 → fmtSize(2048) == '2.0 KB'
|
||||||
final rawContent = 'A' * 2048;
|
final rawContent = 'A' * 2048;
|
||||||
|
|||||||
Reference in New Issue
Block a user