Skip to content

Commit

Permalink
Merge pull request #2 from reportportal/develop
Browse files Browse the repository at this point in the history
Release
  • Loading branch information
HardNorth authored Mar 20, 2023
2 parents 08b8ed9 + d243b1d commit e6dd833
Show file tree
Hide file tree
Showing 6 changed files with 309 additions and 39 deletions.
35 changes: 18 additions & 17 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# 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
# https://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,
Expand All @@ -16,32 +16,33 @@ name: CI Build
on:
push:
branches:
- '*'
- '!main'
- '*'
- '!main'
paths-ignore:
- README.md
- README_TEMPLATE.md
- CHANGELOG.md
- README.md
- README_TEMPLATE.md
- CHANGELOG.md

pull_request:
branches:
- main
- main

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Checkout repository
uses: actions/checkout@v3

- name: Set up JDK 1.8
uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: '8'
- name: Set up JDK 1.8
uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: '8'

- name: Build with Gradle
run: ./gradlew build
- name: Build with Gradle
run: ./gradlew build

- name: Codecov upload
run: bash <(curl -s https://codecov.io/bash)
- name: Codecov upload
run: bash <(curl -s https://codecov.io/bash)
32 changes: 14 additions & 18 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# 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
# https://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,
Expand All @@ -18,17 +18,17 @@ on:
branches:
- main
paths-ignore:
- '.github/**'
- README.md
- README_TEMPLATE.md
- gradle.properties
- CHANGELOG.md

env:
VERSION_FILE: gradle.properties
VERSION_EXTRACT_PATTERN: '(?<=version=).+'
REPOSITORY_URL: 'https://maven.pkg.github.com/'
CHANGE_LOG_FILE: CHANGELOG.md
CHANGE_LOG_TMP_FILE: CHANGELOG_updated.md
REPOSITORY_URL: 'https://maven.pkg.github.com/'
README_FILE: README.md
README_TEMPLATE_FILE: README_TEMPLATE.md
README_VERSION_PLACEHOLDER: $LATEST_VERSION
Expand All @@ -41,7 +41,7 @@ jobs:
uses: actions/checkout@v3

- name: Generate versions
uses: HardNorth/github-version-generate@v1.2.0
uses: HardNorth/github-version-generate@v1
with:
version-source: file
version-file: ${{ env.VERSION_FILE }}
Expand All @@ -54,7 +54,7 @@ jobs:
java-version: '8'

- name: Setup git credentials
uses: oleksiyrudenko/gha-git-credentials@v2
uses: oleksiyrudenko/gha-git-credentials@v2.1.1
with:
name: 'reportportal.io'
email: '[email protected]'
Expand All @@ -71,8 +71,8 @@ jobs:
- name: Update README.md
id: readmeUpdate
run: |
sed 's/${{env.README_VERSION_PLACEHOLDER}}/${{env.RELEASE_VERSION}}/g' ${{env.README_TEMPLATE_FILE}} > ${{env.README_FILE}}
git add ${{env.README_FILE}}
sed 's/${{ env.README_VERSION_PLACEHOLDER }}/${{ env.RELEASE_VERSION }}/g' ${{ env.README_TEMPLATE_FILE }} > ${{ env.README_FILE }}
git add ${{ env.README_FILE }}
git commit -m "Readme update"
- name: Update CHANGELOG.md
Expand All @@ -91,25 +91,21 @@ jobs:
- name: Read changelog Entry
id: readChangelogEntry
uses: mindsers/changelog-reader-action@v1.3.1
uses: mindsers/changelog-reader-action@v2
with:
version: ${{ env.RELEASE_VERSION }}
path: ./${{ env.CHANGE_LOG_FILE }}

- name: Create Release
id: createRelease
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
uses: ncipollo/release-action@v1
with:
tag_name: ${{ env.RELEASE_VERSION }}
release_name: Release ${{ env.RELEASE_VERSION }}
body: ${{ steps.readChangelogEntry.outputs.log_entry }}
draft: false
prerelease: false
tag: ${{ env.RELEASE_VERSION }}
name: Release ${{ env.RELEASE_VERSION }}
body: ${{ steps.readChangelogEntry.outputs.changes }}

- name: Checkout develop branch
uses: actions/checkout@v2
uses: actions/checkout@v3
with:
ref: 'develop'
fetch-depth: 0
Expand All @@ -120,4 +116,4 @@ jobs:
git merge -m 'Merge main branch into develop after a release' origin/main
git status | (! grep -Fq 'both modified:') || git status | grep -F 'both modified:' \
| { echo -e 'Unable to merge main into develop, merge conflicts:'; (! grep -Eo '[^ ]+$') }
git push
git push origin develop
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# Changelog

## [Unreleased]
### Changed
- Client version updated on [5.1.16](https://github.com/reportportal/client-java/releases/tag/5.1.16), by @HardNorth
- `utils-java-formatting` library version updated on version [5.1.5](https://github.com/reportportal/utils-java-formatting/releases/tag/5.1.5), by @HardNorth

## [5.0.0]
### Added
Expand Down
137 changes: 136 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,139 @@
[![stackoverflow](https://img.shields.io/badge/reportportal-stackoverflow-orange.svg?style=flat)](http://stackoverflow.com/questions/tagged/reportportal)
[![Build with Love](https://img.shields.io/badge/build%20with-❤%EF%B8%8F%E2%80%8D-lightgrey.svg)](http://reportportal.io?style=flat)

The latest version: 5.0.0.
The latest version: 5.0.0. Please use `Maven Central` link above to get the logger.

## Overview

Apache HttpComponents Request/Response logging interceptor for Report Portal

The logger intercept and logs all Requests and Responses issued by Apache HttpComponents into Report Portal in Markdown
format, including multipart requests. It recognizes payload types and attach them in corresponding manner: image types
will be logged as images with thumbnails, binary types will be logged as entry attachments, text types will be formatted
and logged in Markdown code blocks.

## Configuration

### Build system configuration

You need to add the logger as one of your dependencies in Maven or Gradle.

#### Maven

`pom.xml`

```xml

<project>
<!-- project declaration omitted -->

<dependencies>
<dependency>
<groupId>com.epam.reportportal</groupId>
<artifactId>logger-java-httpcomponents</artifactId>
<version>5.0.0</version>
<scope>test</scope>
</dependency>
</dependencies>

<!-- build config omitted -->
</project>
```

#### Gradle

`build.gradle`

```groovy
dependencies {
testImplementation 'com.epam.reportportal:logger-java-httpcomponents:5.0.0'
}
```

### HTTP Client configuration

To start getting Request and Response logging in Report Portal you need to add the logger as one of your HTTP Client
interceptors. The best place for it is one before hook methods. E.G. `@BeforeClass` method for TestNG or `@BeforeAll`
method for JUnit 5:

```java
public class BaseTest {
private final ReportPortalHttpLoggingInterceptor logger = new ReportPortalHttpLoggingInterceptor(LogLevel.INFO);

private HttpClient client;

@BeforeClass
public void setupHttpClient() {
client = HttpClientBuilder.create()
.addInterceptorLast((HttpRequestInterceptor) logger)
.addInterceptorLast((HttpResponseInterceptor) logger)
.build();
}
}
```

### Sanitize Request / Response data

To avoid logging sensitive data into Report Portal you can use corresponding converters:

* Cookie converter
* Header converter
* URI converter
* Content prettiers

Cookie, Header and URI converters are set in the logger constructor:

```java
public class BaseTest {
private final ReportPortalHttpLoggingInterceptor logger = new ReportPortalHttpLoggingInterceptor(LogLevel.INFO,
SanitizingHttpHeaderConverter.INSTANCE,
DefaultHttpHeaderConverter.INSTANCE
);

private HttpClient client;

@BeforeClass
public void setupHttpClient() {
client = HttpClientBuilder.create()
.addInterceptorLast((HttpRequestInterceptor) logger)
.addInterceptorLast((HttpResponseInterceptor) logger)
.build();
}
}
```

You are free to implement any converter by yourself with `java.util.function.Function` interface.

Content prettier are more complex, they parse data based on its content type and apply defined transformations. Default
prettiers just pretty-print JSON, HTML and XML data. To apply a custom content prettier call
`ReportPortalHttpLoggingInterceptor.setContentPrettiers`.
E.G.:

```java
public class BaseTest {
private static final Map<String, Function<String, String>> MY_PRETTIERS = new HashMap<String, Function<String, String>>() {{
put(ContentType.APPLICATION_XML.getMimeType(), XmlPrettier.INSTANCE);
put(ContentType.APPLICATION_SOAP_XML.getMimeType(), XmlPrettier.INSTANCE);
put(ContentType.APPLICATION_ATOM_XML.getMimeType(), XmlPrettier.INSTANCE);
put(ContentType.APPLICATION_SVG_XML.getMimeType(), XmlPrettier.INSTANCE);
put(ContentType.APPLICATION_XHTML_XML.getMimeType(), XmlPrettier.INSTANCE);
put(ContentType.TEXT_XML.getMimeType(), XmlPrettier.INSTANCE);
put(ContentType.APPLICATION_JSON.getMimeType(), JsonPrettier.INSTANCE);
put("text/json", JsonPrettier.INSTANCE);
put(ContentType.TEXT_HTML.getMimeType(), HtmlPrettier.INSTANCE);
}};

private final ReportPortalHttpLoggingInterceptor logger = new ReportPortalHttpLoggingInterceptor(LogLevel.INFO).setContentPrettiers(
MY_PRETTIERS);

private HttpClient client;

@BeforeClass
public void setupHttpClient() {
client = HttpClientBuilder.create()
.addInterceptorLast((HttpRequestInterceptor) logger)
.addInterceptorLast((HttpResponseInterceptor) logger)
.build();
}
}
```
Loading

0 comments on commit e6dd833

Please sign in to comment.