Skip to content

Commit

Permalink
Fixes for auto-numbering of MIPs (#45)
Browse files Browse the repository at this point in the history
* Fixes for auto-numbering of MIPs

Update the template with the right placeholder string that the action will replace with the appropriate MIP number.

Also retroactively applies the new format to existing MIPs.

* Update MIP-Template.md

Add file naming guidelines

* frontmatter & autonumbering improvements

improves frontmatter and includes an update to the regular expression that will be used to automatically set MIP numbers.

* Automatic MIP numbering improvement

These changes ensures that automatic MIP numbering can be applied to multiple mip-x.md files with each merged PR. Multiple files can be specified as "mip-x.md", mip-x-foo.md", and "mip-x-bar.md". If the current MIP number was 10, these would be renamed to: mip-10.md, mip-11.md, mip-12.md, respectively.

* Remove .DS_Store

remove and exclude in .gitignore

* Delete .DS_Store

Delete .DS_Store

* Update rename_and_update_mip.js

Iterates through the mip-x*.md files and applies automatic numbering to them.

* fix git add

---------

Co-authored-by: Jiexi Luan <[email protected]>
  • Loading branch information
vandan and jiexi authored May 31, 2024
1 parent 2fee780 commit af246ca
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 46 deletions.
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}"`);
});
}

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
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

0 comments on commit af246ca

Please sign in to comment.