AWS Blogs 前天 00:08
Amazon Q Developer in GitHub (in preview) accelerates code generation
index_new5.html
../../../zaker_core/zaker_tpl_static/wap/tpl_guoji1.html

 

本文介绍了如何在 GitHub 中使用 Amazon Q Developer,这是一个预览版功能,旨在帮助开发者进行特性开发、代码审查和 Java 代码迁移。文章通过一个名为 StoryBook Teller 的 ASP.Core 网站项目,演示了如何利用 Amazon Q Developer 创建 .NET 9 应用程序,包括安装、特性开发和代码审查等环节。它展示了如何通过 GitHub 上的问题分配任务给 Amazon Q Developer,并自动生成代码和 pull request,从而简化开发流程。

✅ **安装与配置**: 首先,需要在 GitHub 中安装 Amazon Q Developer 应用,可以选择应用于所有仓库或特定仓库。安装后,可以在 GitHub 设置中验证应用是否已安装,并随时配置或移除。

✅ **特性开发**: 通过在 GitHub 问题中添加“Amazon Q development agent”标签,可以将任务分配给 Amazon Q Developer。它会根据问题的描述和代码库内容生成代码,并自动创建 pull request。

✅ **代码审查**: Amazon Q Developer 会对生成的代码进行自动检查。用户可以在 pull request 中审查代码,并可以像正常代码审查流程一样,通过评论要求 Amazon Q Developer 进行更改。

✅ **.NET 项目创建**: 文章演示了使用 Amazon Q Developer 创建 .NET 项目,从创建 .NET 9 项目骨架到实现前端和后端功能,Amazon Q Developer 都能胜任。

✅ **.gitignore 文件修改**: 演示了在代码审查过程中,通过评论方式,让 Amazon Q Developer 添加忽略 JetBrains Rider IDE 文件的规则。

