Skip to content

Commit

Permalink
Merge branch 'master' into rubicon-bidder-tid
Browse files Browse the repository at this point in the history
  • Loading branch information
AntoxaAntoxic committed Jan 30, 2025
2 parents 536f5d1 + 7045683 commit c68e47e
Show file tree
Hide file tree
Showing 169 changed files with 11,795 additions and 675 deletions.
34 changes: 34 additions & 0 deletions .github/workflows/code-path-changes.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Notify Code Path Changes

on:
pull_request_target:
types: [opened, synchronize]
paths:
- '**'

env:
OAUTH2_CLIENT_ID: ${{ secrets.OAUTH2_CLIENT_ID }}
OAUTH2_CLIENT_SECRET: ${{ secrets.OAUTH2_CLIENT_SECRET }}
OAUTH2_REFRESH_TOKEN: ${{ secrets.OAUTH2_REFRESH_TOKEN }}
GITHUB_REPOSITORY: ${{ github.repository }}
GITHUB_PR_NUMBER: ${{ github.event.pull_request.number }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

jobs:
notify:
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v3

- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: '18'

- name: Install dependencies
run: npm install axios nodemailer

- name: Run Notification Script
run: |
node .github/workflows/scripts/send-notification-on-change.js
15 changes: 15 additions & 0 deletions .github/workflows/scripts/codepath-notification
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# when a changed file paths matches the regex, send an alert email
# structure of the file is:
#
# javascriptRegex : email address
#
# For example, in PBS Go, there are many paths that can belong to bid adapter:
#
# /adapters/BIDDERCODE
# /openrtb_ext/imp_BIDDERCODE.go
# /static/bidder-params/BIDDERCODE.json
# /static/bidder-info/BIDDERCODE.yaml
#
# The aim is to find a minimal set of regex patterns that matches any file in these paths

rubicon: [email protected]
139 changes: 139 additions & 0 deletions .github/workflows/scripts/send-notification-on-change.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
// send-notification-on-change.js
//
// called by the code-path-changes.yml workflow, this script queries github for
// the changes in the current PR, checks the config file for whether any of those
// file paths are set to alert an email address, and sends email to multiple
// parties if needed

const fs = require('fs');
const path = require('path');
const axios = require('axios');
const nodemailer = require('nodemailer');

async function getAccessToken(clientId, clientSecret, refreshToken) {
try {
const response = await axios.post('https://oauth2.googleapis.com/token', {
client_id: clientId,
client_secret: clientSecret,
refresh_token: refreshToken,
grant_type: 'refresh_token',
});
return response.data.access_token;
} catch (error) {
console.error('Failed to fetch access token:', error.response?.data || error.message);
process.exit(1);
}
}

(async () => {
const configFilePath = path.join(__dirname, 'codepath-notification');
const repo = process.env.GITHUB_REPOSITORY;
const prNumber = process.env.GITHUB_PR_NUMBER;
const token = process.env.GITHUB_TOKEN;

// Generate OAuth2 access token
const clientId = process.env.OAUTH2_CLIENT_ID;
const clientSecret = process.env.OAUTH2_CLIENT_SECRET;
const refreshToken = process.env.OAUTH2_REFRESH_TOKEN;

// validate params
if (!repo || !prNumber || !token || !clientId || !clientSecret || !refreshToken) {
console.error('Missing required environment variables.');
process.exit(1);
}

// the whole process is in a big try/catch. e.g. if the config file doesn't exist, github is down, etc.
try {
// Read and process the configuration file
const configFileContent = fs.readFileSync(configFilePath, 'utf-8');
const configRules = configFileContent
.split('\n')
.filter(line => line.trim() !== '' && !line.trim().startsWith('#')) // Ignore empty lines and comments
.map(line => {
const [regex, email] = line.split(':').map(part => part.trim());
return { regex: new RegExp(regex), email };
});

// Fetch changed files from github
const [owner, repoName] = repo.split('/');
const apiUrl = `https://api.github.com/repos/${owner}/${repoName}/pulls/${prNumber}/files`;
const response = await axios.get(apiUrl, {
headers: {
Authorization: `Bearer ${token}`,
Accept: 'application/vnd.github.v3+json',
},
});

const changedFiles = response.data.map(file => file.filename);
console.log('Changed files:', changedFiles);

// match file pathnames that are in the config and group them by email address
const matchesByEmail = {};
changedFiles.forEach(file => {
configRules.forEach(rule => {
if (rule.regex.test(file)) {
if (!matchesByEmail[rule.email]) {
matchesByEmail[rule.email] = [];
}
matchesByEmail[rule.email].push(file);
}
});
});

// Exit successfully if no matches were found
if (Object.keys(matchesByEmail).length === 0) {
console.log('No matches found. Exiting successfully.');
process.exit(0);
}

console.log('Grouped matches by email:', matchesByEmail);

// get ready to email the changes
const accessToken = await getAccessToken(clientId, clientSecret, refreshToken);

// Configure Nodemailer with OAuth2
// service: 'Gmail',
const transporter = nodemailer.createTransport({
host: "smtp.gmail.com",
port: 465,
secure: true,
auth: {
type: 'OAuth2',
user: '[email protected]',
clientId: clientId,
clientSecret: clientSecret,
refreshToken: refreshToken,
accessToken: accessToken
},
});

// Send one email per recipient
for (const [email, files] of Object.entries(matchesByEmail)) {
const emailBody = `
${email},
<p>
Files owned by you have been changed in open source ${repo}. The <a href="https://github.com/${repo}/pull/${prNumber}">pull request is #${prNumber}</a>. These are the files you own that have been modified:
<ul>
${files.map(file => `<li>${file}</li>`).join('')}
</ul>
`;

try {
await transporter.sendMail({
from: `"Prebid Info" <[email protected]>`,
to: email,
subject: `Files have been changed in open source ${repo}`,
html: emailBody,
});

console.log(`Email sent successfully to ${email}`);
console.log(`${emailBody}`);
} catch (error) {
console.error(`Failed to send email to ${email}:`, error.message);
}
}
} catch (error) {
console.error('Error:', error.message);
process.exit(1);
}
})();
25 changes: 21 additions & 4 deletions adapters/admatic/admatic.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,22 @@ func (a *adapter) MakeRequests(request *openrtb2.BidRequest, requestInfo *adapte
var requests []*adapters.RequestData
var errs []error

headers := http.Header{}
headers.Add("Content-Type", "application/json;charset=utf-8")
headers.Add("Accept", "application/json")
if request.Device != nil {
if len(request.Device.UA) > 0 {
headers.Add("User-Agent", request.Device.UA)
}

if len(request.Device.IPv6) > 0 {
headers.Add("X-Forwarded-For", request.Device.IPv6)
}

if len(request.Device.IP) > 0 {
headers.Add("X-Forwarded-For", request.Device.IP)
}
}
requestCopy := *request
for _, imp := range request.Imp {
requestCopy.Imp = []openrtb2.Imp{imp}
Expand All @@ -52,10 +68,11 @@ func (a *adapter) MakeRequests(request *openrtb2.BidRequest, requestInfo *adapte
}

request := &adapters.RequestData{
Method: http.MethodPost,
Body: requestJSON,
Uri: endpoint,
ImpIDs: openrtb_ext.GetImpIDs(requestCopy.Imp),
Method: http.MethodPost,
Body: requestJSON,
Uri: endpoint,
Headers: headers,
ImpIDs: openrtb_ext.GetImpIDs(requestCopy.Imp),
}

requests = append(requests, request)
Expand Down
26 changes: 26 additions & 0 deletions adapters/admatic/admatictest/exemplary/banner.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
{
"mockBidRequest": {
"id": "test-request-id-banner",
"device": {
"ua": "test-user-agent",
"ip": "123.123.123.123",
"language": "en",
"dnt": 0
},
"imp": [
{
"id": "test-imp-id-banner",
Expand All @@ -24,9 +30,29 @@
"httpCalls": [
{
"expectedRequest": {
"headers": {
"Content-Type": [
"application/json;charset=utf-8"
],
"Accept": [
"application/json"
],
"User-Agent": [
"test-user-agent"
],
"X-Forwarded-For": [
"123.123.123.123"
]
},
"uri": "http://pbs.admatic.com.tr?host=layer.serve.admatic.com.tr",
"body": {
"id": "test-request-id-banner",
"device": {
"ua": "test-user-agent",
"ip": "123.123.123.123",
"language": "en",
"dnt": 0
},
"imp": [
{
"id": "test-imp-id-banner",
Expand Down
122 changes: 122 additions & 0 deletions adapters/admatic/admatictest/exemplary/headers_ipv4.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
{
"mockBidRequest": {
"id": "test-request-id-banner",
"device": {
"ua": "test-user-agent",
"ip": "123.123.123.123",
"language": "en",
"dnt": 0
},
"imp": [
{
"id": "test-imp-id-banner",
"banner": {
"format": [
{
"w": 728,
"h": 90
}
]
},
"ext": {
"bidder": {
"host": "layer.serve.admatic.com.tr",
"networkId": 12345
}
}
}
]
},
"httpCalls": [
{
"expectedRequest": {
"headers": {
"Content-Type": [
"application/json;charset=utf-8"
],
"Accept": [
"application/json"
],
"User-Agent": [
"test-user-agent"
],
"X-Forwarded-For": [
"123.123.123.123"
]
},
"uri": "http://pbs.admatic.com.tr?host=layer.serve.admatic.com.tr",
"body": {
"id": "test-request-id-banner",
"device": {
"ua": "test-user-agent",
"ip": "123.123.123.123",
"language": "en",
"dnt": 0
},
"imp": [
{
"id": "test-imp-id-banner",
"banner": {
"format": [
{
"w": 728,
"h": 90
}
]
},
"ext": {
"bidder": {
"host": "layer.serve.admatic.com.tr",
"networkId": 12345
}
}
}
]
},
"impIDs": ["test-imp-id-banner"]
},
"mockResponse": {
"status": 200,
"body": {
"id": "test-request-id-banner",
"seatbid": [
{
"seat": "admatic",
"bid": [
{
"id": "8ee514f1-b2b8-4abb-89fd-084437d1e800",
"impid": "test-imp-id-banner",
"price": 0.5,
"adm": "some-test-ad-banner",
"crid": "crid_10",
"w": 728,
"h": 90
}
]
}
],
"cur": "USD"
}
}
}
],
"expectedBidResponses": [
{
"currency": "USD",
"bids": [
{
"bid": {
"id": "8ee514f1-b2b8-4abb-89fd-084437d1e800",
"impid": "test-imp-id-banner",
"price": 0.5,
"adm": "some-test-ad-banner",
"crid": "crid_10",
"w": 728,
"h": 90
},
"type": "banner"
}
]
}
]
}
Loading

0 comments on commit c68e47e

Please sign in to comment.