Skip to content

Commit

Permalink
Merge pull request #18 from andrii-bodnar/feat/add-output
Browse files Browse the repository at this point in the history
Add the 'contributors_table' output, improve table layout
  • Loading branch information
andrii-bodnar authored Nov 28, 2022
2 parents 4e487a1 + 21602d5 commit 6e8e0a0
Show file tree
Hide file tree
Showing 10 changed files with 75 additions and 30 deletions.
30 changes: 30 additions & 0 deletions .github/workflows/e2e-PR-Test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: 'e2e-pr-test'

on:
workflow_dispatch:

jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: ./
with:
max_contributors: 10
min_words_contributed: 1
placeholder_start: '<!-- TEST-CONTRIBUTORS-START -->'
placeholder_end: '<!-- TEST-CONTRIBUTORS-END -->'
files: ./__tests__/files/contributors.md
env:
CROWDIN_PROJECT_ID: ${{ secrets.CROWDIN_PROJECT_ID }}
CROWDIN_PERSONAL_TOKEN: ${{ secrets.CROWDIN_PERSONAL_TOKEN }}
CROWDIN_ORGANIZATION: ${{ secrets.CROWDIN_ORGANIZATION }}

- name: Create Pull Request
uses: peter-evans/create-pull-request@v4
with:
title: Update Crowdin Contributors table
body: By [action-crowdin-contributors](https://github.com/andrii-bodnar/action-crowdin-contributors) GitHub action
commit-message: Update Crowdin Contributors table
committer: Crowdin Bot <[email protected]>
branch: crowdin-contributors/patch
10 changes: 0 additions & 10 deletions .github/workflows/e2eTest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,3 @@ jobs:
- name: Test the Readme
run: |
cat ./__tests__/files/contributors.md
git diff
- name: Create Pull Request
uses: peter-evans/create-pull-request@v4
with:
title: Update Crowdin Contributors table
body: By [action-crowdin-contributors](https://github.com/andrii-bodnar/action-crowdin-contributors) GitHub action
commit-message: Update Crowdin Contributors table
committer: Crowdin Bot <[email protected]>
branch: crowdin-contributors/patch
12 changes: 10 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ jobs:
uses: actions/checkout@v3

- name: Generate Crowdin Contributors table
uses: andrii-bodnar/action-crowdin-contributors@0.0.1
uses: andrii-bodnar/action-crowdin-contributors@0.1.0
with:
contributors_per_line: 8
max_contributors: 32
Expand Down Expand Up @@ -79,7 +79,7 @@ jobs:
uses: actions/checkout@v3

- name: Generate Crowdin Contributors table
uses: andrii-bodnar/action-crowdin-contributors@0.0.1
uses: andrii-bodnar/action-crowdin-contributors@0.1.0
with:
contributors_per_line: 8
max_contributors: 32
Expand Down Expand Up @@ -112,6 +112,14 @@ jobs:
| `placeholder_start` | `<!-- CROWDIN-CONTRIBUTORS-START -->` | Placeholder that marks the start of the contributors table |
| `placeholder_end` | `<!-- CROWDIN-CONTRIBUTORS-END -->` | Placeholder that marks the end of the contributors table |

## Outputs

This actions provides the following outputs that can be used by other steps in your workflow:

| Output | Description |
|----------------------|-----------------------------------|
| `contributors_table` | Generated table with contributors |

## Demo

The resulting table will look like this:
Expand Down
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ inputs:
default: '<!-- CROWDIN-CONTRIBUTORS-END -->'
required: false

outputs:
contributors_table:
description: 'Generated table with contributors'

runs:
using: 'node16'
main: 'dist/index.js'
19 changes: 12 additions & 7 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "action-crowdin-contributors",
"version": "0.0.1",
"version": "0.1.0",
"private": true,
"description": "Automate acknowledging translators and proofreaders to your open-source projects in Crowdin",
"main": "lib/main.js",
Expand Down
2 changes: 2 additions & 0 deletions src/contributors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ export class Contributors {
const preparedData = await this.prepareData(reportResults);

this.writer.updateContributorsTable(preparedData);

core.setOutput('contributors_table', this.writer.getTableContent());
}

private async downloadReport(): Promise<any[]> {
Expand Down
20 changes: 13 additions & 7 deletions src/writer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,25 @@ import {ContributorsTableConfig, CredentialsConfig} from './config';
export class Writer {
private credentials: CredentialsConfig;
private config: ContributorsTableConfig;
private tableContent = '';

constructor(credentials: CredentialsConfig, config: ContributorsTableConfig) {
this.credentials = credentials;
this.config = config;
}

public getTableContent(): string {
return this.tableContent;
}

public updateContributorsTable(report: any[]): void {
core.info(`Rendering table with ${report.length} contributor(s)...`);

const tableContent = this.renderReport(report);
this.writeFiles(tableContent);

this.tableContent = tableContent;

core.info('The contributors table successfully updated!');
}

Expand All @@ -33,17 +40,16 @@ export class Writer {
html += '<tr>';

for (let j in result[i]) {
let tda = `<img alt="logo" style="width: ${this.config.imageSize}px" src="${result[i][j].picture}"/>`;
let userData = `<img alt="logo" style="width: ${this.config.imageSize}px" src="${result[i][j].picture}"/>
<br />
<sub><b>${result[i][j].name}</b></sub>`;

if (!this.credentials.organization) {
tda = `<a href="https://crowdin.com/profile/${result[i][j].username}">${tda}</a>`;
userData = `<a href="https://crowdin.com/profile/${result[i][j].username}">${userData}</a>`;
}

// TODO: style for name width
html += `<td style="text-align:center; vertical-align: top;">
${tda}
<br />
<sub><b>${result[i][j].name}</b></sub>
html += `<td align="center" valign="top">
${userData}
<br />
<sub><b>${+result[i][j].translated + +result[i][j].approved} words</b></sub>
</td>`;
Expand Down

0 comments on commit 6e8e0a0

Please sign in to comment.