#express #bitbucket
Вопрос:
Я ищу, как получить частные репозитории из bitbucket в приложении express js. Я использую библиотеку passport-bitbucket-oauth2 для извлечения репозиториев bitbucket.
пусть BitbucketStrategy = требуется(‘паспорт-bitbucket-oauth2’).СТРАТЕГИИ;
//фрагмент кода
app.post('/auth/bitbucket', passport.authenticate('bitbucket', { failWithError: true }));
passport.use(new BitbucketStrategy({
clientID: "",
clientSecret: "",
callbackURL: "http://localhost:3000/auth/bitbucket/callback"
},
function (token, tokenSecret, profile, done) {
return done(null, profile);
}
));
app.get('/auth/bitbucket/callback',
passport.authenticate('bitbucket', { failureRedirect: '/' }),
function (req, res) {
// Successful authentication, redirect to select repo page.
res.redirect('/fetch-repo-bitbucket');
});
app.get('/fetch-repo-bitbucket', function (req, res) {
var options = {
host: "api.bitbucket.org",
path: "/2.0/repositories/" req.user.username,
method: 'GET',
headers: { 'User-Agent': 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0)' }
}
var request = https.request(options, function (response) {
var body = '';
response.on('data', function (chunk) {
body = chunk;
});
response.on('end', function () {
var json = JSON.parse(body);
var repos = [];
Object.keys(json.values).forEach(function (repo) {
console.log(json.values[repo].name);
repos.push(json.values[repo].name);
});
res.render('repo_dropdown', { repositories: repos });
});
});
request.on('error', function (e) {
console.error('and the error is ' e);
});
request.end();
});
Комментарии:
1. Пожалуйста, проясните вашу конкретную проблему или предоставьте дополнительные сведения, чтобы точно указать, что вам нужно. Поскольку это написано в настоящее время, трудно точно сказать, о чем вы просите.