Skip to content

Commit

Permalink
Merge pull request watson-developer-cloud#59 from watson-developer-cl…
Browse files Browse the repository at this point in the history
…oud/add-tests

feat: Add semantic releases and IAM support
  • Loading branch information
germanattanasio authored Jul 20, 2018
2 parents e288303 + d9cf692 commit c74bef7
Show file tree
Hide file tree
Showing 11 changed files with 1,856 additions and 2,333 deletions.
4 changes: 4 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# see https://console.bluemix.net/docs/services/watson/getting-started-credentials.html#service-credentials-for-watson-services
LANGUAGE_TRANSLATOR_USERNAME=<username>
LANGUAGE_TRANSLATOR_PASSWORD=<password>

LANGUAGE_TRANSLATOR_IAM_APIKEY=<password>

LANGUAGE_TRANSLATOR_URL=https://gateway.watsonplatform.net/language-translator/api
11 changes: 8 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
language: node_js
sudo: true
node_js: 4
node_js: 8
script:
- npm run lint
- npm run codecov
Expand All @@ -12,10 +12,15 @@ env:
- BX_SPACE=demos
before_deploy: npm install -g bx-blue-green
deploy:
provider: script
- provider: script
script:
- bx-blue-green-travis
on:
branch: master
repo: watson-developer-cloud/language-translator-nodejs
skip_cleanup: true
skip_cleanup: true
- provider: script
skip_cleanup: true
script: npx semantic-release
on:
node: 8
60 changes: 54 additions & 6 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,64 @@
# Questions

