Skip to content

Repository containing lab 2 in the course DD2480 Software Engineering Fundamentals

Notifications You must be signed in to change notification settings

M1l0d/CI-DD2480-Group13

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

30 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

runme
id version
01HPKGYX39DVNYEW8WRZ6K93VY
v3

CI-DD2480-Group13

Repository containing lab 2 in the course DD2480 Software Engineering Fundamentals

Assignment #2: Continous Integration

This is an assignment to master the core of continuous integration. A small continous integration (CI) server is implemented. This CI server will only contain the core features of continuous integration.

The Files

ContinousIntegrationServer.java

A simple web-hook based continuous integration (CI) server containing a set of methods to handle GitHub push events. Upon receiving a push event from GitHub webhook, this server clones the repository, compiles it using Maven commands ('clean install'), and then deletes the cloned repository after the CI job is completed to avoid clutter. The server is started on a specified port (8013) using Jetty server.

public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response)

Listens for incoming requests and extracts the event type from the request header. The method only proceeds if the event type is 'push'. It then passes on the handling to the handlePushEvent method.

public void handlePushEvent(JSONObject jsonObject)

Processes the push event JSON object by cloning the repository and compiling it using the methods cloneRepository and compileRepository, respectively. The cloned repository is then deleted by a method call to deleteDirectory.

public void cloneRepository(JSONObject jsonObject, File clonedRepoFile, BuildAttempt buildAttempt)

The method extracts the clone URL and branch name from the JSON object and proceeds by using JGit to clone the repository into the specified directory (src/main/resources).

public void compileRepository(String clonedRepoPath, File clonedRepoFile,CommitStatus status, BuildAttempt buildAttempt)

Sets up Maven invocation requests to compile the repository using 'clean install'. The Maven Invoker API is used to execute the requests.

public void deleteRepository(File directory)

The method is used to recursively delete the cloned repository directory after the CI job is done. This is done to avoid clutter and accumulation of unnecessary files.

private boolean isRepositoryCloned(String clonedRepoFile)

This method is used to check if a repository is cloned by looking for the directory and check that it is actually a directory.

ConfigData.java

The code in this file is used to access configuration data stored in a properties file called config.properties. It contains the two methods getAccessToken and getNgrokLink. Since it contains private information, it is not pushed to the repository.

public static String getAccessToken()

This method retrieves the access token for GitHub from the properties file. It loads the properties file using a FileInputStream and extracts the value associated with the key 'access.token'. It handles errors regarding the file reading process.

CommitStatus.java

This code is used to manage commit status on GitHub repositories using the GitHub API.

public CommitStatus(String sha, String targetUrl)
public CommitStatus(String sha, String targetUrl, CloseableHttpClient httpClient)

This is a constructer method that initializes the 'CommitStatus' object with the commit SHA and the target URL of the CI server. Another version of this constructor exists which alos allows passing a custom HTTP client.

public void sendCommitStatus(String state, String description)

This method sends a commit status to GitHub. It constructs a JSON payload containing the information about the commit status. The method sends an HTTP POST request to the GitHub API with the JSON payload to update the commit status. The HTTP response is also handled.

public void setCommitStatusToPending()
public void setCommitStatusToSuccess()
public void setCommitStatusToFailure()
public void setCommitStatusToError()

These four methods are used to set the commit status to either "pending", "success", "failure" or "error" with a corresponding description.

CommitStatusTest.java

This is a test file providing unit tests for the CommitStatus class to ensure that its functionality works as intended.

@Mock CloseableHttpClient httpClient
@Mock CloseableHttpResponse response
@Mock StatusLine statusLine

These are used to mock the HTTP client, HTTP response and the status line of the HTTP response.

void setUp()

Initializes the mock objects using 'MockitoAnnotations.initMocks(this)'.

void testSetCommitStatusWhenRequestIsSuccessful()

This method tests the behaviour when the HTTP request is successful with status code 201. The method mocks the behaviour of the response object to return as a status code of 201. The output stream is captured to check if the expected status code is printed.

void testSetCommitStatusWhenRequestIsNotSuccessful()

This method tests the behaviour when the HTTP request is not successful with status code 400. Similarly to the previous method, this method mocks the behaviour of the response object to return a status code of 400. The output stream is once more captured to verify that the expected status code is printed.

All tests in CommitStatusTest.java use JUnit assertions to verify that the expected status code is printed in the output stream.

ContinousIntegrationTest.java

This is a test file providing unit tests for the ContinousIntegrationServer class to ensure that its functionality works as intended.

