diff --git a/README.md b/README.md index 5f8b56b..86c4ca8 100644 --- a/README.md +++ b/README.md @@ -11,42 +11,44 @@ on: release: types: [published] +env: + REPOSITORY_NAME: ${{ github.event.repository.name }} + jobs: certificate: runs-on: ubuntu-latest name: certificate OSHWA project steps: - - uses: actions/checkout@v3 - - uses: nerdyscout/oshwa-action@main - with: - token: ${{ secrets.OSHWA_TOKEN }} - responsiblePartyType: "Individual" - responsibleParty: $GITHUB_REPOSITORY_OWNER - bindingParty: "" - country: "" - projectName: ${GITHUB_REPOSITORY#*/} - projectWebsite: "https://" $GITHUB_REPOSITORY_OWNER "github.io/" ${GITHUB_REPOSITORY#*/} - projectVersion: $GITHUB_REF_NAME - # previousVersions: ["US000000","US000001"] - projectDescription: "" - primaryType: "Electronics" - documentationUrl: "https://github.com/" $GITHUB_REPOSITORY "/docs" - hardwareLicense: "CERN" - softwareLicense: "GPL" - documentationLicense: "CC BY" - noCommercialRestriction: true - noDocumentationRestriction: true - openHardwareComponents: true - creatorContribution: true - noUseRestriction: true - redistributedWork: true - noSpecificProduct: true - noComponentRestriction: true - technologyNeutral: true - CertificationMarkTerms: {'accurateContactInformation':{},'complianceWithOfficialCertificationGuidelines': {},'oshwaCertificationMark': {},'violationsEnforcement': {},'responsibility': {'term': 'I have the ability to bind those responsible for the certified item to this agreement.','agreement': true}} - relationship: "self" - agreementTerms: true - parentName: $GITHUB_REPOSITORY_OWNER + - uses: nerdyscout/oshwa-action@main + with: + token: ${{ secrets.OSHWA_TOKEN }} + responsiblePartyType: "Individual" + responsibleParty: ${{ github.repository_owner }} + bindingParty: "" + country: "" + projectName: ${{ env.REPOSITORY_NAME }} + projectWebsite: "https://${{ github.repository_owner }}.github.io/${{ env.REPOSITORY_NAME }}" + projectVersion: ${{ github.ref_name }} + # previousVersions: ["US000000","US000001"] + projectDescription: "" + primaryType: "Electronics" + documentationUrl: "https://github.com/${{ github.repository }}/docs" + hardwareLicense: "CERN" + softwareLicense: "GPL" + documentationLicense: "CC BY" + noCommercialRestriction: true + noDocumentationRestriction: true + openHardwareComponents: true + creatorContribution: true + noUseRestriction: true + redistributedWork: true + noSpecificProduct: true + noComponentRestriction: true + technologyNeutral: true + CertificationMarkTerms: {'accurateContactInformation':{},'complianceWithOfficialCertificationGuidelines': {},'oshwaCertificationMark': {},'violationsEnforcement': {},'responsibility': {'term': 'I have the ability to bind those responsible for the certified item to this agreement.','agreement': true}} + relationship: "self" + agreementTerms: true + parentName: ${{ github.repository_owner }} ``` ## Inputs diff --git a/dist/index.js b/dist/index.js index 9f8c56d..d42595e 100644 --- a/dist/index.js +++ b/dist/index.js @@ -6849,21 +6849,21 @@ module.exports = webrequest; const webrequest = __nccwpck_require__(88) -function post_project(url, token, payload) { +async function post_project(url, token, payload) { const auth = { 'Authorization': 'Bearer ' + token }; - return response = webrequest(url + 'projects/', 'post', payload, auth); + return await webrequest(url + 'projects/', 'post', payload, auth); } module.exports.post_project = post_project; -function get_project(url, token, id) { +async function get_project(url, token, id) { const auth = { 'Authorization': 'Bearer ' + token }; - return response = webrequest(url + 'projects/' + id, 'get', '', auth); + return await webrequest(url + 'projects/' + id, 'get', '', auth); } module.exports.get_project = get_project; -function get_options(url, token) { +async function get_options(url, token) { const auth = { 'Authorization': 'Bearer ' + token }; - return response = webrequest(url + 'options/', 'get', '', auth); + return await webrequest(url + 'options/', 'get', '', auth); } module.exports.get_options = get_options; @@ -7043,78 +7043,77 @@ const core = __nccwpck_require__(2810); const oshwa = __nccwpck_require__(5741); async function main() { - try { - // consts - const token = core.getInput('token'); - const url = core.getInput('url') - // inputs from action - var payload = { - "responsiblePartyType": core.getInput('responsiblePartyType'), - "responsibleParty": core.getInput('responsibleParty'), - "bindingParty": core.getInput('bindingParty'), - "country": core.getInput('country'), - "streetAddress1": core.getInput('streetAddress1'), - "streetAddress2": core.getInput('streetAddress2'), - "city": core.getInput('city'), - "state": core.getInput('state'), - "postalCode": core.getInput('postalCode'), - "privateContact": core.getInput('privateContact'), - "publicContact": core.getInput('publicContact'), - "projectName": core.getInput('projectName'), - "projectWebsite": core.getInput('projectWebsite'), - "projectVersion": core.getInput('projectVersion'), - "previousVersions": core.getInput('previousVersions'), - "projectDescription": core.getInput('projectDescription'), - "primaryType": core.getInput('primaryType'), - "additionalType": core.getInput('additionalType'), - "projectKeywords": core.getInput('projectKeywords'), - "citations": core.getInput('citation'), - "documentationUrl": core.getInput('documentationUrl'), - "availableFileFormat": core.getInput('availableFileFormat'), - "hardwareLicense": core.getInput('hardwareLicense'), - "softwareLicense": core.getInput('softwareLicense'), - "documentationLicense": core.getInput('documentationLicense'), - "noCommercialRestriction": core.getInput('noCommercialRestriction'), - "explanationNcr": core.getInput('explanationNcr'), - "noDocumentationRestriction": core.getInput('noDocumentationRestriction'), - "explanationNdr": core.getInput('explanationNdr'), - "openHardwareComponents": core.getInput('openHardwareComponents'), - "explanationOhwc": core.getInput('explanationOhwc'), - "creatorContribution": core.getInput('creatorContribution'), - "explanationCcr": core.getInput('explanationCcr'), - "noUseRestriction": core.getInput('noUseRestriction'), - "explanationNur": core.getInput('explanationNur'), - "redistributedWork": core.getInput('redistributedWork'), - "explanationRwr": core.getInput('explanationRwr'), - "noSpecificProduct": core.getInput('noSpecificProduct'), - "explanationNsp": core.getInput('explanationNsp'), - "noComponentRestriction": core.getInput('noComponentRestriction'), - "explanationNor": core.getInput('explanationNor'), - "technologyNeutral": core.getInput('technologyNeutral'), - "explanationTn": core.getInput('explanationTn'), - "certificationMarkTerms": { - "accurateContactInformation": { - "term": "I have provided OSHWA with accurate contact information, recognize that all official communications from OSHWA will be directed to that contact information, and will update that contact information as necessary.", - "agreement": true - } - }, - "explanationCertificationTerms": core.getInput('explanationCertificationTerms'), - "relationship": core.getInput('relationship'), - "agreementTerms": core.getInput('agreementTerms'), - "parentName": core.getInput('parentName') - }; - - // http request to external API - const response = await oshwa.post_project(url, token, JSON.stringify(payload, undefined, 2)); + // consts + const token = core.getInput('token'); + const url = core.getInput('url'); + // inputs from action + const payload = { + responsiblePartyType: core.getInput('responsiblePartyType'), + responsibleParty: core.getInput('responsibleParty'), + bindingParty: core.getInput('bindingParty'), + country: core.getInput('country'), + streetAddress1: core.getInput('streetAddress1'), + streetAddress2: core.getInput('streetAddress2'), + city: core.getInput('city'), + state: core.getInput('state'), + postalCode: core.getInput('postalCode'), + privateContact: core.getInput('privateContact'), + publicContact: core.getInput('publicContact'), + projectName: core.getInput('projectName'), + projectWebsite: core.getInput('projectWebsite'), + projectVersion: core.getInput('projectVersion'), + previousVersions: core.getInput('previousVersions'), + projectDescription: core.getInput('projectDescription'), + primaryType: core.getInput('primaryType'), + additionalType: core.getInput('additionalType'), + projectKeywords: core.getInput('projectKeywords'), + citations: core.getInput('citation'), + documentationUrl: core.getInput('documentationUrl'), + availableFileFormat: core.getInput('availableFileFormat'), + hardwareLicense: core.getInput('hardwareLicense'), + softwareLicense: core.getInput('softwareLicense'), + documentationLicense: core.getInput('documentationLicense'), + noCommercialRestriction: core.getInput('noCommercialRestriction'), + explanationNcr: core.getInput('explanationNcr'), + noDocumentationRestriction: core.getInput('noDocumentationRestriction'), + explanationNdr: core.getInput('explanationNdr'), + openHardwareComponents: core.getInput('openHardwareComponents'), + explanationOhwc: core.getInput('explanationOhwc'), + creatorContribution: core.getInput('creatorContribution'), + explanationCcr: core.getInput('explanationCcr'), + noUseRestriction: core.getInput('noUseRestriction'), + explanationNur: core.getInput('explanationNur'), + redistributedWork: core.getInput('redistributedWork'), + explanationRwr: core.getInput('explanationRwr'), + noSpecificProduct: core.getInput('noSpecificProduct'), + explanationNsp: core.getInput('explanationNsp'), + noComponentRestriction: core.getInput('noComponentRestriction'), + explanationNor: core.getInput('explanationNor'), + technologyNeutral: core.getInput('technologyNeutral'), + explanationTn: core.getInput('explanationTn'), + certificationMarkTerms: { + accurateContactInformation: { + term: "I have provided OSHWA with accurate contact information, recognize that all official communications from OSHWA will be directed to that contact information, and will update that contact information as necessary.", + agreement: true + } + }, + explanationCertificationTerms: core.getInput('explanationCertificationTerms'), + relationship: core.getInput('relationship'), + agreementTerms: core.getInput('agreementTerms'), + parentName: core.getInput('parentName') + }; + try { + const response = await oshwa.post_project(url, token, JSON.stringify(payload)); console.log(response); if (response.status >= 400) { - core.setFailed(`HTTP request failed with status code: ${response.res.statusCode}`); + core.setFailed(`HTTP request failed with status code: ${response.status}`); } else { core.setOutput('response', response.res); } } catch (error) { + console.log(error); core.setFailed(error.message); } } diff --git a/index.js b/index.js index 2e49df9..73665e4 100644 --- a/index.js +++ b/index.js @@ -2,78 +2,93 @@ const core = require('@actions/core'); const oshwa = require('./oshwa'); async function main() { - try { - // consts - const token = core.getInput('token'); - const url = core.getInput('url') - // inputs from action - var payload = { - "responsiblePartyType": core.getInput('responsiblePartyType'), - "responsibleParty": core.getInput('responsibleParty'), - "bindingParty": core.getInput('bindingParty'), - "country": core.getInput('country'), - "streetAddress1": core.getInput('streetAddress1'), - "streetAddress2": core.getInput('streetAddress2'), - "city": core.getInput('city'), - "state": core.getInput('state'), - "postalCode": core.getInput('postalCode'), - "privateContact": core.getInput('privateContact'), - "publicContact": core.getInput('publicContact'), - "projectName": core.getInput('projectName'), - "projectWebsite": core.getInput('projectWebsite'), - "projectVersion": core.getInput('projectVersion'), - "previousVersions": core.getInput('previousVersions'), - "projectDescription": core.getInput('projectDescription'), - "primaryType": core.getInput('primaryType'), - "additionalType": core.getInput('additionalType'), - "projectKeywords": core.getInput('projectKeywords'), - "citations": core.getInput('citation'), - "documentationUrl": core.getInput('documentationUrl'), - "availableFileFormat": core.getInput('availableFileFormat'), - "hardwareLicense": core.getInput('hardwareLicense'), - "softwareLicense": core.getInput('softwareLicense'), - "documentationLicense": core.getInput('documentationLicense'), - "noCommercialRestriction": core.getInput('noCommercialRestriction'), - "explanationNcr": core.getInput('explanationNcr'), - "noDocumentationRestriction": core.getInput('noDocumentationRestriction'), - "explanationNdr": core.getInput('explanationNdr'), - "openHardwareComponents": core.getInput('openHardwareComponents'), - "explanationOhwc": core.getInput('explanationOhwc'), - "creatorContribution": core.getInput('creatorContribution'), - "explanationCcr": core.getInput('explanationCcr'), - "noUseRestriction": core.getInput('noUseRestriction'), - "explanationNur": core.getInput('explanationNur'), - "redistributedWork": core.getInput('redistributedWork'), - "explanationRwr": core.getInput('explanationRwr'), - "noSpecificProduct": core.getInput('noSpecificProduct'), - "explanationNsp": core.getInput('explanationNsp'), - "noComponentRestriction": core.getInput('noComponentRestriction'), - "explanationNor": core.getInput('explanationNor'), - "technologyNeutral": core.getInput('technologyNeutral'), - "explanationTn": core.getInput('explanationTn'), - "certificationMarkTerms": { - "accurateContactInformation": { - "term": "I have provided OSHWA with accurate contact information, recognize that all official communications from OSHWA will be directed to that contact information, and will update that contact information as necessary.", - "agreement": true - } + // consts + const token = core.getInput('token'); + const url = core.getInput('url'); + // inputs from action + const payload = { + responsiblePartyType: core.getInput('responsiblePartyType'), + responsibleParty: core.getInput('responsibleParty'), + bindingParty: core.getInput('bindingParty'), + country: core.getInput('country'), + streetAddress1: core.getInput('streetAddress1'), + streetAddress2: core.getInput('streetAddress2'), + city: core.getInput('city'), + state: core.getInput('state'), + postalCode: core.getInput('postalCode'), + privateContact: core.getInput('privateContact'), + publicContact: core.getInput('publicContact'), + projectName: core.getInput('projectName'), + projectWebsite: core.getInput('projectWebsite'), + projectVersion: core.getInput('projectVersion'), + previousVersions: core.getInput('previousVersions'), + projectDescription: core.getInput('projectDescription'), + primaryType: core.getInput('primaryType'), + additionalType: core.getInput('additionalType'), + projectKeywords: core.getInput('projectKeywords'), + citations: core.getInput('citation'), + documentationUrl: core.getInput('documentationUrl'), + availableFileFormat: core.getInput('availableFileFormat'), + hardwareLicense: core.getInput('hardwareLicense'), + softwareLicense: core.getInput('softwareLicense'), + documentationLicense: core.getInput('documentationLicense'), + noCommercialRestriction: core.getInput('noCommercialRestriction'), + explanationNcr: core.getInput('explanationNcr'), + noDocumentationRestriction: core.getInput('noDocumentationRestriction'), + explanationNdr: core.getInput('explanationNdr'), + openHardwareComponents: core.getInput('openHardwareComponents'), + explanationOhwc: core.getInput('explanationOhwc'), + creatorContribution: core.getInput('creatorContribution'), + explanationCcr: core.getInput('explanationCcr'), + noUseRestriction: core.getInput('noUseRestriction'), + explanationNur: core.getInput('explanationNur'), + redistributedWork: core.getInput('redistributedWork'), + explanationRwr: core.getInput('explanationRwr'), + noSpecificProduct: core.getInput('noSpecificProduct'), + explanationNsp: core.getInput('explanationNsp'), + noComponentRestriction: core.getInput('noComponentRestriction'), + explanationNor: core.getInput('explanationNor'), + technologyNeutral: core.getInput('technologyNeutral'), + explanationTn: core.getInput('explanationTn'), + certificationMarkTerms: { + accurateContactInformation: { + term: "I have provided OSHWA with accurate contact information, recognize that all official communications from OSHWA will be directed to that contact information, and will update that contact information as necessary.", + agreement: true }, - "explanationCertificationTerms": core.getInput('explanationCertificationTerms'), - "relationship": core.getInput('relationship'), - "agreementTerms": core.getInput('agreementTerms'), - "parentName": core.getInput('parentName') - }; - - // http request to external API - const response = await oshwa.post_project(url, token, JSON.stringify(payload, undefined, 2)); + complianceWithOfficialCertificationGuidelines: { + term: "I will only use the certification mark in compliance with official certification guidelines.", + agreement: true + }, + oshwaCertificationMark: { + term: "I acknowledge that all right, title, and interest in the certification mark remains with OSHWA.", + agreement: true + }, + violationsEnforcement: { + term: "I acknowledge that OSHWA has the right to enforce violations of the use of the mark. This enforcement may involve financial penalties for misuse in bad faith.", + agreement: true + }, + responsibility: { + term: "I have the ability to bind those responsible for the certified item to this agreement.", + agreement: true + } + }, + explanationCertificationTerms: core.getInput('explanationCertificationTerms'), + relationship: core.getInput('relationship'), + agreementTerms: core.getInput('agreementTerms'), + parentName: core.getInput('parentName') + }; + try { + const response = await oshwa.post_project(url, token, JSON.stringify(payload)); console.log(response); if (response.status >= 400) { - core.setFailed(`HTTP request failed with status code: ${response.res.statusCode}`); + core.setFailed(`HTTP request failed with status code: ${response.status}`); } else { core.setOutput('response', response.res); } } catch (error) { + console.log(error); core.setFailed(error.message); } } diff --git a/oshwa.js b/oshwa.js index e3c5c66..2c1ca2b 100644 --- a/oshwa.js +++ b/oshwa.js @@ -1,19 +1,19 @@ const webrequest = require('webrequest-action/webrequest') -function post_project(url, token, payload) { - const auth = { 'Authorization': 'Bearer ' + token }; - return response = webrequest(url + 'projects/', 'post', payload, auth); +async function post_project(url, token, payload) { + const headers = { 'Authorization': 'Bearer ' + token, 'Content-Type': 'application/json' }; + return await webrequest(url + 'projects/', 'post', payload, headers); } module.exports.post_project = post_project; -function get_project(url, token, id) { - const auth = { 'Authorization': 'Bearer ' + token }; - return response = webrequest(url + 'projects/' + id, 'get', '', auth); +async function get_project(url, token, id) { + const headers = { 'Authorization': 'Bearer ' + token }; + return await webrequest(url + 'projects/' + id, 'get', '', headers); } module.exports.get_project = get_project; -function get_options(url, token) { - const auth = { 'Authorization': 'Bearer ' + token }; - return response = webrequest(url + 'options/', 'get', '', auth); +async function get_options(url, token) { + const headers = { 'Authorization': 'Bearer ' + token }; + return await webrequest(url + 'options/', 'get', '', headers); } module.exports.get_options = get_options; diff --git a/test.js b/test.js index df722a5..f252561 100644 --- a/test.js +++ b/test.js @@ -2,12 +2,11 @@ const oshwa = require('./oshwa'); const url = 'https://my-json-server.typicode.com/nerdyscout/oshwa-action/'; const payload = { "responseponsiblePartyType": "Individual", "responseponsibleParty": "Company Name", "bindingParty": "Jane Doe", "country": "United States of America", "streetAddresponses1": "255 Pouros Circle", "streetAddresponses2": "Suite 123", "city": "Raleigh", "state": "NC", "postalCode": "27616", "privateContact": "jane@example.com", "publicContact": "jane.doe@example.com", "projectName": "My Open Source Project", "projectWebsite": "https://www.example.com", "projectVersion": "1.0", "previousVersions": ["US000236"], "projectDescription": "Lorem ipsum dolor sit amet.", "primaryType": "Electronics", "additionalType": ["3D Printing"], "projectKeywords": ["3D Printing", "electronics"], "citations": [{ "title": "First Citation", "url": "https://www.example.com" }], "documentationUrl": "https://www.example.com", "availableFileFormat": false, "hardwareLicense": "CERN", "softwareLicense": "Apache", "documentationLicense": "CC 0", "noCommercialresponsetriction": false, "explanationNcr": "Lorem ipsum dolor sit amet.", "noDocumentationresponsetriction": false, "explanationNdr": "Lorem ipsum dolor sit amet.", "openHardwareComponents": "false", "explanationOhwc": "Lorem ipsum dolor sit amet.", "creatorContribution": false, "explanationCcr": "Lorem ipsum dolor sit amet.", "noUseresponsetriction": false, "explanationNur": "Lorem ipsum dolor sit amet.", "redistributedWork": false, "explanationRwr": "Lorem ipsum dolor sit amet.", "noSpecificProduct": "false", "explanationNsp": "Lorem ipsum dolor sit amet.", "noComponentresponsetriction": false, "explanationNor": "Lorem ipsum dolor sit amet.", "technologyNeutral": false, "explanationTn": "Lorem ipsum dolor sit amet.", "certificationMarkTerms": { "accurateContactInformation": { "term": "I have provided OSHWA with accurate contact information, recognize that all official communications from OSHWA will be directed to that contact information, and will update that contact information as necessary.", "agreement": true } }, "explanationCertificationTerms": "Lorem ipsum dolor sit amet.", "relationship": "self", "agreementTerms": true, "parentName": "J Doe" }; -const token = ""; test('oshwa get project', async () => { expect.assertions(2); - const response = await oshwa.get_project(url, token, "US000001"); + const response = await oshwa.get_project(url, "", "US000001"); console.log(response); expect(response.status).toBe(200); @@ -16,8 +15,8 @@ test('oshwa get project', async () => { test('oshwa post project', async () => { expect.assertions(2); - const response = await oshwa.post_project(url, token, payload); + const response = await oshwa.post_project(url, "", payload); console.log(response); expect(response.status).toBe(201);