If you are having difficulties running the app or have a question about the service, please ask a question on [dW Answers](https://developer.ibm.com/answers/questions/ask/?topics=watson) or [Stack Overflow](http://stackoverflow.com/questions/ask?tags=ibm-watson).
If you are having problems using the APIs or have a question about the IBM
Watson Services, please ask a question on
[dW Answers](https://developer.ibm.com/answers/questions/ask/?topics=watson)
or [Stack Overflow](http://stackoverflow.com/questions/ask?tags=ibm-watson).

# Code

* Our style guide is based on [Google's](https://google.github.io/styleguide/jsguide.html), most of it is automaticaly enforced (and can be automatically applied with `npm run autofix`)
* Commits should follow the [Angular commit message guidelines](https://github.com/angular/angular/blob/master/CONTRIBUTING.md#-commit-message-guidelines). This is because our release tool uses this format for determining release versions and generating changelogs. To make this easier, we recommend using the [Commitizen CLI](https://github.com/commitizen/cz-cli) with the `cz-conventional-changelog` adapter.

# Issues

If you encounter an issue with this sample app, you are welcome to submit a [bug report](https://github.com/watson-developer-cloud/language-translator-nodejs/issues). Before that, please search for similar issues. It's possible somebody has encountered this issue already.
If you encounter an issue with the Node.js library, you are welcome to submit
a [bug report](https://github.com/watson-developer-cloud/language-translator-nodejs/issues).
Before that, please search for similar issues. It's possible somebody has
already encountered this issue.

# Pull Requests

If you want to contribute to the repository, here's a quick guide:
If you want to contribute to the repository, follow these steps:

1. Fork the repo.
1. develop your code changes: `npm install -d`
1. Commit your changes
1. Push to your fork and submit a pull request
2. Develop and test your code changes: `npm install -d && npm test`.
3. Travis-CI will run the tests for all services once your changes are merged.
4. Add a test for your changes. Only refactoring and documentation changes require no new tests.
5. Make the test pass.
6. Commit your changes.
7. Push to your fork and submit a pull request.

# Developer's Certificate of Origin 1.1

By making a contribution to this project, I certify that:

(a) The contribution was created in whole or in part by me and I
have the right to submit it under the open source license
indicated in the file; or

(b) The contribution is based upon previous work that, to the best
of my knowledge, is covered under an appropriate open source
license and I have the right under that license to submit that
work with modifications, whether created in whole or in part
by me, under the same open source license (unless I am
permitted to submit under a different license), as indicated
in the file; or

(c) The contribution was provided directly to me by some other
person who certified (a), (b) or (c) and I have not modified
it.

(d) I understand and agree that this project and the contribution
are public and that a record of the contribution (including all
personal information I submit with it, including my sign-off) is
maintained indefinitely and may be redistributed consistent with
this project or the open source license(s) involved.

## Tests

Ideally, we'd like to see both unit and innervation tests on each method.
(Unit tests do not actually connect to the Watson service, integration tests do.)

Out of the box, `npm test` runs linting and unit tests, but skips the integration tests,
because they require credentials.
141 changes: 72 additions & 69 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
# Language Translator Node.js [![Build Status](https://travis-ci.org/watson-developer-cloud/language-translator-nodejs.svg?branch=master)](https://travis-ci.org/watson-developer-cloud/language-translator-nodejs)
<h1 align="center" style="border-bottom: none;">🚀 Language Translator Sample Application</h1>
<h3 align="center">This Node.js app demonstrates some of the Language Translator service features.
</h3>
<p align="center">
<a href="http://travis-ci.org/watson-developer-cloud/language-translator-nodejs">
<img alt="Travis" src="https://travis-ci.org/watson-developer-cloud/language-translator-nodejs.svg?branch=master">
</a>
<a href="#badge">
<img alt="semantic-release" src="https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg">
</a>
</p>
</p>

The IBM Watson&trade; [Language Translator][service_url] service provides an Application Programming Interface (API) that lets you identify the language of text, and then use a custom business domain to translate the text from one supported language to another.
You can translate either by letting the service identify the source language or by selecting a source language and then by selecting a target language, and a business domain. Domain translation is linguistically targeted these business domains:
Expand All @@ -8,108 +19,100 @@

Give it a try! Click the button below to fork into IBM DevOps Services and deploy your own copy of this application on IBM Cloud.

[![Deploy to IBM Cloud](https://bluemix.net/deploy/button.png)](https://bluemix.net/deploy?repository=https://github.com/watson-developer-cloud/language-translator-nodejs)

## Getting started
## Prerequisites

1. You need an IBM Cloud account. If you don't have one, [sign up][sign_up]. Experimental Watson Services are free to use.
1. Sign up for an [IBM Cloud account](https://console.bluemix.net/registration/).
1. Download the [IBM Cloud CLI](https://console.bluemix.net/docs/cli/index.html#overview).
1. Create an instance of the Language Translator service and get your credentials:
- Go to the [Language Translator](https://console.bluemix.net/catalog/services/language-translator) page in the IBM Cloud Catalog.
- Log in to your IBM Cloud account.
- Click **Create**.
- Click **Show** to view the service credentials.
- Copy the `apikey` value, or copy the `username` and `password` values if your service instance doesn't provide an `apikey`.
- Copy the `url` value.

1. Download and install the [Cloud-foundry CLI][cloud_foundry] tool if you haven't already.
## Configuring the application

1. Edit the `manifest.yml` file and change `<application-name>` to something unique. The name you use determines the URL of your application. For example, `<application-name>.mybluemix.net`.
1. In the application folder, copy the *.env.example* file and create a file called *.env*

```yaml
applications:
- services:
- language-translator-service
name: <application-name>
command: node app.js
path: .
memory: 128M
```
cp .env.example .env
```
1. Connect to IBM Clod with the command line tool.
```sh
cf api https://api.ng.bluemix.net
cf login
```
2. Open the *.env* file and add the service credentials that you obtained in the previous step.
1. Create the Language Translator service in the IBM Cloud.
Example *.env* file that configures the `apikey` and `url` for a Language Translator service instance hosted in the US East region:
```sh
cf create-service language_translator lite language-translator-service
cf create-service-key language-translator-service myKey
cf service-key language-translator-service myKey
```
LANGUAGE_TRANSLATOR_IAM_APIKEY=X4rbi8vwZmKpXfowaS3GAsA7vdy17Qh7km5D6EzKLHL2
LANGUAGE_TRANSLATOR_URL=https://gateway-wdc.watsonplatform.net/language-translator/api
```
1. Create a `.env` file in the root directory by copying the sample `.env.example` file using the following command:

```none
cp .env.example .env
```
You will update the `.env` with the information you retrieved in steps 5.

The `.env` file will look something like the following:
- If your service instance uses `username` and `password` credentials, add the `LANGUAGE_TRANSLATOR_USERNAME` and `LANGUAGE_TRANSLATOR_PASSWORD` variables to the *.env* file.
```none
LANGUAGE_TRANSLATOR_USERNAME=<username>
LANGUAGE_TRANSLATOR_PASSWORD=<password>
LANGUAGE_TRANSLATOR_URL=<url>
```
Example *.env* file that configures the `username`, `password`, and `url` for a Language Translator service instance hosted in the Sydney region:
1. Install the dependencies you application need:
```
LANGUAGE_TRANSLATOR_USERNAME=522be-7b41-ab44-dec3-g1eab2ha73c6
LANGUAGE_TRANSLATOR_PASSWORD=A4Z5BdGENrwu8
LANGUAGE_TRANSLATOR_URL=https://gateway-syd.watsonplatform.net/language-translator/api
```
## Running locally
```none
npm install
```
1. Install the dependencies
1. Start the application locally:
```
npm install
```
```none
npm start
```
1. Run the application
1. Point your browser to [http://localhost:3000](http://localhost:3000).
```
npm start
```
1. **Optional:** Push the application to IBM Cloud:
1. View the application in a browser at `localhost:3000`
```none
cf push
```
## Deploying to IBM Cloud as a Cloud Foundry Application
After completing the steps above, you are ready to test your application. Start a browser and enter the URL of your application.
1. Login to IBM Cloud with the [IBM Cloud CLI](https://console.bluemix.net/docs/cli/index.html#overview)
<your application name>.mybluemix.net
```
ibmcloud login
```
1. Target a Cloud Foundry organization and space.
For more details about developing applications that use Watson Developer Cloud services in the IBM Cloud, see [Getting started with Watson Developer Cloud and IBM Cloud][getting_started].
```
ibmcloud target --cf
```
## Troubleshooting
1. Edit the *manifest.yml* file. Change the **name** field to something unique.
For example, `- name: my-app-name`.
1. Deploy the application
* The main source of troubleshooting and recovery information is the IBM Cloud log. To view the log, run the following command:
```
ibmcloud app push
```
```sh
$ cf logs <application-name> --recent
```
1. View the application online at the app URL.
For example: https://my-app-name.mybluemix.net
* For more details about the service, see the [documentation][docs] for the Language Translator.
## License
This sample code is licensed under Apache 2.0. Full license text is available in [LICENSE](LICENSE).
This sample code is using jQuery which is licensed under MIT.
This sample code is using bootstrap which is licensed under MIT.
This sample code is licensed under Apache 2.0.
Full license text is available in [LICENSE](LICENSE).
## Contributing
See [CONTRIBUTING](CONTRIBUTING.md).
See [CONTRIBUTING](CONTRIBUTING.md).
## Open Source @ IBM
Find more open source projects on the [IBM Github Page](http://ibm.github.io/)
[cloud_foundry]: https://github.com/cloudfoundry/cli
Find more open source projects on the
[IBM Github Page](http://ibm.github.io/).
[service_url]: https://www.ibm.com/watson/services/language-translator/
[getting_started]: https://console.bluemix.net/docs/services/watson/getting-started-credentials.html#service-credentials-for-watson-services
[sign_up]: https://console.bluemix.net/registration/
[docs]: https://console.bluemix.net/docs/services/language-translator/getting-started.html
[docs]: https://console.bluemix.net/docs/services/language-translator/index.html#about
3 changes: 1 addition & 2 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ require('./config/express')(app);

var translator = new LanguageTranslatorV3({
// If unspecified here, the LANGUAGE_TRANSLATOR_USERNAME and LANGUAGE_TRANSLATOR_PASSWORD environment properties will be checked
// LANGUAGE_TRANSLATOR_IAM_APIKEY if apikey is present
// After that, the SDK will fall back to the ibm-cloud-provided VCAP_SERVICES environment property
// username: '<username>',
// password: '<password>'
url: 'https://gateway.watsonplatform.net/language-translator/api',
version: '2018-05-01',
headers: {
'X-Watson-Technology-Preview': '2018-05-01',
Expand All @@ -42,7 +42,6 @@ app.get('/', function(req, res) {
// the header should be hidden. Default is to show header
res.render('index', {
hideHeader: !!(req.query.hide_header == 'true' || req.query.hide_header == '1'),
analytics: !!process.env.BLUEMIX_ANALYTICS,
});
});

Expand Down
Loading

0 comments on commit c74bef7

Please sign in to comment.