Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions .github/workflows/disable-auto-reopen-after-second-close.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: Disable auto-reopen after second close

on:
pull_request:
types: [closed]

permissions:
issues: write
pull-requests: write

jobs:
disable:
runs-on: ubuntu-latest
steps:
- name: Disable automatic reopen
uses: actions/github-script@v7
with:
script: |
const pr = context.payload.pull_request;

// Ignore merged PRs
if (pr.merged) return;

const labels = pr.labels.map(l => l.name);

// Only act if it was previously reopened once
if (!labels.includes('reopen-used')) return;

// Mark auto-reopen as permanently disabled
await github.rest.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: pr.number,
labels: ['reopen-locked']
});

await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: pr.number,
body:
"This PR was reopened once and then closed again.\n\n" +
"Automatic reopening via `/not-a-mistake` is now disabled.\n" +
"Maintainers may still reopen this PR manually if needed."
});
67 changes: 67 additions & 0 deletions .github/workflows/mistake-pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
name: Auto-close mistake PRs

on:
pull_request:
types: [opened, synchronize, reopened]

permissions:
issues: write
pull-requests: write

jobs:
detect:
runs-on: ubuntu-latest
steps:
- name: Detect mistake PR
uses: actions/github-script@v7
with:
script: |
const pr = context.payload.pull_request;
const labels = pr.labels.map(l => l.name);

// Skip if auto-reopen is disabled or already used
if (labels.includes('reopen-used') || labels.includes('reopen-locked')) {
return;
}

// Get changed files
const files = await github.paginate(
github.rest.pulls.listFiles,
{
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: pr.number,
}
);

// Detect newly added OR copied files
const hasNewFiles = files.some(
f => f.status === 'added' || f.status === 'copied'
);

if (!hasNewFiles) return;

// Label as mistake PR
await github.rest.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: pr.number,
labels: ['mistake-pr']
});

// Explain and close
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: pr.number,
body:
"This PR was automatically closed because it adds new files.\n\n" +
"If this is intentional, comment `/not-a-mistake` **once** to reopen it."
});

await github.rest.pulls.update({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: pr.number,
state: 'closed'
});
84 changes: 84 additions & 0 deletions .github/workflows/reopen-once.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
name: Reopen mistake PR once

on:
issue_comment:
types: [created]

permissions:
issues: write
pull-requests: write

jobs:
reopen:
runs-on: ubuntu-latest
steps:
- name: Handle /not-a-mistake
uses: actions/github-script@v7
with:
script: |
const comment = context.payload.comment;
const issue = context.payload.issue;

if (!issue.pull_request) return;
if (comment.body.trim() !== '/not-a-mistake') return;

const pr = await github.rest.pulls.get({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: issue.number
});

const labels = pr.data.labels.map(l => l.name);

// Only PR author may use this
if (comment.user.login !== pr.data.user.login) {
return;
}

// Must be closed and labeled mistake-pr
if (pr.data.state !== 'closed') return;
if (!labels.includes('mistake-pr')) return;

// Auto-reopen already disabled
if (labels.includes('reopen-used') || labels.includes('reopen-locked')) {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue.number,
body:
"Automatic reopening is disabled for this PR.\n\n" +
"A maintainer may still reopen it manually if needed."
});
return;
}

// Mark reopen as used FIRST (prevents race)
await github.rest.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue.number,
labels: ['reopen-used']
});

await github.rest.issues.removeLabel({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue.number,
name: 'mistake-pr'
});

await github.rest.pulls.update({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: issue.number,
state: 'open'
});

await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue.number,
body:
"PR reopened.\n\n" +
"If this PR is closed again, automatic reopening will be disabled."
});
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.pedropathing.paths.*;
import com.pedropathing.telemetry.SelectableOpMode;
import com.pedropathing.util.*;
import static com.pedropathing.math.MathFunctions.quadraticFit;
import com.qualcomm.robotcore.eventloop.opmode.OpMode;
import com.qualcomm.robotcore.eventloop.opmode.TeleOp;
import com.qualcomm.robotcore.hardware.DcMotorEx;
Expand Down Expand Up @@ -856,7 +857,7 @@ public void loop() {
}

case DONE: {
double[] coeffs = MathFunctions.QuadraticRegression.quadraticFit(data);
double[] coeffs = quadraticFit(data);

telemetryM.debug("Tuning Complete");
telemetryM.debug("kFriction (kQ)", coeffs[1]);
Expand Down
Loading