Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OAuth2 Github client #7

Merged
merged 32 commits into from
Jan 23, 2024
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 46 additions & 5 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,11 @@ SOFTWARE.
<org.jacoco.version>0.8.10</org.jacoco.version>
<cactoos-matchers.version>0.25</cactoos-matchers.version>
<maven-verifier-plugin.version>1.1</maven-verifier-plugin.version>
<maven-checkstyle-plugin.version>3.3.0</maven-checkstyle-plugin.version>
<eokson.version>0.3.2</eokson.version>
<jcabi-jdbc.version>0.19.0</jcabi-jdbc.version>
<jcabi-http.version>2.0.0</jcabi-http.version>
<qulice.version>0.22.0</qulice.version>
<spring-addons.version>7.1.8</spring-addons.version>
</properties>
<dependencies>
<dependency>
Expand All @@ -55,6 +58,26 @@ SOFTWARE.
<artifactId>spring-boot-starter-web</artifactId>
<!-- version from parent POM -->
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-oauth2-resource-server</artifactId>
<!-- version from parent POM -->
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
<!-- version from parent POM -->
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
<!-- version from parent POM -->
</dependency>
<dependency>
<groupId>org.liquibase</groupId>
<artifactId>liquibase-core</artifactId>
<!-- version from parent POM -->
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
Expand All @@ -72,11 +95,21 @@ SOFTWARE.
<artifactId>jcabi-http</artifactId>
<version>${jcabi-http.version}</version>
</dependency>
<dependency>
<groupId>com.jcabi</groupId>
<artifactId>jcabi-jdbc</artifactId>
<version>${jcabi-jdbc.version}</version>
</dependency>
<dependency>
<groupId>org.cactoos</groupId>
<artifactId>cactoos</artifactId>
<version>${cactoos.version}</version>
</dependency>
<dependency>
<groupId>io.github.eo-cqrs</groupId>
<artifactId>eokson</artifactId>
<version>${eokson.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
Expand Down Expand Up @@ -199,17 +232,25 @@ SOFTWARE.
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>${maven-checkstyle-plugin.version}</version>
<groupId>com.qulice</groupId>
<artifactId>qulice-maven-plugin</artifactId>
<version>${qulice.version}</version>
<configuration>
<suppressionsLocation>checkstyle-suppressions.xml</suppressionsLocation>
<license>file:${basedir}/LICENSE.txt</license>
</configuration>
<executions>
<execution>
<goals>
<goal>check</goal>
</goals>
<configuration>
<excludes>
<exclude>duplicatefinder:.*</exclude>
<exclude>dependencies:.*</exclude>
<exclude>checkstyle:/src/test/.*</exclude>
dukris marked this conversation as resolved.
Show resolved Hide resolved
<exclude>pmd:/src/test/.*</exclude>
</excludes>
</configuration>
</execution>
</executions>
</plugin>
Expand Down
19 changes: 11 additions & 8 deletions src/main/java/git/tracehub/pmo/PmoApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,21 @@
/**
* Entry point.
*
* @checkstyle HideUtilityClassConstructorCheck (10 lines)
* @since 0.0.0
*/
@SpringBootApplication
@SuppressWarnings("PMD.UseUtilityClass")
public class PmoApplication {

/**
* Application entry point.
*
* @param args Application arguments
*/
public static void main(final String[] args) {
SpringApplication.run(PmoApplication.class, args);
}
/**
* Application entry point.
*
* @param args Application arguments
*/
@SuppressWarnings("ProhibitPublicStaticMethods")
public static void main(final String[] args) {
SpringApplication.run(PmoApplication.class, args);
}

}
32 changes: 32 additions & 0 deletions src/main/java/git/tracehub/pmo/agents/Action.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Copyright (c) 2023-2024 Tracehub
dukris marked this conversation as resolved.
Show resolved Hide resolved
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to read
* the Software only. Permissions is hereby NOT GRANTED to use, copy, modify,
* merge, publish, distribute, sublicense, and/or sell copies of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

package git.tracehub.pmo.agents;

/**
* Action.
*
* @since 0.0.0
*/
public interface Action {

/**
* Execute.
*/
void exec();

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/*
* Copyright (c) 2023-2024 Tracehub
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to read
* the Software only. Permissions is hereby NOT GRANTED to use, copy, modify,
* merge, publish, distribute, sublicense, and/or sell copies of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

package git.tracehub.pmo.agents.github;

import com.jcabi.http.Request;
import com.jcabi.http.request.JdkRequest;
import com.jcabi.http.response.RestResponse;
import git.tracehub.pmo.agents.Action;
import io.github.eocqrs.eokson.Jocument;
import io.github.eocqrs.eokson.MutableJson;
import java.net.HttpURLConnection;
import lombok.RequiredArgsConstructor;
import lombok.SneakyThrows;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;

/**
* Invite collaborator.
*
* @since 0.0.0
*/
@RequiredArgsConstructor
public final class InviteCollaborator implements Action {

/**
* Owner and repo.
*/
private final String location;

/**
* Username.
*/
private final String username;

/**
* Token.
*/
private final String token;

@Override
@SneakyThrows
public void exec() {
new JdkRequest(
"https://api.github.com/repos/%s/collaborators/%s".formatted(
dukris marked this conversation as resolved.
Show resolved Hide resolved
this.location.replaceAll(
"([^@/]+)@([^/]+)/([^:]+):.*", "$2/$3"
),
this.username
)
).method(Request.PUT)
.body()
.set(
new Jocument(
new MutableJson()
.with("permission", "admin")
).toString()
).back()
.header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
.header(
HttpHeaders.AUTHORIZATION,
"Bearer %s".formatted(this.token)
).fetch()
.as(RestResponse.class)
.assertStatus(HttpURLConnection.HTTP_CREATED);
}

}
23 changes: 23 additions & 0 deletions src/main/java/git/tracehub/pmo/agents/github/package-info.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Copyright (c) 2023-2024 Tracehub
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to read
* the Software only. Permissions is hereby NOT GRANTED to use, copy, modify,
* merge, publish, distribute, sublicense, and/or sell copies of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

/**
* Github.
*
* @since 0.0.0
*/
package git.tracehub.pmo.agents.github;
23 changes: 23 additions & 0 deletions src/main/java/git/tracehub/pmo/agents/package-info.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Copyright (c) 2023-2024 Tracehub
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to read
* the Software only. Permissions is hereby NOT GRANTED to use, copy, modify,
* merge, publish, distribute, sublicense, and/or sell copies of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

/**
* Agents.
*
* @since 0.0.0
*/
package git.tracehub.pmo.agents;
Loading