Maintainer's Dream
The distributed workflow for Linux source code development is called Benevolent Dictator. Some maintainers collect contributors' work in their own repository according to their expertise, and the dictator will merge from these lieutenants' repositories. These lieutenants receive work through emailed patches. You can subscribe to these back-and-forth patches and comments between maintainers and contributors via mailing lists at vger.kernel.org , for instance,?linux-usb?and?netdev?mailing lists.
I noticed lots of patches get shared in the community each week. Since VSCode is handy for checking commits and trying different builds with its remote development and git features, I've been using it for that. But, I couldn't find an extension to easily add these patches. So I made one.
With this extension, you can view your inbox, check contributions and conversations, and, with just one click, merge shared patches to build your customized Linux. A Maintainer's Dream came true!
I developed this extension using JavaScript and ChatGPT, with no prior knowledge of either VSCode extension API or JavaScript. I used VSCode, imap-simple, and simple-git Node.js libraries to fetch emails and apply patches.
const vscode = require('vscode');
const imaps = require('imap-simple');
const simpleGit = require('simple-git');
The gist of email fetching is as follows:
领英推荐
const connection = await imaps.connect(mail_config);
await connection.openBox(config.get('inbox', 'Inbox'));
const results = await connection.search(searchCriteria, fetchOptions);
results.forEach((res) => {
const header = res.parts.filter((part) => {
return part.which === 'HEADER';
});
const body = res.parts.filter((part) => {
return part.which === 'TEXT';
});
emails.set(res.attributes.uid, { sub: header[0].body.subject[0], msg: body[0].body });
});
When an email is clicked on, I show the content in an editor:
vscode.workspace.openTextDocument({
language: 'diff',
content: this.emails.get(item.id).msg
}).then((document) => {
vscode.window.showTextDocument(document, {
viewColumn: vscode.ViewColumn.One,
preserveFocus: true,
preview: true,
viewOptions: {
readOnly: true
}
});
});
And when the user decides to apply the patch, the message of the email is fed into git apply.
# Notice changing the line endings
fs.writeFileSync(filePath, treeDataProvider.emails.get(email.id).msg.replace(/\r\n/g, "\n"), {
encoding: "utf8"
});
const git = simpleGit(vscode.workspace.workspaceFolders[0].uri.fsPath);
await git.applyPatch(filePath, {
'--whitespace': 'fix',
'--reject': null,
'--verbose': null
});
The core functionality consists of just around 200 lines of code, yet it significantly enhances a maintainer's workflow, making their life much easier.
There's still space for additional features, such as deleting emails or marking them as read. If you have any ideas for improvements or suggestions for my JavaScript coding style, feel free to share them.
I build Technology & tech is building the future. Let's Chat ?? Developer | Founder | Trendsetter | Marketing Maverick | Innovator
10 个月Very insightful and useful, explaining VSCode extension and how it can help maintainers and contributors. Thanks for sharing the benefits it can bring to the open-source community.? Best wishes, Mohammad Rahimi ??