<table id="amazon-polly-audio-table"><tbody><tr><td id="amazon-polly-audio-tab"><p></p></td></tr></tbody></table><p>Starting today, you can now use <a href="https://github.com/apps/amazon-q-developer&quot;&gt;Amazon Q Developer in GitHub</a> in preview! This is fantastic news for the millions of developers who use GitHub on a daily basis, whether at work or for personal projects. They can now use Amazon Q Developer for feature development, code reviews, and Java code migration directly within the GitHub interface.</p><p>To demonstrate, I’m going to use Amazon Q Developer to help me create an application from zero called StoryBook Teller. I want this to be an ASP.Core website using .NET 9 that takes three images from the user and uses <a href="https://aws.amazon.com/bedrock/&quot;&gt;Amazon Bedrock</a> with Anthropic’s Claude to generate a story based on them.</p><p>Let me show you how this works.</p><p><strong>Installation</strong></p><p>The first thing you need to do is install the <a href="https://github.com/apps/amazon-q-developer&quot;&gt;Amazon Q Developer application in GitHub</a>, and you can begin using it immediately without connecting to an AWS account.</p><p>You’ll then be presented with a choice to add it to all your repositories or select specific ones. In this case, I want to add it to my storybook-teller-demo repo, so I choose <strong>Only selected repositories</strong> and type in the name to find it.</p><p><a href="https://d2908q01vomqb2.cloudfront.net/da4b9237bacccdf19c0760cab7aec4a8359010b0/2025/05/01/selecting-only-specific-repositories.png&quot;&gt;&lt;img class="aligncenter size-full wp-image-95753" src="https://d2908q01vomqb2.cloudfront.net/da4b9237bacccdf19c0760cab7aec4a8359010b0/2025/05/01/selecting-only-specific-repositories.png&quot; alt="" width="608" height="818" /></a></p><p>This is all you need to do to make the Amazon Q Developer app ready to use inside your selected repos. You can verify that the app is installed by navigating to your GitHub account <strong>Settings</strong> and the app should be listed in the <strong>Applications</strong> page.</p><p><a href="https://d2908q01vomqb2.cloudfront.net/da4b9237bacccdf19c0760cab7aec4a8359010b0/2025/05/01/amazon-q-developer-in-my-github-app-marked.png&quot;&gt;&lt;img class="aligncenter wp-image-95752 size-full" src="https://d2908q01vomqb2.cloudfront.net/da4b9237bacccdf19c0760cab7aec4a8359010b0/2025/05/01/amazon-q-developer-in-my-github-app-marked.png&quot; alt="" width="968" height="447" /></a></p><p>You can choose <strong>Configure</strong> to view permissions and add Amazon Q Developer to repositories or remove it at any time.</p><p>Now let’s use Amazon Q Developer to help us build our application.</p><p><strong>Feature development<br /></strong> When Amazon Q Developer is installed into a repository, you can assign GitHub issues to the Amazon Q development agent to develop features for you. It will then generate code using the whole codebase in your repository as context as well as the issue’s description. This is why it’s important to list your requirements as accurately and clearly as possible in your GitHub issues, the same way that you should always strive for anyway.</p><p>I have created five issues in my StoryBook Teller repository that cover all my requirements for this app, from creating a skeleton .NET 9 project to implementing frontend and backend.</p><p><a href="https://d2908q01vomqb2.cloudfront.net/da4b9237bacccdf19c0760cab7aec4a8359010b0/2025/04/17/empty-repository-with-5-issues.png&quot;&gt;&lt;img class="aligncenter size-full wp-image-95272" src="https://d2908q01vomqb2.cloudfront.net/da4b9237bacccdf19c0760cab7aec4a8359010b0/2025/04/17/empty-repository-with-5-issues.png&quot; alt="" width="1761" height="561" /></a></p><p>Let’s use Amazon Q Developer to develop the application from scratch and help us implement all these features!</p><p>To begin with, I want Amazon Q Developer to help me create the .NET project. To do this, I open the first issue, and in the <strong>Labels</strong> section, I find and select <strong>Amazon Q development agent</strong>.</p><p><a href="https://d2908q01vomqb2.cloudfront.net/da4b9237bacccdf19c0760cab7aec4a8359010b0/2025/04/21/marked-choosing-label-setup-story.png&quot;&gt;&lt;img class="aligncenter size-full wp-image-95396" src="https://d2908q01vomqb2.cloudfront.net/da4b9237bacccdf19c0760cab7aec4a8359010b0/2025/04/21/marked-choosing-label-setup-story.png&quot; alt="" width="1278" height="814" /></a></p><p>That’s all there is to it! The issue is now assigned to Amazon Q Developer. After the label is added, the Amazon Q development agent automatically starts working behind the scenes providing progress updates through the comments, starting with one saying, <code>I'm working on it</code>.</p><p><a href="https://d2908q01vomqb2.cloudfront.net/da4b9237bacccdf19c0760cab7aec4a8359010b0/2025/05/01/q-developer-i-am-working-on-it-comment.png&quot;&gt;&lt;img class="aligncenter size-full wp-image-95754" src="https://d2908q01vomqb2.cloudfront.net/da4b9237bacccdf19c0760cab7aec4a8359010b0/2025/05/01/q-developer-i-am-working-on-it-comment.png&quot; alt="" width="935" height="188" /></a></p><p>As you might expect, the amount of time it takes will depend on the complexity of the feature. When it’s done, it will automatically create a pull request with all the changes.</p><p><a href="https://d2908q01vomqb2.cloudfront.net/da4b9237bacccdf19c0760cab7aec4a8359010b0/2025/05/01/q-developer-finished-full-issue-loo-marked.png&quot;&gt;&lt;img class="aligncenter size-full wp-image-95755" src="https://d2908q01vomqb2.cloudfront.net/da4b9237bacccdf19c0760cab7aec4a8359010b0/2025/05/01/q-developer-finished-full-issue-loo-marked.png&quot; alt="" width="959" height="756" /></a></p><p>The first thing I want to do is make sure that the generated code works, so I’m going to download the code changes and run the app locally on my computer.</p><p>I go to my terminal and type <code>git fetch origin pull/6/head:pr-6</code> to get the code for the pull request it created. I double-check the contents and I can see that I do indeed have an ASP.Core project generated using .NET 9, as I expected.</p><p>I then run <code>dotnet run</code> and open the app with the URL given in the output.</p><p><a href="https://d2908q01vomqb2.cloudfront.net/da4b9237bacccdf19c0760cab7aec4a8359010b0/2025/04/17/running-app-after-setup-story-done.png&quot;&gt;&lt;img class="aligncenter size-full wp-image-95281" src="https://d2908q01vomqb2.cloudfront.net/da4b9237bacccdf19c0760cab7aec4a8359010b0/2025/04/17/running-app-after-setup-story-done.png&quot; alt="" width="635" height="330" /></a></p><p>Brilliant, it works! Amazon Q Developer took care of implementing this one exactly as I wanted based on the requirements I provided in the GitHub issue. Now that I have tested that the app works, I want to review the code itself before I accept the changes.</p><p><strong>Code review</strong><br />I go back to GitHub and open the pull request. The first thing I notice is that Amazon Q Developer has performed some automatic checks on the generated code.</p><p><a href="https://d2908q01vomqb2.cloudfront.net/da4b9237bacccdf19c0760cab7aec4a8359010b0/2025/05/01/pull-request-with-automated-code-review-done-marked.png&quot;&gt;&lt;img class="aligncenter wp-image-95756 size-full" src="https://d2908q01vomqb2.cloudfront.net/da4b9237bacccdf19c0760cab7aec4a8359010b0/2025/05/01/pull-request-with-automated-code-review-done-marked.png&quot; alt="" width="917" height="983" /></a></p><p>This is great! It has already done quite a bit of the work for me. However, I want to review it before I merge the pull request. To do that, I navigate to the <strong>Files changed</strong> tab.</p><p><a href="https://d2908q01vomqb2.cloudfront.net/da4b9237bacccdf19c0760cab7aec4a8359010b0/2025/04/17/files-changed-tab-marked.png&quot;&gt;&lt;img class="aligncenter size-full wp-image-95283" src="https://d2908q01vomqb2.cloudfront.net/da4b9237bacccdf19c0760cab7aec4a8359010b0/2025/04/17/files-changed-tab-marked.png&quot; alt="" width="567" height="132" /></a></p><p>I review the code, and I like what I see! However, looking at the contents of .gitignore, I notice something that I want to change. I can see that Amazon Q Developer made good assumptions and added exclusion rules for Visual Studio (VS) Code files. However, JetBrains Rider is my favorite integrated development environment (IDE) for .NET development, so I want to add rules for it, too.</p><p>You can ask Amazon Q Developer to reiterate and make changes by using the normal code review flow in the GitHub interface. In this case, I add a comment to the .gitignore code saying, <code>add patterns to ignore Rider IDE files</code>. I then choose <strong>Start a review</strong>, which will queue the change in the review.</p><p><a href="https://d2908q01vomqb2.cloudfront.net/da4b9237bacccdf19c0760cab7aec4a8359010b0/2025/04/17/gitignore-comment-added-review-pending.png&quot;&gt;&lt;img class="aligncenter size-full wp-image-95284" src="https://d2908q01vomqb2.cloudfront.net/da4b9237bacccdf19c0760cab7aec4a8359010b0/2025/04/17/gitignore-comment-added-review-pending.png&quot; alt="" width="715" height="322" /></a></p><p>I select <strong>Finish your review</strong> and <strong>Request changes.</strong></p><p><a href="https://d2908q01vomqb2.cloudfront.net/da4b9237bacccdf19c0760cab7aec4a8359010b0/2025/05/01/selecting-request-change-marked.png&quot;&gt;&lt;img class="aligncenter wp-image-95757 size-full" src="https://d2908q01vomqb2.cloudfront.net/da4b9237bacccdf19c0760cab7aec4a8359010b0/2025/05/01/selecting-request-change-marked.png&quot; alt="" width="683" height="594" /></a></p><p>Soon after I submit the review, I’m redirected to the Conversation tab. Amazon Q Developer starts working on it, resuming the same feedback loop and encouraging me to continue with the review process until I’m satisfied.</p><p>Every time Q Developer makes changes, it will run the automated checks on the generated code. In this case, the code was somewhat straightforward, so it was expected that the automatic code review wouldn’t raise any issues. But what happens if we have more complex code?</p><p>Let’s take another example and use Amazon Q Developer to implement the feature for enabling image uploads on the website. I use the same flow I described in the previous section. However, I notice that the automated checks on the pull request flagged a warning this time, stating that the API generated to support image uploads on the backend is missing authorization checks effectively allowing direct public access. It explains the security risk in detail and provides useful links.</p><p><a href="https://d2908q01vomqb2.cloudfront.net/da4b9237bacccdf19c0760cab7aec4a8359010b0/2025/05/01/security-warning-found-with-image-upload-full-view-with-message-of-q-working-on-fix-suggestion.png&quot;&gt;&lt;img class="aligncenter size-full wp-image-95759" src="https://d2908q01vomqb2.cloudfront.net/da4b9237bacccdf19c0760cab7aec4a8359010b0/2025/05/01/security-warning-found-with-image-upload-full-view-with-message-of-q-working-on-fix-suggestion.png&quot; alt="" width="945" height="578" /></a></p><p>It then automatically generates a suggested code fix.</p><p><a href="https://d2908q01vomqb2.cloudfront.net/da4b9237bacccdf19c0760cab7aec4a8359010b0/2025/05/01/generating-code-fix-suggestion-for-security-warning.png&quot;&gt;&lt;img class="aligncenter size-full wp-image-95758" src="https://d2908q01vomqb2.cloudfront.net/da4b9237bacccdf19c0760cab7aec4a8359010b0/2025/05/01/generating-code-fix-suggestion-for-security-warning.png&quot; alt="" width="948" height="166" /></a></p><p>When it’s done, you can review the code and choose to Commit changes if you’re happy with the changes.</p><p><a href="https://d2908q01vomqb2.cloudfront.net/da4b9237bacccdf19c0760cab7aec4a8359010b0/2025/05/01/commit-suggested-code-fix.png&quot;&gt;&lt;img class="aligncenter size-full wp-image-95760" src="https://d2908q01vomqb2.cloudfront.net/da4b9237bacccdf19c0760cab7aec4a8359010b0/2025/05/01/commit-suggested-code-fix.png&quot; alt="" width="759" height="189" /></a></p><p>After fixing this and testing it, I’m happy with the code for this issue and move on applying the same process to other ones. I assign the Amazon Q development agent to each one of my remaining issues, wait for it to generate the code, and go through the iterative review process asking it to fix any issues for me along the way. I then test my application at the end of that software cycle and am very pleased to see that Amazon Q Developer managed to handle all issues, from project setup, to boilerplate code, to more complex backend and frontend. A true full-stack developer!</p><p><a href="https://d2908q01vomqb2.cloudfront.net/da4b9237bacccdf19c0760cab7aec4a8359010b0/2025/05/01/application-ready-after-all-issues-done.png&quot;&gt;&lt;img class="aligncenter size-full wp-image-95764" src="https://d2908q01vomqb2.cloudfront.net/da4b9237bacccdf19c0760cab7aec4a8359010b0/2025/05/01/application-ready-after-all-issues-done.png&quot; alt="" width="2234" height="1062" /></a></p><p>I did notice some things that I wanted to change along the way. For example, it defaulted to using the Invoke API to send the uploaded images to Amazon Bedrock instead of the Converse API. However, because I didn’t state this in my requirements, it had no way of knowing. This highlights the importance of being as precise as possible in your issue’s titles and descriptions to give Q Developer the necessary context and make the development process as efficient as possible.</p><p>Having said that, it’s still straightforward to review the generated code on the pull requests, add comments, and let the Amazon Q Developer agent keep working on changes until you’re happy with the final result. Alternatively, you can accept the changes in the pull request and create separate issues that you can assign to Q Developer later when you’re ready to develop them.</p><p><strong>Code transformation</strong><br />You can also transform legacy Java codebases to modern versions with Q Developer. Currently, it can update applications from Java 8 or Java 11 to Java 17, with more options coming in future releases.</p><p>The process is very similar to the one I demonstrated earlier in this post, except for a few things.</p><p>First, you need to create an issue within a GitHub repository containing a Java 8 or Java 11 application. The title and description don’t really matter in this case. It might even be a short title such as “Migration,” leaving the description empty. Then, on <strong>Labels,</strong> you assign the <strong>Amazon Q transform agent</strong> label to the issue.</p><p><a href="https://d2908q01vomqb2.cloudfront.net/da4b9237bacccdf19c0760cab7aec4a8359010b0/2025/04/21/q-transform-label.png&quot;&gt;&lt;img class="aligncenter size-full wp-image-95395" src="https://d2908q01vomqb2.cloudfront.net/da4b9237bacccdf19c0760cab7aec4a8359010b0/2025/04/21/q-transform-label.png&quot; alt="" width="329" height="481" /></a></p><p>Much like before, Amazon Q Developer will start working immediately behind the scenes before generating the code on a pull request that you can review. This time, however, it’s the Amazon Q transform agent doing the work which is specialized in code migration and will take all the necessary steps to analyze and migrate the code from Java 8 to Java 17.</p><p><a href="https://d2908q01vomqb2.cloudfront.net/da4b9237bacccdf19c0760cab7aec4a8359010b0/2025/05/01/transform-starts-working.png&quot;&gt;&lt;img class="aligncenter wp-image-95761 size-full" src="https://d2908q01vomqb2.cloudfront.net/da4b9237bacccdf19c0760cab7aec4a8359010b0/2025/05/01/transform-starts-working.png&quot; alt="" width="948" height="355" /></a></p><p>Notice that it also needs a workflow to be created, as per the documentation. If you don’t have it enabled yet, it will display clear instructions to help you get everything set up before trying again.</p><p><a href="https://d2908q01vomqb2.cloudfront.net/da4b9237bacccdf19c0760cab7aec4a8359010b0/2025/05/01/transform-needs-github-actions-enabled.png&quot;&gt;&lt;img class="aligncenter wp-image-95763 size-full" src="https://d2908q01vomqb2.cloudfront.net/da4b9237bacccdf19c0760cab7aec4a8359010b0/2025/05/01/transform-needs-github-actions-enabled.png&quot; alt="" width="856" height="177" /></a></p><p>As expected, the amount of time needed to perform a migration depends on the size and complexity of your application.</p><p><strong>Conclusion</strong><br />Using Amazon Q Developer in GitHub is like having a full-stack developer that you can collaborate with to develop new features, accelerate the code review process, and rely on to enhance the security posture and quality of your code. You can also use it to automate migration from Java 8 and 11 applications to Java 17 making it much easier to get started on that migration project that you might have been postponing for a while. Best of all, you can do all this from the comfort of your own GitHub environment.</p><p><strong>Now available</strong><br />You can now start using <a href="https://github.com/apps/amazon-q-developer&quot;&gt;Amazon Q Developer today for free in GitHub</a>, no AWS account setup needed.</p><p>Amazon Q Developer in GitHub is currently in preview.</p><p>— <a href="https://www.linkedin.com/in/codingmatheus/&quot;&gt;Matheus Guimaraes | codingmatheus</a></p><hr /><p>How is the News Blog doing? Take this <a href="https://amazonmr.au1.qualtrics.com/jfe/form/SV_eyD5tC5xNGCdCmi&quot;&gt;1 minute survey</a>!</p><p><em>(This <a href="https://amazonmr.au1.qualtrics.com/jfe/form/SV_eyD5tC5xNGCdCmi&quot;&gt;survey&lt;/a&gt; is hosted by an external company. AWS handles your information as described in the <a href="https://aws.amazon.com/privacy/?trk=4b29643c-e00f-4ab6-ab9c-b1fb47aa1708&amp;amp;sc_channel=blog&quot;&gt;AWS Privacy Notice</a>. AWS will own the data gathered via this survey and will not share the information collected with survey respondents.)</em></p>

Fish AI Reader

Fish AI Reader

AI辅助创作,多种专业模板,深度分析,高质量内容生成。从观点提取到深度思考,FishAI为您提供全方位的创作支持。新版本引入自定义参数,让您的创作更加个性化和精准。

FishAI

FishAI

鱼阅,AI 时代的下一个智能信息助手,助你摆脱信息焦虑

联系邮箱 441953276@qq.com

相关标签

Amazon Q Developer GitHub 软件开发 代码审查 AI
相关文章