public void setUp()

Initializes the ContinousIntegrationServer instance before each test method execution.

public void testThatItClonesRepositorySuccessfully()

This method tests the cloneRepository method to check that it clones the repository successfully. It creates a JSONObject to simulate the payload received from the GitHub webhook. The cloneRepository method is called with the JSONObject and a file representing the cloned repository directory. The method asserts that the cloned repository directory exists.

public void testSetCommitStatusWhenRequestIsSuccessful()

The method tests the deleteDirectory method to ensure that it deletes a repository successfully. Similarly to the testing method before, a JSONObject is set up together with the cloned repository file. A repository is cloned and 5 seconds is waited (assuming it takes less than 5 seconds to clone). The repository is then deleted and the method asserts that the repository does not exist.

All tests in CommitStatusTest.java use JUnit assertions (assertTrue/assertFalse) to verify that the expected behaviour of the methods.

BuildAttempt.java

BuildAttempt is a class that holds functionality to get, set and save details on build attempts

public void setCommitId(String commitId)

Sets objects commitId to current commitId.

public void setBuildDate(String buildDate)

Sets objects buildDate to current buildDate.

public void setBuildLog(String buildLog)

Sets objects buildLog to current buildLog.

public void setCommitMadeBy(String commitMadeBy)

Sets objects commitMadeBy to current commitMadeBy.

public void setBuildSuccess(String buildSuccess)

Sets objects buildSuccess to current buildSuccess.

public String getBuildDate()

Returns buildDate.

public String getBuildLog()

Returns buildLog.

public String getBuildSuccess()

Returns buildSuccess.

public String getCommitMadeBy()

Returns commitMadeBy.

public String getCommitId()

Returns commitId

public void saveToJsonFile()

Saves the current BuildAttempt object into a JSON file

CustomOutputHandler.java

Class is used to handle Invocation Output created when building the repository

public void consumeLine(String line)

Appends each line from output to StringBuilder

public String getOutput()

Returns the output from the current OutputHandler

Build history

Recent build history can be acessed through this url

Way of working

We are currently in the state of “Working Well” as we feel that a little more time is needed to assure that we are continually tuning and adapting our way-of-working. Since the last assignment, stakeholders have agreed to our way-of-working and we have made sure to inspect the practices and tools we work with regularly. We have been able to adapt and tune this way-of-working in accordance to the current assignment, so those goals are expected to be reached with a little more time. By working with this some more, we will also be able to reach the goals of being able to apply all of these practices without thinking about them, and everything will be more natural for us.

Team

We feel that we are currently in the state of “Performing”. We as a team are able to consistently meet our commitments and we can adapt to the changing context, which in this case are the different assignments. We are able to tackle problems together without outside help and we are well on our way to eliminate any wasted work and inefficiencies. Since there are still assignments left, we have not yet reached the stage of “Adjourned”. What is left for us to do is to become even more efficient as a team by eliminating wasted work and to just keep working towards completing all assignments.

Statement of contributions

We have all as a team put in a lot of work on our assigned tasks. This time around, there has been a lot more teamwork where we have helped each other out by discussing and pair-programming. In this statement of contributions, some of that help is reflected where it was the most prevalent, but more help has been spread out across the tasks and the team.

Alexander Widman - AlexWidman :

  • Co-author for ContinuousIntegrationServerTest.java
  • Co-author for Documentation in README.md
  • Helped with ContinuousIntegrationServer.java

Alva Sundström - alvasundstrom :

  • Co-author for ContinuousIntegrationServer.java
  • Author of Buildattempt.java
  • Author of CustomOutputHandler.java
  • Co-author for ContinuousIntegrationServerTest.java

Annie Kihlert - kihlert :

  • Co-author for ContinuousIntegrationServerTest.java
  • Co-author for Documentation in README.md
  • Helped with ContinuousIntegrationServer.java

Milad Sarbandi Farhani - M1l0d :

  • Co-author for ContinuousIntegrationServer.java
  • Helped with ContinuousIntegrationServerTest.java
  • Co-author for Documentation in README.md
  • Configuration of Maven.

Tomas Weldetinsae - tywe00 :

  • Author of CommitStatus.java
  • Author of ConfigData.java
  • Author of CommitStatusTest.java
  • Co-author for ContinuousIntegrationServerTest.java
  • Helped with ContinuousIntegrationServer.java

About

Repository containing lab 2 in the course DD2480 Software Engineering Fundamentals

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages