Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes for auto-numbering of MIPs #45

Merged
merged 8 commits into from
May 31, 2024
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
38 changes: 20 additions & 18 deletions .github/scripts/rename_and_update_mip.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,41 +6,43 @@ const MIPsFolderPath = path.join(__dirname, "..", "..", "MIPs");

function getMIPFiles() {
const files = fs.readdirSync(MIPsFolderPath);
return files.filter((file) => file.match(/^(mip-(\d+|x))\.md$/i));
return files.filter((file) => file.match(/^mip-x([\w-]+)?\.md$/i));
}

function getNextMIPNumber(mipFiles) {
const numberedMipFiles = mipFiles.filter((file) => file.match(/^mip-\d+\.md$/i));
function getNextMIPNumber() {
const allFiles = fs.readdirSync(MIPsFolderPath);
const numberedMipFiles = allFiles.filter((file) => file.match(/^mip-\d+\.md$/i));
const mipNumbers = numberedMipFiles.map((file) => parseInt(file.match(/^mip-(\d+)\.md$/i)[1], 10));
return mipNumbers.length > 0 ? Math.max(...mipNumbers) + 1 : 1;
}


function renameAndUpdateMIPFile() {
function renameAndUpdateMIPFiles() {
const mipFiles = getMIPFiles();

if (mipFiles.length === 0) {
console.log("No MIP files found.");
return;
}

const nextMIPNumber = getNextMIPNumber(mipFiles);
mipFiles.forEach((file) => {
const nextMIPNumber = getNextMIPNumber();

const oldFilePath = path.join(MIPsFolderPath, "mip-x.md");
const newFilePath = path.join(MIPsFolderPath, `mip-${nextMIPNumber}.md`);
const oldFilePath = path.join(MIPsFolderPath, file);
const newFilePath = path.join(MIPsFolderPath, `mip-${nextMIPNumber}.md`);

if (!fs.existsSync(oldFilePath)) {
console.log("No mip-x.md file found.");
return;
}
if (!fs.existsSync(oldFilePath)) {
console.log(oldFilePath + " not found.");
return;
}

const content = fs.readFileSync(oldFilePath, "utf-8");
const updatedContent = content.replace(/mip-x/gi, `MIP-${nextMIPNumber}`);
const content = fs.readFileSync(oldFilePath, "utf-8");
const updatedContent = content.replace(/mip: x/gi, `mip: ${nextMIPNumber}`);

fs.writeFileSync(newFilePath, updatedContent);
fs.unlinkSync(oldFilePath);
fs.writeFileSync(newFilePath, updatedContent);
fs.unlinkSync(oldFilePath);

execSync(`git add ${oldFilePath} ${newFilePath}`);
execSync(`git add "${oldFilePath}" "${newFilePath}"`);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i wrapped these paths in quotes to ensure whitespace doesn't break the command

});
}

renameAndUpdateMIPFile();
renameAndUpdateMIPFiles();
2 changes: 1 addition & 1 deletion .github/workflows/mip-number-assignment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,6 @@ jobs:
if git diff-index --quiet HEAD --; then
echo "No changes to commit"
else
git commit -m "Assign MIP number"
git commit -m "Assign MIP number(s)"
git push origin main
fi
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Mac files
.DS_Store
15 changes: 9 additions & 6 deletions MIP-Template.md
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ideally this template change would have come in a separate PR before this one, but not that big of a deal

Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
---
MIP: X
Title: MIP Title
Status: Draft
Stability: n/a
mip: x
title: MIP Title
status: Draft
stability: n/a
discussions-to: https://github.com/MetaMask/metamask-improvement-proposals/discussions
Type: Community
Created: 2023-04-28
type: Community
created: 2023-04-28
---
> [!NOTE]
> Rename this file to mip-x.md in your proposal. If more than one MIP will be submitted, then a suffix can be added to each file as mip-x-foo.md, mip-x-bar.md, etc. MIP numbering will automatically be applied with renamed filenames when merged.

["Status" should be one of: Draft | Review | Last Call | Accepted | Implemented | Postponed | Declined | Discontinued]

["Stability" describes the stability of the implementation. Prior to implementation it should be left as "n/a". Once implemented, the stability will be one of: Experimental | Stable | Deprecated]
Expand Down
14 changes: 7 additions & 7 deletions MIPs/mip-1.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
---
MIP: 1
Title: Extend `wallet_watchAsset` to Support ERC-721 and ERC-1155 Tokens (NFTs)
Status: Implemented
Stability: Experimental
mip: 1
title: Extend `wallet_watchAsset` to Support ERC-721 and ERC-1155 Tokens (NFTs)
status: Implemented
stability: Experimental
discussions-to: https://github.com/MetaMask/metamask-improvement-proposals/discussions/22
Author(s): Alex Donesky (@adonesky1)
Type: Maintainer
Created: 2023-04-11
author(s): Alex Donesky (@adonesky1)
type: Maintainer
created: 2023-04-11
---

## Summary
Expand Down
14 changes: 7 additions & 7 deletions MIPs/mip-2.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
---
MIP: 2
Title: Implement `wallet_revokePermissions` for Flexible Permission Revocation
Status: Implemented
Stability: Experimental
mip: 2
title: Implement `wallet_revokePermissions` for Flexible Permission Revocation
status: Implemented
stability: Experimental
discussions-to: https://github.com/MetaMask/metamask-improvement-proposals/discussions/28
Author(s): Julia Collins (@julesat22), Shane Jonas (@shanejonas)
Type: Community
Created: 2023-10-06
author(s): Julia Collins (@julesat22), Shane Jonas (@shanejonas)
type: Community
created: 2023-10-06
---

## Summary
Expand Down
14 changes: 7 additions & 7 deletions MIPs/mip-3.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
---
MIP: X
Title: Discontinuing the eth_sign signature method
Status: Last Call
Stability: Deprecated
mip: 3
title: Discontinuing the eth_sign signature method
status: Last Call
stability: Deprecated
discussions-to: https://github.com/MetaMask/metamask-improvement-proposals/discussions/41
Author(s): Vandan Parikh(@vandan), Shane Jonas (@shanejonas), Alex Donesky (@adonesky1)
Type: Maintainer
Created: 2024-05-15
author(s): Vandan Parikh(@vandan), Shane Jonas (@shanejonas), Alex Donesky (@adonesky1)
type: Maintainer
created: 2024-05-15
---

## Summary
Expand Down
Loading