Transcription
Hello, welcome to another video of code snippet. And in this video, we are going to look into GitHub Copilot, which is an AI assistant for developers and which makes our life easy. We are in the world of AI, and if something like GitHub Copilot is available for us, why not use it?
So, in this video, we will look into how GitHub Copilot helps us and how we can integrate that with IntelliJ IDE, as IntelliJ is a famous IDE for Java developers, or in order to build Spring Boot applications. So, let's quickly jump into the agenda of this particular video.
So, we are going to look into GitHub Copilot. So, we'll see what exactly is Copilot. We'll see integration with IntelliJ IDE. Now, it integrates with VS Code seamlessly. But as a Java and Spring Boot developer, it is essential to integrate that with IntelliJ IDE as well. So, we will look into that one.
After that, we will see different modes of Copilot: chat mode, autocomplete mode, and agent mode. After that, we will look into the plans. Right? So, you can use it for free as well. If you want to opt for paid plans, you can go ahead and do that. That is something we will look into.
So, let's go ahead and let's go to the GitHub Copilot website. So, if you search GitHub Copilot on Google and click on the first link, you will land at this page. It's an AI that builds with you. It is your AI-powered assistant, and now it is supercharged with agent mode. Agent mode is something that is just launched by GitHub, right? It's a very powerful thing, and we are going to look into how it works, right?
And if I scroll down over here, then if you are using VS Code, you can directly open it from here, and your Copilot will be ready for use because it works very well with VS Code, and it works very well with IntelliJ as well. So, in this video, we will look into how we can integrate that with IntelliJ. VS Code will park for the other day.
So, what we will do, let's go ahead and let's jump into IntelliJ and let's see how we can integrate this guy inside IntelliJ. Right. So, let me just move to IntelliJ. So, this is basically one of my projects. This is basically a Spring Boot application that I have opened. And what I will do now, what we want to do, we want to first install GitHub Copilot inside this particular IntelliJ, right? How we can do that? There are multiple ways.
So, what you can do, you can just go to settings from here. You can just go ahead and search plugins. Once you land inside plugins, you can just go ahead and search over here saying GitHub Copilot. You'll get something like this. You can just directly go ahead and install it. And it is just giving a brief overview. So, it says autonomous coding with agent mode. It says ask anything in Copilot chat. It says autocomplete coding suggestions. Right? There are many features, basically.
So, what I will do, I'll just go ahead and say install from here, and here I'll just say accept. So, it will just download and install it for me. Now, if you see, it is downloaded and it is asking me to restart my IDE. So, I will just click on this, and it will restart my IDE for me. There we go. It is coming back up.
So, our IDE is restarted. Now, if you see here at the right-hand side, I'm getting something called as GitHub Copilot chat. As soon as I click on this, it says welcome to Copilot. GitHub Copilot is your AI pair programmer, and we offer Copilot for free. Right? So, it is free as well.
What we need to do, we need to go ahead and sign in for GitHub Copilot. So, let me just go ahead and click on it. What we need to do? We need to just go to this URL and paste this particular code. So, what I'll do, I'll just say copy and open. So, it opened in a browser. So, let me just pull it over here. Let me expand it. And here I will just add my email ID. So, here I have added my username and password. So, you just need to log in by using your GitHub account. And I'll just say sign in. And I'll just say sign in as code snippet Java.
And here, what we need to do, we just need to paste the code that we have copied, right? The code that we have copied from here. And we can just say continue. And here, what you can do, you can just say authorize GitHub Copilot IDE plugin, and we are all set. So, now we are successfully logged in, and it says GitHub Copilot successfully logged in. All right. So, now your GitHub Copilot is successfully installed inside your IntelliJ IDE. Pretty simple stuff, right?
And this is basically how it looks here. If you see, you have three different options. First, you have Ask. After that, you have Agent, and third, you have Edit mode. Right? Here you can give any prompt to your Copilot, and based on this, it will just start working here. If you see, you have different models, right? So, here you have Cloud Sonnet 3.5, you have GPT models, you have Gemini models, right? You can use whatever you want.
Now, if I go ahead and open any file over here, let's say this WeatherController, then you will see that the file is attached over here. That means we are asking questions related to this file now. So, let's just ask, what is the purpose of this PreAuthorize annotation over here? So, what I will do, I'll say, "What is the purpose of this PreAuthorize annotation over here?" and I will just say send. And you'll see it is just reading everything, and now it is telling me that the PreAuthorize annotation secures the getWeather endpoint so that only users with the admin or user roles can access it. So, it is telling me everything about this PreAuthorize annotation. Right?
Now, that was the simple Q&A that you can do over here. But what else you can do? For example, let's say I go to this other controller, right? WeatherLogController. Now, here we have get mapping and post mapping. Now, let's write a prompt to add a put mapping as well, right? So that we can update the log, right? So, I will just write, "Write an API to update the log using put mapping." And I will just say send. Let's see what happens now.
Now, if you see, to add an API update weather log, create a put mapping. So, it created a put mapping for us, right? You can just go ahead, copy this code, paste it over here, and at the end, it also says, "Make sure your weather service has updateLog method implemented." So, we can also just say, "Also give the updateLog method in WeatherLogService." And let's send it. And there we go. We also have this particular method as well. And it again assumes that our weather service log repository have the respective methods like the save method, right? Which we will ideally have, right? So, what we need to do, we just need to copy this code and paste it, and our job is done.
So, now here, what we are doing, we are just having a chat with it, and it is telling us what to do. But now, GitHub Copilot has something called as an agent mode as well, right? So, you can just go ahead and select agent from here. Now, once you select and give this prompt, let's see what happens. So, here I added a prompt as, "Let's add an update log API." Here I'm saying, "Let's add update log API in controller in this controller and add respective methods in service and repository layer if needed." And let's try to send it now. Let's see what happens.
So, if you see over here, it is reading our WeatherLogService. It is reading our LogRepository. And now, if you see over here, it has added this for us, right? So, if you see over here, this particular update log API is added, and here it is asking us for accept. So, if you think this code is fine, just accept it from here, and accept this line as well. After that, it updated this WeatherLogService for us as well. And here we can just accept this code as well if you want, otherwise we can reject it.
Now, if you see this code in the service layer, it is just taking the log from the repository and it is just setting the timestamp and performed by. Now, if you see the weather log, it has more fields, right? So, what it is saying, it is saying, "Update other fields as needed." What we can do, we can just ask it to update all the fields from WeatherLog entity, and we can just send it. Let's see what it is doing this time. So, what it is doing, first it is reading your WeatherLog now, and now it is editing our WeatherLogService. Now, what it did, it updated your set action and set city as well. Now, we can just accept it. We can say accept all, and our API is implemented for us, right? Did we write anything? We did not write anything, rather than our friend just wrote the entire code for us, right? Simple stuff, isn't it? So, that is the power of your agent mode, right? It can write your code automatically.
Now, this is adding code in an existing file. How about creating new files? Here, let's ask it to create a utility method for your unit conversions. For example, kilometer per hour to m/hour. Right? What I will do? I'll just write a prompt over here. What I'm saying? I'm just saying, "Create a util class for unit conversion of air like kilometer per hour to m/hour." And let's try to send it.
Now, see what it is doing. It is trying to find if there is anything matching with util. Now, it found what it found? It found reading directory util. So, it is reading the directory util. So, it found that there is a util directory inside our project. Now, if you see over here, what it did, it created a method to convert kilometer per hour to m/hour. Let's accept it. Now, if you see, it created a utility method, AirUnitConversionUtil, right? And it has placed that file inside our util folder over here, right? And it has successfully created this method as well to convert kilometer per hour to m/hour, right? So, whatever prompt we have gave, it has successfully used that and created this method for us. How cool is that?
Now, I'm giving very casual inputs over here. Your prompt is clear, it will create a more clear output for you, right? So, that is basically the beauty of your agent mode. It will just write the code for you. You just have to verify it. Never blindly trust the code written by this guy. Always verify the code, if it is fulfilling your functionality.
Now, that's about adding the code. How about your unit test? What I will do? I'll just go inside this service over here. I'll just say, "Write JUnit test for this particular service." And I'll just say enter. Again, a very short prompt I'm giving over here. Nothing much.
Now, it is trying to search if there is already any test. It is reading everything that it needs from our repository, and it started adding your test class. So, if you see over here, it added this particular test class for us. So, in the service layer, it has added WeatherServiceTest for us. Let's accept it and let's see what it did.
If you see over here, it has added many tests for us, right? Many tests, basically. And we did not really write a single line over here. And if you see over here, if I run this, let's try to run this over here. Let's see what happens. If you see, all the tests already passed, right? So, it did not even make a single mistake over here. It mocked everything. It injected the mocks over here. It is making use of @BeforeEach. It is writing the test for us. It is making use of Mockito.when as well. Assert.assertEquals, it is making use of. It is making use of verify methods, right? Pretty straightforward stuff it has written for us, right? Did we write anything? No, we did not. It just wrote everything on its own. Well, that's about your agent mode. You can just write anything.
And how about refactoring? Refactoring is again a major part of it. You can just have any legacy code. What you can do? You can just ask this guy to write clean code in functional style, and it will just modify that code for you, right? You don't really have to worry about that. You just need to verify that code, right? That is basically the agent mode for you. So, this agent will write the code for you seamlessly. You don't really have to worry about it. And it is basically a powerful feature that is recently introduced by your GitHub Copilot.
Now, let's go back to our agenda. We have seen chat. We have seen agent. How about autocomplete, right? Autocomplete. Let's see how it works. Now, let's go back to, let's say, UserController. And here, if you see, what do we have over here? We have this post mapping. We have this post mapping as well. So, we are trying to create users over here. And here, what I will do, I'll just try to write a comment. And do you see this over here? Your first GitHub Copilot suggestion. And this is basically the suggestion. And it will start displaying the autocomplete suggestions as you write your code. I'll say, "Got it." And if I place tab over here, it will just autocomplete stuff for us, right?
Now, what we will do, let's try to add a get mapping. If you see over here, it is autocompleting it for me. So, I just typed get mapping, and I have typed get. So, if I press tab, it will just autocomplete, and I will just again press tab. So, if you see, it is autocompleting stuff for me, right? Autocompleting stuff for me, writing code for me. So, it is basically what we expect, right? So, in UserService, we should have something called as getUserByName. This method is basically not present over there, that's why it is giving an error. And here, what we can do, we can just add that method. So, we can just say, "There we go." Did I type anything? I did not type. So, what I'll just say, I'll just say tab, and that particular method is autocompleted for me, right? That is how your autocomplete works. If you don't want to use this agent mode and writing your own code, this will again come in handy, and this will autocomplete stuff for you. This is again a cool stuff.
So, this method also, it autocompleted. So, what we need to do now, just UserDetailRepository.findByUsername, and this username is passed over here. So, it just reads the existing stuff, and it will just give you the suggestion. You can just go ahead and autocomplete that, right? Cool stuff, isn't it? That's how it works. That's how your autocomplete works, right? Pretty cool stuff.
So, you can just ask questions on chat. You can use agent mode, write the code directly. Otherwise, you can make use of autocomplete as well, which will complete the stuff for you, isn't it? If you start using it, it will save a lot of your time, right? If you are a developer, if you're a seasoned developer, have 5-10 years of experience, you know your stuff, right? You know what to write, what not to write, then you can make use of this, and you can just verify the code what has been written by this guy. And once you verify it, it is just fine for you. It will save you 30 to 40% of your time, which you can actually go ahead and utilize into other things like focusing on your business logic or improving your knowledge on other things, right? So, that is how AI comes into picture in the life of a developer.
Now, here, if you see, you will also find something called as edit mode over here. So, we have Ask, Agent, and Edit. Right? Now, Edit is something which looks into the code snippet that you are selecting over here and tries to modify it based on your prompt. But Agent mode looks into your entire codebase over here. It scans your entire codebase, and then it will try to write the perfect code based on your current logic, right? So, that is basically the difference in your Edit and Agent mode. So, your Agent mode is pretty powerful stuff.
Now, what we will do, we will just go back over here, and we have seen everything. We have seen what is Copilot. We have integrated it in IntelliJ. We have seen the different modes of it. Now, let's go ahead and look into the plans. Let's go back over here. And if you see over here, see plans and pricing, right? All right. So, if you see over here, so these are individual pricings, basically. So, you can make use of it for free, right? Just like we did. Now, you can just get started with it, and you can you can just install it, be it in VS Code or IntelliJ, and get started.
So, what you get for free? 50 agent mode or chat requests per month. So, we have been using these chat modes, right? So, you'll get only 50. So, use them wisely if you're using it for free. 2,000 completions per month. So, we have just made use of autocompletes, right? So, 2,000 completions you can make use of, so that you can access these models, right? So, in the free version, you will get only these things.
So, if you start paying, let's say Pro or Pro Plus, then you will get a lot of things. So, unlimited agent and chat with GPT-5, which is GPT-5's latest agent, unlimited code completions you will get, you'll get access to more models, right? There are something called as premium requests, other than Copilot free, that you will get. There are a lot of advanced stuff you will get over here. And if you go ahead with Pro Plus, then you'll get more models, basically, and more premium requests, right? So, if you want to go ahead and try it, try it by using free. If you think it is helping you, just go ahead with this plan. It is a value for money plan. $10 is not that much, right? Or you can go with $100 per year. It's again a simple plan over here.
So, those are basically individual plans. For businesses, you have different plans as well. You can just go ahead and check it out if you have a business and want to bring it inside your organization. That is basically the GitHub Copilot for you. I have been using it for a while now, and I thought that it would be helpful for you as well.
Now, if you are an experienced developer, you know what you're writing. You have been working in Java, Spring Boot, or any other language for a while now, you can just go ahead and start working with it. If you are a fresher, then I would suggest write your own code, otherwise you will not learn. If you start relying on GitHub Copilot, then you may not be able to think in the right direction while writing your code, right? So, if you're a fresher, first learn to write your code, learn to build your logic before using this particular AI models and stuff, right?
That's it for this video. If you like the video, hit the like button. Don't forget to subscribe to Code Snippet. Share this video with your friends so that they are also aware about GitHub Copilot. That's it for this video. See you in the next video.