Skip to content

Commit

Permalink
Release 1.0.1 (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
APiankouski authored Dec 12, 2024
1 parent 580bca0 commit 2dc23be
Show file tree
Hide file tree
Showing 68 changed files with 527 additions and 86 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ jobs:
- name: Checkout repository
uses: actions/checkout@v2

- name: Set up JDK 11
- name: Set up JDK 21
uses: actions/setup-java@v2
with:
distribution: 'adopt'
java-version: '11'
java-version: '21'

- name: Grant execute permission for gradlew
run: chmod +x gradlew
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/manually-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ jobs:
- name: Checkout repository
uses: actions/checkout@v2

- name: Set up JDK 11
- name: Set up JDK 21
uses: actions/setup-java@v2
with:
distribution: 'adopt'
java-version: '11'
java-version: '21'

- name: Grant execute permission for gradlew
run: chmod +x gradlew
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ jobs:
- name: Checkout repository
uses: actions/checkout@v2

- name: Set up JDK 11
- name: Set up JDK 21
uses: actions/setup-java@v2
with:
distribution: 'adopt'
java-version: '11'
java-version: '21'

- name: Grant execute permission for gradlew
run: chmod +x gradlew
Expand Down
56 changes: 26 additions & 30 deletions plugin-slack/build.gradle → build.gradle
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@
import com.github.spotbugs.SpotBugsTask

plugins {
id "io.spring.dependency-management" version "1.0.9.RELEASE"
id "io.spring.dependency-management" version "1.1.4"
id 'java'
id 'jacoco'
id "com.github.spotbugs" version "3.0.0"
id "com.github.node-gradle.node" version "2.2.1"
}


node {
version = '20.11.0'
npmVersion = '10.2.4'
download = true
workDir = file("${project.buildDir}/plugin-slack/ui")
nodeModulesDir = file("${project.rootDir}/plugin-slack/ui")
workDir = file("${project.buildDir}/ui")
nodeModulesDir = file("${project.rootDir}/ui")
}

npm_run_build {
Expand Down Expand Up @@ -42,33 +38,32 @@ dependencyManagement {
}
}

ext['junit-jupiter.version'] = "${junitVersion}"

dependencies {
if (releaseMode) {
implementation 'com.epam.reportportal:commons-dao'
implementation 'com.epam.reportportal:plugin-api'
annotationProcessor 'com.epam.reportportal:plugin-api'
} else {
implementation 'com.github.reportportal:commons-dao:acf1ec7'
implementation 'com.github.reportportal:plugin-api:188792e'
annotationProcessor 'com.github.reportportal:plugin-api:188792e'
implementation 'com.github.reportportal:commons-dao:a98c172'
implementation 'com.github.reportportal:plugin-api:develop-SNAPSHOT'
annotationProcessor 'com.github.reportportal:plugin-api:develop-SNAPSHOT'
}

compile("com.slack.api:slack-api-client:1.27.1") {
exclude group: "org.slf4j"
}
compile 'com.squareup.okhttp3:okhttp:4.12.0'
implementation 'org.hibernate:hibernate-core:5.6.15.Final'
}
compileOnly "org.projectlombok:lombok:${lombokVersion}"
annotationProcessor "org.projectlombok:lombok:${lombokVersion}"
testCompileOnly "org.projectlombok:lombok:${lombokVersion}"
testAnnotationProcessor "org.projectlombok:lombok:${lombokVersion}"

spotbugs {
sourceSets = [sourceSets.main]
reportLevel = "high"
}
tasks.withType(SpotBugsTask) {
reports {
xml.enabled false
html.enabled true
}
implementation 'com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.18.2'
implementation 'org.hibernate:hibernate-core:5.6.15.Final'
testImplementation 'org.mockito:mockito-core:5.14.2'
testImplementation 'org.mockito:mockito-junit-jupiter:5.14.2'
testImplementation "org.junit.jupiter:junit-jupiter"
testImplementation "org.junit.jupiter:junit-jupiter-api"
testImplementation "org.junit.jupiter:junit-jupiter-engine"
testImplementation 'net.bytebuddy:byte-buddy:1.14.9'
}

test {
Expand All @@ -79,7 +74,7 @@ test {
exceptionFormat = 'short'
}
reports {
junitXml.enabled = true
junitXml.required = true
}
}

Expand Down Expand Up @@ -109,7 +104,7 @@ jar {
}
manifest {
attributes(
"Class-Path": configurations.compile.collect { it.getName() }.join(' '),
"Class-Path": configurations.compileClasspath.collect { it.getName() }.join(' '),
"Plugin-Id": "${pluginId}",
"Plugin-Version": "${project.version}",
"Plugin-Provider": "Report Portal",
Expand All @@ -126,9 +121,10 @@ shadowJar {
from("ui/build") {
into("/resources")
}
configurations = [project.configurations.compile]
configurations = [project.configurations.compileClasspath]
zip64 true
dependencies {
include(dependency('commons-io:commons-io:2.15.1'))
}
}

Expand All @@ -138,9 +134,9 @@ task plugin(type: Jar) {
with jar
}
into('lib') {
from configurations.compile
from configurations.compileClasspath
}
extension('zip')
archiveExtension.set('zip')
}

task assemblePlugin(type: Copy) {
Expand Down
2 changes: 2 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
version=1.0.0
description=EPAM Report Portal. Slack plugin.
pluginId = slack
lombokVersion=1.18.36
junitVersion=5.11.0
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
3 changes: 2 additions & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.2-bin.zip
networkTimeout=10000
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
3 changes: 0 additions & 3 deletions plugin-slack/gradle.properties

This file was deleted.

24 changes: 0 additions & 24 deletions plugin-slack/project-properties.gradle

This file was deleted.

29 changes: 24 additions & 5 deletions project-properties.gradle
Original file line number Diff line number Diff line change
@@ -1,12 +1,31 @@
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
java {
sourceCompatibility = JavaVersion.VERSION_21
targetCompatibility = JavaVersion.VERSION_21
}

def commonScriptsUrl = 'https://raw.githubusercontent.com/reportportal/gradle-scripts/'

project.ext {
publishRepo = "https://maven.pkg.github.com/reportportal/plugin-slack"
releaseMode = project.hasProperty("releaseMode")
pluginsDir = "$buildDir/jars"

pluginsDir = "$buildDir/plugins"
scriptsUrl = commonScriptsUrl + (releaseMode ? getProperty('scripts.version') : 'develop')
excludeTests = [
'**/entity/**',
'**/model/**',
]
limits = [
'instruction': 30,
'branch' : 17,
'line' : 30,
'complexity' : 26,
'method' : 29,
'class' : 30
]
}

wrapper {
gradleVersion = '5.4.1'
gradleVersion = '8.10.2'
}


3 changes: 1 addition & 2 deletions settings.gradle
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
rootProject.name = 'plugin-slack-epam'
include 'plugin-slack'
rootProject.name = 'plugin-slack'

Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/*
* Copyright 2024 EPAM Systems
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.epam.reportportal.extension.slack;

import com.epam.reportportal.extension.CommonPluginCommand;
Expand Down Expand Up @@ -47,6 +63,7 @@
import org.springframework.context.support.AbstractApplicationContext;
import org.springframework.core.io.FileSystemResource;
import org.springframework.jdbc.datasource.init.ResourceDatabasePopulator;
import org.springframework.web.client.RestTemplate;

/**
* @author Andrei Piankouski
Expand Down Expand Up @@ -100,6 +117,9 @@ public class SlackPluginExtension implements ReportPortalExtensionPoint, Disposa
@Autowired
private ProjectRepository projectRepository;

// @Autowired // uncomment for future release
private final RestTemplate restTemplate = new RestTemplate();

@Autowired
private ApplicationContext applicationContext;

Expand Down Expand Up @@ -131,7 +151,7 @@ public SlackPluginExtension(Map<String, Object> initParams) {

launchFinishEventListenerSupplier = new MemoizingSupplier<>(
() -> new SlackLaunchFinishEventListener(projectRepository,
launchRepository, senderCaseMatcher.get(), attachmentResolverSupplier.get()));
launchRepository, senderCaseMatcher.get(), attachmentResolverSupplier.get(), restTemplate));
}

@PostConstruct
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,23 +27,23 @@
import com.epam.ta.reportportal.entity.project.Project;
import com.epam.ta.reportportal.entity.project.ProjectUtils;
import com.epam.ta.reportportal.entity.project.email.SenderCase;
import com.slack.api.Slack;
import java.util.Map;
import java.util.Optional;
import org.apache.commons.lang3.BooleanUtils;
import org.springframework.context.ApplicationListener;
import org.springframework.web.client.RestTemplate;

/**
* @author <a href="mailto:[email protected]">Andrei Piankouski</a>
*/
public class SlackLaunchFinishEventListener implements
ApplicationListener<LaunchFinishedPluginEvent> {

private final static String SLACK_NOTIFICATION_ATTRIBUTE = "notifications.slack.enabled";
public final static String SLACK_NOTIFICATION_ATTRIBUTE = "notifications.slack.enabled";

private final static String WEBHOOK_DETAILS = "webhookURL";
public final static String WEBHOOK_DETAILS = "webhookURL";

private final static String PLUGIN_NOTIFICATION_TYPE = "slack";
public final static String PLUGIN_NOTIFICATION_TYPE = "slack";

private final ProjectRepository projectRepository;

Expand All @@ -52,15 +52,18 @@ public class SlackLaunchFinishEventListener implements
private final SenderCaseMatcher senderCaseMatcher;

private final AttachmentResolver attachmentResolver;
private final RestTemplate restTemplate;


public SlackLaunchFinishEventListener(
ProjectRepository projectRepository, LaunchRepository launchRepository,
SenderCaseMatcher senderCaseMatcher, AttachmentResolver attachmentResolver) {
SenderCaseMatcher senderCaseMatcher, AttachmentResolver attachmentResolver,
RestTemplate restTemplate) {
this.projectRepository = projectRepository;
this.launchRepository = launchRepository;
this.senderCaseMatcher = senderCaseMatcher;
this.attachmentResolver = attachmentResolver;
this.restTemplate = restTemplate;
}

@Override
Expand Down Expand Up @@ -103,7 +106,7 @@ private void sendNotification(SenderCase senderCase, Launch launch, String launc
Optional<String> webhookUrl = getWebhookUrl(senderCase);
Optional<String> attachment = resolveAttachment(launch, launchLink);
if (webhookUrl.isPresent() && attachment.isPresent()) {
sendSlackNotification(webhookUrl.get(), attachment.get());
restTemplate.postForLocation(webhookUrl.get(), attachment.get());
}
}

Expand All @@ -116,13 +119,6 @@ private Optional<String> resolveAttachment(Launch launch, String launchLink) {
return attachmentResolver.resolve(launch, launchLink);
}

private void sendSlackNotification(String webhookUrl, String attachment) {
try (Slack slack = Slack.getInstance()) {
slack.send(webhookUrl, attachment);
} catch (Exception e) {
throw new ReportPortalException("Failed to send Slack notification", e);
}
}

private boolean isNotificationsEnabled(Project project) {
Map<String, String> projectConfig = ProjectUtils.getConfigParameters(
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -204,4 +204,4 @@
]
}
]
}
}
Loading

0 comments on commit 2dc23be

Please sign in to comment.