Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 6c94a28b authored by Guillaume Jacquart's avatar Guillaume Jacquart
Browse files

Upload to repository from ci

parent 8328dbbd
Loading
Loading
Loading
Loading
Loading
+48 −5
Original line number Diff line number Diff line
const outputFile = "list/e_trackers.json"


const ciJobToken = process.env.CI_JOB_TOKEN
const ciApiV4Url = process.env.CI_API_V4_URL
const giltabProjectId = "1183"

const adawayUri = "https://adaway.org/hosts.txt"
const exodusUri = "https://reports.exodus-privacy.eu.org/api/trackers"


const https = require('https')
const fs = require('fs')
const url = require('url')
//const process = require('process')

function fetch(url) {
@@ -60,7 +66,11 @@ fetch(adawayUri)
    console.log("DONE")  
})
.then(toto => {
    printTrackers()
    return printTrackers()
})
.then(trackersJson => {
    //saveTrackersFile(trackersJson)
    uploadTrackers(trackersJson)
})
.catch(err => {
    console.log(err)
@@ -147,8 +157,41 @@ function toLevel2Domain(hostname) {
}

function printTrackers() {    
    fs.writeFileSync(outputFile, JSON.stringify({
    return JSON.stringify({
        trackers: trackers,
        createdAt: new Date().toISOString()
    }))
    })
}

function saveTrackersFile(trackersJson) {
    fs.writeFileSync(outputFile, trackersJson)
}

function uploadTrackers(trackersJson) { return new Promise((resolve, reject) => {
    const body = JSON.stringify({
        content: trackersJson,
        branch: 'main',
        commit_message: `Update trackers list ; ${trackers.length} trackers`
    })

    const urlComponents = url.parse(`${ciApiV4Url}/projects/${encodeURIComponent(giltabProjectId)}/repository/files/${encodeURIComponent(outputFile)}`)

    const options = {
        method: 'PUT',
        port: 443,
        hostname: urlComponents.hostname,
        path: urlComponents.path,
        headers: {
            'PRIVATE-TOKEN': ciJobToken,
            'Content-Type': 'application/json',
            'Content-Length': body.length,
        }
    }

    const req = https.request(options, res => {})
    req.on('error', reject)

    req.write(body)
    req.end()
    resolve()
})}
+1 −1

File changed.

Preview size limit exceeded, changes collapsed.